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

Write the PromQL for the HTTP error ratio of a service, and explain the pitfalls.

BeginnerScenarioPrometheus and PromQL at Scale
Answer

Situation read → Ratios of rates are the standard SLI form. Pitfalls are in aggregation and zero traffic.

What I'd do →

sum(rate(http_requests_total{job="api",code=~"5.."}[5m]))
/
sum(rate(http_requests_total{job="api"}[5m]))
  1. Aggregate numerator and denominator before dividing, to avoid dividing per-instance series that do not match.
  2. If there are no 5xx at all, the numerator is empty and the division returns nothing. Use or vector(0) on the numerator if you need a value: (sum(rate(...{code=~"5.."}[5m])) or vector(0)) / sum(rate(...[5m])).
  3. With zero traffic the result is NaN or empty, so guard with an and on a minimum rate.

Why → Empty vectors and NaN silently break alerts and dashboards.

Interview tip → Call out the empty-numerator case unprompted.

All Monitoring & Observability questions Roadmap: Monitoring & alerting

More on Prometheus and PromQL at Scale