mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 06:04:05 -08:00
Make getValuesAtIntervalOp consume all chunk data in one pass.
This is mainly a small performance improvement, since we skip past the last extracted time immediately if it was also the last sample in the chunk, instead of trying to extract non-existent values before the chunk end again and again and only gradually approaching the end of the chunk.
This commit is contained in:
parent
83d60bed89
commit
f2b48b8c4a
|
@ -161,12 +161,12 @@ func (g *getValuesAtIntervalOp) ExtractSamples(in model.Values) (out model.Value
|
||||||
lastExtractedTime := out[len(out)-1].Timestamp
|
lastExtractedTime := out[len(out)-1].Timestamp
|
||||||
in = in.TruncateBefore(lastExtractedTime.Add(1))
|
in = in.TruncateBefore(lastExtractedTime.Add(1))
|
||||||
g.from = g.from.Add(g.interval)
|
g.from = g.from.Add(g.interval)
|
||||||
if lastExtractedTime.Equal(lastChunkTime) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
for !g.from.After(lastExtractedTime) {
|
for !g.from.After(lastExtractedTime) {
|
||||||
g.from = g.from.Add(g.interval)
|
g.from = g.from.Add(g.interval)
|
||||||
}
|
}
|
||||||
|
if lastExtractedTime.Equal(lastChunkTime) {
|
||||||
|
break
|
||||||
|
}
|
||||||
if g.from.After(g.through) {
|
if g.from.After(g.through) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -1610,6 +1610,16 @@ func TestGetValuesAtIntervalOp(t *testing.T) {
|
||||||
t.Fatalf("%d. expected length %d, got %d: %v", i, len(scenario.out), len(actual), scenario.op)
|
t.Fatalf("%d. expected length %d, got %d: %v", i, len(scenario.out), len(actual), scenario.op)
|
||||||
t.Fatalf("%d. expected length %d, got %d", i, len(scenario.out), len(actual))
|
t.Fatalf("%d. expected length %d, got %d", i, len(scenario.out), len(actual))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(scenario.in) < 1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
opTime := scenario.op.CurrentTime()
|
||||||
|
lastExtractedTime := scenario.out[len(scenario.out)-1].Timestamp
|
||||||
|
if opTime != nil && opTime.Before(lastExtractedTime) {
|
||||||
|
t.Fatalf("%d. expected op.CurrentTime() to be nil or after current chunk, %v, %v", i, scenario.op.CurrentTime(), scenario.out)
|
||||||
|
}
|
||||||
|
|
||||||
for j, out := range scenario.out {
|
for j, out := range scenario.out {
|
||||||
if out != actual[j] {
|
if out != actual[j] {
|
||||||
t.Fatalf("%d. expected output %v, got %v", i, scenario.out, actual)
|
t.Fatalf("%d. expected output %v, got %v", i, scenario.out, actual)
|
||||||
|
|
Loading…
Reference in a new issue