Make mad_over_time experimental and move tests

Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
pull/13059/head
Jeanette Tan 1 year ago
parent 9bf4cc993e
commit 2910b48180

@ -15,7 +15,6 @@ package promql
import (
"context"
"fmt"
"math"
"testing"
"time"
@ -87,52 +86,3 @@ func TestKahanSum(t *testing.T) {
expected := 2.0
require.Equal(t, expected, kahanSum(vals))
}
func TestMadOverTime(t *testing.T) {
cases := []struct {
series []int
expectedRes float64
}{
{
series: []int{4, 6, 2, 1, 999, 1, 2},
expectedRes: 1,
},
}
for i, c := range cases {
t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) {
engine := newTestEngine()
storage := teststorage.New(t)
t.Cleanup(func() { storage.Close() })
seriesName := "float_series"
ts := int64(0)
app := storage.Appender(context.Background())
lbls := labels.FromStrings("__name__", seriesName)
var err error
for _, num := range c.series {
_, err = app.Append(0, lbls, ts, float64(num))
require.NoError(t, err)
ts += int64(1 * time.Minute / time.Millisecond)
}
require.NoError(t, app.Commit())
queryAndCheck := func(queryString string, exp Vector) {
qry, err := engine.NewInstantQuery(context.Background(), storage, nil, queryString, timestamp.Time(ts))
require.NoError(t, err)
res := qry.Exec(context.Background())
require.NoError(t, res.Err)
vector, err := res.Vector()
require.NoError(t, err)
require.Equal(t, exp, vector)
}
queryString := fmt.Sprintf(`mad_over_time(%s[%dm])`, seriesName, len(c.series))
queryAndCheck(queryString, []Sample{{T: ts, F: c.expectedRes, Metric: labels.EmptyLabels()}})
})
}
}

@ -258,6 +258,7 @@ var Functions = map[string]*Function{
Name: "mad_over_time",
ArgTypes: []ValueType{ValueTypeMatrix},
ReturnType: ValueTypeVector,
Experimental: true,
},
"max_over_time": {
Name: "max_over_time",

@ -739,6 +739,14 @@ eval instant at 1m stdvar_over_time(metric[1m])
eval instant at 1m stddev_over_time(metric[1m])
{} 0
# Tests for mad_over_time.
clear
load 10s
metric 4 6 2 1 999 1 2
eval instant at 70s mad_over_time(metric[70s])
{} 1
# Tests for quantile_over_time
clear

Loading…
Cancel
Save