diff --git a/app/vmselect/promql/rollup.go b/app/vmselect/promql/rollup.go index 3bb5f8463..cedcf1958 100644 --- a/app/vmselect/promql/rollup.go +++ b/app/vmselect/promql/rollup.go @@ -1308,8 +1308,11 @@ 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 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 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. // // This should prevent from improper increase() results for os-level counters // such as cpu time or bytes sent over the network interface. @@ -1317,12 +1320,15 @@ func rollupDelta(rfa *rollupFuncArg) float64 { // // This also should prevent from improper increase() results when a part of label values are changed // without counter reset. - d := float64(10) + var d float64 if len(values) > 1 { d = values[1] - values[0] } 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 ad9a7b7e4..b736d6259 100644 --- a/app/vmselect/promql/rollup_test.go +++ b/app/vmselect/promql/rollup_test.go @@ -1171,8 +1171,16 @@ func TestRollupDelta(t *testing.T) { f(nan, nan, nan, []float64{5, 6, 8}, 8) f(2, nan, nan, []float64{5, 6, 8}, 6) - // Too big initial value must be skipped. + // 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) + + // Big initial value with with zero delta after that. f(nan, nan, nan, []float64{1000}, 0) + f(nan, nan, nan, []float64{1000, 1000}, 0) + + // Big initial value with small delta after that. f(nan, nan, nan, []float64{1000, 1001, 1002}, 2) // Non-nan realPrevValue diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 47cdf0c41..0b50310fe 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -21,6 +21,7 @@ * BUGFIX: do not enable strict parsing for `-promscrape.config` if `-promscrape.config.dryRun` comand-line flag is set. Strict parsing can be enabled with `-promscrape.config.strictParse` command-line flag. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/944 * BUGFIX: vminsert: properly update `vm_rpc_rerouted_rows_processed_total` metric. Previously it wasn't updated. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/955 * BUGFIX: vmagent: properly recover when opening incorrectly stored persistent queue. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/964 +* BUGFIX: assume the previous value is 0 when calculating `increase()` for the first point on the graph if its value doesn't exceed 100 and the delta between two first points equals to 0. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/962 # [v1.49.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.49.0)