-
Notifications
You must be signed in to change notification settings - Fork 537
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
frontend: update query pruning #10026
base: main
Are you sure you want to change the base?
Conversation
9dcc588
to
c70d552
Compare
863b5b1
to
97a767d
Compare
The current method of excluding/including sub query results in PromQL by comparing to -Inf or +Inf is no longer valid after prometheus/prometheus#15245 due to comparison of native histograms to a float with < or > result in Jeanette's warning, not empty set. To ease migrating to the correct version, I'm not removing the old prune code yet, just adding the new method. The new method uses logical AND operation to intersect the sub query with either a const vector() or an empty vector(). E.g. subquery and on() (vector(1)==1) subquery and on() (vector(-1)==1) which become: subquery (vector(-1)==1) Signed-off-by: György Krajcsovits <[email protected]>
97a767d
to
98d8813
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.
I think we can further prune the expression in some cases:
{ | ||
// "and on()" is not on top level, "or" has lower precedence. | ||
`(avg(rate(foo[1m]))) and on() (vector(0) == 1) or avg(rate(bar[1m]))`, | ||
`(vector(0) == 1) or avg(rate(bar[1m]))`, |
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.
Couldn't we simplify this further, to avg(rate(bar[1m]))
?
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.
That's more complicated. The main point is to avoid loading chunks and (vector(0)==1)
doesn't load chunks, so should be very efficient.
We can add that logic in a new PR, seems to be independent from this optimization, wdyt?
But having two algorithms raises the question of whether they need to be run repeatedly to optimize away everything, so it gets even more complicated.
{ | ||
// "and on()" is not on top level, due to left-right associativity. | ||
`(avg(rate(foo[1m]))) and on() (vector(0) == 1) and avg(rate(bar[1m]))`, | ||
`(vector(0) == 1) and avg(rate(bar[1m]))`, |
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.
Couldn't we simplify this further, to vector(0) == 1
?
}, | ||
{ // The const expression is on the wrong side. | ||
`(vector(0) == 1) and on() (avg(rate(foo[1m])))`, | ||
`(vector(0) == 1) and on() (avg(rate(foo[1m])))`, |
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.
Same as below - I think this can be simplified to vector(0) == 1
.
}, | ||
{ // Matching on labels. | ||
`(avg(rate(foo[1m]))) and on(id) (vector(0) == 1)`, | ||
`(avg(rate(foo[1m]))) and on(id) (vector(0) == 1)`, |
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.
Couldn't this be simplified to vector(0) == 1
? The right side will never produce a result, so we'll never return anything from the left side.
}, | ||
{ // Not "on" expression. | ||
`(avg(rate(foo[1m]))) and ignoring() (vector(0) == 1)`, | ||
`(avg(rate(foo[1m]))) and ignoring() (vector(0) == 1)`, |
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.
Same as above - the right side will never produce a result.
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.
Looks good at first glance. (I assume you don't want a code-level review from me, just that the idea is correct.)
What this PR does
The current method of excluding/including sub query results in PromQL by comparing to -Inf or +Inf is no longer valid after prometheus/prometheus#15245 due to comparison of native histograms to a float with < or > result in Jeanette's warning, not empty set.
To ease migration away from the old wrong logic, I'm adding the new logic first.
The new method uses logical AND operation to intersect the sub query with either a const vector() or an empty vector(). E.g.
which become:
Which issue(s) this PR fixes or relates to
Fixes N/A
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]
.about-versioning.md
updated with experimental features.