diff --git a/app/vmselect/promql/exec_test.go b/app/vmselect/promql/exec_test.go index 7ec9f90427..789726f18b 100644 --- a/app/vmselect/promql/exec_test.go +++ b/app/vmselect/promql/exec_test.go @@ -6419,9 +6419,9 @@ func TestExecSuccess(t *testing.T) { resultExpected := []netstorage.Result{r} f(q, resultExpected) }) - t.Run(`deriv(1)`, func(t *testing.T) { + t.Run(`deriv(N)`, func(t *testing.T) { t.Parallel() - q := `deriv(1)` + q := `deriv(1000)` r := netstorage.Result{ MetricName: metricNameExpected, Values: []float64{0, 0, 0, 0, 0, 0}, diff --git a/app/vmselect/promql/rollup.go b/app/vmselect/promql/rollup.go index f650f9bc48..2ef33f6e44 100644 --- a/app/vmselect/promql/rollup.go +++ b/app/vmselect/promql/rollup.go @@ -850,7 +850,7 @@ func linearRegression(rfa *rollupFuncArg) (float64, float64) { if n == 0 { return nan, nan } - if n == 1 { + if areConstValues(values) { return values[0], 0 } @@ -877,6 +877,20 @@ func linearRegression(rfa *rollupFuncArg) (float64, float64) { return v, k } +func areConstValues(values []float64) bool { + if len(values) <= 1 { + return true + } + vPrev := values[0] + for _, v := range values[1:] { + if v != vPrev { + return false + } + vPrev = v + } + return true +} + func newRollupDurationOverTime(args []interface{}) (rollupFunc, error) { if err := expectRollupArgsNum(args, 2); err != nil { return nil, err diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e25bfc5b8d..8c9ec1ae0f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -15,6 +15,7 @@ sort: 15 * BUGFIX: vmauth: properly take into account the value passed to `-maxIdleConnsPerBackend` command-line flag. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1300). * BUGFIX: vmagent: fix [reading data from Kafka](https://docs.victoriametrics.com/vmagent.html#reading-metrics-from-kafka). * BUGFIX: vmalert: fix [replay mode](https://docs.victoriametrics.com/vmalert.html#rules-backfilling) in enterprise version. +* BUGFIX: consistently return zero from [deriv()](https://docs.victoriametrics.com/MetricsQL.html#deriv) function applied to a constant time series. Previously it could return small non-zero values in this case. ## [v1.69.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.69.0) diff --git a/docs/vmauth.md b/docs/vmauth.md index 827e678e90..43a2605672 100644 --- a/docs/vmauth.md +++ b/docs/vmauth.md @@ -47,6 +47,7 @@ Each `url_prefix` in the [-auth.config](#auth-config) may contain either a singl users: # Requests with the 'Authorization: Bearer XXXX' header are proxied to http://localhost:8428 . # For example, http://vmauth:8427/api/v1/query is proxied to http://localhost:8428/api/v1/query + # Requests with the Basic Auth username=XXXX are proxied to http://localhost:8428 as well. - bearer_token: "XXXX" url_prefix: "http://localhost:8428"