diff --git a/storage/metric/operation.go b/storage/metric/operation.go index 595cfaf19..f390caaae 100644 --- a/storage/metric/operation.go +++ b/storage/metric/operation.go @@ -161,12 +161,12 @@ func (g *getValuesAtIntervalOp) ExtractSamples(in model.Values) (out model.Value lastExtractedTime := out[len(out)-1].Timestamp in = in.TruncateBefore(lastExtractedTime.Add(1)) g.from = g.from.Add(g.interval) - if lastExtractedTime.Equal(lastChunkTime) { - break - } for !g.from.After(lastExtractedTime) { g.from = g.from.Add(g.interval) } + if lastExtractedTime.Equal(lastChunkTime) { + break + } if g.from.After(g.through) { break } diff --git a/storage/metric/operation_test.go b/storage/metric/operation_test.go index 772f439da..a7744ce3a 100644 --- a/storage/metric/operation_test.go +++ b/storage/metric/operation_test.go @@ -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", 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 { if out != actual[j] { t.Fatalf("%d. expected output %v, got %v", i, scenario.out, actual)