From fd6ca57c14f1ceee89bf71567f757a24e2e6b18f Mon Sep 17 00:00:00 2001 From: Zakhar Bessarab Date: Mon, 25 Sep 2023 16:01:00 +0400 Subject: [PATCH] app/vmselect/promql: add implementation of median_over_time for rollup functions list (#5042) `median_over_time` is handled by predefined WITH template in MetricsQL library which translates it to `quantile_over_time(0.5)` This makes it impossble to use `median_over_time` as a usual rollup function for `aggr_over_time`. See: https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5034 Signed-off-by: Zakhar Bessarab --- app/vmselect/promql/rollup.go | 10 ++++++++-- docs/CHANGELOG.md | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/vmselect/promql/rollup.go b/app/vmselect/promql/rollup.go index 2cf8273445..cfbc030554 100644 --- a/app/vmselect/promql/rollup.go +++ b/app/vmselect/promql/rollup.go @@ -7,11 +7,12 @@ import ( "strings" "sync" + "github.com/VictoriaMetrics/metrics" + "github.com/VictoriaMetrics/metricsql" + "github.com/VictoriaMetrics/VictoriaMetrics/lib/decimal" "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" "github.com/VictoriaMetrics/VictoriaMetrics/lib/storage" - "github.com/VictoriaMetrics/metrics" - "github.com/VictoriaMetrics/metricsql" ) var minStalenessInterval = flag.Duration("search.minStalenessInterval", 0, "The minimum interval for staleness calculations. "+ @@ -125,6 +126,7 @@ var rollupAggrFuncs = map[string]rollupFunc{ "lifetime": rollupLifetime, "mad_over_time": rollupMAD, "max_over_time": rollupMax, + "median_over_time": rollupMedian, "min_over_time": rollupMin, "mode_over_time": rollupModeOverTime, "present_over_time": rollupPresent, @@ -1396,6 +1398,10 @@ func rollupMax(rfa *rollupFuncArg) float64 { return maxValue } +func rollupMedian(rfa *rollupFuncArg) float64 { + return quantile(0.5, rfa.values) +} + func rollupTmin(rfa *rollupFuncArg) float64 { // There is no need in handling NaNs here, since they must be cleaned up // before calling rollup funcs. diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a32ceb4131..eec787fa7c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -55,6 +55,7 @@ The sandbox cluster installation is running under the constant load generated by * BUGFIX: [VictoriaMetrics enterprise](https://docs.victoriametrics.com/enterprise.html) validate `-dedup.minScrapeInterval` value and `-downsampling.period` intervals are multiples of each other. See [these docs](https://docs.victoriametrics.com/#downsampling). * BUGFIX: [vmbackup](https://docs.victoriametrics.com/vmbackup.html): properly copy `appliedRetention.txt` files inside `<-storageDataPath>/{data}` folders during [incremental backups](https://docs.victoriametrics.com/vmbackup.html#incremental-backups). Previously the new `appliedRetention.txt` could be skipped during incremental backups, which could lead to increased load on storage after restoring from backup. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5005). * BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): suppress `context canceled` error messages in logs when `vmagent` is reloading service discovery config. This error could appear starting from [v1.93.5](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.93.5). See [this PR](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5048). +* BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): allow using `median_over_time` in [`aggr_over_time`](https://docs.victoriametrics.com/MetricsQL.html#aggr_over_time) [rollup function](https://docs.victoriametrics.com/MetricsQL.html#rollup-functions). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5034). ## [v1.93.5](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.93.5)