You need CPU usage per team, but metrics only have namespace labels and teams are in pod labels. How do you join them?
IntermediateScenarioPrometheus and PromQL at Scale
Answer
Situation read → You need to enrich one metric with labels from another using a many-to-one join.
What I'd do → Use kube_pod_labels from kube-state-metrics (value always 1) and group_left:
sum by (label_team) (
rate(container_cpu_usage_seconds_total{container!=""}[5m])
* on (namespace, pod) group_left (label_team)
kube_pod_labels
)
- kube-state-metrics must allow the label:
--metric-labels-allowlist=pods=[team]. - Consider a recording rule since this join is expensive.
- Alternatively label at the namespace level and use
kube_namespace_labels.
Why → group_left copies labels from the "one" side to the "many" side without changing the value.
Interview tip → Remember the multiplier trick: info metrics have value 1, so multiplication keeps the original value.
More on Prometheus and PromQL at Scale
Prometheus memory has grown to 60 GB and keeps climbing. How do you find the cause?IntermediateA developer added `user_id` as a metric label. What is the problem and what do you advise?BeginnerYour dashboard shows the average of per-pod p99 latencies. Why is it wrong, and how do you compute a correct fleet-wide p99?IntermediateChoose histogram bucket boundaries for a service with a 300 ms latency SLO.AdvancedYou have 500 short-lived batch jobs that finish before Prometheus can scrape them. How do you capture their metrics?IntermediateYour EC2 fleet autoscales constantly. How do you keep Prometheus targets up to date?Intermediate