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 <roman@victoriametrics.com>

Signed-off-by: hagen1778 <roman@victoriametrics.com>
This commit is contained in:
Roman Khavronenko 2022-09-26 14:33:25 +02:00 committed by Aliaksandr Valialkin
parent dca89c7d2f
commit 5839112cda
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
2 changed files with 6 additions and 15 deletions

View file

@ -1485,11 +1485,8 @@ func rollupDelta(rfa *rollupFuncArg) float64 {
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/894 // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/894
return values[len(values)-1] - rfa.realPrevValue return values[len(values)-1] - rfa.realPrevValue
} }
// Assume that the previous non-existing value was 0 only in the following cases: // 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.
// - 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.
// //
// This should prevent from improper increase() results for os-level counters // This should prevent from improper increase() results for os-level counters
// such as cpu time or bytes sent over the network interface. // 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) { } else if !math.IsNaN(rfa.realNextValue) {
d = rfa.realNextValue - values[0] d = rfa.realNextValue - values[0]
} }
if d == 0 {
d = 10
}
if math.Abs(values[0]) < 10*(math.Abs(d)+1) { if math.Abs(values[0]) < 10*(math.Abs(d)+1) {
prevValue = 0 prevValue = 0
} else { } else {

View file

@ -1383,19 +1383,16 @@ func TestRollupDelta(t *testing.T) {
// Small initial value // Small initial value
f(nan, nan, nan, []float64{1}, 1) f(nan, nan, nan, []float64{1}, 1)
f(nan, nan, nan, []float64{10}, 10) f(nan, nan, nan, []float64{10}, 0)
f(nan, nan, nan, []float64{100}, 100) f(nan, nan, nan, []float64{100}, 0)
f(nan, nan, nan, []float64{1, 2, 3}, 3) f(nan, nan, nan, []float64{1, 2, 3}, 3)
f(1, nan, nan, []float64{1, 2, 3}, 2) f(1, nan, nan, []float64{1, 2, 3}, 2)
f(nan, nan, nan, []float64{5, 6, 8}, 8) f(nan, nan, nan, []float64{5, 6, 8}, 8)
f(2, nan, nan, []float64{5, 6, 8}, 6) f(2, nan, nan, []float64{5, 6, 8}, 6)
// Moderate initial value with zero delta after that. f(nan, nan, nan, []float64{100, 100}, 0)
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/962
f(nan, nan, nan, []float64{100}, 100)
f(nan, nan, nan, []float64{100, 100}, 100)
// 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}, 0)
f(nan, nan, nan, []float64{1000, 1000}, 0) f(nan, nan, nan, []float64{1000, 1000}, 0)