From 5839112cdaed5071687ca3b119aff32ecf152f9c Mon Sep 17 00:00:00 2001 From: Roman Khavronenko Date: Mon, 26 Sep 2022 14:33:25 +0200 Subject: [PATCH] vmselect/rollup: rm workaround for slow-changing counters (#3163) The workaround was introduced to fix https://github.com/VictoriaMetrics/VictoriaMetrics/issues/962. However, it didn't prove itself useful. Instead, it is recommended using `increase_pure` function. Removing the workaround makes VM to produce accurate results when calculating `delta` or `increase` functions over slow-changing counters with vary intervals between data points. Signed-off-by: hagen1778 Signed-off-by: hagen1778 --- app/vmselect/promql/rollup.go | 10 ++-------- app/vmselect/promql/rollup_test.go | 11 ++++------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/app/vmselect/promql/rollup.go b/app/vmselect/promql/rollup.go index 8c40bbdbcd..62f2e040e0 100644 --- a/app/vmselect/promql/rollup.go +++ b/app/vmselect/promql/rollup.go @@ -1485,11 +1485,8 @@ func rollupDelta(rfa *rollupFuncArg) float64 { // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/894 return values[len(values)-1] - rfa.realPrevValue } - // Assume that the previous non-existing value was 0 only in the following cases: - // - // - If the delta with the next value equals to 0. - // This is the case for slow-changing counter - see https://github.com/VictoriaMetrics/VictoriaMetrics/issues/962 - // - If the first value doesn't exceed too much the delta with the next value. + // Assume that the previous non-existing value was 0 + // only if the first value doesn't exceed too much the delta with the next value. // // This should prevent from improper increase() results for os-level counters // such as cpu time or bytes sent over the network interface. @@ -1503,9 +1500,6 @@ func rollupDelta(rfa *rollupFuncArg) float64 { } else if !math.IsNaN(rfa.realNextValue) { d = rfa.realNextValue - values[0] } - if d == 0 { - d = 10 - } if math.Abs(values[0]) < 10*(math.Abs(d)+1) { prevValue = 0 } else { diff --git a/app/vmselect/promql/rollup_test.go b/app/vmselect/promql/rollup_test.go index 477f139d86..02db211327 100644 --- a/app/vmselect/promql/rollup_test.go +++ b/app/vmselect/promql/rollup_test.go @@ -1383,19 +1383,16 @@ func TestRollupDelta(t *testing.T) { // Small initial value f(nan, nan, nan, []float64{1}, 1) - f(nan, nan, nan, []float64{10}, 10) - f(nan, nan, nan, []float64{100}, 100) + f(nan, nan, nan, []float64{10}, 0) + f(nan, nan, nan, []float64{100}, 0) f(nan, nan, nan, []float64{1, 2, 3}, 3) f(1, nan, nan, []float64{1, 2, 3}, 2) f(nan, nan, nan, []float64{5, 6, 8}, 8) f(2, nan, nan, []float64{5, 6, 8}, 6) - // Moderate initial value with zero delta after that. - // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/962 - f(nan, nan, nan, []float64{100}, 100) - f(nan, nan, nan, []float64{100, 100}, 100) + f(nan, nan, nan, []float64{100, 100}, 0) - // Big initial value with with zero delta after that. + // Big initial value with zero delta after that. f(nan, nan, nan, []float64{1000}, 0) f(nan, nan, nan, []float64{1000, 1000}, 0)