app/vmselect/promql: properly preserve metric name after applying functions in any case from transformFuncsKeepMetricGroup

This commit is contained in:
Aliaksandr Valialkin 2019-07-09 23:10:15 +03:00
parent 6ddfb06b52
commit 2db685c19c
2 changed files with 26 additions and 1 deletions

View File

@ -574,6 +574,30 @@ func TestExecSuccess(t *testing.T) {
resultExpected := []netstorage.Result{r}
f(q, resultExpected)
})
t.Run(`clamp_max(alias(time(),"foobar"), 1400)`, func(t *testing.T) {
t.Parallel()
q := `clamp_max(alias(time(), "foobar"), 1400)`
r := netstorage.Result{
MetricName: metricNameExpected,
Values: []float64{1000, 1200, 1400, 1400, 1400, 1400},
Timestamps: timestampsExpected,
}
r.MetricName.MetricGroup = []byte("foobar")
resultExpected := []netstorage.Result{r}
f(q, resultExpected)
})
t.Run(`CLAmp_MAx(alias(time(),"foobar"), 1400)`, func(t *testing.T) {
t.Parallel()
q := `CLAmp_MAx(alias(time(), "foobar"), 1400)`
r := netstorage.Result{
MetricName: metricNameExpected,
Values: []float64{1000, 1200, 1400, 1400, 1400, 1400},
Timestamps: timestampsExpected,
}
r.MetricName.MetricGroup = []byte("foobar")
resultExpected := []netstorage.Result{r}
f(q, resultExpected)
})
t.Run("clamp_min(time(), -time()+3000)", func(t *testing.T) {
t.Parallel()
q := `clamp_min(time(), -time()+2500)`

View File

@ -125,7 +125,8 @@ func newTransformFuncOneArg(tf func(v float64) float64) transformFunc {
}
func doTransformValues(arg []*timeseries, tf func(values []float64), fe *funcExpr) ([]*timeseries, error) {
keepMetricGroup := transformFuncsKeepMetricGroup[fe.Name]
name := strings.ToLower(fe.Name)
keepMetricGroup := transformFuncsKeepMetricGroup[name]
for _, ts := range arg {
if !keepMetricGroup {
ts.MetricName.ResetMetricGroup()