Interview Prep/Monitoring & Observability/Prometheus and PromQL at Scale

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
)
  1. kube-state-metrics must allow the label: --metric-labels-allowlist=pods=[team].
  2. Consider a recording rule since this join is expensive.
  3. 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.

All Monitoring & Observability questions Roadmap: Monitoring & alerting

More on Prometheus and PromQL at Scale