diff --git a/promql/functions_test.go b/promql/functions_test.go index abc8f9dc6..faf6859e7 100644 --- a/promql/functions_test.go +++ b/promql/functions_test.go @@ -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()}}) - }) - } -} diff --git a/promql/parser/functions.go b/promql/parser/functions.go index aafb375da..46d50d547 100644 --- a/promql/parser/functions.go +++ b/promql/parser/functions.go @@ -255,9 +255,10 @@ var Functions = map[string]*Function{ ReturnType: ValueTypeVector, }, "mad_over_time": { - Name: "mad_over_time", - ArgTypes: []ValueType{ValueTypeMatrix}, - ReturnType: ValueTypeVector, + Name: "mad_over_time", + ArgTypes: []ValueType{ValueTypeMatrix}, + ReturnType: ValueTypeVector, + Experimental: true, }, "max_over_time": { Name: "max_over_time", diff --git a/promql/testdata/functions.test b/promql/testdata/functions.test index b5263a96f..b4547886a 100644 --- a/promql/testdata/functions.test +++ b/promql/testdata/functions.test @@ -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