diff --git a/app/vmselect/promql/rollup.go b/app/vmselect/promql/rollup.go index 6099b58c83..a627c209ea 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 fdb79c8d37..fcf598b63a 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) }) }