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.") } 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 } 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