I have a variable latency_target = 5s. How use it in a PromQL query as a histogram label selector:
sum(rate(histogram{le="$latency_target"}[$interval]))
This does not work, dues to s suffix. I tried to use duration function, but it does not work
If you want calculating the percentage of requests with durations not exceeding the given threshold (aka SLI / SLA / SLO or the inverse of histogram_quantile()), from Prometheus histogram, then there are bad and good news:
0..1) of queries with durations not exceeding 1.5 seconds over the last 10 minutes:You can freely substitute the first arg to
histogram_share()function with Grafana variable, which contains Prometheus-compatible duration, as well as the lookbehind window in square brackets for the rate() function:This query should work correctly for any Prometheus-compatible durations behind
latency_targetand$intervalvariables.