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.

All SRE & Reliability questions Roadmap: SRE & incident response

More on SLIs, SLOs & SLAs