Interview Prep/Monitoring & Observability/PromQL and recording rules

`topk(5, ...)` shows more than 5 series on a graph

BeginnerTroubleshootingPromQL and recording rules
Answer

Likely causes → topk is evaluated per step in a range query, so different series win at different times.

Diagnose → Run as an instant query; you get exactly 5.

Fix → For a stable set, pick the top 5 over the whole range with a variable, or use topk(5, avg_over_time(...[$__range])) as an instant query in a table panel.

Prevent → Explain this in the panel description; it surprises everyone once.

All Monitoring & Observability questions Roadmap: Monitoring & alerting

More on PromQL and recording rules