instant and range query duration

37 views
Skip to first unread message

kiran

unread,
Nov 15, 2020, 10:42:46 PM11/15/20
to Prometheus Users
Hello all,

I am new to PromQL and would like to understand as I could not find things (unless I am missing it) here: 

1. For an instant query, if I dont give timestamp, then what is the logic/default timestamp.
2. For range query, what is the default step value if no value is provided?
3. For range query, are start, and end parameters optional?  
4. I see that time duration can be given after the metric in square brackets (e.g http_requests_total[5m]). Is giving time duration this way the same as giving range query with equivalent unix timestamp values for start and end parameters?

So I am trying to understand if both the queries below are same and yield same result(including result format):

/api/v1/query_range?query=<metricname>[<duration>]
/api/v1/query_range?query=<metricname>&start=<strartunixtimestamp>&end=<endunixtimestamp>

5. I see that giving duration in square brackets is working for instant query as well(e.g /api/v1/query?query=<metricname>[<duration>]), but not sure what timeseries it is retrieving. Any valid cases to use this way?


Matthias Rampke

unread,
Nov 16, 2020, 3:04:54 AM11/16/20
to kiran, Prometheus Users
1. Now
2. Uh, not sure, probably better to specify one 😬
3. Probably not, end might default to "now" implicitly?
4. They are different – there are two different types involved here.
`http_request_total` returns an instant vector: a 1-dimensional list of the value at that instance for each label combination.
`http_request_total[1m]` is a matrix: for each label combination, it has a list of values going back 1 minute with some automatic step IIRC. Normally you don't handle these directly; they are used e.g. by rate() to calculate the rate of counters over this period.
5. It us returning this matrix.

The query_range API is an optimized way to make many "instant" requests at once. You can get logically the same results by calling the query API many times with different time stamps. For each instant, the response can be of different types, although in most common queries they will be of the "instant vector" type because that is what you can build a graph from.

/MR


--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/CAOnWYZVk%3D-MRzawQ_BHamf_vtS-7960uM5kigO%3DtE559RaGoEw%40mail.gmail.com.

kiran

unread,
Nov 17, 2020, 11:16:35 AM11/17/20
to Matthias Rampke, Prometheus Users
Thank you, Matthias. Please see my comments below.

On Monday, November 16, 2020, Matthias Rampke <matt...@prometheus.io> wrote:
1. Now
I would like to understand the definition of ‘Now’. Is it more recent one with a certain timeframe? If so what timeframe?
2. Uh, not sure, probably better to specify one 😬
3. Probably not, end might default to "now" implicitly?
4. They are different – there are two different types involved here.
`http_request_total` returns an instant vector: a 1-dimensional list of the value at that instance for each label combination.
`http_request_total[1m]` is a matrix: for each label combination, it has a list of values going back 1 minute with some automatic step IIRC. Normally you don't handle these directly; they are used e.g. by rate() to calculate the rate of counters over this period.

So is giving duration sane as range query with start time, end time and step?
 
5. It us returning this matrix.

The query_range API is an optimized way to make many "instant" requests at once. You can get logically the same results by calling the query API many times with different time stamps. For each instant, the response can be of different types, although in most common queries they will be of the "instant vector" type because that is what you can build a graph from.

/MR

On Mon, Nov 16, 2020, 04:42 kiran <kira...@gmail.com> wrote:
Hello all,

I am new to PromQL and would like to understand as I could not find things (unless I am missing it) here: 

1. For an instant query, if I dont give timestamp, then what is the logic/default timestamp.
2. For range query, what is the default step value if no value is provided?
3. For range query, are start, and end parameters optional?  
4. I see that time duration can be given after the metric in square brackets (e.g http_requests_total[5m]). Is giving time duration this way the same as giving range query with equivalent unix timestamp values for start and end parameters?

So I am trying to understand if both the queries below are same and yield same result(including result format):

/api/v1/query_range?query=<metricname>[<duration>]
/api/v1/query_range?query=<metricname>&start=<strartunixtimestamp>&end=<endunixtimestamp>

5. I see that giving duration in square brackets is working for instant query as well(e.g /api/v1/query?query=<metricname>[<duration>]), but not sure what timeseries it is retrieving. Any valid cases to use this way?


--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.

Matthias Rampke

unread,
Nov 18, 2020, 3:53:45 AM11/18/20
to kiran, Prometheus Users
On Tue, Nov 17, 2020 at 4:16 PM kiran <kira...@gmail.com> wrote:
Thank you, Matthias. Please see my comments below.

On Monday, November 16, 2020, Matthias Rampke <matt...@prometheus.io> wrote:
1. Now
I would like to understand the definition of ‘Now’. Is it more recent one with a certain timeframe? If so what timeframe?

Sort of. Logically, it is the current value of all time series that match; but practically some time has passed since each of them have been last scraped. This is where the "lookback delta" (default 5 minutes) comes into play: Prometheus will look for this last value for up to 5 minutes before the query time.
 
4. …

So is giving duration sane as range query with start time, end time and step?

They return roughly the same data, but in a different format.
 
/MR



On Mon, Nov 16, 2020, 04:42 kiran <kira...@gmail.com> wrote:
Hello all,

I am new to PromQL and would like to understand as I could not find things (unless I am missing it) here: 

1. For an instant query, if I dont give timestamp, then what is the logic/default timestamp.
2. For range query, what is the default step value if no value is provided?
3. For range query, are start, and end parameters optional?  
4. I see that time duration can be given after the metric in square brackets (e.g http_requests_total[5m]). Is giving time duration this way the same as giving range query with equivalent unix timestamp values for start and end parameters?

So I am trying to understand if both the queries below are same and yield same result(including result format):

/api/v1/query_range?query=<metricname>[<duration>]
/api/v1/query_range?query=<metricname>&start=<strartunixtimestamp>&end=<endunixtimestamp>

5. I see that giving duration in square brackets is working for instant query as well(e.g /api/v1/query?query=<metricname>[<duration>]), but not sure what timeseries it is retrieving. Any valid cases to use this way?


--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.

Julius Volz

unread,
Nov 19, 2020, 3:28:01 PM11/19/20
to kiran, Prometheus Users
Hi,

I just saw this question. Check out https://promlabs.com/blog/2020/07/02/selecting-data-in-promql and https://promlabs.com/blog/2020/06/18/the-anatomy-of-a-promql-query, which should answer most of your questions in more detail.

In addition to answers Matthias provided:

2. + 3. All three range query parameters are mandatory, otherwise the API returns an error.

4. A range vector selector (like "foo[5m]") returns *all* samples under the provided window. Doing a range *query* over an instant selector ("foo") over that same range is *not* equivalent, as the resolution step applies, and thus a) all output points will be aligned to that resolution, b) raw samples with a higher frequency than your resolution are *skipped*, and c) the returned format is different. Also, staleness handling is a concept that only happens for instant vector selectors, see https://promlabs.com/blog/2020/07/02/selecting-data-in-promql#instant-vector-selectors and the "Staleness" section therein.

Regards,
Julius

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/CAOnWYZVk%3D-MRzawQ_BHamf_vtS-7960uM5kigO%3DtE559RaGoEw%40mail.gmail.com.


--
Julius Volz
PromLabs - promlabs.com

kiran

unread,
Nov 19, 2020, 10:26:24 PM11/19/20
to Julius Volz, Prometheus Users
Thank you Julius.

-So range vector selector (like "foo[5m]") is run on range_query url(/api/v1/query_range) and not on instant query(/api/v1/query) url right?
If it needs to be given on /api/v1/query_range), the documentation refers to only this where start, end and step parameters are to be given. The documentation does not clear for a beginner like me and it is returning results on both instant and range urls.


-So which one of the below is preferred if both are range queries. I am assuming when we specify duration(e.g 30s instead of start and end times), in the backend it still derives on the fly start and end dates and then return results. So in that case is step parameter applied?

b.ca...@pobox.com

unread,
Nov 21, 2020, 8:22:18 AM11/21/20
to Prometheus Users
As far as I know, the /query_range endpoint only accepts an *instant* query.  The instant query is swept between the given start and end times at the given step. In other words, it repeats the instant query at multiple points in time, as if you'd hit the /query endpoint multiple times.

However, you *can* send a range query to the /query endpoint. It will return all the values within that range, with their exact timestamps (i.e. it returns the "raw" data, not resampled at intervals)

Aside: if using 'curl' then you should add the '-g' flag to stop it interpreting globbing characters like '[' and']'

curl: (3) [globbing] bad range in column 45
... this works
Reply all
Reply to author
Forward
0 new messages