-
Notifications
You must be signed in to change notification settings - Fork 9.6k
PromQL: allow arithmetic operations in durations in PromQL parser #16249
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
Conversation
c68ebe7
to
ff7f462
Compare
ff7f462
to
798ff24
Compare
ca60a28
to
c0fb4ba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mostly nit comments
bc3012f
to
80b364e
Compare
From my point of view this is approved as technically ok. Not sure if this PR or my direction in #15899 would be easier to extend with supporting more expressions (functions, db access), but doesn't matter - it addresses current concerns. Ping @beorn7 @fionaliao @juliusv as they reviewed #15899 as well. |
Ah yeah, I was wondering what the relationship was between this PR and the alternative one at #15899. This one here looks simpler in some ways, but it also seems to do a few surprising things like:
Without reviewing every detail of both PRs, overall I think I'm more partial to the concept in #15899 (but applied to duration expressions in general, not just offsets) where the duration expressions are reflected in the AST, duration expressions are evaluated with the normal PromQL engine machinery, and there is only a separate validator (that I can reason about independently) that runs over duration expressions and checks whether they do anything forbidden. It also currently allows more constructs than this PR and would be more extensible in the future I think? |
I did this indeed as a simplification of such calculations done by the PromQL parser. I understand that keeping the AST might better. I am not convinced about extending it further than duration literals however as it would create very complex and unpredictable queries. I will reflect the changes in the AST and move the operations down to the PromQL engine. |
@roidelapluie Yeah, I think reflecting those expressions in the normal AST would be a good thing already, and I also don't think we need to practically allow more operations than you are currently allowing. |
866c38d
to
c57dd7f
Compare
Can you have a new look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good, I've added some comments
Updated the parser to allow calculations in PromQL durations. This enables durations in the form of: rate(http_requests_total[10m+2s]) The computation of the calculations is done directly at the parse level and does not hit the PromQL Engine. The lexer has also been updated and improved, in particular for subqueries. Buxfix: rate(http_requests_total[0]) is no longer allowed. Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
c57dd7f
to
6689f80
Compare
6689f80
to
9e14c50
Compare
I implemented tests in a different way, not testing the parser,can you have a look? |
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
9e14c50
to
2cf2bf5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with nit comment
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
cc @juliusv can you have a look? |
Merging because no input for > 1w and approved by krajo. |
This test has been removed upstream after the PR for duration selector math was merged. See prometheus/prometheus#16249 Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com>
* Update mimir-prometheus to v1.8.2-0.20250423083340-007de9b763aa * Fix build * Fix build problems from vendor due to pinning that is now irrelevant as dskit now has google.golang.org/grpc v1.71.1 * Fix test * Remove streamingpromql engine test with 0 range This test has been removed upstream after the PR for duration selector math was merged. See prometheus/prometheus#16249 Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com> * Remove more 0 length range selectors and sync tests Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com> * Disable duration expression testing in MQE until we enable it Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com> * Remove comment from test since it was breaking the unit test Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com> * Add @56quarters 's changes to go.mod --------- Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com> Co-authored-by: Nick Pillitteri <nick.pillitteri@grafana.com>
Updated the parser to allow calculations in PromQL durations.
This enables durations in the form of:
rate(http_requests_total[10m+2s])
The computation of the calculations is done directly at the parse level and does not hit the PromQL Engine. The lexer has also been updated and improved, in particular for subqueries.
Partial fix for #12318