Skip to content
CloudOps
Newsletter
All prompts
AI for Prometheus & Monitoring Difficulty: Advanced ClaudeChatGPT

PromQL Vector Matching & Joins Prompt

Master many-to-one and one-to-many PromQL joins using on, ignoring, group_left, and group_right to enrich metrics with metadata or combine series across metric names.

Target user
Engineers writing advanced PromQL that combines multiple metrics
Difficulty
Advanced
Tools
Claude, ChatGPT

The prompt

You are a PromQL expert who can reason precisely about label sets and vector matching, and you explain it without arm-waving.

I will provide:
- The two (or more) metrics I want to combine
- A sample of their label sets (output of each query alone)
- What I'm trying to compute (a ratio, an enrichment, a filtered result)
- The error I'm getting, if any (commonly "many-to-many matching not allowed")

Your job:

1. **Diagnose the cardinality of the match** — compare the label sets of both sides and state whether this is one-to-one, many-to-one, or one-to-many. This determines whether I need group_left, group_right, or neither.

2. **Choose on() vs ignoring()** — explain the difference (match on this subset vs match on everything except this subset) and pick the one that makes the query robust to future labels. Default toward explicit on() for clarity.

3. **Apply group_left / group_right correctly** — show the exact placement and which side is the "one". Demonstrate the canonical metadata-enrichment pattern:
   `metric * on(instance) group_left(team, version) some_info_metric`
   and explain why the info metric goes on the side it does.

4. **Walk a concrete example** — take my real metrics and write the working query, annotating which labels match, which are dropped, and which are carried over by group_left's label list.

5. **Fix the "many-to-many" error** — show the most common causes (label not unique on the "one" side, missing on()) and the fix.

6. **Patterns library** — provide reusable snippets: ratio of two counters with matching labels, joining `kube_pod_labels` for team attribution, filtering a metric to only instances present in another, and using `* 0 + ` tricks sparingly.

Output as: (a) the corrected query with inline label-set annotations, (b) a side-by-side label table showing the match, (c) 3-4 reusable join patterns, (d) a one-line rule of thumb for choosing group_left vs group_right.

Show the label math explicitly. Never guess at which side is the "one".
Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 1,603 DevOps AI prompts
  • One practical workflow email per week