From 86d7618d843f4a3a90e7e05e2228b94fe6f7744c Mon Sep 17 00:00:00 2001 From: beorn7 Date: Wed, 7 Feb 2024 18:07:51 +0100 Subject: [PATCH] promql: Fix wrongly scoped range vectors Fixes #11708. If a range vector is fixen in time with the @ modifier, it gets still moved around for different steps in a range query. Since no additional points are retrieved from the TSDB, this leads to steadily emptying the range, leading to the weird behavior described in isse #11708. This only happens for functions listed in `AtModifierUnsafeFunctions`, and the only of those that takes a range vector is `predict_linear`, which is the reason why we see it only for this particular function. Signed-off-by: beorn7 --- promql/engine.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/promql/engine.go b/promql/engine.go index 02004e5f9..575ca58ea 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -1494,10 +1494,14 @@ func (ev *evaluator) eval(expr parser.Expr) (parser.Value, annotations.Annotatio otherInArgs[j][0].F = otherArgs[j][0].Floats[step].F } } - maxt := ts - offset - mint := maxt - selRange - // Evaluate the matrix selector for this series for this step. - floats, histograms = ev.matrixIterSlice(it, mint, maxt, floats, histograms) + // Evaluate the matrix selector for this series + // for this step, but only if this is the 1st + // iteration or no @ modifier has been used. + if ts == ev.startTimestamp || selVS.Timestamp == nil { + maxt := ts - offset + mint := maxt - selRange + floats, histograms = ev.matrixIterSlice(it, mint, maxt, floats, histograms) + } if len(floats)+len(histograms) == 0 { continue }