mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 20:37:12 +01:00
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:
parent
674888fdc9
commit
d15d0127fe
@ -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"))
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user