Prometheus Scrape Config Relabel Target Pruning Design Prompt
Design relabel_configs in a scrape job to keep/drop the right targets from service discovery, rewrite the instance/job labels, and prune noisy discovered endpoints before they ever scrape.
- Target user
- Platform engineers and SREs managing Prometheus scrape configs
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior platform engineer who writes `relabel_configs` to select and shape scrape targets from service discovery. I will provide: - The SD mechanism (kubernetes_sd, ec2_sd, consul_sd, file_sd) and a sample of the `__meta_*` labels it exposes - Which targets I want to keep and which to drop (by namespace, tag, port, annotation, etc.) - The desired final label set (job, instance, env, team) and the metrics path/port - Any current config that is scraping too much or labeling inconsistently Your job: 1. **Map the meta labels** — list the relevant `__meta_*` source labels for this SD and what each carries, so selection is based on real fields. 2. **Keep/drop first** — write the ordering: `keep`/`drop` actions early to prune targets before any scrape happens, reducing wasted scrapes and cardinality. 3. **Set address and port** — use `__address__`, `__meta_*_port`, and `__metrics_path__` rewrites so each target hits the correct endpoint. 4. **Shape final labels** — produce clean `job`, `instance`, and topology labels via `replace`/`labelmap`, and drop leftover `__meta_*` noise. 5. **Avoid pitfalls** — flag separator/regex anchoring mistakes, action ordering bugs, and accidental label collisions that merge series. 6. **Distinguish stages** — clarify what belongs in `relabel_configs` (pre-scrape, target selection) vs `metric_relabel_configs` (post-scrape, per-sample). Output as: (a) annotated `relabel_configs` YAML, (b) a before/after target list, (c) a note on which rules drop targets vs rename labels, (d) a `promtool` or `/service-discovery` verification step.
Related prompts
-
Prometheus Relabeling Rules Prompt
Author and debug relabel_configs and metric_relabel_configs to filter targets, rewrite labels, drop expensive series, and normalize metadata before and after scraping.
-
Prometheus Scrape Config & Service Discovery Prompt
Configure Prometheus scrape targets — kubernetes_sd, ec2_sd, file_sd, consul_sd, relabeling, scrape interval tuning.