diff --git a/app/vmselect/promql/exec_test.go b/app/vmselect/promql/exec_test.go index 24265ee71..99816421d 100644 --- a/app/vmselect/promql/exec_test.go +++ b/app/vmselect/promql/exec_test.go @@ -789,6 +789,18 @@ func TestExecSuccess(t *testing.T) { resultExpected := []netstorage.Result{} f(q, resultExpected) }) + t.Run(`alias()`, func(t *testing.T) { + t.Parallel() + q := `alias(time(), "foobar")` + r := netstorage.Result{ + MetricName: metricNameExpected, + Values: []float64{1000, 1200, 1400, 1600, 1800, 2000}, + Timestamps: timestampsExpected, + } + r.MetricName.MetricGroup = []byte("foobar") + resultExpected := []netstorage.Result{r} + f(q, resultExpected) + }) t.Run(`label_set(tag)`, func(t *testing.T) { t.Parallel() q := `label_set(time(), "tagname", "tagvalue")` @@ -3535,6 +3547,9 @@ func TestExecError(t *testing.T) { f(`keep_last_value()`) f(`distinct_over_time()`) f(`distinct()`) + f(`alias()`) + f(`alias(1)`) + f(`alias(1, "foo", "bar")`) // Invalid argument type f(`median_over_time({}, 2)`) @@ -3568,6 +3583,7 @@ func TestExecError(t *testing.T) { f(`label_transform(1, "foo", 3, 4)`) f(`label_transform(1, "foo", "bar", 4)`) f(`label_transform(1, "foo", "invalid(regexp", "baz`) + f(`alias(1, 2)`) // Duplicate timeseries f(`(label_set(1, "foo", "bar") or label_set(2, "foo", "baz")) diff --git a/app/vmselect/promql/parser.go b/app/vmselect/promql/parser.go index 5193d1a3a..b909f7774 100644 --- a/app/vmselect/promql/parser.go +++ b/app/vmselect/promql/parser.go @@ -25,6 +25,7 @@ func getDefaultWithArgExprs() []*withArgExpr { `median_over_time(m) = quantile_over_time(0.5, m)`, `range_median(q) = range_quantile(0.5, q)`, + `alias(q, name) = label_set(q, "__name__", name)`, }) }) return defaultWithArgExprs