From 000c154641d1ce29a856fa6d8885477a1e59131e Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 4 Aug 2019 19:32:18 +0300 Subject: [PATCH] app/vmselect/promql: tune automatic window adjustement Increase the windows adjustement for small scrape intervals, since they usually have higher jitter. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/139 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/134 --- app/vmselect/promql/rollup.go | 23 ++++++++++++++++++++--- app/vmselect/promql/rollup_test.go | 10 +++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/vmselect/promql/rollup.go b/app/vmselect/promql/rollup.go index 6099b58c8..a627c209e 100644 --- a/app/vmselect/promql/rollup.go +++ b/app/vmselect/promql/rollup.go @@ -231,10 +231,27 @@ func getMaxPrevInterval(timestamps []int64) int64 { } d := (timestamps[len(timestamps)-1] - timestamps[0]) / int64(len(timestamps)-1) if d <= 0 { - return 1 + return int64(maxSilenceInterval) } - // Slightly increase d in order to handle possible jitter in scrape interval. - return d + (d / 4) + // Increase d more for smaller scrape intervals in order to hide possible gaps + // when high jitter is present. + // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/139 . + if d <= 2*1000 { + return d + 4*d + } + if d <= 4*1000 { + return d + 2*d + } + if d <= 8*1000 { + return d + d + } + if d <= 16*1000 { + return d + d/2 + } + if d <= 32*1000 { + return d + d/4 + } + return d + d/8 } func removeCounterResets(values []float64) { diff --git a/app/vmselect/promql/rollup_test.go b/app/vmselect/promql/rollup_test.go index fdb79c8d3..fcf598b63 100644 --- a/app/vmselect/promql/rollup_test.go +++ b/app/vmselect/promql/rollup_test.go @@ -347,7 +347,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, nan} + valuesExpected := []float64{2, 0, 0, 0, 0, 0, 0, 0} timestampsExpected := []int64{120, 124, 128, 132, 136, 140, 144, 148} testRowsEqual(t, values, rc.Timestamps, valuesExpected, timestampsExpected) }) @@ -371,15 +371,15 @@ func TestRollupWindowNoPoints(t *testing.T) { t.Run("afterEnd", func(t *testing.T) { rc := rollupConfig{ Func: rollupFirst, - Start: 141, - End: 171, + Start: 161, + End: 191, Step: 10, Window: 3, } rc.Timestamps = getTimestamps(rc.Start, rc.End, rc.Step) values := rc.Do(nil, testValues, testTimestamps) - valuesExpected := []float64{34, nan, nan, nan} - timestampsExpected := []int64{141, 151, 161, 171} + valuesExpected := []float64{34, 34, 34, nan} + timestampsExpected := []int64{161, 171, 181, 191} testRowsEqual(t, values, rc.Timestamps, valuesExpected, timestampsExpected) }) }