Skip to content

Commit

Permalink
Correctly track points no longer used by matrixIterSlice's slice. (pr…
Browse files Browse the repository at this point in the history
…ometheus#7307)

Signed-off-by: Brian Brazil <[email protected]>
  • Loading branch information
brian-brazil authored May 28, 2020
1 parent 7a541bd commit 3932a71
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions promql/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,7 @@ func (ev *evaluator) eval(expr parser.Expr) parser.Value {
// Process all the calls for one time series at a time.
it := storage.NewBuffer(selRange)
for i, s := range selVS.Series {
ev.currentSamples -= len(points)
points = points[:0]
it.Reset(s.Iterator())
ss := Series{
Expand Down Expand Up @@ -1170,6 +1171,7 @@ func (ev *evaluator) eval(expr parser.Expr) parser.Value {
}
}

ev.currentSamples -= len(points)
putPointSlice(points)

// The absent_over_time function returns 0 or 1 series. So far, the matrix
Expand Down Expand Up @@ -1480,11 +1482,13 @@ func (ev *evaluator) matrixIterSlice(it *storage.BufferedSeriesIterator, mint, m
var drop int
for drop = 0; out[drop].T < mint; drop++ {
}
ev.currentSamples -= drop
copy(out, out[drop:])
out = out[:len(out)-drop]
// Only append points with timestamps after the last timestamp we have.
mint = out[len(out)-1].T + 1
} else {
ev.currentSamples -= len(out)
out = out[:0]
}

Expand Down
14 changes: 14 additions & 0 deletions promql/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@ func TestMaxQuerySamples(t *testing.T) {
test, err := NewTest(t, `
load 10s
metric 1 2
bigmetric{a="1"} 1 2
bigmetric{a="2"} 1 2
`)
testutil.Ok(t, err)
defer test.Close()
Expand Down Expand Up @@ -799,6 +801,18 @@ load 10s
End: time.Unix(10, 0),
Interval: 5 * time.Second,
},
{
Query: "rate(bigmetric[1s])",
MaxSamples: 1,
Result: Result{
nil,
Matrix{},
nil,
},
Start: time.Unix(0, 0),
End: time.Unix(10, 0),
Interval: 5 * time.Second,
},
}

engine := test.QueryEngine()
Expand Down

0 comments on commit 3932a71

Please sign in to comment.