How do you build a latency SLI from a Prometheus histogram?
IntermediateConceptSLIs, SLOs & SLAs
Answer
Use the bucket whose le equals your threshold as "good" and _count as "valid". The threshold must be an actual bucket boundary, otherwise you are measuring the next bucket up.
sum(rate(http_request_duration_seconds_bucket{job="checkout",le="0.3"}[5m]))
/
sum(rate(http_request_duration_seconds_count{job="checkout"}[5m]))
That gives the fraction under 300 ms. Do not use histogram_quantile() for SLO math: percentiles cannot be averaged or turned into an error budget, while bucket ratios can.
More on SLIs, SLOs & SLAs
Define SLI, SLO and SLA with an example of each.BeginnerWhy should the SLA be looser than the SLO?BeginnerWhy are SLIs best expressed as a ratio of good events to valid events?IntermediateWhat is the difference between request-based and time-based (window-based) SLIs?AdvancedWhere should you measure an SLI, and what are the trade-offs?AdvancedWhat types of SLIs exist beyond availability and latency?Intermediate