Skip to content

Commit

Permalink
Merge pull request prometheus#13559 from prometheus/beorn7/promql
Browse files Browse the repository at this point in the history
promql: Fix wrongly scoped range vectors
  • Loading branch information
beorn7 authored Feb 12, 2024
2 parents b66b0a5 + 553d92a commit 1efca80
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion model/labels/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}

Expand Down
12 changes: 8 additions & 4 deletions promql/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions promql/testdata/functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1efca80

Please sign in to comment.