From f78ffe565f2675d3e7b90b73dbdf4062f5976443 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 4 Sep 2019 16:22:06 +0300 Subject: [PATCH] app/vmselect/promql: do not return artificial points beyond the last point in time series --- app/vmselect/promql/rollup.go | 2 +- app/vmselect/promql/rollup_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/vmselect/promql/rollup.go b/app/vmselect/promql/rollup.go index 7d3c888330..de14eb0e77 100644 --- a/app/vmselect/promql/rollup.go +++ b/app/vmselect/promql/rollup.go @@ -211,7 +211,7 @@ func (rc *rollupConfig) Do(dstValues []float64, values []float64, timestamps []i rfa.prevValue = nan rfa.prevTimestamp = tStart - maxPrevInterval - if i > 0 && timestamps[i-1] > rfa.prevTimestamp { + if i < len(timestamps) && i > 0 && timestamps[i-1] > rfa.prevTimestamp { rfa.prevValue = values[i-1] rfa.prevTimestamp = timestamps[i-1] } diff --git a/app/vmselect/promql/rollup_test.go b/app/vmselect/promql/rollup_test.go index eba0447b3a..90c6c58dce 100644 --- a/app/vmselect/promql/rollup_test.go +++ b/app/vmselect/promql/rollup_test.go @@ -359,7 +359,7 @@ func TestRollupNoWindowNoPoints(t *testing.T) { } rc.Timestamps = getTimestamps(rc.Start, rc.End, rc.Step) values := rc.Do(nil, testValues, testTimestamps) - valuesExpected := []float64{2, 0, 0, 0, 0, 0, 0, 0} + valuesExpected := []float64{2, 0, 0, 0, nan, nan, nan, nan} timestampsExpected := []int64{120, 124, 128, 132, 136, 140, 144, 148} testRowsEqual(t, values, rc.Timestamps, valuesExpected, timestampsExpected) }) @@ -390,7 +390,7 @@ func TestRollupWindowNoPoints(t *testing.T) { } rc.Timestamps = getTimestamps(rc.Start, rc.End, rc.Step) values := rc.Do(nil, testValues, testTimestamps) - valuesExpected := []float64{34, 34, 34, nan} + valuesExpected := []float64{nan, nan, nan, nan} timestampsExpected := []int64{161, 171, 181, 191} testRowsEqual(t, values, rc.Timestamps, valuesExpected, timestampsExpected) }) @@ -421,7 +421,7 @@ func TestRollupNoWindowPartialPoints(t *testing.T) { } rc.Timestamps = getTimestamps(rc.Start, rc.End, rc.Step) values := rc.Do(nil, testValues, testTimestamps) - valuesExpected := []float64{12, 44, 34, 34} + valuesExpected := []float64{12, 44, 34, nan} timestampsExpected := []int64{100, 120, 140, 160} testRowsEqual(t, values, rc.Timestamps, valuesExpected, timestampsExpected) }) @@ -466,7 +466,7 @@ func TestRollupWindowPartialPoints(t *testing.T) { } rc.Timestamps = getTimestamps(rc.Start, rc.End, rc.Step) values := rc.Do(nil, testValues, testTimestamps) - valuesExpected := []float64{44, 34, 34, 34} + valuesExpected := []float64{44, 34, 34, nan} timestampsExpected := []int64{100, 120, 140, 160} testRowsEqual(t, values, rc.Timestamps, valuesExpected, timestampsExpected) }) @@ -480,7 +480,7 @@ func TestRollupWindowPartialPoints(t *testing.T) { } rc.Timestamps = getTimestamps(rc.Start, rc.End, rc.Step) values := rc.Do(nil, testValues, testTimestamps) - valuesExpected := []float64{nan, 54, 44, 34} + valuesExpected := []float64{nan, 54, 44, nan} timestampsExpected := []int64{0, 50, 100, 150} testRowsEqual(t, values, rc.Timestamps, valuesExpected, timestampsExpected) })