From def5573f9204508fba028ee0df200eef806e0bfc Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 8 Feb 2024 02:30:55 +0200 Subject: [PATCH] app/vmselect/promql: properly handle precision errors in rollup functions changes(), increases_over_time() and resets() shouldn't take into account value changes, which may occur because of precision errors. The maximum guaranteed precision for raw samples stored in VictoriaMetrics is 12 decimal digits. So do not count relative changes for values if they are smaller than 1e-12 comparing to the value. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/767 --- app/vmselect/promql/rollup.go | 16 ++++++++++++++++ docs/CHANGELOG.md | 1 + 2 files changed, 17 insertions(+) diff --git a/app/vmselect/promql/rollup.go b/app/vmselect/promql/rollup.go index 14d9c5c08..e0ef427cf 100644 --- a/app/vmselect/promql/rollup.go +++ b/app/vmselect/promql/rollup.go @@ -1916,6 +1916,10 @@ func rollupChangesPrometheus(rfa *rollupFuncArg) float64 { n := 0 for _, v := range values[1:] { if v != prevValue { + if math.Abs(v-prevValue) < 1e-12*math.Abs(v) { + // This may be precision error. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/767#issuecomment-1650932203 + continue + } n++ prevValue = v } @@ -1939,6 +1943,10 @@ func rollupChanges(rfa *rollupFuncArg) float64 { } for _, v := range values { if v != prevValue { + if math.Abs(v-prevValue) < 1e-12*math.Abs(v) { + // This may be precision error. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/767#issuecomment-1650932203 + continue + } n++ prevValue = v } @@ -1967,6 +1975,10 @@ func rollupIncreases(rfa *rollupFuncArg) float64 { n := 0 for _, v := range values { if v > prevValue { + if math.Abs(v-prevValue) < 1e-12*math.Abs(v) { + // This may be precision error. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/767#issuecomment-1650932203 + continue + } n++ } prevValue = v @@ -1998,6 +2010,10 @@ func rollupResets(rfa *rollupFuncArg) float64 { n := 0 for _, v := range values { if v < prevValue { + if math.Abs(v-prevValue) < 1e-12*math.Abs(v) { + // This may be precision error. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/767#issuecomment-1650932203 + continue + } n++ } prevValue = v diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3b039c73a..4f7ff35cb 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -38,6 +38,7 @@ The sandbox cluster installation is running under the constant load generated by * FEATURE: [dashboards/all](https://grafana.com/orgs/victoriametrics): add new panel `CPU spent on GC`. It should help identifying cases when too much CPU is spent on garbage collection, and advice users on how this can be addressed. * BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): properly propagate [label filters](https://docs.victoriametrics.com/keyconcepts/#filtering) from multiple arguments passed to [aggregate functions](https://docs.victoriametrics.com/metricsql/#aggregate-functions). For example, `sum({job="foo"}, {job="bar"}) by (job) + a` was improperly optimized to `sum({job="foo"}, {job="bar"}) by (job) + a{job="foo"}` before being executed. This could lead to unexpected results. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5604). +* BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): properly handle precision errors when calculating [changes](https://docs.victoriametrics.com/metricsql/#changes), [changes_prometheus](https://docs.victoriametrics.com/metricsql/#changes_prometheus), [increases_over_time](https://docs.victoriametrics.com/metricsql/#increases_over_time) and [resets](https://docs.victoriametrics.com/metricsql/#resets) functions. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/767). * BUGFIX: all VictoriaMetrics components: consistently return 200 http status code from [`/-/reload` endpoint](https://docs.victoriametrics.com/vmagent/#configuration-update). Previously [single-node VictoriaMetrics](https://docs.victoriametrics.com/) was returning 204 http status code. See [this feature request](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5774). * BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): fix the graph dragging for Firefox and Safari. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5764). * BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): fix handling invalid timezone. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5732).