Video in progress
`histogram_quantile` shows a p99 of 5 seconds, but the slowest request in the logs took 1.2 seconds. How is that possible?
A histogram does not store exact values, only the counts in its buckets. If there is no bucket between 1 s and 5 s, Prometheus interpolates p99 linearly inside that range, and the result lands near a bucket boundary. You need to put denser buckets around your SLO.
📖 Answer
histogram_quantile finds which bucket the 99th percentile falls into and assumes the values inside the bucket are spread evenly. Say the buckets are 0.5, 1, 5, 10 and 2% of requests take between 1.1 and 1.2 s. They fall into the le="5" bucket, and Prometheus assumes "these requests are spread evenly between 1 and 5", so it reports p99 close to 3 or 5.
The second cause is values above the highest finite bucket. If the percentile lands in the +Inf bucket, the function returns the last finite boundary, so a real 30 s request shows up as "10 s".
In Micrometer you configure the buckets:
management:
metrics:
distribution:
percentiles-histogram:
http.server.requests: true
slo:
http.server.requests: 100ms, 250ms, 500ms, 1s, 2s # exact boundaries
minimum-expected-value:
http.server.requests: 10ms
maximum-expected-value:
http.server.requests: 10s
The boundaries you give with slo become exact buckets, so you can compute an SLI like "the share of requests faster than 500 ms" directly, without interpolation:
sum(rate(http_server_requests_seconds_bucket{le="0.5"}[5m]))
/ sum(rate(http_server_requests_seconds_count[5m]))
A practical rule: measuring an SLO with a bucket ratio is more accurate than with a percentile.
Sign up to mark studied questions and save your progress.