app/vmselect/promql: add alias(q, name) function that sets the given name to all the time series in q

This commit is contained in:
Aliaksandr Valialkin 2019-05-24 02:41:45 +03:00
parent 674888fdc9
commit d15d0127fe
2 changed files with 17 additions and 0 deletions

View file

@ -789,6 +789,18 @@ func TestExecSuccess(t *testing.T) {
resultExpected := []netstorage.Result{} resultExpected := []netstorage.Result{}
f(q, resultExpected) 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.Run(`label_set(tag)`, func(t *testing.T) {
t.Parallel() t.Parallel()
q := `label_set(time(), "tagname", "tagvalue")` q := `label_set(time(), "tagname", "tagvalue")`
@ -3535,6 +3547,9 @@ func TestExecError(t *testing.T) {
f(`keep_last_value()`) f(`keep_last_value()`)
f(`distinct_over_time()`) f(`distinct_over_time()`)
f(`distinct()`) f(`distinct()`)
f(`alias()`)
f(`alias(1)`)
f(`alias(1, "foo", "bar")`)
// Invalid argument type // Invalid argument type
f(`median_over_time({}, 2)`) 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", 3, 4)`)
f(`label_transform(1, "foo", "bar", 4)`) f(`label_transform(1, "foo", "bar", 4)`)
f(`label_transform(1, "foo", "invalid(regexp", "baz`) f(`label_transform(1, "foo", "invalid(regexp", "baz`)
f(`alias(1, 2)`)
// Duplicate timeseries // Duplicate timeseries
f(`(label_set(1, "foo", "bar") or label_set(2, "foo", "baz")) f(`(label_set(1, "foo", "bar") or label_set(2, "foo", "baz"))

View file

@ -25,6 +25,7 @@ func getDefaultWithArgExprs() []*withArgExpr {
`median_over_time(m) = quantile_over_time(0.5, m)`, `median_over_time(m) = quantile_over_time(0.5, m)`,
`range_median(q) = range_quantile(0.5, q)`, `range_median(q) = range_quantile(0.5, q)`,
`alias(q, name) = label_set(q, "__name__", name)`,
}) })
}) })
return defaultWithArgExprs return defaultWithArgExprs