-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Infer max query downsample resolution from promql query #7012
base: main
Are you sure you want to change the base?
Conversation
Does it make sense to solve this at the store level? Since the range is passed in hints, we can decide whether to send downsampled or aggregated chunks to queriers. |
Interesting idea. Yeah I think it works to get the range of matrix selector. Doing it at the query API level seems more flexible. |
Looking at the code, I think it would be best to set max resolution here based on the selected range. We can still query raw blocks over a large range, but we should cap the max resolution for small ranges to make sure downsampled blocks cannot be requested. Otherwise we have to make many places in the codebase, and it will be hard to handle cases with different ranges in a binary expression. |
Can we make the engine set a hint since it already analyzes the query and then stores can just act on the hint that the engine provides? |
Umm, do we want to set different max resolution per select or use one max resolution value for the whole query? My current implementation is the latter. Having different max resolution might also work, but I am wondering if it has some issues with our current results cache as it assumes a single resolution for the whole query. |
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 see, then we can stay on the safe side and calculate the value based on all selectors.
Ideally we should remove
I am wondering if this is a valid usecase. I can only think of people who want to run
It sounds fine to have different resolutions per vector selector. |
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.
We were talking about this on KubeCon on Friday and the same day we had a question about why rate[5m]
doesn't work on downsampled data so I think we should merge this. There is only one in-line suggestion.
pkg/api/query/v1.go
Outdated
if f, ok := node.(*parser.Call); ok { | ||
switch f.Func.Name { | ||
// Functions that require at least 2 samples. | ||
case "rate", "irate", "increase", "idelta", "deriv", "predict_linear": |
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'm 99% sure that we will forget to update this list once a new function appears that takes in a range vector. Perhaps this list could be converted into a list of functions like map[string]bool
and then a unit test could be added that would check whether all parser.Functions
are covered. This would make it so that it would be impossible to add another PromQL function without checking whether it needs to be added to this.
Now I am more towards the solution mentioned by @fpetkovski to use Select hints and Range to figure out the resolution. |
Is there a plan to merge this PR? It seems like a really necessary feature for me :-) Thank you! |
4b72f2c
to
8d17bba
Compare
I have updated the PR with your suggestion. PTAL @fpetkovski @GiedriusS |
Signed-off-by: Ben Ye <benye@amazon.com>
8d17bba
to
6d6b81a
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.
This makes sense to me 👍
Changes
This is useful to help with #6929.
No matter of auto downsample is enabled or not, always try to infer max allowed resolution based on promql query.
The main idea is from @fpetkovski to check
Range
andFunc
from hints to see if the promql function requires at least 2 samples in the range and then we adjust max allowed resolution accordingly.For example I have a query like
rate[2m]
. Becauserate
function requires at least 2 samples to run so minimum resolution is 1m. This should avoid picking higher resolution like 5m or 1h.Verification
Added unit test.