From efd4e05fcadc1e7c83b8a6f80ea37736e4817410 Mon Sep 17 00:00:00 2001 From: Aryansharma9917 Date: Sun, 14 May 2023 18:04:22 +0530 Subject: [PATCH] #138 : Added absent_over_time support function --- engine/engine_test.go | 10 ++++++++++ execution/function/functions.go | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/engine/engine_test.go b/engine/engine_test.go index 57315d02..735cb8d3 100644 --- a/engine/engine_test.go +++ b/engine/engine_test.go @@ -184,6 +184,16 @@ func TestQueriesAgainstOldEngine(t *testing.T) { http_requests_total{pod="nginx-2"} -5+2x18`, query: "abs(http_requests_total)", }, + { + name: "absent_over_time", + load: `load 30s + http_requests_total{pod="nginx-1"} 1+1x15 + http_requests_total{pod="nginx-2"} 1+2x18 + http_requests_total{pod="nginx-2"} 1+2x18 + http_requests_total{pod="nginx-2"} 1+2x18 + http_requests_total{pod="nginx-2"} 1+2x18`, + query: "absent_over_time(http_requests_total[30s])", + }, { name: "ceil", load: `load 30s diff --git a/execution/function/functions.go b/execution/function/functions.go index e59aab56..302536fc 100644 --- a/execution/function/functions.go +++ b/execution/function/functions.go @@ -87,6 +87,13 @@ var Funcs = map[string]FunctionCall{ "deg": simpleFunc(func(v float64) float64 { return v * 180 / math.Pi }), + "absent_over_time": simpleFunc(func(v float64) float64 { + if v > 0 { + return 0 + } else { + return 1 + } + }), "sgn": simpleFunc(func(v float64) float64 { var sign float64 if v > 0 {