From e7e40159edbb604e0707c379a441fc4128e5a47b Mon Sep 17 00:00:00 2001 From: Cyril Tovena Date: Mon, 7 Dec 2020 17:18:04 +0100 Subject: [PATCH 1/2] Add absent_over_time This adds absent_over_time which is super useful when alerting, it can be combine with any logql selector including parsers and filter to returns a timeseries with 1 when logs go missing. Fixes #2893 Signed-off-by: Cyril Tovena --- docs/sources/logql/_index.md | 3 +- pkg/logql/ast.go | 5 +- pkg/logql/ast_test.go | 2 + pkg/logql/engine_test.go | 35 +++++ pkg/logql/evaluator.go | 91 ++++++++++- pkg/logql/expr.y | 3 +- pkg/logql/expr.y.go | 296 ++++++++++++++++++----------------- pkg/logql/functions.go | 6 + pkg/logql/lex.go | 1 + pkg/logql/parser_test.go | 18 +++ 10 files changed, 308 insertions(+), 152 deletions(-) diff --git a/docs/sources/logql/_index.md b/docs/sources/logql/_index.md index b5e28679db17..c65c2245e93d 100644 --- a/docs/sources/logql/_index.md +++ b/docs/sources/logql/_index.md @@ -430,8 +430,9 @@ Supported function for operating over unwrapped ranges are: - `stdvar_over_time(unwrapped-range)`: the population standard variance of the values in the specified interval. - `stddev_over_time(unwrapped-range)`: the population standard deviation of the values in the specified interval. - `quantile_over_time(scalar,unwrapped-range)`: the φ-quantile (0 ≤ φ ≤ 1) of the values in the specified interval. +- `absent_over_time(unwrapped-range)`: returns an empty vector if the range vector passed to it has any elements and a 1-element vector with the value 1 if the range vector passed to it has no elements. (`absent_over_time` is useful for alerting on when no time series and logs stream exist for label combination for a certain amount of time.) -Except for `sum_over_time`, unwrapped range aggregations support grouping. +Except for `sum_over_time` and `absent_over_time`, unwrapped range aggregations support grouping. ```logql ([parameter,] ) [without|by (