Latency SLO: "99% of requests under 300 ms." How do you measure it correctly in Prometheus?

IntermediateScenarioSLOs and Error Budgets
Answer

Situation read → A latency SLO is a ratio of fast requests to all requests, not a p99 gauge.

What I'd do →

  1. Ensure the histogram has a bucket at exactly 0.3.
  2. SLI = requests under 300 ms / all requests:
sum(rate(http_request_duration_seconds_bucket{job="api",le="0.3"}[5m]))
/
sum(rate(http_request_duration_seconds_count{job="api"}[5m]))
  1. Use this ratio in burn-rate alerts the same way as availability.

Why → Ratios aggregate correctly across pods and time; percentiles do not.

Interview tip → "Latency SLOs are counted as good events under a threshold."

All Monitoring & Observability questions

More on SLOs and Error Budgets