How does `histogram_quantile()` work?
IntermediateConceptPromQL & Recording Rules
Answer
It estimates a quantile from cumulative bucket counters by finding the bucket where the rank falls and linearly interpolating within it.
histogram_quantile(0.95,
sum by (le, service) (rate(http_request_duration_seconds_bucket[5m])))
Always keep le in the by clause and rate() the buckets first. Accuracy depends on bucket boundaries: if all requests are between 0.5 and 1 s and you only have those two buckets, p95 is a guess within that range.
More on PromQL & Recording Rules
What are the PromQL data types?BeginnerWhat label matchers does PromQL support?BeginnerExplain `rate()`.Beginner`rate()` vs `irate()`: what is the difference?IntermediateWhat does `increase()` return and why is it sometimes a non-integer?IntermediateWhy must you `rate()` before `sum()`, never the reverse?Intermediate