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']' root@prometheus:~# curl 'http://localhost:9090/api/v1/query?query=up[30s]' curl: (3) [globbing] bad range in column 45 root@prometheus:~# curl -g 'http://localhost:9090/api/v1/query?query=up[30s]' ... this works On Friday, 20 November 2020 at 03:26:24 UTC [email protected] wrote: > 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. > > *https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries > <https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries>* > > -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? > > $ curl > 'http://localhost:9090/api/v1/query_range?query=up&start=2015-07-01T20:10:30.781Z&end=2015-07-01T20:11:00.781Z&step=15s' > > $ curl 'http://localhost:9090/api/v1/query_range?query=up[30s]' > > > On Thu, Nov 19, 2020 at 3:27 PM Julius Volz <[email protected]> wrote: > >> 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 >> >> On Mon, Nov 16, 2020 at 4:42 AM kiran <[email protected]> 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: >>> https://prometheus.io/docs/prometheus/latest/querying/api/ >>> >>> 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 [email protected]. >>> 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 >>> >>> <https://groups.google.com/d/msgid/prometheus-users/CAOnWYZVk%3D-MRzawQ_BHamf_vtS-7960uM5kigO%3DtE559RaGoEw%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> >> >> >> -- >> Julius Volz >> PromLabs - promlabs.com >> > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/e821f225-aff0-49ca-8aaa-9ca26ae90cc4n%40googlegroups.com.

