From b65d655afa5a8fa401e78bd0eeb5f5e9160ce72d Mon Sep 17 00:00:00 2001 From: Kien Nguyen Date: Wed, 18 Sep 2024 15:07:37 +0700 Subject: [PATCH] add query step --- prometheus/prometheus-query-steps.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 prometheus/prometheus-query-steps.md diff --git a/prometheus/prometheus-query-steps.md b/prometheus/prometheus-query-steps.md new file mode 100644 index 0000000..482485f --- /dev/null +++ b/prometheus/prometheus-query-steps.md @@ -0,0 +1,9 @@ +# How Prometheus's query steps (aka query resolution) work + +Source: + +In general, when you write a simple Prometheus PromQL query, it is evaluated at some point in time (normally the current instant, unless you use [offset modifier](https://prometheus.io/docs/prometheus/latest/querying/basics/#offset-modifier)). This includes queries with [range vector selectors](https://prometheus.io/docs/prometheus/latest/querying/basics/#range-vector-selectors); the range vector selector chooses how far back to go from the current instant. This is the experience you will get in Prometheus's expression browser console. + +In a Prometheus graphing query, there is a range of time you're covering and the there is the *query step*. How Prometheus appears to work is that your expression is repeatedly evaluated at instants throughout the time range, starting at the first instant of the time range and then moving forward by the query step until things end. The query step or query resolution (plus the absolute time range) determines how many points you will get back. The HTTP API documentation for range queries makes this more or less explicit in its example; in a query against a 30-second range with a query step of 15 seconds, there are three data points returned, one at the start time, one in the middle, and one at the end time. + +**A range query's query step is completely independent from any range durations specified in the PromQL expression it evaluates**. If you have 'rate(http_requests_total[5m])', you can evaluate this at a query step of 15 seconds and Prometheus doesn't care either way. What happens is that every 15 seconds, you look back 5 minutes and take the rate between then and now. It is rather likely that this rate won't change much on a 15 second basis, so you'll probably get a smooth result. On the other hand, if you use a very large query step with this query, you may see your graphs go very jagged and spiky because you're sampling very infrequently. You may also get surprisingly jagged and staircased results if you have very small query steps.