From c394ce94622411e9f4c4a6c5a554a2145fc4bbdd Mon Sep 17 00:00:00 2001 From: jkellerer Date: Wed, 4 Nov 2020 14:06:14 +0100 Subject: [PATCH] LogQL: Add unwrap bytes() conversion function (#2876) * Unwrap bytes: Added bytes() op to parser & lexer * Unwrap bytes: Added bytes() conversion function --- docs/sources/logql/_index.md | 4 +- pkg/logql/ast.go | 1 + pkg/logql/ast_test.go | 5 + pkg/logql/expr.y | 5 +- pkg/logql/expr.y.go | 658 +++++++++-------------- pkg/logql/functions.go | 2 + pkg/logql/lex.go | 1 + pkg/logql/log/metrics_extraction.go | 13 + pkg/logql/log/metrics_extraction_test.go | 18 + pkg/logql/parser_test.go | 21 + 10 files changed, 324 insertions(+), 404 deletions(-) diff --git a/docs/sources/logql/_index.md b/docs/sources/logql/_index.md index 824a53b014923..3c2a83ff1a740 100644 --- a/docs/sources/logql/_index.md +++ b/docs/sources/logql/_index.md @@ -492,7 +492,9 @@ 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 only the function `duration_seconds` (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`). +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: diff --git a/pkg/logql/ast.go b/pkg/logql/ast.go index 3705e3a44e02c..1902d1bfcfcac 100644 --- a/pkg/logql/ast.go +++ b/pkg/logql/ast.go @@ -528,6 +528,7 @@ const ( OpUnwrap = "unwrap" // conversion Op + OpConvBytes = "bytes" OpConvDuration = "duration" OpConvDurationSeconds = "duration_seconds" ) diff --git a/pkg/logql/ast_test.go b/pkg/logql/ast_test.go index 1a6672fa1e792..7ebe137aaced2 100644 --- a/pkg/logql/ast_test.go +++ b/pkg/logql/ast_test.go @@ -85,6 +85,11 @@ func Test_SampleExpr_String(t *testing.T) { / count_over_time({namespace="tns"} | logfmt | label_format foo=bar[5m]) )`, + `sum by (job) ( + sum_over_time({namespace="tns"} |= "level=error" | json | foo=5 and bar<25ms | unwrap bytes(latency)[5m]) + / + count_over_time({namespace="tns"} | logfmt | label_format foo=bar[5m]) + )`, `sum by (job) ( sum_over_time( {namespace="tns"} |= "level=error" | json | avg=5 and bar<25ms | unwrap duration(latency) [5m] diff --git a/pkg/logql/expr.y b/pkg/logql/expr.y index a01241059fbdd..e43e15f484f9a 100644 --- a/pkg/logql/expr.y +++ b/pkg/logql/expr.y @@ -89,7 +89,7 @@ import ( %token MATCHERS LABELS EQ RE NRE OPEN_BRACE CLOSE_BRACE OPEN_BRACKET CLOSE_BRACKET COMMA DOT PIPE_MATCH PIPE_EXACT OPEN_PARENTHESIS CLOSE_PARENTHESIS BY WITHOUT COUNT_OVER_TIME RATE SUM AVG MAX MIN COUNT STDDEV STDVAR BOTTOMK TOPK BYTES_OVER_TIME BYTES_RATE BOOL JSON REGEXP LOGFMT PIPE LINE_FMT LABEL_FMT UNWRAP AVG_OVER_TIME SUM_OVER_TIME MIN_OVER_TIME - MAX_OVER_TIME STDVAR_OVER_TIME STDDEV_OVER_TIME QUANTILE_OVER_TIME DURATION_CONV DURATION_SECONDS_CONV + MAX_OVER_TIME STDVAR_OVER_TIME STDDEV_OVER_TIME QUANTILE_OVER_TIME BYTES_CONV DURATION_CONV DURATION_SECONDS_CONV // Operators are listed with increasing precedence. %left OR @@ -146,7 +146,8 @@ unwrapExpr: ; convOp: - DURATION_CONV { $$ = OpConvDuration } + BYTES_CONV { $$ = OpConvBytes } + | DURATION_CONV { $$ = OpConvDuration } | DURATION_SECONDS_CONV { $$ = OpConvDurationSeconds } ; diff --git a/pkg/logql/expr.y.go b/pkg/logql/expr.y.go index 1b99d052d7919..5bdaf8120b7f2 100644 --- a/pkg/logql/expr.y.go +++ b/pkg/logql/expr.y.go @@ -1,18 +1,15 @@ // Code generated by goyacc -p expr -o pkg/logql/expr.y.go pkg/logql/expr.y. DO NOT EDIT. -//line pkg/logql/expr.y:2 package logql import __yyfmt__ "fmt" -//line pkg/logql/expr.y:2 import ( "github.com/grafana/loki/pkg/logql/log" "github.com/prometheus/prometheus/pkg/labels" "time" ) -//line pkg/logql/expr.y:12 type exprSymType struct { yys int Expr Expr @@ -104,23 +101,24 @@ const MAX_OVER_TIME = 57393 const STDVAR_OVER_TIME = 57394 const STDDEV_OVER_TIME = 57395 const QUANTILE_OVER_TIME = 57396 -const DURATION_CONV = 57397 -const DURATION_SECONDS_CONV = 57398 -const OR = 57399 -const AND = 57400 -const UNLESS = 57401 -const CMP_EQ = 57402 -const NEQ = 57403 -const LT = 57404 -const LTE = 57405 -const GT = 57406 -const GTE = 57407 -const ADD = 57408 -const SUB = 57409 -const MUL = 57410 -const DIV = 57411 -const MOD = 57412 -const POW = 57413 +const BYTES_CONV = 57397 +const DURATION_CONV = 57398 +const DURATION_SECONDS_CONV = 57399 +const OR = 57400 +const AND = 57401 +const UNLESS = 57402 +const CMP_EQ = 57403 +const NEQ = 57404 +const LT = 57405 +const LTE = 57406 +const GT = 57407 +const GTE = 57408 +const ADD = 57409 +const SUB = 57410 +const MUL = 57411 +const DIV = 57412 +const MOD = 57413 +const POW = 57414 var exprToknames = [...]string{ "$end", @@ -177,6 +175,7 @@ var exprToknames = [...]string{ "STDVAR_OVER_TIME", "STDDEV_OVER_TIME", "QUANTILE_OVER_TIME", + "BYTES_CONV", "DURATION_CONV", "DURATION_SECONDS_CONV", "OR", @@ -201,9 +200,6 @@ const exprEofCode = 1 const exprErrCode = 2 const exprInitialStackSize = 16 -//line pkg/logql/expr.y:345 - -//line yacctab:1 var exprExca = [...]int{ -1, 1, 1, -1, @@ -212,142 +208,142 @@ var exprExca = [...]int{ const exprPrivate = 57344 -const exprLast = 396 +const exprLast = 397 var exprAct = [...]int{ 70, 171, 53, 153, 145, 4, 179, 100, 63, 2, 52, 45, 61, 56, 5, 217, 120, 214, 235, 66, - 14, 40, 41, 42, 43, 44, 45, 249, 11, 42, - 43, 44, 45, 252, 76, 235, 6, 213, 256, 244, + 14, 40, 41, 42, 43, 44, 45, 250, 11, 42, + 43, 44, 45, 253, 235, 213, 6, 76, 257, 213, 17, 18, 28, 29, 31, 32, 30, 33, 34, 35, - 36, 19, 20, 214, 225, 91, 116, 118, 119, 227, - 94, 21, 22, 23, 24, 25, 26, 27, 92, 215, - 214, 224, 214, 247, 59, 124, 155, 118, 119, 15, - 16, 57, 58, 122, 129, 176, 130, 131, 132, 133, + 36, 19, 20, 214, 242, 91, 116, 118, 119, 245, + 94, 21, 22, 23, 24, 25, 26, 27, 92, 214, + 214, 71, 72, 224, 214, 124, 155, 118, 119, 176, + 15, 16, 167, 122, 129, 167, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, - 69, 128, 71, 72, 173, 117, 71, 72, 150, 46, + 69, 167, 71, 72, 232, 111, 117, 221, 150, 46, 47, 50, 51, 48, 49, 40, 41, 42, 43, 44, - 45, 60, 162, 59, 161, 156, 159, 160, 157, 158, - 57, 58, 178, 172, 225, 181, 170, 11, 174, 226, - 175, 59, 111, 110, 127, 123, 126, 68, 57, 58, - 186, 182, 183, 184, 37, 38, 39, 46, 47, 50, + 45, 110, 162, 168, 248, 161, 156, 159, 160, 157, + 158, 128, 178, 172, 127, 181, 215, 225, 174, 59, + 175, 59, 227, 126, 68, 225, 57, 58, 57, 58, + 226, 182, 183, 184, 37, 38, 39, 46, 47, 50, 51, 48, 49, 40, 41, 42, 43, 44, 45, 209, - 60, 173, 211, 177, 216, 91, 219, 222, 94, 169, - 115, 212, 187, 223, 122, 220, 210, 167, 60, 167, + 106, 173, 211, 186, 216, 91, 219, 222, 94, 177, + 169, 212, 115, 223, 122, 220, 210, 60, 103, 60, 228, 38, 39, 46, 47, 50, 51, 48, 49, 40, - 41, 42, 43, 44, 45, 255, 213, 251, 106, 232, - 106, 221, 167, 250, 233, 91, 236, 240, 106, 234, - 166, 241, 243, 91, 147, 215, 103, 125, 103, 185, - 59, 74, 147, 246, 168, 11, 103, 57, 58, 73, - 242, 214, 248, 6, 165, 253, 164, 17, 18, 28, - 29, 31, 32, 30, 33, 34, 35, 36, 19, 20, - 173, 106, 148, 146, 230, 231, 238, 239, 21, 22, - 23, 24, 25, 26, 27, 59, 170, 60, 163, 103, - 151, 59, 57, 58, 149, 59, 15, 16, 57, 58, - 113, 218, 57, 58, 75, 106, 106, 97, 99, 98, - 121, 104, 105, 217, 112, 173, 144, 114, 11, 147, - 147, 173, 109, 103, 103, 55, 123, 192, 101, 164, - 193, 191, 60, 189, 3, 163, 190, 188, 60, 254, - 245, 62, 60, 77, 78, 79, 80, 81, 82, 83, - 84, 85, 86, 87, 88, 89, 90, 148, 146, 146, - 106, 207, 152, 204, 208, 206, 205, 203, 201, 96, - 198, 202, 200, 199, 197, 180, 195, 95, 103, 196, - 194, 229, 65, 67, 154, 67, 154, 54, 107, 102, - 108, 93, 10, 9, 13, 8, 97, 99, 98, 237, - 104, 105, 12, 7, 64, 1, + 41, 42, 43, 44, 45, 121, 97, 99, 98, 187, + 104, 105, 215, 11, 233, 91, 236, 59, 113, 234, + 74, 123, 244, 91, 57, 58, 170, 243, 125, 11, + 73, 59, 112, 247, 256, 114, 11, 123, 57, 58, + 252, 218, 251, 249, 6, 106, 254, 173, 17, 18, + 28, 29, 31, 32, 30, 33, 34, 35, 36, 19, + 20, 173, 106, 103, 241, 60, 238, 239, 240, 21, + 22, 23, 24, 25, 26, 27, 147, 59, 170, 60, + 103, 230, 231, 59, 57, 58, 59, 166, 15, 16, + 57, 58, 165, 57, 58, 207, 75, 106, 208, 206, + 106, 204, 164, 106, 205, 203, 192, 173, 164, 193, + 191, 147, 163, 173, 147, 103, 55, 147, 103, 185, + 189, 103, 163, 190, 188, 60, 201, 151, 255, 202, + 200, 60, 149, 144, 60, 77, 78, 79, 80, 81, + 82, 83, 84, 85, 86, 87, 88, 89, 90, 106, + 148, 146, 198, 148, 146, 199, 197, 146, 195, 3, + 229, 196, 194, 154, 101, 109, 62, 103, 65, 246, + 180, 67, 67, 154, 152, 96, 95, 54, 107, 102, + 108, 93, 10, 9, 13, 97, 99, 98, 8, 104, + 105, 217, 237, 12, 7, 64, 1, } var exprPact = [...]int{ - 13, -1000, 97, -1000, -1000, 271, 13, -1000, -1000, -1000, - -1000, 370, 124, 77, -1000, 232, 224, -1000, -1000, -1000, + 13, -1000, 96, -1000, -1000, 272, 13, -1000, -1000, -1000, + -1000, 366, 121, 77, -1000, 223, 213, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, - -1000, -1000, -1000, -1000, -1000, -1000, -1000, -6, -6, -6, - -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, - -6, -6, 271, -1000, 109, 345, 306, -1000, -1000, -1000, - -1000, 119, 118, 97, 288, 164, -1000, 44, 293, 220, - 123, 121, 78, -1000, -1000, 13, -1000, 13, 13, 13, + -1000, -1000, -1000, -1000, -1000, -1000, -1000, -3, -3, -3, + -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, + -3, -3, 272, -1000, 125, 165, 359, -1000, -1000, -1000, + -1000, 97, 81, 96, 216, 166, -1000, 44, 198, 221, + 120, 111, 108, -1000, -1000, 13, -1000, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, - 13, -1000, 300, -1000, 290, -1000, -1000, -1000, -1000, 278, - -1000, -1000, -1000, 203, 274, 371, 64, -1000, -1000, -1000, - -1000, -1000, -1000, -1000, 368, -1000, 272, 240, 238, 214, - 210, 160, 127, 122, 61, 154, 13, 360, 360, 133, - 49, 49, -39, -39, -60, -60, -60, -60, -45, -45, - -45, -45, -45, -45, -1000, 290, 203, 203, 203, -1000, - 205, -1000, 131, -1000, 170, 319, 313, 362, 356, 354, - 349, 347, -1000, -1000, -1000, -1000, -1000, -1000, 81, 122, - 261, 28, 60, 256, 267, 187, 81, 13, 47, 115, - -1000, 35, 213, 290, 291, -1000, 369, 259, -1000, -1000, + 13, -1000, 327, -1000, 292, -1000, -1000, -1000, -1000, 326, + -1000, -1000, -1000, 240, 321, 368, 64, -1000, -1000, -1000, + -1000, -1000, -1000, -1000, 367, -1000, 306, 296, 286, 281, + 99, 161, 269, 214, 55, 160, 13, 365, 365, 132, + 48, 48, -40, -40, -61, -61, -61, -61, -46, -46, + -46, -46, -46, -46, -1000, 292, 240, 240, 240, -1000, + 295, -1000, 154, -1000, 197, 316, 302, 354, 348, 322, + 297, 291, -1000, -1000, -1000, -1000, -1000, -1000, 46, 214, + 263, 26, 127, 344, 217, 83, 46, 13, 49, 126, + -1000, 118, 257, 292, 298, -1000, 358, 276, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, - 185, -27, 261, -1000, 203, -1000, 26, 211, 208, 197, - 216, -1000, -1000, 15, -1000, 325, -1000, -1000, -1000, -1000, - -1000, -1000, 81, -27, 290, -1000, -1000, 50, -1000, -1000, - -17, 204, 198, 9, 81, -1000, -1000, 324, -27, -32, - -1000, -1000, 196, -1000, 14, -1000, -1000, + 80, -27, 263, -1000, 240, -1000, 25, 211, 255, 30, + 203, -1000, -1000, 35, -1000, 364, -1000, -1000, -1000, -1000, + -1000, -1000, 46, -27, 292, -1000, -1000, 101, -1000, -1000, + -1000, -17, 233, 231, 9, 46, -1000, -1000, 323, -27, + -32, -1000, -1000, 225, -1000, 14, -1000, -1000, } var exprPgo = [...]int{ - 0, 395, 8, 13, 0, 6, 324, 5, 16, 7, - 394, 393, 392, 389, 14, 385, 384, 383, 382, 294, - 381, 10, 2, 380, 379, 378, 4, 377, 367, 359, - 3, 352, 1, 318, + 0, 396, 8, 13, 0, 6, 359, 5, 16, 7, + 395, 394, 393, 392, 14, 388, 384, 383, 382, 296, + 381, 10, 2, 380, 379, 378, 4, 377, 376, 375, + 3, 374, 1, 364, } var exprR1 = [...]int{ 0, 1, 2, 2, 7, 7, 7, 7, 7, 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 32, 32, 32, 13, - 13, 11, 11, 11, 11, 15, 15, 15, 15, 15, - 3, 3, 3, 3, 14, 14, 14, 10, 10, 9, - 9, 9, 9, 21, 21, 22, 22, 22, 22, 22, - 27, 27, 20, 20, 20, 28, 30, 30, 31, 31, - 31, 29, 26, 26, 26, 26, 26, 26, 26, 26, - 33, 33, 25, 25, 25, 25, 25, 25, 25, 23, - 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, - 24, 24, 24, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, 19, 19, - 18, 18, 18, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 5, 5, 4, 4, + 13, 13, 11, 11, 11, 11, 15, 15, 15, 15, + 15, 3, 3, 3, 3, 14, 14, 14, 10, 10, + 9, 9, 9, 9, 21, 21, 22, 22, 22, 22, + 22, 27, 27, 20, 20, 20, 28, 30, 30, 31, + 31, 31, 29, 26, 26, 26, 26, 26, 26, 26, + 26, 33, 33, 25, 25, 25, 25, 25, 25, 25, + 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, + 24, 24, 24, 24, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, 17, 19, + 19, 18, 18, 18, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 5, 5, 4, 4, } var exprR2 = [...]int{ 0, 1, 1, 1, 1, 1, 1, 1, 3, 1, 2, 3, 2, 4, 3, 5, 3, 5, 3, 5, 4, 6, 3, 4, 3, 2, 3, 6, 3, 1, - 1, 4, 6, 5, 7, 4, 5, 5, 6, 7, - 1, 1, 1, 1, 3, 3, 3, 1, 3, 3, - 3, 3, 3, 1, 2, 1, 2, 2, 2, 2, - 2, 3, 1, 1, 2, 2, 3, 3, 1, 3, - 3, 2, 1, 1, 1, 3, 2, 3, 3, 3, - 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, + 1, 1, 4, 6, 5, 7, 4, 5, 5, 6, + 7, 1, 1, 1, 1, 3, 3, 3, 1, 3, + 3, 3, 3, 3, 1, 2, 1, 2, 2, 2, + 2, 2, 3, 1, 1, 2, 2, 3, 3, 1, + 3, 3, 2, 1, 1, 1, 3, 2, 3, 3, + 3, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 0, 1, - 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, + 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, + 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 3, 4, 4, + 1, 1, 1, 1, 1, 3, 4, 4, } var exprChk = [...]int{ -1000, -1, -2, -6, -7, -14, 23, -11, -15, -17, - -18, 15, -12, -16, 7, 66, 67, 27, 28, 38, + -18, 15, -12, -16, 7, 67, 68, 27, 28, 38, 39, 48, 49, 50, 51, 52, 53, 54, 29, 30, - 33, 31, 32, 34, 35, 36, 37, 57, 58, 59, - 66, 67, 68, 69, 70, 71, 60, 61, 64, 65, - 62, 63, -21, -22, -27, 44, -3, 21, 22, 14, - 61, -7, -6, -2, -10, 2, -9, 5, 23, 23, + 33, 31, 32, 34, 35, 36, 37, 58, 59, 60, + 67, 68, 69, 70, 71, 72, 61, 62, 65, 66, + 63, 64, -21, -22, -27, 44, -3, 21, 22, 14, + 62, -7, -6, -2, -10, 2, -9, 5, 23, 23, -4, 25, 26, 7, 7, -19, 40, -19, -19, -19, -19, -19, -19, -19, -19, -19, -19, -19, -19, -19, -19, -22, -3, -20, -26, -28, -29, 41, 43, 42, -9, -33, -24, 23, 45, 46, 5, -25, -23, 6, - 24, 24, 16, 2, 19, 16, 12, 61, 13, 14, + 24, 24, 16, 2, 19, 16, 12, 62, 13, 14, -8, 7, -14, 23, -7, 7, 23, 23, 23, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, 6, -26, 58, 19, 57, 6, - -26, 6, -31, -30, 5, 12, 61, 64, 65, 62, - 63, 60, -9, 6, 6, 6, 6, 2, 24, 19, + -2, -2, -2, -2, 6, -26, 59, 19, 58, 6, + -26, 6, -31, -30, 5, 12, 62, 65, 66, 63, + 64, 61, -9, 6, 6, 6, 6, 2, 24, 19, 9, -32, -21, 44, -14, -8, 24, 19, -7, -5, 5, -5, -26, -26, -26, 24, 19, 12, 8, 4, 7, 8, 4, 7, 8, 4, 7, 8, 4, 7, @@ -355,37 +351,37 @@ var exprChk = [...]int{ -8, -32, -21, 9, 44, 9, -32, 47, 24, -32, -21, 24, -4, -7, 24, 19, 24, 24, -30, 2, 5, 6, 24, -32, -26, 9, 5, -13, 55, 56, - 9, 24, 24, -32, 24, 5, -4, 23, -32, 44, - 9, 9, 24, -4, 5, 9, 24, + 57, 9, 24, 24, -32, 24, 5, -4, 23, -32, + 44, 9, 9, 24, -4, 5, 9, 24, } var exprDef = [...]int{ 0, -2, 1, 2, 3, 9, 0, 4, 5, 6, - 7, 0, 0, 0, 120, 0, 0, 132, 133, 134, - 135, 136, 137, 138, 139, 140, 141, 142, 123, 124, - 125, 126, 127, 128, 129, 130, 131, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 10, 53, 55, 0, 0, 40, 41, 42, - 43, 3, 2, 0, 0, 0, 47, 0, 0, 0, - 0, 0, 0, 121, 122, 0, 119, 0, 0, 0, + 7, 0, 0, 0, 121, 0, 0, 133, 134, 135, + 136, 137, 138, 139, 140, 141, 142, 143, 124, 125, + 126, 127, 128, 129, 130, 131, 132, 119, 119, 119, + 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, + 119, 119, 10, 54, 56, 0, 0, 41, 42, 43, + 44, 3, 2, 0, 0, 0, 48, 0, 0, 0, + 0, 0, 0, 122, 123, 0, 120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 54, 0, 56, 57, 58, 59, 62, 63, 0, - 72, 73, 74, 0, 0, 0, 0, 80, 81, 60, - 8, 11, 44, 45, 0, 46, 0, 0, 0, 0, - 0, 0, 0, 0, 3, 120, 0, 0, 0, 103, - 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, - 114, 115, 116, 117, 61, 76, 0, 0, 0, 64, - 0, 65, 71, 68, 0, 0, 0, 0, 0, 0, - 0, 0, 48, 49, 50, 51, 52, 25, 31, 0, - 12, 0, 0, 0, 0, 0, 35, 0, 3, 0, - 143, 0, 77, 78, 79, 75, 0, 0, 87, 94, - 101, 86, 93, 100, 82, 89, 96, 83, 90, 97, - 84, 91, 98, 85, 92, 99, 88, 95, 102, 33, + 0, 55, 0, 57, 58, 59, 60, 63, 64, 0, + 73, 74, 75, 0, 0, 0, 0, 81, 82, 61, + 8, 11, 45, 46, 0, 47, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 121, 0, 0, 0, 104, + 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, + 115, 116, 117, 118, 62, 77, 0, 0, 0, 65, + 0, 66, 72, 69, 0, 0, 0, 0, 0, 0, + 0, 0, 49, 50, 51, 52, 53, 25, 32, 0, + 12, 0, 0, 0, 0, 0, 36, 0, 3, 0, + 144, 0, 78, 79, 80, 76, 0, 0, 88, 95, + 102, 87, 94, 101, 83, 90, 97, 84, 91, 98, + 85, 92, 99, 86, 93, 100, 89, 96, 103, 34, 0, 14, 22, 16, 0, 18, 0, 0, 0, 0, - 0, 24, 37, 3, 36, 0, 145, 146, 69, 70, - 66, 67, 32, 23, 28, 20, 26, 0, 29, 30, - 13, 0, 0, 0, 38, 144, 34, 0, 15, 0, - 17, 19, 0, 39, 0, 21, 27, + 0, 24, 38, 3, 37, 0, 146, 147, 70, 71, + 67, 68, 33, 23, 28, 20, 26, 0, 29, 30, + 31, 13, 0, 0, 0, 39, 145, 35, 0, 15, + 0, 17, 19, 0, 40, 0, 21, 27, } var exprTok1 = [...]int{ @@ -400,6 +396,7 @@ var exprTok2 = [...]int{ 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, + 72, } var exprTok3 = [...]int{ 0, @@ -411,8 +408,6 @@ var exprErrorMessages = [...]struct { msg string }{} -//line yaccpar:1 - /* parser for yacc output */ var ( @@ -744,864 +739,725 @@ exprdefault: case 1: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:104 { exprlex.(*lexer).expr = exprDollar[1].Expr } case 2: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:107 { exprVAL.Expr = exprDollar[1].LogExpr } case 3: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:108 { exprVAL.Expr = exprDollar[1].MetricExpr } case 4: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:112 { exprVAL.MetricExpr = exprDollar[1].RangeAggregationExpr } case 5: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:113 { exprVAL.MetricExpr = exprDollar[1].VectorAggregationExpr } case 6: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:114 { exprVAL.MetricExpr = exprDollar[1].BinOpExpr } case 7: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:115 { exprVAL.MetricExpr = exprDollar[1].LiteralExpr } case 8: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:116 { exprVAL.MetricExpr = exprDollar[2].MetricExpr } case 9: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:120 { exprVAL.LogExpr = newMatcherExpr(exprDollar[1].Selector) } case 10: exprDollar = exprS[exprpt-2 : exprpt+1] -//line pkg/logql/expr.y:121 { exprVAL.LogExpr = newPipelineExpr(newMatcherExpr(exprDollar[1].Selector), exprDollar[2].PipelineExpr) } case 11: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:122 { exprVAL.LogExpr = exprDollar[2].LogExpr } case 12: exprDollar = exprS[exprpt-2 : exprpt+1] -//line pkg/logql/expr.y:126 { exprVAL.LogRangeExpr = newLogRange(newMatcherExpr(exprDollar[1].Selector), exprDollar[2].duration, nil) } case 13: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:127 { exprVAL.LogRangeExpr = newLogRange(newMatcherExpr(exprDollar[2].Selector), exprDollar[4].duration, nil) } case 14: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:128 { exprVAL.LogRangeExpr = newLogRange(newMatcherExpr(exprDollar[1].Selector), exprDollar[2].duration, exprDollar[3].UnwrapExpr) } case 15: exprDollar = exprS[exprpt-5 : exprpt+1] -//line pkg/logql/expr.y:129 { exprVAL.LogRangeExpr = newLogRange(newMatcherExpr(exprDollar[2].Selector), exprDollar[4].duration, exprDollar[5].UnwrapExpr) } case 16: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:130 { exprVAL.LogRangeExpr = newLogRange(newMatcherExpr(exprDollar[1].Selector), exprDollar[3].duration, exprDollar[2].UnwrapExpr) } case 17: exprDollar = exprS[exprpt-5 : exprpt+1] -//line pkg/logql/expr.y:131 { exprVAL.LogRangeExpr = newLogRange(newMatcherExpr(exprDollar[2].Selector), exprDollar[5].duration, exprDollar[3].UnwrapExpr) } case 18: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:132 { exprVAL.LogRangeExpr = newLogRange(newPipelineExpr(newMatcherExpr(exprDollar[1].Selector), exprDollar[2].PipelineExpr), exprDollar[3].duration, nil) } case 19: exprDollar = exprS[exprpt-5 : exprpt+1] -//line pkg/logql/expr.y:133 { exprVAL.LogRangeExpr = newLogRange(newPipelineExpr(newMatcherExpr(exprDollar[2].Selector), exprDollar[3].PipelineExpr), exprDollar[5].duration, nil) } case 20: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:134 { exprVAL.LogRangeExpr = newLogRange(newPipelineExpr(newMatcherExpr(exprDollar[1].Selector), exprDollar[2].PipelineExpr), exprDollar[4].duration, exprDollar[3].UnwrapExpr) } case 21: exprDollar = exprS[exprpt-6 : exprpt+1] -//line pkg/logql/expr.y:135 { exprVAL.LogRangeExpr = newLogRange(newPipelineExpr(newMatcherExpr(exprDollar[2].Selector), exprDollar[3].PipelineExpr), exprDollar[6].duration, exprDollar[4].UnwrapExpr) } case 22: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:136 { exprVAL.LogRangeExpr = newLogRange(newPipelineExpr(newMatcherExpr(exprDollar[1].Selector), exprDollar[3].PipelineExpr), exprDollar[2].duration, nil) } case 23: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:137 { exprVAL.LogRangeExpr = newLogRange(newPipelineExpr(newMatcherExpr(exprDollar[1].Selector), exprDollar[3].PipelineExpr), exprDollar[2].duration, exprDollar[4].UnwrapExpr) } case 24: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:138 { exprVAL.LogRangeExpr = exprDollar[2].LogRangeExpr } case 26: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:143 { exprVAL.UnwrapExpr = newUnwrapExpr(exprDollar[3].str, "") } case 27: exprDollar = exprS[exprpt-6 : exprpt+1] -//line pkg/logql/expr.y:144 { exprVAL.UnwrapExpr = newUnwrapExpr(exprDollar[5].str, exprDollar[3].ConvOp) } case 28: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:145 { exprVAL.UnwrapExpr = exprDollar[1].UnwrapExpr.addPostFilter(exprDollar[3].LabelFilter) } case 29: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:149 { - exprVAL.ConvOp = OpConvDuration + exprVAL.ConvOp = OpConvBytes } case 30: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:150 { - exprVAL.ConvOp = OpConvDurationSeconds + exprVAL.ConvOp = OpConvDuration } case 31: + exprDollar = exprS[exprpt-1 : exprpt+1] + { + exprVAL.ConvOp = OpConvDurationSeconds + } + case 32: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:154 { exprVAL.RangeAggregationExpr = newRangeAggregationExpr(exprDollar[3].LogRangeExpr, exprDollar[1].RangeOp, nil, nil) } - case 32: + case 33: exprDollar = exprS[exprpt-6 : exprpt+1] -//line pkg/logql/expr.y:155 { exprVAL.RangeAggregationExpr = newRangeAggregationExpr(exprDollar[5].LogRangeExpr, exprDollar[1].RangeOp, nil, &exprDollar[3].str) } - case 33: + case 34: exprDollar = exprS[exprpt-5 : exprpt+1] -//line pkg/logql/expr.y:156 { exprVAL.RangeAggregationExpr = newRangeAggregationExpr(exprDollar[3].LogRangeExpr, exprDollar[1].RangeOp, exprDollar[5].Grouping, nil) } - case 34: + case 35: exprDollar = exprS[exprpt-7 : exprpt+1] -//line pkg/logql/expr.y:157 { exprVAL.RangeAggregationExpr = newRangeAggregationExpr(exprDollar[5].LogRangeExpr, exprDollar[1].RangeOp, exprDollar[7].Grouping, &exprDollar[3].str) } - case 35: + case 36: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:162 { exprVAL.VectorAggregationExpr = mustNewVectorAggregationExpr(exprDollar[3].MetricExpr, exprDollar[1].VectorOp, nil, nil) } - case 36: + case 37: exprDollar = exprS[exprpt-5 : exprpt+1] -//line pkg/logql/expr.y:163 { exprVAL.VectorAggregationExpr = mustNewVectorAggregationExpr(exprDollar[4].MetricExpr, exprDollar[1].VectorOp, exprDollar[2].Grouping, nil) } - case 37: + case 38: exprDollar = exprS[exprpt-5 : exprpt+1] -//line pkg/logql/expr.y:164 { exprVAL.VectorAggregationExpr = mustNewVectorAggregationExpr(exprDollar[3].MetricExpr, exprDollar[1].VectorOp, exprDollar[5].Grouping, nil) } - case 38: + case 39: exprDollar = exprS[exprpt-6 : exprpt+1] -//line pkg/logql/expr.y:166 { exprVAL.VectorAggregationExpr = mustNewVectorAggregationExpr(exprDollar[5].MetricExpr, exprDollar[1].VectorOp, nil, &exprDollar[3].str) } - case 39: + case 40: exprDollar = exprS[exprpt-7 : exprpt+1] -//line pkg/logql/expr.y:167 { exprVAL.VectorAggregationExpr = mustNewVectorAggregationExpr(exprDollar[5].MetricExpr, exprDollar[1].VectorOp, exprDollar[7].Grouping, &exprDollar[3].str) } - case 40: + case 41: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:171 { exprVAL.Filter = labels.MatchRegexp } - case 41: + case 42: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:172 { exprVAL.Filter = labels.MatchEqual } - case 42: + case 43: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:173 { exprVAL.Filter = labels.MatchNotRegexp } - case 43: + case 44: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:174 { exprVAL.Filter = labels.MatchNotEqual } - case 44: + case 45: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:178 { exprVAL.Selector = exprDollar[2].Matchers } - case 45: + case 46: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:179 { exprVAL.Selector = exprDollar[2].Matchers } - case 46: + case 47: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:180 { } - case 47: + case 48: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:184 { exprVAL.Matchers = []*labels.Matcher{exprDollar[1].Matcher} } - case 48: + case 49: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:185 { exprVAL.Matchers = append(exprDollar[1].Matchers, exprDollar[3].Matcher) } - case 49: + case 50: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:189 { exprVAL.Matcher = mustNewMatcher(labels.MatchEqual, exprDollar[1].str, exprDollar[3].str) } - case 50: + case 51: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:190 { exprVAL.Matcher = mustNewMatcher(labels.MatchNotEqual, exprDollar[1].str, exprDollar[3].str) } - case 51: + case 52: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:191 { exprVAL.Matcher = mustNewMatcher(labels.MatchRegexp, exprDollar[1].str, exprDollar[3].str) } - case 52: + case 53: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:192 { exprVAL.Matcher = mustNewMatcher(labels.MatchNotRegexp, exprDollar[1].str, exprDollar[3].str) } - case 53: + case 54: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:196 { exprVAL.PipelineExpr = MultiStageExpr{exprDollar[1].PipelineStage} } - case 54: + case 55: exprDollar = exprS[exprpt-2 : exprpt+1] -//line pkg/logql/expr.y:197 { exprVAL.PipelineExpr = append(exprDollar[1].PipelineExpr, exprDollar[2].PipelineStage) } - case 55: + case 56: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:201 { exprVAL.PipelineStage = exprDollar[1].LineFilters } - case 56: + case 57: exprDollar = exprS[exprpt-2 : exprpt+1] -//line pkg/logql/expr.y:202 { exprVAL.PipelineStage = exprDollar[2].LabelParser } - case 57: + case 58: exprDollar = exprS[exprpt-2 : exprpt+1] -//line pkg/logql/expr.y:203 { exprVAL.PipelineStage = &labelFilterExpr{LabelFilterer: exprDollar[2].LabelFilter} } - case 58: + case 59: exprDollar = exprS[exprpt-2 : exprpt+1] -//line pkg/logql/expr.y:204 { exprVAL.PipelineStage = exprDollar[2].LineFormatExpr } - case 59: + case 60: exprDollar = exprS[exprpt-2 : exprpt+1] -//line pkg/logql/expr.y:205 { exprVAL.PipelineStage = exprDollar[2].LabelFormatExpr } - case 60: + case 61: exprDollar = exprS[exprpt-2 : exprpt+1] -//line pkg/logql/expr.y:209 { exprVAL.LineFilters = newLineFilterExpr(nil, exprDollar[1].Filter, exprDollar[2].str) } - case 61: + case 62: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:210 { exprVAL.LineFilters = newLineFilterExpr(exprDollar[1].LineFilters, exprDollar[2].Filter, exprDollar[3].str) } - case 62: + case 63: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:213 { exprVAL.LabelParser = newLabelParserExpr(OpParserTypeJSON, "") } - case 63: + case 64: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:214 { exprVAL.LabelParser = newLabelParserExpr(OpParserTypeLogfmt, "") } - case 64: + case 65: exprDollar = exprS[exprpt-2 : exprpt+1] -//line pkg/logql/expr.y:215 { exprVAL.LabelParser = newLabelParserExpr(OpParserTypeRegexp, exprDollar[2].str) } - case 65: + case 66: exprDollar = exprS[exprpt-2 : exprpt+1] -//line pkg/logql/expr.y:218 { exprVAL.LineFormatExpr = newLineFmtExpr(exprDollar[2].str) } - case 66: + case 67: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:221 { exprVAL.LabelFormat = log.NewRenameLabelFmt(exprDollar[1].str, exprDollar[3].str) } - case 67: + case 68: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:222 { exprVAL.LabelFormat = log.NewTemplateLabelFmt(exprDollar[1].str, exprDollar[3].str) } - case 68: + case 69: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:226 { exprVAL.LabelsFormat = []log.LabelFmt{exprDollar[1].LabelFormat} } - case 69: + case 70: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:227 { exprVAL.LabelsFormat = append(exprDollar[1].LabelsFormat, exprDollar[3].LabelFormat) } - case 71: + case 72: exprDollar = exprS[exprpt-2 : exprpt+1] -//line pkg/logql/expr.y:231 { exprVAL.LabelFormatExpr = newLabelFmtExpr(exprDollar[2].LabelsFormat) } - case 72: + case 73: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:234 { exprVAL.LabelFilter = log.NewStringLabelFilter(exprDollar[1].Matcher) } - case 73: + case 74: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:235 { exprVAL.LabelFilter = exprDollar[1].UnitFilter } - case 74: + case 75: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:236 { exprVAL.LabelFilter = exprDollar[1].NumberFilter } - case 75: + case 76: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:237 { exprVAL.LabelFilter = exprDollar[2].LabelFilter } - case 76: + case 77: exprDollar = exprS[exprpt-2 : exprpt+1] -//line pkg/logql/expr.y:238 { exprVAL.LabelFilter = log.NewAndLabelFilter(exprDollar[1].LabelFilter, exprDollar[2].LabelFilter) } - case 77: + case 78: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:239 { exprVAL.LabelFilter = log.NewAndLabelFilter(exprDollar[1].LabelFilter, exprDollar[3].LabelFilter) } - case 78: + case 79: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:240 { exprVAL.LabelFilter = log.NewAndLabelFilter(exprDollar[1].LabelFilter, exprDollar[3].LabelFilter) } - case 79: + case 80: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:241 { exprVAL.LabelFilter = log.NewOrLabelFilter(exprDollar[1].LabelFilter, exprDollar[3].LabelFilter) } - case 80: + case 81: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:245 { exprVAL.UnitFilter = exprDollar[1].DurationFilter } - case 81: + case 82: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:246 { exprVAL.UnitFilter = exprDollar[1].BytesFilter } - case 82: - exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:249 - { - exprVAL.DurationFilter = log.NewDurationLabelFilter(log.LabelFilterGreaterThan, exprDollar[1].str, exprDollar[3].duration) - } case 83: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:250 { - exprVAL.DurationFilter = log.NewDurationLabelFilter(log.LabelFilterGreaterThanOrEqual, exprDollar[1].str, exprDollar[3].duration) + exprVAL.DurationFilter = log.NewDurationLabelFilter(log.LabelFilterGreaterThan, exprDollar[1].str, exprDollar[3].duration) } case 84: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:251 { - exprVAL.DurationFilter = log.NewDurationLabelFilter(log.LabelFilterLesserThan, exprDollar[1].str, exprDollar[3].duration) + exprVAL.DurationFilter = log.NewDurationLabelFilter(log.LabelFilterGreaterThanOrEqual, exprDollar[1].str, exprDollar[3].duration) } case 85: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:252 { - exprVAL.DurationFilter = log.NewDurationLabelFilter(log.LabelFilterLesserThanOrEqual, exprDollar[1].str, exprDollar[3].duration) + exprVAL.DurationFilter = log.NewDurationLabelFilter(log.LabelFilterLesserThan, exprDollar[1].str, exprDollar[3].duration) } case 86: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:253 { - exprVAL.DurationFilter = log.NewDurationLabelFilter(log.LabelFilterNotEqual, exprDollar[1].str, exprDollar[3].duration) + exprVAL.DurationFilter = log.NewDurationLabelFilter(log.LabelFilterLesserThanOrEqual, exprDollar[1].str, exprDollar[3].duration) } case 87: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:254 { - exprVAL.DurationFilter = log.NewDurationLabelFilter(log.LabelFilterEqual, exprDollar[1].str, exprDollar[3].duration) + exprVAL.DurationFilter = log.NewDurationLabelFilter(log.LabelFilterNotEqual, exprDollar[1].str, exprDollar[3].duration) } case 88: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:255 { exprVAL.DurationFilter = log.NewDurationLabelFilter(log.LabelFilterEqual, exprDollar[1].str, exprDollar[3].duration) } case 89: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:259 { - exprVAL.BytesFilter = log.NewBytesLabelFilter(log.LabelFilterGreaterThan, exprDollar[1].str, exprDollar[3].bytes) + exprVAL.DurationFilter = log.NewDurationLabelFilter(log.LabelFilterEqual, exprDollar[1].str, exprDollar[3].duration) } case 90: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:260 { - exprVAL.BytesFilter = log.NewBytesLabelFilter(log.LabelFilterGreaterThanOrEqual, exprDollar[1].str, exprDollar[3].bytes) + exprVAL.BytesFilter = log.NewBytesLabelFilter(log.LabelFilterGreaterThan, exprDollar[1].str, exprDollar[3].bytes) } case 91: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:261 { - exprVAL.BytesFilter = log.NewBytesLabelFilter(log.LabelFilterLesserThan, exprDollar[1].str, exprDollar[3].bytes) + exprVAL.BytesFilter = log.NewBytesLabelFilter(log.LabelFilterGreaterThanOrEqual, exprDollar[1].str, exprDollar[3].bytes) } case 92: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:262 { - exprVAL.BytesFilter = log.NewBytesLabelFilter(log.LabelFilterLesserThanOrEqual, exprDollar[1].str, exprDollar[3].bytes) + exprVAL.BytesFilter = log.NewBytesLabelFilter(log.LabelFilterLesserThan, exprDollar[1].str, exprDollar[3].bytes) } case 93: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:263 { - exprVAL.BytesFilter = log.NewBytesLabelFilter(log.LabelFilterNotEqual, exprDollar[1].str, exprDollar[3].bytes) + exprVAL.BytesFilter = log.NewBytesLabelFilter(log.LabelFilterLesserThanOrEqual, exprDollar[1].str, exprDollar[3].bytes) } case 94: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:264 { - exprVAL.BytesFilter = log.NewBytesLabelFilter(log.LabelFilterEqual, exprDollar[1].str, exprDollar[3].bytes) + exprVAL.BytesFilter = log.NewBytesLabelFilter(log.LabelFilterNotEqual, exprDollar[1].str, exprDollar[3].bytes) } case 95: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:265 { exprVAL.BytesFilter = log.NewBytesLabelFilter(log.LabelFilterEqual, exprDollar[1].str, exprDollar[3].bytes) } case 96: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:269 { - exprVAL.NumberFilter = log.NewNumericLabelFilter(log.LabelFilterGreaterThan, exprDollar[1].str, mustNewFloat(exprDollar[3].str)) + exprVAL.BytesFilter = log.NewBytesLabelFilter(log.LabelFilterEqual, exprDollar[1].str, exprDollar[3].bytes) } case 97: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:270 { - exprVAL.NumberFilter = log.NewNumericLabelFilter(log.LabelFilterGreaterThanOrEqual, exprDollar[1].str, mustNewFloat(exprDollar[3].str)) + exprVAL.NumberFilter = log.NewNumericLabelFilter(log.LabelFilterGreaterThan, exprDollar[1].str, mustNewFloat(exprDollar[3].str)) } case 98: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:271 { - exprVAL.NumberFilter = log.NewNumericLabelFilter(log.LabelFilterLesserThan, exprDollar[1].str, mustNewFloat(exprDollar[3].str)) + exprVAL.NumberFilter = log.NewNumericLabelFilter(log.LabelFilterGreaterThanOrEqual, exprDollar[1].str, mustNewFloat(exprDollar[3].str)) } case 99: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:272 { - exprVAL.NumberFilter = log.NewNumericLabelFilter(log.LabelFilterLesserThanOrEqual, exprDollar[1].str, mustNewFloat(exprDollar[3].str)) + exprVAL.NumberFilter = log.NewNumericLabelFilter(log.LabelFilterLesserThan, exprDollar[1].str, mustNewFloat(exprDollar[3].str)) } case 100: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:273 { - exprVAL.NumberFilter = log.NewNumericLabelFilter(log.LabelFilterNotEqual, exprDollar[1].str, mustNewFloat(exprDollar[3].str)) + exprVAL.NumberFilter = log.NewNumericLabelFilter(log.LabelFilterLesserThanOrEqual, exprDollar[1].str, mustNewFloat(exprDollar[3].str)) } case 101: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:274 { - exprVAL.NumberFilter = log.NewNumericLabelFilter(log.LabelFilterEqual, exprDollar[1].str, mustNewFloat(exprDollar[3].str)) + exprVAL.NumberFilter = log.NewNumericLabelFilter(log.LabelFilterNotEqual, exprDollar[1].str, mustNewFloat(exprDollar[3].str)) } case 102: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:275 { exprVAL.NumberFilter = log.NewNumericLabelFilter(log.LabelFilterEqual, exprDollar[1].str, mustNewFloat(exprDollar[3].str)) } case 103: + exprDollar = exprS[exprpt-3 : exprpt+1] + { + exprVAL.NumberFilter = log.NewNumericLabelFilter(log.LabelFilterEqual, exprDollar[1].str, mustNewFloat(exprDollar[3].str)) + } + case 104: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:281 { exprVAL.BinOpExpr = mustNewBinOpExpr("or", exprDollar[3].BinOpModifier, exprDollar[1].Expr, exprDollar[4].Expr) } - case 104: + case 105: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:282 { exprVAL.BinOpExpr = mustNewBinOpExpr("and", exprDollar[3].BinOpModifier, exprDollar[1].Expr, exprDollar[4].Expr) } - case 105: + case 106: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:283 { exprVAL.BinOpExpr = mustNewBinOpExpr("unless", exprDollar[3].BinOpModifier, exprDollar[1].Expr, exprDollar[4].Expr) } - case 106: + case 107: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:284 { exprVAL.BinOpExpr = mustNewBinOpExpr("+", exprDollar[3].BinOpModifier, exprDollar[1].Expr, exprDollar[4].Expr) } - case 107: + case 108: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:285 { exprVAL.BinOpExpr = mustNewBinOpExpr("-", exprDollar[3].BinOpModifier, exprDollar[1].Expr, exprDollar[4].Expr) } - case 108: + case 109: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:286 { exprVAL.BinOpExpr = mustNewBinOpExpr("*", exprDollar[3].BinOpModifier, exprDollar[1].Expr, exprDollar[4].Expr) } - case 109: + case 110: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:287 { exprVAL.BinOpExpr = mustNewBinOpExpr("/", exprDollar[3].BinOpModifier, exprDollar[1].Expr, exprDollar[4].Expr) } - case 110: + case 111: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:288 { exprVAL.BinOpExpr = mustNewBinOpExpr("%", exprDollar[3].BinOpModifier, exprDollar[1].Expr, exprDollar[4].Expr) } - case 111: + case 112: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:289 { exprVAL.BinOpExpr = mustNewBinOpExpr("^", exprDollar[3].BinOpModifier, exprDollar[1].Expr, exprDollar[4].Expr) } - case 112: + case 113: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:290 { exprVAL.BinOpExpr = mustNewBinOpExpr("==", exprDollar[3].BinOpModifier, exprDollar[1].Expr, exprDollar[4].Expr) } - case 113: + case 114: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:291 { exprVAL.BinOpExpr = mustNewBinOpExpr("!=", exprDollar[3].BinOpModifier, exprDollar[1].Expr, exprDollar[4].Expr) } - case 114: + case 115: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:292 { exprVAL.BinOpExpr = mustNewBinOpExpr(">", exprDollar[3].BinOpModifier, exprDollar[1].Expr, exprDollar[4].Expr) } - case 115: + case 116: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:293 { exprVAL.BinOpExpr = mustNewBinOpExpr(">=", exprDollar[3].BinOpModifier, exprDollar[1].Expr, exprDollar[4].Expr) } - case 116: + case 117: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:294 { exprVAL.BinOpExpr = mustNewBinOpExpr("<", exprDollar[3].BinOpModifier, exprDollar[1].Expr, exprDollar[4].Expr) } - case 117: + case 118: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:295 { exprVAL.BinOpExpr = mustNewBinOpExpr("<=", exprDollar[3].BinOpModifier, exprDollar[1].Expr, exprDollar[4].Expr) } - case 118: + case 119: exprDollar = exprS[exprpt-0 : exprpt+1] -//line pkg/logql/expr.y:299 { exprVAL.BinOpModifier = BinOpOptions{} } - case 119: + case 120: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:300 { exprVAL.BinOpModifier = BinOpOptions{ReturnBool: true} } - case 120: + case 121: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:304 { exprVAL.LiteralExpr = mustNewLiteralExpr(exprDollar[1].str, false) } - case 121: + case 122: exprDollar = exprS[exprpt-2 : exprpt+1] -//line pkg/logql/expr.y:305 { exprVAL.LiteralExpr = mustNewLiteralExpr(exprDollar[2].str, false) } - case 122: + case 123: exprDollar = exprS[exprpt-2 : exprpt+1] -//line pkg/logql/expr.y:306 { exprVAL.LiteralExpr = mustNewLiteralExpr(exprDollar[2].str, true) } - case 123: + case 124: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:310 { exprVAL.VectorOp = OpTypeSum } - case 124: + case 125: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:311 { exprVAL.VectorOp = OpTypeAvg } - case 125: + case 126: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:312 { exprVAL.VectorOp = OpTypeCount } - case 126: + case 127: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:313 { exprVAL.VectorOp = OpTypeMax } - case 127: + case 128: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:314 { exprVAL.VectorOp = OpTypeMin } - case 128: + case 129: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:315 { exprVAL.VectorOp = OpTypeStddev } - case 129: + case 130: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:316 { exprVAL.VectorOp = OpTypeStdvar } - case 130: + case 131: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:317 { exprVAL.VectorOp = OpTypeBottomK } - case 131: + case 132: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:318 { exprVAL.VectorOp = OpTypeTopK } - case 132: + case 133: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:322 { exprVAL.RangeOp = OpRangeTypeCount } - case 133: + case 134: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:323 { exprVAL.RangeOp = OpRangeTypeRate } - case 134: + case 135: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:324 { exprVAL.RangeOp = OpRangeTypeBytes } - case 135: + case 136: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:325 { exprVAL.RangeOp = OpRangeTypeBytesRate } - case 136: + case 137: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:326 { exprVAL.RangeOp = OpRangeTypeAvg } - case 137: + case 138: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:327 { exprVAL.RangeOp = OpRangeTypeSum } - case 138: + case 139: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:328 { exprVAL.RangeOp = OpRangeTypeMin } - case 139: + case 140: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:329 { exprVAL.RangeOp = OpRangeTypeMax } - case 140: + case 141: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:330 { exprVAL.RangeOp = OpRangeTypeStdvar } - case 141: + case 142: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:331 { exprVAL.RangeOp = OpRangeTypeStddev } - case 142: + case 143: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:332 { exprVAL.RangeOp = OpRangeTypeQuantile } - case 143: + case 144: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:337 { exprVAL.Labels = []string{exprDollar[1].str} } - case 144: + case 145: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:338 { exprVAL.Labels = append(exprDollar[1].Labels, exprDollar[3].str) } - case 145: + case 146: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:342 { exprVAL.Grouping = &grouping{without: false, groups: exprDollar[3].Labels} } - case 146: + case 147: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:343 { exprVAL.Grouping = &grouping{without: true, groups: exprDollar[3].Labels} } diff --git a/pkg/logql/functions.go b/pkg/logql/functions.go index 9cf56d4dd95bf..4cd7cf0bdffbc 100644 --- a/pkg/logql/functions.go +++ b/pkg/logql/functions.go @@ -50,6 +50,8 @@ func (r rangeAggregationExpr) extractor(gr *grouping, all bool) (log.SampleExtra if r.left.unwrap != nil { var convOp string switch r.left.unwrap.operation { + case OpConvBytes: + convOp = log.ConvertBytes case OpConvDuration, OpConvDurationSeconds: convOp = log.ConvertDuration default: diff --git a/pkg/logql/lex.go b/pkg/logql/lex.go index 336b56674afc5..c977d008d81f3 100644 --- a/pkg/logql/lex.go +++ b/pkg/logql/lex.go @@ -86,6 +86,7 @@ var functionTokens = map[string]int{ OpTypeTopK: TOPK, // conversion Op + OpConvBytes: BYTES_CONV, OpConvDuration: DURATION_CONV, OpConvDurationSeconds: DURATION_SECONDS_CONV, } diff --git a/pkg/logql/log/metrics_extraction.go b/pkg/logql/log/metrics_extraction.go index 7c0791c8c482c..98149dc3506fa 100644 --- a/pkg/logql/log/metrics_extraction.go +++ b/pkg/logql/log/metrics_extraction.go @@ -7,9 +7,12 @@ import ( "github.com/pkg/errors" "github.com/prometheus/prometheus/pkg/labels" + + "github.com/dustin/go-humanize" ) const ( + ConvertBytes = "bytes" ConvertDuration = "duration" ConvertFloat = "float" ) @@ -117,6 +120,8 @@ func LabelExtractorWithStages( ) (SampleExtractor, error) { var convFn convertionFn switch conversion { + case ConvertBytes: + convFn = convertBytes case ConvertDuration: convFn = convertDuration case ConvertFloat: @@ -195,3 +200,11 @@ func convertDuration(v string) (float64, error) { } return d.Seconds(), nil } + +func convertBytes(v string) (float64, error) { + b, err := humanize.ParseBytes(v) + if err != nil { + return 0, err + } + return float64(b), nil +} diff --git a/pkg/logql/log/metrics_extraction_test.go b/pkg/logql/log/metrics_extraction_test.go index c6133c6bb81d5..a0b5d53fc5d6e 100644 --- a/pkg/logql/log/metrics_extraction_test.go +++ b/pkg/logql/log/metrics_extraction_test.go @@ -90,6 +90,24 @@ func Test_labelSampleExtractor_Extract(t *testing.T) { }, true, }, + { + "convert bytes", + mustSampleExtractor(LabelExtractorWithStages( + "foo", ConvertBytes, []string{"bar", "buzz"}, false, false, nil, NoopStage, + )), + labels.Labels{ + {Name: "foo", Value: "13 MiB"}, + {Name: "bar", Value: "foo"}, + {Name: "buzz", Value: "blip"}, + {Name: "namespace", Value: "dev"}, + }, + 13 * 1024 * 1024, + labels.Labels{ + {Name: "bar", Value: "foo"}, + {Name: "buzz", Value: "blip"}, + }, + true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/logql/parser_test.go b/pkg/logql/parser_test.go index 7ee139bcb549d..10cde5bcf152c 100644 --- a/pkg/logql/parser_test.go +++ b/pkg/logql/parser_test.go @@ -1228,6 +1228,27 @@ func TestParse(t *testing.T) { OpRangeTypeStdvar, nil, nil, ), }, + { + in: `sum_over_time({namespace="tns"} |= "level=error" | json |foo>=5,bar<25ms| unwrap bytes(foo) [5m])`, + exp: newRangeAggregationExpr( + newLogRange(&pipelineExpr{ + left: newMatcherExpr([]*labels.Matcher{{Type: labels.MatchEqual, Name: "namespace", Value: "tns"}}), + pipeline: MultiStageExpr{ + newLineFilterExpr(nil, labels.MatchEqual, "level=error"), + newLabelParserExpr(OpParserTypeJSON, ""), + &labelFilterExpr{ + LabelFilterer: log.NewAndLabelFilter( + log.NewNumericLabelFilter(log.LabelFilterGreaterThanOrEqual, "foo", 5), + log.NewDurationLabelFilter(log.LabelFilterLesserThan, "bar", 25*time.Millisecond), + ), + }, + }, + }, + 5*time.Minute, + newUnwrapExpr("foo", OpConvBytes)), + OpRangeTypeSum, nil, nil, + ), + }, { in: `sum_over_time({namespace="tns"} |= "level=error" | json |foo>=5,bar<25ms| unwrap latency [5m])`, exp: newRangeAggregationExpr(