FiloDB icon indicating copy to clipboard operation
FiloDB copied to clipboard

feat(query): add promql @ modifier

Open alextheimer opened this issue 3 years ago • 0 comments

Pull Request checklist

  • [x] The commit(s) message(s) follows the contribution guidelines ?
  • [x] Tests for the changes have been added (for bug fixes / features) ?
  • [ ] Docs have been added / updated (for bug fixes / features) ?

New behavior : Adds support for queries such as:

http_requests_total @ 1609746000
http_requests_total[5m] @ 1609746000
http_requests_total[5m:30s] @ 1609746000

where the @ modifier simply aligns a query's evaluation time with the @ timestamp.

Per the PromQL spec, @ can be used in conjunction with offset, as in:

http_requests_total @ 1609746000 offset 5m
http_requests_total offset 5m @ 1609746000

where the relative order of the modifiers does not matter.

Additionally, start() and end() can be used as timestamps, where:

  • for a range query, start() and end() evaluate to the query's start and end times, respectively.
  • for an instant query, start() and end() both resolve to the query's evaluation time. Examples:
http_requests_total @ start() offset 5m
http_requests_total[10m] offset 1h @ end()

This modifier is particularly useful for situations such as (from prometheus.io):

rate(http_requests_total[1m]) # This acts like the actual selector.
  and
topk(5, rate(http_requests_total[1h] @ end())) # This acts like a ranking function which filters the selector.

See the docs and this blog post for more information.

Additional Notes:

  • Fixes bug where offset-containing queries on histogram data throws an exception.

alextheimer avatar Nov 04 '21 00:11 alextheimer