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]))
- Aggregate numerator and denominator before dividing, to avoid dividing per-instance series that do not match.
- 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])). - With zero traffic the result is NaN or empty, so guard with an
andon a minimum rate.
Why → Empty vectors and NaN silently break alerts and dashboards.
Interview tip → Call out the empty-numerator case unprompted.
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