From a94825b16900b5bdb034e9147277230f11056511 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 12 Oct 2020 11:36:47 +0300 Subject: [PATCH] Revert "app/vmselect/promql: remove metric name after applying `clamp_min` and `clamp_max` functions in order to be consistent with Prometheus" This reverts commit bb61a4769bf7e3f4b200c3970138f289a6ff8bdc. Reason for revert: the previous behavior for VictoriaMetrics is easier to understand and use by users - functions, which don't change the meaning of the time series shouldn't drop metric name. Now the following functions do not drop metric name: * clamp_min * clamp_max Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/674 --- app/vmselect/promql/exec_test.go | 2 ++ app/vmselect/promql/transform.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/vmselect/promql/exec_test.go b/app/vmselect/promql/exec_test.go index 6f347e613..cf4e1c6e3 100644 --- a/app/vmselect/promql/exec_test.go +++ b/app/vmselect/promql/exec_test.go @@ -636,6 +636,7 @@ func TestExecSuccess(t *testing.T) { Values: []float64{1000, 1200, 1400, 1400, 1400, 1400}, Timestamps: timestampsExpected, } + r.MetricName.MetricGroup = []byte("foobar") resultExpected := []netstorage.Result{r} f(q, resultExpected) }) @@ -647,6 +648,7 @@ func TestExecSuccess(t *testing.T) { Values: []float64{1000, 1200, 1400, 1400, 1400, 1400}, Timestamps: timestampsExpected, } + r.MetricName.MetricGroup = []byte("foobar") resultExpected := []netstorage.Result{r} f(q, resultExpected) }) diff --git a/app/vmselect/promql/transform.go b/app/vmselect/promql/transform.go index b43638b13..cc1e00027 100644 --- a/app/vmselect/promql/transform.go +++ b/app/vmselect/promql/transform.go @@ -17,6 +17,11 @@ import ( "github.com/valyala/histogram" ) +var transformFuncsKeepMetricGroup = map[string]bool{ + "clamp_max": true, + "clamp_min": true, +} + var transformFuncs = map[string]transformFunc{ // Standard promql funcs // See funcs accepting instant-vector on https://prometheus.io/docs/prometheus/latest/querying/functions/ . @@ -125,8 +130,12 @@ func newTransformFuncOneArg(tf func(v float64) float64) transformFunc { } func doTransformValues(arg []*timeseries, tf func(values []float64), fe *metricsql.FuncExpr) ([]*timeseries, error) { + name := strings.ToLower(fe.Name) + keepMetricGroup := transformFuncsKeepMetricGroup[name] for _, ts := range arg { - ts.MetricName.ResetMetricGroup() + if !keepMetricGroup { + ts.MetricName.ResetMetricGroup() + } tf(ts.Values) } return arg, nil