PCA (Prometheus Certified Associate) sample exam question with answer 396

Question:
Given the histogram metric http_request_duration_seconds, which of the following queries gives the median of request durations over the last five minutes?

  1. med(http_request_duration_seconds[5m])
  2. avg_over_time(http_request_duration_seconds[5m])
  3. rate(http_request_duration_seconds_sum[5m]) / rate(http_request_duration_seconds_count[5m])
  4. histogram_quantile(0.5, rate(http_request_duration_seconds_bucket[5m]))
Answer:
D - correct answer. For this question it is helpful to know that the median of the data can alternatively be represented as the 50th percentile. Thus, the median for a histogram metric can be calculated by using the histogram_quantile function with a quantile of 0.5
A - there is no PromQL function called med
B - is incorrect as http_request_duration_seconds is not one of the series generated by a histogram of that name and thus the query would return no results. Additionally, the avg_over_time temporal aggregation is not appropriate for calculating the median
C - is incorrect as this query yields the mean (average) of request durations over the last five minutes, not the median