Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(query): add promql @ modifier #1281

Open
wants to merge 47 commits into
base: develop
Choose a base branch
from
Open

Conversation

alextheimer
Copy link
Contributor

@alextheimer alextheimer commented Nov 4, 2021

Pull Request checklist

  • The commit(s) message(s) follows the contribution guidelines ?
  • 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 alextheimer marked this pull request as ready for review November 5, 2021 14:42
Copy link
Contributor

@TanviBhavsar TanviBhavsar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments. As discussed please add support for start() and end() with "@"

def getTimeParamsWithAt(timeParams: TimeRangeParams, at: Option[Long]): TimeRangeParams = {
at match {
case Some(timestamp) => {
val delta = timestamp - timeParams.end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when timeParams.end is greater than timestamp?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The negative delta is alright-- the equation I want to satisfy is:

timeParams.end + delta = timestamp

}

lazy val rangeVectorSelector2: PackratParser[RangeExpression] =
labelSelection ~ simpleLookback ~ offset.? ^^ {
case ls ~ simpleLookback ~ opt =>
RangeExpression(None, ls, simpleLookback.duration, opt.map(_.duration))
RangeExpression(None, ls, simpleLookback.duration, opt.map(_.duration), None) // TODO(a_theimer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change TODO as discussed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@alextheimer alextheimer marked this pull request as draft November 15, 2021 15:48
@TanviBhavsar TanviBhavsar self-requested a review November 18, 2021 22:07
@alextheimer alextheimer changed the title feat(query): add promql @ modifier ==WIP== // feat(query): add promql @ modifier Jan 6, 2022
parser = "shadow"
parser = "antlr"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note!

@alextheimer alextheimer changed the title ==WIP== // feat(query): add promql @ modifier feat(query): add promql @ modifier Jan 18, 2022
@alextheimer alextheimer marked this pull request as ready for review January 18, 2022 06:48
@yu-shipit yu-shipit mentioned this pull request Sep 29, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants