PCA practice question 6 of 15

Which function would you use to calculate the 95th percentile latency from histogram data?

Full set: 60 questions
Answer options
A: quantile_over_time(0.95, http_request_duration_seconds[5m])
B: histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le)) Correct answer
C: percentile(http_request_duration_seconds, 0.95)
D: topk(0.95, http_request_duration_seconds)
Correct Answer:
B. histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le))
Explanation

The histogramquantile() function is specifically designed in Prometheus Query Language (PromQL) to calculate quantiles from histogram buckets. The query histogramquantile(0.95, sum(rate(httprequestdurationsecondsbucket[5m])) by (le)) correctly follows the required pattern. It first calculates the per-second rate of observations in each bucket over a 5-minute window using rate(). Then, sum(...) by (le) aggregates these rates across different instances while preserving the bucket boundary (le) label, which is essential for the quantile calculation. Finally, histogramquantile() takes this aggregated data and the desired quantile (0.95) to compute the 95th percentile value.

Why Incorrect

A. quantileovertime calculates a quantile over a time range for a gauge metric, not from the distribution provided by a histogram's buckets.
C. percentile() is not a valid function in the standard Prometheus Query Language (PromQL).
D. topk is used to select the top 'k' time series by value; it does not compute statistical percentiles from a data distribution.

References

1. Prometheus Authors. (n.d.). Querying functions | Prometheus Documentation.

Section: histogramquantile(φ float64, b instant-vector)

Details: The official documentation explicitly states, "Calculates the φ-quantile (0 ≤ φ ≤ 1) from the buckets b of a histogram." It provides the canonical example: histogramquantile(0.9, sum(rate(httprequestdurationsecondsbucket[10m])) by (le)), which directly supports the structure of the correct answer (B).

2. Prometheus Authors. (n.d.). Metric types | Prometheus Documentation.

Section: Histogram

Details: This document explains the structure of a histogram metric, including the bucket{le="..."} time series. It clarifies that to calculate quantiles, one must use the histogramquantile() function on the bucket series, reinforcing why option B is the correct approach.

3. Prometheus Authors. (n.d.). Querying functions | Prometheus Documentation.

Section: quantileovertime(φ float64, q range-vector)

Details: The documentation for quantileovertime confirms it calculates the φ-quantile over the values in a range vector, which is fundamentally different from calculating a quantile from a histogram's distribution of observations. This supports why option A is incorrect.

Scroll to Top