Fix correctness issue in predict_linear with step invariant#527
Fix correctness issue in predict_linear with step invariant#527harry671003 wants to merge 3 commits intothanos-io:mainfrom
Conversation
Signed-off-by: 🌲 Harry 🌊 John 🏔 <johrry@amazon.com>
Signed-off-by: 🌲 Harry 🌊 John 🏔 <johrry@amazon.com>
Signed-off-by: 🌲 Harry 🌊 John 🏔 <johrry@amazon.com>
2ec4376 to a43f047 Compare | query: `predict_linear({__name__="http_requests_total",pod!~"nginx-1"}[5m] @ start(), -0.37690610678629094)`, | ||
| end: time.Unix(600, 0), | ||
| start: time.Unix(300, 0), | ||
| }, |
There was a problem hiding this comment.
Is this an issue for predict linear only or it can impact any function that takes matrix selector with step invariant?
There was a problem hiding this comment.
It will only impact functions that are at modifier unsafe that takes matrix selector as arg.
So far only applicable to predict_linear.
| Can we just wrap the matrix function into step invariant operator? https://github.com/thanos-io/promql-engine/blob/main/execution/step_invariant/step_invariant.go#L47 ? |
| We could just push step inviarnace up in a preprocessor like here: https://github.com/thanos-io/promql-engine/blob/main/logicalplan/plan.go#L335 |
The PromQL parser parses the query into: After calling promql.PreprocessExpr() in plan.go this becomes: In Prometheus, predict_linear is marked as at modifier unsafe. So it cannot be wrapped with StepInvariance: |
| I see, I wonder if we maybe should jsut fall back for now for correctness sake - this seems to be fairly niche usecase that we must weigh against added complexity |
I'm okay with doing the fallback. There is one concern, we'll have to exclude the functions.test file from acceptance tests. |


Issue
Our continuous correctness tests found an issue with predict_linear with step invariant matrix selector.
Eg:
predict_linear({__name__="http_requests_total", pod!~"nginx-1"}[5m] @ start(), -0.37690610678629094)This PR addresses the problem by allowing the matrixScanner to act in an invariant way similar to Prometheus engine.
See: https://github.com/prometheus/prometheus/blob/2a5ed8b8a55fecaa79236ef4adb9f0b82b34587c/promql/engine.go#L1788