From 384ab025e0239479a086ec8affd12f30be80dfea Mon Sep 17 00:00:00 2001 From: beorn7 Date: Wed, 7 Feb 2024 18:06:05 +0100 Subject: [PATCH 1/3] promql: Expose issue #11708 The shorter range in the test makes early points drop out of the range in range queries, exposing the issue. Signed-off-by: beorn7 --- promql/testdata/functions.test | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/promql/testdata/functions.test b/promql/testdata/functions.test index c40a6272b..4e104e406 100644 --- a/promql/testdata/functions.test +++ b/promql/testdata/functions.test @@ -221,19 +221,19 @@ eval instant at 50m deriv(testcounter_reset_middle[100m]) # intercept at t=0: 6.818181818181818 # intercept at t=3000: 38.63636363636364 # intercept at t=3000+3600: 76.81818181818181 -eval instant at 50m predict_linear(testcounter_reset_middle[100m], 3600) +eval instant at 50m predict_linear(testcounter_reset_middle[50m], 3600) {} 76.81818181818181 # intercept at t = 3000+3600 = 6600 -eval instant at 50m predict_linear(testcounter_reset_middle[100m] @ 3000, 3600) +eval instant at 50m predict_linear(testcounter_reset_middle[50m] @ 3000, 3600) {} 76.81818181818181 # intercept at t = 600+3600 = 4200 -eval instant at 10m predict_linear(testcounter_reset_middle[100m] @ 3000, 3600) +eval instant at 10m predict_linear(testcounter_reset_middle[50m] @ 3000, 3600) {} 51.36363636363637 # intercept at t = 4200+3600 = 7800 -eval instant at 70m predict_linear(testcounter_reset_middle[100m] @ 3000, 3600) +eval instant at 70m predict_linear(testcounter_reset_middle[50m] @ 3000, 3600) {} 89.54545454545455 # With http_requests, there is a sample value exactly at the end of From 86d7618d843f4a3a90e7e05e2228b94fe6f7744c Mon Sep 17 00:00:00 2001 From: beorn7 Date: Wed, 7 Feb 2024 18:07:51 +0100 Subject: [PATCH 2/3] 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 } From 553d92affd423db09112be2c04e64a7de8671358 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Wed, 7 Feb 2024 18:12:26 +0100 Subject: [PATCH 3/3] model/labels: Fix new lint warning in test Signed-off-by: beorn7 --- model/labels/labels_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/model/labels/labels_test.go b/model/labels/labels_test.go index c497851d1..0221c66eb 100644 --- a/model/labels/labels_test.go +++ b/model/labels/labels_test.go @@ -708,7 +708,8 @@ func TestScratchBuilder(t *testing.T) { func TestLabels_Hash(t *testing.T) { lbls := FromStrings("foo", "bar", "baz", "qux") - require.Equal(t, lbls.Hash(), lbls.Hash()) + hash1, hash2 := lbls.Hash(), lbls.Hash() + require.Equal(t, hash1, hash2) require.NotEqual(t, lbls.Hash(), FromStrings("foo", "bar").Hash(), "different labels match.") }