diff --git a/engine/engine_test.go b/engine/engine_test.go index 30118e6e..77719780 100644 --- a/engine/engine_test.go +++ b/engine/engine_test.go @@ -340,6 +340,18 @@ func TestQueriesAgainstOldEngine(t *testing.T) { http_requests_total{pod="nginx-2"} 1+2x18`, query: "count_over_time(http_requests_total[30s])", }, + { + name: "absent", + load: `load 30s + http_requests_total{pod="nginx-1"} 0 + http_requests_total{pod="nginx-2"} 1`, + query: "absent(http_requests_total[30s])", + }, + { + name: "absent", + load: `load 30s`, + query: "absent(http_requests_total[30s])", + }, { name: "average", load: `load 30s diff --git a/execution/function/functions.go b/execution/function/functions.go index b4dc75e0..3afdc7ec 100644 --- a/execution/function/functions.go +++ b/execution/function/functions.go @@ -68,6 +68,21 @@ var Funcs = map[string]FunctionCall{ "asinh": simpleFunc(math.Asinh), "acosh": simpleFunc(math.Acosh), "atanh": simpleFunc(math.Atanh), + "absent": func(f FunctionArgs) promql.Sample { + if len(f.Points) == 0 { + return promql.Sample{ + Metric: f.Labels, + Point: promql.Point{ + T: f.StepTime, + V: 1, + }, + } + } + return promql.Sample{ + Metric: f.Labels, + Point: promql.Point{}, + } + }, "rad": simpleFunc(func(v float64) float64 { return v * math.Pi / 180 }),