From d68cdb8f9c14bb428e1379d8d86c6afcccc62d40 Mon Sep 17 00:00:00 2001 From: Cyril Tovena Date: Mon, 7 Dec 2020 11:23:23 +0100 Subject: [PATCH] Support rate for unwrap expressions. This allows to bytes throughput if there were printed in a log line. Examples : ```logql sum by (device) (rate({app="network-dev"} |= "192.16.8.1" | json | unwrap recv_bytes [1m])) ``` Closes #3044 Signed-off-by: Cyril Tovena --- docs/sources/logql/_index.md | 5 ++-- pkg/logql/ast.go | 2 +- pkg/logql/engine_test.go | 49 +++++++++++++++++++++++++++++++++++- pkg/logql/functions.go | 13 +++++++--- 4 files changed, 62 insertions(+), 7 deletions(-) diff --git a/docs/sources/logql/_index.md b/docs/sources/logql/_index.md index 50a89785e59b..d3c69fa91965 100644 --- a/docs/sources/logql/_index.md +++ b/docs/sources/logql/_index.md @@ -417,12 +417,13 @@ The unwrap expression is noted `| unwrap label_identifier` where the label ident Since label values are string, by default a conversion into a float (64bits) will be attempted, in case of failure the `__error__` label is added to the sample. Optionally the label identifier can be wrapped by a conversion function `| unwrap (label_identifier)`, which will attempt to convert the label value from a specific format. -We currently support the functions: +We currently support the functions: - `duration_seconds(label_identifier)` (or its short equivalent `duration`) which will convert the label value in seconds from the [go duration format](https://golang.org/pkg/time/#ParseDuration) (e.g `5m`, `24s30ms`). - `bytes(label_identifier)` which will convert the label value to raw bytes applying the bytes unit (e.g. `5 MiB`, `3k`, `1G`). Supported function for operating over unwrapped ranges are: +- `rate(log-range)`: calculates per second rate of all values in the specified interval. - `sum_over_time(unwrapped-range)`: the sum of all values in the specified interval. - `avg_over_time(unwrapped-range)`: the average value of all points in the specified interval. - `max_over_time(unwrapped-range)`: the maximum value of all points in the specified interval. @@ -431,7 +432,7 @@ Supported function for operating over unwrapped ranges are: - `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. -Except for `sum_over_time`, `min_over_time` and `max_over_time` unwrapped range aggregations support grouping. +Except for `sum_over_time` and `rate` unwrapped range aggregations support grouping. ```logql ([parameter,] ) [without|by (