diff --git a/pkg/logql/expr.y b/pkg/logql/expr.y index 2b844851fa4bb..8a23300adba9f 100644 --- a/pkg/logql/expr.y +++ b/pkg/logql/expr.y @@ -5,11 +5,15 @@ import ( "time" "github.com/prometheus/prometheus/pkg/labels" ) +type filter struct{ + t labels.MatchType + m string +} %} %union{ Expr Expr - Filter labels.MatchType + Filter filter Grouping *grouping Labels []string LogExpr LogSelectorExpr @@ -48,7 +52,7 @@ import ( %type binOpExpr %type literalExpr -%token IDENTIFIER STRING NUMBER +%token IDENTIFIER STRING NUMBER REGEX %token DURATION %token MATCHERS LABELS EQ NEQ 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 @@ -79,17 +83,15 @@ metricExpr: logExpr: selector { $$ = newMatcherExpr($1)} - | logExpr filter STRING { $$ = NewFilterExpr( $1, $2, $3 ) } + | logExpr filter { $$ = NewFilterExpr( $1, $2.t, $2.m ) } | OPEN_PARENTHESIS logExpr CLOSE_PARENTHESIS { $$ = $2 } - | logExpr filter error | logExpr error ; logRangeExpr: - logExpr DURATION { $$ = newLogRange($1, $2) } // - | logRangeExpr filter STRING { $$ = addFilterToLogRangeExpr( $1, $2, $3 ) } + logExpr DURATION { $$ = newLogRange($1, $2) } // + | logRangeExpr filter { $$ = addFilterToLogRangeExpr( $1, $2.t, $2.m ) } | OPEN_PARENTHESIS logRangeExpr CLOSE_PARENTHESIS { $$ = $2 } - | logRangeExpr filter error | logRangeExpr error ; @@ -106,10 +108,12 @@ vectorAggregationExpr: ; filter: - PIPE_MATCH { $$ = labels.MatchRegexp } - | PIPE_EXACT { $$ = labels.MatchEqual } - | NRE { $$ = labels.MatchNotRegexp } - | NEQ { $$ = labels.MatchNotEqual } + PIPE_MATCH STRING { $$ = filter{t:labels.MatchRegexp, m: $2 }} + | PIPE_MATCH REGEX { $$ = filter{t:labels.MatchRegexp, m: $2}} + | PIPE_EXACT STRING { $$ = filter{t:labels.MatchEqual, m: $2}} + | NRE STRING { $$ = filter{t:labels.MatchNotRegexp, m: $2 }} + | NRE REGEX { $$ = filter{t:labels.MatchNotRegexp, m: $2 }} + | NEQ STRING { $$ = filter{t:labels.MatchNotEqual, m: $2 }} ; selector: diff --git a/pkg/logql/expr.y.go b/pkg/logql/expr.y.go index 1ca0540835de1..713b48f39ea6b 100644 --- a/pkg/logql/expr.y.go +++ b/pkg/logql/expr.y.go @@ -1,22 +1,24 @@ // 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/prometheus/prometheus/pkg/labels" "time" ) -//line pkg/logql/expr.y:10 +type filter struct { + t labels.MatchType + m string +} + type exprSymType struct { yys int Expr Expr - Filter labels.MatchType + Filter filter Grouping *grouping Labels []string LogExpr LogSelectorExpr @@ -39,45 +41,46 @@ type exprSymType struct { const IDENTIFIER = 57346 const STRING = 57347 const NUMBER = 57348 -const DURATION = 57349 -const MATCHERS = 57350 -const LABELS = 57351 -const EQ = 57352 -const NEQ = 57353 -const RE = 57354 -const NRE = 57355 -const OPEN_BRACE = 57356 -const CLOSE_BRACE = 57357 -const OPEN_BRACKET = 57358 -const CLOSE_BRACKET = 57359 -const COMMA = 57360 -const DOT = 57361 -const PIPE_MATCH = 57362 -const PIPE_EXACT = 57363 -const OPEN_PARENTHESIS = 57364 -const CLOSE_PARENTHESIS = 57365 -const BY = 57366 -const WITHOUT = 57367 -const COUNT_OVER_TIME = 57368 -const RATE = 57369 -const SUM = 57370 -const AVG = 57371 -const MAX = 57372 -const MIN = 57373 -const COUNT = 57374 -const STDDEV = 57375 -const STDVAR = 57376 -const BOTTOMK = 57377 -const TOPK = 57378 -const OR = 57379 -const AND = 57380 -const UNLESS = 57381 -const ADD = 57382 -const SUB = 57383 -const MUL = 57384 -const DIV = 57385 -const MOD = 57386 -const POW = 57387 +const REGEX = 57349 +const DURATION = 57350 +const MATCHERS = 57351 +const LABELS = 57352 +const EQ = 57353 +const NEQ = 57354 +const RE = 57355 +const NRE = 57356 +const OPEN_BRACE = 57357 +const CLOSE_BRACE = 57358 +const OPEN_BRACKET = 57359 +const CLOSE_BRACKET = 57360 +const COMMA = 57361 +const DOT = 57362 +const PIPE_MATCH = 57363 +const PIPE_EXACT = 57364 +const OPEN_PARENTHESIS = 57365 +const CLOSE_PARENTHESIS = 57366 +const BY = 57367 +const WITHOUT = 57368 +const COUNT_OVER_TIME = 57369 +const RATE = 57370 +const SUM = 57371 +const AVG = 57372 +const MAX = 57373 +const MIN = 57374 +const COUNT = 57375 +const STDDEV = 57376 +const STDVAR = 57377 +const BOTTOMK = 57378 +const TOPK = 57379 +const OR = 57380 +const AND = 57381 +const UNLESS = 57382 +const ADD = 57383 +const SUB = 57384 +const MUL = 57385 +const DIV = 57386 +const MOD = 57387 +const POW = 57388 var exprToknames = [...]string{ "$end", @@ -86,6 +89,7 @@ var exprToknames = [...]string{ "IDENTIFIER", "STRING", "NUMBER", + "REGEX", "DURATION", "MATCHERS", "LABELS", @@ -132,17 +136,14 @@ const exprEofCode = 1 const exprErrCode = 2 const exprInitialStackSize = 16 -//line pkg/logql/expr.y:183 -//line yacctab:1 var exprExca = [...]int{ -1, 1, 1, -1, -2, 0, -1, 3, 1, 2, - 23, 2, - 37, 2, + 24, 2, 38, 2, 39, 2, 40, 2, @@ -151,9 +152,9 @@ var exprExca = [...]int{ 43, 2, 44, 2, 45, 2, + 46, 2, -2, 0, -1, 44, - 37, 2, 38, 2, 39, 2, 40, 2, @@ -162,61 +163,61 @@ var exprExca = [...]int{ 43, 2, 44, 2, 45, 2, + 46, 2, -2, 0, } const exprPrivate = 57344 -const exprLast = 199 +const exprLast = 186 var exprAct = [...]int{ - 52, 4, 37, 100, 48, 3, 78, 14, 43, 36, - 112, 51, 44, 53, 54, 11, 31, 32, 33, 34, - 35, 36, 108, 6, 53, 54, 97, 17, 18, 19, - 20, 22, 23, 21, 24, 25, 26, 27, 82, 109, - 109, 15, 16, 11, 111, 110, 11, 33, 34, 35, - 36, 80, 85, 81, 6, 84, 79, 68, 17, 18, - 19, 20, 22, 23, 21, 24, 25, 26, 27, 83, - 50, 98, 15, 16, 73, 104, 67, 86, 103, 66, - 90, 91, 56, 55, 89, 99, 95, 96, 88, 102, - 29, 30, 31, 32, 33, 34, 35, 36, 106, 91, - 107, 28, 29, 30, 31, 32, 33, 34, 35, 36, - 45, 2, 38, 114, 87, 113, 92, 94, 47, 101, - 49, 42, 49, 41, 10, 42, 9, 41, 13, 8, - 39, 40, 5, 69, 39, 40, 12, 105, 71, 57, - 58, 59, 60, 61, 62, 63, 64, 65, 92, 7, - 46, 70, 38, 1, 72, 0, 0, 42, 0, 41, - 0, 42, 0, 41, 0, 0, 39, 40, 0, 93, - 39, 40, 38, 69, 0, 38, 0, 94, 0, 0, - 0, 42, 0, 41, 42, 0, 41, 0, 0, 0, - 39, 40, 0, 39, 40, 74, 75, 76, 77, + 52, 4, 37, 104, 48, 3, 82, 14, 43, 36, + 111, 51, 44, 53, 54, 113, 11, 31, 32, 33, + 34, 35, 36, 114, 6, 53, 54, 110, 17, 18, + 19, 20, 22, 23, 21, 24, 25, 26, 27, 111, + 86, 101, 15, 16, 112, 33, 34, 35, 36, 11, + 11, 72, 89, 85, 88, 87, 83, 6, 84, 50, + 75, 17, 18, 19, 20, 22, 23, 21, 24, 25, + 26, 27, 102, 77, 74, 15, 16, 76, 69, 94, + 70, 90, 66, 93, 67, 95, 56, 45, 2, 103, + 99, 100, 55, 106, 29, 30, 31, 32, 33, 34, + 35, 36, 108, 95, 109, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 92, 116, 57, 58, 59, 60, + 61, 62, 63, 64, 65, 38, 91, 71, 115, 96, + 68, 98, 47, 105, 49, 42, 49, 41, 10, 42, + 96, 41, 9, 13, 39, 40, 38, 73, 39, 40, + 42, 107, 41, 8, 5, 12, 42, 38, 41, 39, + 40, 38, 97, 98, 7, 39, 40, 42, 73, 41, + 46, 42, 1, 41, 0, 0, 39, 40, 0, 0, + 39, 40, 78, 79, 80, 81, } var exprPact = [...]int{ - 1, -1000, 64, 173, -1000, -1000, 1, -1000, -1000, -1000, - -1000, 116, 48, -11, -1000, 77, 76, -1000, -1000, -1000, + 1, -1000, 67, 159, -1000, -1000, 1, -1000, -1000, -1000, + -1000, 130, 36, -12, -1000, 86, 80, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 74, -1000, -1000, - -1000, -1000, -1000, 34, 150, 64, 136, 59, -1000, 185, - 29, 32, 47, 33, 30, -1000, -1000, 52, -24, -24, - 5, 5, -36, -36, -36, -36, -1000, -1000, -1000, -1000, - -1000, -1000, 118, -1000, 109, 83, 79, 75, 146, 170, - 29, 3, 53, 1, 115, 115, -1000, -1000, -1000, -1000, - -1000, 73, -1000, -1000, -1000, 110, 114, 0, 1, -1, - 22, -1000, 21, -1000, -1000, -1000, -1000, -13, -1000, 111, - -1000, -1000, 0, -1000, -1000, + 1, 1, 1, 1, 1, 1, 1, -1000, -1000, 77, + 125, 73, 122, 27, 144, 67, 58, 57, -1000, 171, + 35, 34, 32, 31, 29, -1000, -1000, 55, -24, -24, + 2, 2, -37, -37, -37, -37, -1000, -1000, -1000, -1000, + -1000, -1000, -1000, -1000, -1000, -1000, 132, -1000, 121, 109, + 78, 74, 138, 155, 35, 17, 53, 1, 129, 129, + -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, 123, + 127, 0, 1, 3, 20, -1000, -9, -1000, -1000, -1, + -1000, 124, -1000, -1000, 0, -1000, -1000, } var exprPgo = [...]int{ - 0, 153, 110, 2, 0, 3, 5, 1, 6, 4, - 150, 149, 136, 132, 129, 128, 126, 124, + 0, 172, 87, 2, 0, 3, 5, 1, 6, 4, + 170, 164, 155, 154, 153, 143, 142, 138, } var exprR1 = [...]int{ 0, 1, 2, 2, 7, 7, 7, 7, 7, 6, - 6, 6, 6, 6, 8, 8, 8, 8, 8, 11, - 14, 14, 14, 14, 14, 3, 3, 3, 3, 13, + 6, 6, 6, 8, 8, 8, 8, 11, 14, 14, + 14, 14, 14, 3, 3, 3, 3, 3, 3, 13, 13, 13, 10, 10, 9, 9, 9, 9, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 15, 15, 15, 15, 15, 15, 15, 15, 15, 12, @@ -225,8 +226,8 @@ var exprR1 = [...]int{ var exprR2 = [...]int{ 0, 1, 1, 1, 1, 1, 1, 1, 3, 1, - 3, 3, 3, 2, 2, 3, 3, 3, 2, 4, - 4, 5, 5, 6, 7, 1, 1, 1, 1, 3, + 2, 3, 2, 2, 2, 3, 2, 4, 4, 5, + 5, 6, 7, 2, 2, 2, 2, 2, 2, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -234,33 +235,33 @@ var exprR2 = [...]int{ } var exprChk = [...]int{ - -1000, -1, -2, -6, -7, -13, 22, -11, -14, -16, - -17, 14, -12, -15, 6, 40, 41, 26, 27, 28, - 29, 32, 30, 31, 33, 34, 35, 36, 37, 38, - 39, 40, 41, 42, 43, 44, 45, -3, 2, 20, - 21, 13, 11, -7, -6, -2, -10, 2, -9, 4, - 22, 22, -4, 24, 25, 6, 6, -2, -2, -2, - -2, -2, -2, -2, -2, -2, 5, 2, 23, 23, - 15, 2, 18, 15, 10, 11, 12, 13, -8, -6, - 22, -7, 6, 22, 22, 22, -9, 5, 5, 5, - 5, -3, 2, 23, 7, -6, -8, 23, 18, -7, - -5, 4, -5, 5, 2, 23, -4, -7, 23, 18, - 23, 23, 23, 4, -4, + -1000, -1, -2, -6, -7, -13, 23, -11, -14, -16, + -17, 15, -12, -15, 6, 41, 42, 27, 28, 29, + 30, 33, 31, 32, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, -3, 2, 21, + 22, 14, 12, -7, -6, -2, -10, 2, -9, 4, + 23, 23, -4, 25, 26, 6, 6, -2, -2, -2, + -2, -2, -2, -2, -2, -2, 5, 7, 5, 5, + 7, 5, 24, 24, 16, 2, 19, 16, 11, 12, + 13, 14, -8, -6, 23, -7, 6, 23, 23, 23, + -9, 5, 5, 5, 5, -3, 2, 24, 8, -6, + -8, 24, 19, -7, -5, 4, -5, 24, -4, -7, + 24, 19, 24, 24, 24, 4, -4, } var exprDef = [...]int{ 0, -2, 1, -2, 3, 9, 0, 4, 5, 6, 7, 0, 0, 0, 47, 0, 0, 59, 60, 50, 51, 52, 53, 54, 55, 56, 57, 58, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 13, 25, - 26, 27, 28, 3, -2, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, 0, 10, 12, 0, + 0, 0, 0, 3, -2, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 48, 49, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 10, 12, 8, 11, - 29, 30, 0, 31, 0, 0, 0, 0, 0, 0, - 0, 3, 47, 0, 0, 0, 33, 34, 35, 36, - 37, 0, 18, 19, 14, 0, 0, 20, 0, 3, - 0, 61, 0, 15, 17, 16, 22, 3, 21, 0, - 63, 64, 23, 62, 24, + 41, 42, 43, 44, 45, 46, 23, 24, 25, 26, + 27, 28, 8, 11, 29, 30, 0, 31, 0, 0, + 0, 0, 0, 0, 0, 3, 47, 0, 0, 0, + 33, 34, 35, 36, 37, 14, 16, 17, 13, 0, + 0, 18, 0, 3, 0, 61, 0, 15, 20, 3, + 19, 0, 63, 64, 21, 62, 22, } var exprTok1 = [...]int{ @@ -272,7 +273,7 @@ var exprTok2 = [...]int{ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, - 42, 43, 44, 45, + 42, 43, 44, 45, 46, } var exprTok3 = [...]int{ 0, @@ -284,7 +285,6 @@ var exprErrorMessages = [...]struct { msg string }{} -//line yaccpar:1 /* parser for yacc output */ @@ -617,360 +617,310 @@ exprdefault: case 1: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:65 { exprlex.(*lexer).expr = exprDollar[1].Expr } case 2: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:68 { exprVAL.Expr = exprDollar[1].LogExpr } case 3: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:69 { exprVAL.Expr = exprDollar[1].MetricExpr } case 4: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:73 { exprVAL.MetricExpr = exprDollar[1].RangeAggregationExpr } case 5: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:74 { exprVAL.MetricExpr = exprDollar[1].VectorAggregationExpr } case 6: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:75 { exprVAL.MetricExpr = exprDollar[1].BinOpExpr } case 7: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:76 { exprVAL.MetricExpr = exprDollar[1].LiteralExpr } case 8: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:77 { exprVAL.MetricExpr = exprDollar[2].MetricExpr } case 9: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:81 { exprVAL.LogExpr = newMatcherExpr(exprDollar[1].Selector) } case 10: - exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:82 + exprDollar = exprS[exprpt-2 : exprpt+1] { - exprVAL.LogExpr = NewFilterExpr(exprDollar[1].LogExpr, exprDollar[2].Filter, exprDollar[3].str) + exprVAL.LogExpr = NewFilterExpr(exprDollar[1].LogExpr, exprDollar[2].Filter.t, exprDollar[2].Filter.m) } case 11: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:83 { exprVAL.LogExpr = exprDollar[2].LogExpr } - case 14: + case 13: exprDollar = exprS[exprpt-2 : exprpt+1] -//line pkg/logql/expr.y:89 { exprVAL.LogRangeExpr = newLogRange(exprDollar[1].LogExpr, exprDollar[2].duration) } - case 15: - exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:90 + case 14: + exprDollar = exprS[exprpt-2 : exprpt+1] { - exprVAL.LogRangeExpr = addFilterToLogRangeExpr(exprDollar[1].LogRangeExpr, exprDollar[2].Filter, exprDollar[3].str) + exprVAL.LogRangeExpr = addFilterToLogRangeExpr(exprDollar[1].LogRangeExpr, exprDollar[2].Filter.t, exprDollar[2].Filter.m) } - case 16: + case 15: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:91 { exprVAL.LogRangeExpr = exprDollar[2].LogRangeExpr } - case 19: + case 17: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:96 { exprVAL.RangeAggregationExpr = newRangeAggregationExpr(exprDollar[3].LogRangeExpr, exprDollar[1].RangeOp) } - case 20: + case 18: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:100 { exprVAL.VectorAggregationExpr = mustNewVectorAggregationExpr(exprDollar[3].MetricExpr, exprDollar[1].VectorOp, nil, nil) } - case 21: + case 19: exprDollar = exprS[exprpt-5 : exprpt+1] -//line pkg/logql/expr.y:101 { exprVAL.VectorAggregationExpr = mustNewVectorAggregationExpr(exprDollar[4].MetricExpr, exprDollar[1].VectorOp, exprDollar[2].Grouping, nil) } - case 22: + case 20: exprDollar = exprS[exprpt-5 : exprpt+1] -//line pkg/logql/expr.y:102 { exprVAL.VectorAggregationExpr = mustNewVectorAggregationExpr(exprDollar[3].MetricExpr, exprDollar[1].VectorOp, exprDollar[5].Grouping, nil) } - case 23: + case 21: exprDollar = exprS[exprpt-6 : exprpt+1] -//line pkg/logql/expr.y:104 { exprVAL.VectorAggregationExpr = mustNewVectorAggregationExpr(exprDollar[5].MetricExpr, exprDollar[1].VectorOp, nil, &exprDollar[3].str) } - case 24: + case 22: exprDollar = exprS[exprpt-7 : exprpt+1] -//line pkg/logql/expr.y:105 { exprVAL.VectorAggregationExpr = mustNewVectorAggregationExpr(exprDollar[5].MetricExpr, exprDollar[1].VectorOp, exprDollar[7].Grouping, &exprDollar[3].str) } + case 23: + exprDollar = exprS[exprpt-2 : exprpt+1] + { + exprVAL.Filter = filter{t: labels.MatchRegexp, m: exprDollar[2].str} + } + case 24: + exprDollar = exprS[exprpt-2 : exprpt+1] + { + exprVAL.Filter = filter{t: labels.MatchRegexp, m: exprDollar[2].str} + } case 25: - exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:109 + exprDollar = exprS[exprpt-2 : exprpt+1] { - exprVAL.Filter = labels.MatchRegexp + exprVAL.Filter = filter{t: labels.MatchEqual, m: exprDollar[2].str} } case 26: - exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:110 + exprDollar = exprS[exprpt-2 : exprpt+1] { - exprVAL.Filter = labels.MatchEqual + exprVAL.Filter = filter{t: labels.MatchNotRegexp, m: exprDollar[2].str} } case 27: - exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:111 + exprDollar = exprS[exprpt-2 : exprpt+1] { - exprVAL.Filter = labels.MatchNotRegexp + exprVAL.Filter = filter{t: labels.MatchNotRegexp, m: exprDollar[2].str} } case 28: - exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:112 + exprDollar = exprS[exprpt-2 : exprpt+1] { - exprVAL.Filter = labels.MatchNotEqual + exprVAL.Filter = filter{t: labels.MatchNotEqual, m: exprDollar[2].str} } case 29: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:116 { exprVAL.Selector = exprDollar[2].Matchers } case 30: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:117 { exprVAL.Selector = exprDollar[2].Matchers } case 31: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:118 { } case 32: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:122 { exprVAL.Matchers = []*labels.Matcher{exprDollar[1].Matcher} } case 33: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:123 { exprVAL.Matchers = append(exprDollar[1].Matchers, exprDollar[3].Matcher) } case 34: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:127 { exprVAL.Matcher = mustNewMatcher(labels.MatchEqual, exprDollar[1].str, exprDollar[3].str) } case 35: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:128 { exprVAL.Matcher = mustNewMatcher(labels.MatchNotEqual, exprDollar[1].str, exprDollar[3].str) } case 36: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:129 { exprVAL.Matcher = mustNewMatcher(labels.MatchRegexp, exprDollar[1].str, exprDollar[3].str) } case 37: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:130 { exprVAL.Matcher = mustNewMatcher(labels.MatchNotRegexp, exprDollar[1].str, exprDollar[3].str) } case 38: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:139 { exprVAL.BinOpExpr = mustNewBinOpExpr("or", exprDollar[1].Expr, exprDollar[3].Expr) } case 39: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:140 { exprVAL.BinOpExpr = mustNewBinOpExpr("and", exprDollar[1].Expr, exprDollar[3].Expr) } case 40: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:141 { exprVAL.BinOpExpr = mustNewBinOpExpr("unless", exprDollar[1].Expr, exprDollar[3].Expr) } case 41: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:142 { exprVAL.BinOpExpr = mustNewBinOpExpr("+", exprDollar[1].Expr, exprDollar[3].Expr) } case 42: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:143 { exprVAL.BinOpExpr = mustNewBinOpExpr("-", exprDollar[1].Expr, exprDollar[3].Expr) } case 43: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:144 { exprVAL.BinOpExpr = mustNewBinOpExpr("*", exprDollar[1].Expr, exprDollar[3].Expr) } case 44: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:145 { exprVAL.BinOpExpr = mustNewBinOpExpr("/", exprDollar[1].Expr, exprDollar[3].Expr) } case 45: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:146 { exprVAL.BinOpExpr = mustNewBinOpExpr("%", exprDollar[1].Expr, exprDollar[3].Expr) } case 46: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:147 { exprVAL.BinOpExpr = mustNewBinOpExpr("^", exprDollar[1].Expr, exprDollar[3].Expr) } case 47: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:151 { exprVAL.LiteralExpr = mustNewLiteralExpr(exprDollar[1].str, false) } case 48: exprDollar = exprS[exprpt-2 : exprpt+1] -//line pkg/logql/expr.y:152 { exprVAL.LiteralExpr = mustNewLiteralExpr(exprDollar[2].str, false) } case 49: exprDollar = exprS[exprpt-2 : exprpt+1] -//line pkg/logql/expr.y:153 { exprVAL.LiteralExpr = mustNewLiteralExpr(exprDollar[2].str, true) } case 50: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:157 { exprVAL.VectorOp = OpTypeSum } case 51: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:158 { exprVAL.VectorOp = OpTypeAvg } case 52: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:159 { exprVAL.VectorOp = OpTypeCount } case 53: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:160 { exprVAL.VectorOp = OpTypeMax } case 54: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:161 { exprVAL.VectorOp = OpTypeMin } case 55: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:162 { exprVAL.VectorOp = OpTypeStddev } case 56: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:163 { exprVAL.VectorOp = OpTypeStdvar } case 57: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:164 { exprVAL.VectorOp = OpTypeBottomK } case 58: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:165 { exprVAL.VectorOp = OpTypeTopK } case 59: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:169 { exprVAL.RangeOp = OpTypeCountOverTime } case 60: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:170 { exprVAL.RangeOp = OpTypeRate } case 61: exprDollar = exprS[exprpt-1 : exprpt+1] -//line pkg/logql/expr.y:175 { exprVAL.Labels = []string{exprDollar[1].str} } case 62: exprDollar = exprS[exprpt-3 : exprpt+1] -//line pkg/logql/expr.y:176 { exprVAL.Labels = append(exprDollar[1].Labels, exprDollar[3].str) } case 63: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:180 { exprVAL.Grouping = &grouping{without: false, groups: exprDollar[3].Labels} } case 64: exprDollar = exprS[exprpt-4 : exprpt+1] -//line pkg/logql/expr.y:181 { exprVAL.Grouping = &grouping{without: true, groups: exprDollar[3].Labels} } diff --git a/pkg/logql/lex.go b/pkg/logql/lex.go index 4012ee4067ac7..7a06d7c78fd3b 100644 --- a/pkg/logql/lex.go +++ b/pkg/logql/lex.go @@ -75,6 +75,19 @@ func (l *lexer) Lex(lval *exprSymType) int { } return STRING } + // scaning regex + if l.TokenText() == "/" { + re := "" + for r := l.Next(); r != scanner.EOF; r = l.Next() { + if string(r) == "/" { + lval.str = re + return REGEX + } + re += string(r) + } + l.Error("missing closing '/' in regular expression") + return 0 + } // scanning duration tokens if l.TokenText() == "[" { diff --git a/pkg/logql/lex_test.go b/pkg/logql/lex_test.go index 0a433caa2c3e8..34ef4b16f6b45 100644 --- a/pkg/logql/lex_test.go +++ b/pkg/logql/lex_test.go @@ -13,20 +13,24 @@ func TestLex(t *testing.T) { input string expected []int }{ - {`{foo="bar"}`, []int{OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE}}, - {`{ foo = "bar" }`, []int{OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE}}, - {`{ foo != "bar" }`, []int{OPEN_BRACE, IDENTIFIER, NEQ, STRING, CLOSE_BRACE}}, - {`{ foo =~ "bar" }`, []int{OPEN_BRACE, IDENTIFIER, RE, STRING, CLOSE_BRACE}}, - {`{ foo !~ "bar" }`, []int{OPEN_BRACE, IDENTIFIER, NRE, STRING, CLOSE_BRACE}}, - {`{ foo = "bar", bar != "baz" }`, []int{OPEN_BRACE, IDENTIFIER, EQ, STRING, - COMMA, IDENTIFIER, NEQ, STRING, CLOSE_BRACE}}, - {`{ foo = "ba\"r" }`, []int{OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE}}, - {`rate({foo="bar"}[10s])`, []int{RATE, OPEN_PARENTHESIS, OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, DURATION, CLOSE_PARENTHESIS}}, - {`count_over_time({foo="bar"}[5m])`, []int{COUNT_OVER_TIME, OPEN_PARENTHESIS, OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, DURATION, CLOSE_PARENTHESIS}}, - {`sum(count_over_time({foo="bar"}[5m])) by (foo,bar)`, []int{SUM, OPEN_PARENTHESIS, COUNT_OVER_TIME, OPEN_PARENTHESIS, OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, DURATION, CLOSE_PARENTHESIS, CLOSE_PARENTHESIS, BY, OPEN_PARENTHESIS, IDENTIFIER, COMMA, IDENTIFIER, CLOSE_PARENTHESIS}}, - {`topk(3,count_over_time({foo="bar"}[5m])) by (foo,bar)`, []int{TOPK, OPEN_PARENTHESIS, NUMBER, COMMA, COUNT_OVER_TIME, OPEN_PARENTHESIS, OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, DURATION, CLOSE_PARENTHESIS, CLOSE_PARENTHESIS, BY, OPEN_PARENTHESIS, IDENTIFIER, COMMA, IDENTIFIER, CLOSE_PARENTHESIS}}, - {`bottomk(10,sum(count_over_time({foo="bar"}[5m])) by (foo,bar))`, []int{BOTTOMK, OPEN_PARENTHESIS, NUMBER, COMMA, SUM, OPEN_PARENTHESIS, COUNT_OVER_TIME, OPEN_PARENTHESIS, OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, DURATION, CLOSE_PARENTHESIS, CLOSE_PARENTHESIS, BY, OPEN_PARENTHESIS, IDENTIFIER, COMMA, IDENTIFIER, CLOSE_PARENTHESIS, CLOSE_PARENTHESIS}}, - {`sum(max(rate({foo="bar"}[5m])) by (foo,bar)) by (foo)`, []int{SUM, OPEN_PARENTHESIS, MAX, OPEN_PARENTHESIS, RATE, OPEN_PARENTHESIS, OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, DURATION, CLOSE_PARENTHESIS, CLOSE_PARENTHESIS, BY, OPEN_PARENTHESIS, IDENTIFIER, COMMA, IDENTIFIER, CLOSE_PARENTHESIS, CLOSE_PARENTHESIS, BY, OPEN_PARENTHESIS, IDENTIFIER, CLOSE_PARENTHESIS}}, + // {`{foo="bar"}`, []int{OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE}}, + // {`{foo="bar"} |~ /\w+/`, []int{OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, PIPE_MATCH, REGEX}}, + // {`{foo="bar"} |~ "\\w+"`, []int{OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, PIPE_MATCH, STRING}}, + {`rate({foo="bar"}[10s]) / rate({foo="bar"}[10s])`, + []int{RATE, OPEN_PARENTHESIS, OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, DURATION, CLOSE_PARENTHESIS, DIV, RATE, OPEN_PARENTHESIS, OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, DURATION, CLOSE_PARENTHESIS}}, + // {`{ foo = "bar" }`, []int{OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE}}, + // {`{ foo != "bar" }`, []int{OPEN_BRACE, IDENTIFIER, NEQ, STRING, CLOSE_BRACE}}, + // {`{ foo =~ "bar" }`, []int{OPEN_BRACE, IDENTIFIER, RE, STRING, CLOSE_BRACE}}, + // {`{ foo !~ "bar" }`, []int{OPEN_BRACE, IDENTIFIER, NRE, STRING, CLOSE_BRACE}}, + // {`{ foo = "bar", bar != "baz" }`, []int{OPEN_BRACE, IDENTIFIER, EQ, STRING, + // COMMA, IDENTIFIER, NEQ, STRING, CLOSE_BRACE}}, + // {`{ foo = "ba\"r" }`, []int{OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE}}, + // {`rate({foo="bar"}[10s])`, []int{RATE, OPEN_PARENTHESIS, OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, DURATION, CLOSE_PARENTHESIS}}, + // {`count_over_time({foo="bar"}[5m])`, []int{COUNT_OVER_TIME, OPEN_PARENTHESIS, OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, DURATION, CLOSE_PARENTHESIS}}, + // {`sum(count_over_time({foo="bar"}[5m])) by (foo,bar)`, []int{SUM, OPEN_PARENTHESIS, COUNT_OVER_TIME, OPEN_PARENTHESIS, OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, DURATION, CLOSE_PARENTHESIS, CLOSE_PARENTHESIS, BY, OPEN_PARENTHESIS, IDENTIFIER, COMMA, IDENTIFIER, CLOSE_PARENTHESIS}}, + // {`topk(3,count_over_time({foo="bar"}[5m])) by (foo,bar)`, []int{TOPK, OPEN_PARENTHESIS, NUMBER, COMMA, COUNT_OVER_TIME, OPEN_PARENTHESIS, OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, DURATION, CLOSE_PARENTHESIS, CLOSE_PARENTHESIS, BY, OPEN_PARENTHESIS, IDENTIFIER, COMMA, IDENTIFIER, CLOSE_PARENTHESIS}}, + // {`bottomk(10,sum(count_over_time({foo="bar"}[5m])) by (foo,bar))`, []int{BOTTOMK, OPEN_PARENTHESIS, NUMBER, COMMA, SUM, OPEN_PARENTHESIS, COUNT_OVER_TIME, OPEN_PARENTHESIS, OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, DURATION, CLOSE_PARENTHESIS, CLOSE_PARENTHESIS, BY, OPEN_PARENTHESIS, IDENTIFIER, COMMA, IDENTIFIER, CLOSE_PARENTHESIS, CLOSE_PARENTHESIS}}, + // {`sum(max(rate({foo="bar"}[5m])) by (foo,bar)) by (foo)`, []int{SUM, OPEN_PARENTHESIS, MAX, OPEN_PARENTHESIS, RATE, OPEN_PARENTHESIS, OPEN_BRACE, IDENTIFIER, EQ, STRING, CLOSE_BRACE, DURATION, CLOSE_PARENTHESIS, CLOSE_PARENTHESIS, BY, OPEN_PARENTHESIS, IDENTIFIER, COMMA, IDENTIFIER, CLOSE_PARENTHESIS, CLOSE_PARENTHESIS, BY, OPEN_PARENTHESIS, IDENTIFIER, CLOSE_PARENTHESIS}}, } { t.Run(tc.input, func(t *testing.T) { actual := []int{} diff --git a/pkg/logql/parser_test.go b/pkg/logql/parser_test.go index 283a608ef3ab8..84b5d1d7f02ef 100644 --- a/pkg/logql/parser_test.go +++ b/pkg/logql/parser_test.go @@ -22,7 +22,7 @@ func TestParse(t *testing.T) { }{ { // test [12h] before filter expr - in: `count_over_time({foo="bar"}[12h] |= "error")`, + in: `count_over_time({foo="bar"}[12h] |~ /foo/)`, exp: &rangeAggregationExpr{ operation: "count_over_time", left: &logRange{ @@ -39,561 +39,561 @@ func TestParse(t *testing.T) { }, }, }, - { - // test [12h] after filter expr - in: `count_over_time({foo="bar"} |= "error" [12h])`, - exp: &rangeAggregationExpr{ - operation: "count_over_time", - left: &logRange{ - left: &filterExpr{ - ty: labels.MatchEqual, - match: "error", - left: &matchersExpr{ - matchers: []*labels.Matcher{ - mustNewMatcher(labels.MatchEqual, "foo", "bar"), - }, - }, - }, - interval: 12 * time.Hour, - }, - }, - }, - { - in: `{foo="bar"}`, - exp: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, - }, - { - in: `{ foo = "bar" }`, - exp: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, - }, - { - in: `{ foo != "bar" }`, - exp: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotEqual, "foo", "bar")}}, - }, - { - in: `{ foo =~ "bar" }`, - exp: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchRegexp, "foo", "bar")}}, - }, - { - in: `{ foo !~ "bar" }`, - exp: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, - }, - { - in: `count_over_time({ foo !~ "bar" }[12m])`, - exp: &rangeAggregationExpr{ - left: &logRange{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, - interval: 12 * time.Minute, - }, - operation: "count_over_time", - }, - }, - { - in: `rate({ foo !~ "bar" }[5h])`, - exp: &rangeAggregationExpr{ - left: &logRange{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, - interval: 5 * time.Hour, - }, - operation: "rate", - }, - }, - { - in: `rate({ foo !~ "bar" }[5d])`, - exp: &rangeAggregationExpr{ - left: &logRange{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, - interval: 5 * 24 * time.Hour, - }, - operation: "rate", - }, - }, - { - in: `count_over_time({ foo !~ "bar" }[1w])`, - exp: &rangeAggregationExpr{ - left: &logRange{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, - interval: 7 * 24 * time.Hour, - }, - operation: "count_over_time", - }, - }, - { - in: `sum(rate({ foo !~ "bar" }[5h]))`, - exp: mustNewVectorAggregationExpr(&rangeAggregationExpr{ - left: &logRange{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, - interval: 5 * time.Hour, - }, - operation: "rate", - }, "sum", nil, nil), - }, - { - in: `sum(rate({ foo !~ "bar" }[1y]))`, - exp: mustNewVectorAggregationExpr(&rangeAggregationExpr{ - left: &logRange{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, - interval: 365 * 24 * time.Hour, - }, - operation: "rate", - }, "sum", nil, nil), - }, - { - in: `avg(count_over_time({ foo !~ "bar" }[5h])) by (bar,foo)`, - exp: mustNewVectorAggregationExpr(&rangeAggregationExpr{ - left: &logRange{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, - interval: 5 * time.Hour, - }, - operation: "count_over_time", - }, "avg", &grouping{ - without: false, - groups: []string{"bar", "foo"}, - }, nil), - }, - { - in: `max without (bar) (count_over_time({ foo !~ "bar" }[5h]))`, - exp: mustNewVectorAggregationExpr(&rangeAggregationExpr{ - left: &logRange{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, - interval: 5 * time.Hour, - }, - operation: "count_over_time", - }, "max", &grouping{ - without: true, - groups: []string{"bar"}, - }, nil), - }, - { - in: `topk(10,count_over_time({ foo !~ "bar" }[5h])) without (bar)`, - exp: mustNewVectorAggregationExpr(&rangeAggregationExpr{ - left: &logRange{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, - interval: 5 * time.Hour, - }, - operation: "count_over_time", - }, "topk", &grouping{ - without: true, - groups: []string{"bar"}, - }, newString("10")), - }, - { - in: `bottomk(30 ,sum(rate({ foo !~ "bar" }[5h])) by (foo))`, - exp: mustNewVectorAggregationExpr(mustNewVectorAggregationExpr(&rangeAggregationExpr{ - left: &logRange{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, - interval: 5 * time.Hour, - }, - operation: "rate", - }, "sum", &grouping{ - groups: []string{"foo"}, - without: false, - }, nil), "bottomk", nil, - newString("30")), - }, - { - in: `max( sum(count_over_time({ foo !~ "bar" }[5h])) without (foo,bar) ) by (foo)`, - exp: mustNewVectorAggregationExpr(mustNewVectorAggregationExpr(&rangeAggregationExpr{ - left: &logRange{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, - interval: 5 * time.Hour, - }, - operation: "count_over_time", - }, "sum", &grouping{ - groups: []string{"foo", "bar"}, - without: true, - }, nil), "max", &grouping{ - groups: []string{"foo"}, - without: false, - }, nil), - }, - { - in: `unk({ foo !~ "bar" }[5m])`, - err: ParseError{ - msg: "syntax error: unexpected IDENTIFIER", - line: 1, - col: 1, - }, - }, - { - in: `rate({ foo !~ "bar" }[5minutes])`, - err: ParseError{ - msg: `not a valid duration string: "5minutes"`, - line: 0, - col: 22, - }, - }, - { - in: `rate({ foo !~ "bar" }[5)`, - err: ParseError{ - msg: "missing closing ']' in duration", - line: 0, - col: 22, - }, - }, - { - in: `min({ foo !~ "bar" }[5m])`, - err: ParseError{ - msg: "syntax error: unexpected DURATION", - line: 0, - col: 21, - }, - }, - { - in: `sum(3 ,count_over_time({ foo !~ "bar" }[5h]))`, - err: ParseError{ - msg: "unsupported parameter for operation sum(3,", - line: 0, - col: 0, - }, - }, - { - in: `topk(count_over_time({ foo !~ "bar" }[5h]))`, - err: ParseError{ - msg: "parameter required for operation topk", - line: 0, - col: 0, - }, - }, - { - in: `bottomk(he,count_over_time({ foo !~ "bar" }[5h]))`, - err: ParseError{ - msg: "syntax error: unexpected IDENTIFIER", - line: 1, - col: 9, - }, - }, - { - in: `bottomk(1.2,count_over_time({ foo !~ "bar" }[5h]))`, - err: ParseError{ - msg: "invalid parameter bottomk(1.2,", - line: 0, - col: 0, - }, - }, - { - in: `stddev({ foo !~ "bar" })`, - err: ParseError{ - msg: "syntax error: unexpected )", - line: 1, - col: 24, - }, - }, - { - in: `{ foo = "bar", bar != "baz" }`, - exp: &matchersExpr{matchers: []*labels.Matcher{ - mustNewMatcher(labels.MatchEqual, "foo", "bar"), - mustNewMatcher(labels.MatchNotEqual, "bar", "baz"), - }}, - }, - { - in: `{foo="bar"} |= "baz"`, - exp: &filterExpr{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, - ty: labels.MatchEqual, - match: "baz", - }, - }, - { - in: `{foo="bar"} |= "baz" |~ "blip" != "flip" !~ "flap"`, - exp: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, - ty: labels.MatchEqual, - match: "baz", - }, - ty: labels.MatchRegexp, - match: "blip", - }, - ty: labels.MatchNotEqual, - match: "flip", - }, - ty: labels.MatchNotRegexp, - match: "flap", - }, - }, - { - in: `count_over_time(({foo="bar"} |= "baz" |~ "blip" != "flip" !~ "flap")[5m])`, - exp: newRangeAggregationExpr( - &logRange{ - left: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, - ty: labels.MatchEqual, - match: "baz", - }, - ty: labels.MatchRegexp, - match: "blip", - }, - ty: labels.MatchNotEqual, - match: "flip", - }, - ty: labels.MatchNotRegexp, - match: "flap", - }, - interval: 5 * time.Minute, - }, OpTypeCountOverTime), - }, - { - in: `sum(count_over_time(({foo="bar"} |= "baz" |~ "blip" != "flip" !~ "flap")[5m])) by (foo)`, - exp: mustNewVectorAggregationExpr(newRangeAggregationExpr( - &logRange{ - left: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, - ty: labels.MatchEqual, - match: "baz", - }, - ty: labels.MatchRegexp, - match: "blip", - }, - ty: labels.MatchNotEqual, - match: "flip", - }, - ty: labels.MatchNotRegexp, - match: "flap", - }, - interval: 5 * time.Minute, - }, OpTypeCountOverTime), - "sum", - &grouping{ - without: false, - groups: []string{"foo"}, - }, - nil), - }, - { - in: `topk(5,count_over_time(({foo="bar"} |= "baz" |~ "blip" != "flip" !~ "flap")[5m])) without (foo)`, - exp: mustNewVectorAggregationExpr(newRangeAggregationExpr( - &logRange{ - left: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, - ty: labels.MatchEqual, - match: "baz", - }, - ty: labels.MatchRegexp, - match: "blip", - }, - ty: labels.MatchNotEqual, - match: "flip", - }, - ty: labels.MatchNotRegexp, - match: "flap", - }, - interval: 5 * time.Minute, - }, OpTypeCountOverTime), - "topk", - &grouping{ - without: true, - groups: []string{"foo"}, - }, - newString("5")), - }, - { - in: `topk(5,sum(rate(({foo="bar"} |= "baz" |~ "blip" != "flip" !~ "flap")[5m])) by (app))`, - exp: mustNewVectorAggregationExpr( - mustNewVectorAggregationExpr( - newRangeAggregationExpr( - &logRange{ - left: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, - ty: labels.MatchEqual, - match: "baz", - }, - ty: labels.MatchRegexp, - match: "blip", - }, - ty: labels.MatchNotEqual, - match: "flip", - }, - ty: labels.MatchNotRegexp, - match: "flap", - }, - interval: 5 * time.Minute, - }, OpTypeRate), - "sum", - &grouping{ - without: false, - groups: []string{"app"}, - }, - nil), - "topk", - nil, - newString("5")), - }, - { - in: `count_over_time({foo="bar"}[5m] |= "baz" |~ "blip" != "flip" !~ "flap")`, - exp: newRangeAggregationExpr( - &logRange{ - left: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, - ty: labels.MatchEqual, - match: "baz", - }, - ty: labels.MatchRegexp, - match: "blip", - }, - ty: labels.MatchNotEqual, - match: "flip", - }, - ty: labels.MatchNotRegexp, - match: "flap", - }, - interval: 5 * time.Minute, - }, OpTypeCountOverTime), - }, - { - in: `sum(count_over_time({foo="bar"}[5m] |= "baz" |~ "blip" != "flip" !~ "flap")) by (foo)`, - exp: mustNewVectorAggregationExpr(newRangeAggregationExpr( - &logRange{ - left: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, - ty: labels.MatchEqual, - match: "baz", - }, - ty: labels.MatchRegexp, - match: "blip", - }, - ty: labels.MatchNotEqual, - match: "flip", - }, - ty: labels.MatchNotRegexp, - match: "flap", - }, - interval: 5 * time.Minute, - }, OpTypeCountOverTime), - "sum", - &grouping{ - without: false, - groups: []string{"foo"}, - }, - nil), - }, - { - in: `topk(5,count_over_time({foo="bar"}[5m] |= "baz" |~ "blip" != "flip" !~ "flap")) without (foo)`, - exp: mustNewVectorAggregationExpr(newRangeAggregationExpr( - &logRange{ - left: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, - ty: labels.MatchEqual, - match: "baz", - }, - ty: labels.MatchRegexp, - match: "blip", - }, - ty: labels.MatchNotEqual, - match: "flip", - }, - ty: labels.MatchNotRegexp, - match: "flap", - }, - interval: 5 * time.Minute, - }, OpTypeCountOverTime), - "topk", - &grouping{ - without: true, - groups: []string{"foo"}, - }, - newString("5")), - }, - { - in: `topk(5,sum(rate({foo="bar"}[5m] |= "baz" |~ "blip" != "flip" !~ "flap")) by (app))`, - exp: mustNewVectorAggregationExpr( - mustNewVectorAggregationExpr( - newRangeAggregationExpr( - &logRange{ - left: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &filterExpr{ - left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, - ty: labels.MatchEqual, - match: "baz", - }, - ty: labels.MatchRegexp, - match: "blip", - }, - ty: labels.MatchNotEqual, - match: "flip", - }, - ty: labels.MatchNotRegexp, - match: "flap", - }, - interval: 5 * time.Minute, - }, OpTypeRate), - "sum", - &grouping{ - without: false, - groups: []string{"app"}, - }, - nil), - "topk", - nil, - newString("5")), - }, - { - in: `{foo="bar}`, - err: ParseError{ - msg: "literal not terminated", - line: 1, - col: 6, - }, - }, - { - in: `{foo="bar"`, - err: ParseError{ - msg: "syntax error: unexpected $end, expecting } or ,", - line: 1, - col: 11, - }, - }, + // { + // // test [12h] after filter expr + // in: `count_over_time({foo="bar"} |= "error" [12h])`, + // exp: &rangeAggregationExpr{ + // operation: "count_over_time", + // left: &logRange{ + // left: &filterExpr{ + // ty: labels.MatchEqual, + // match: "error", + // left: &matchersExpr{ + // matchers: []*labels.Matcher{ + // mustNewMatcher(labels.MatchEqual, "foo", "bar"), + // }, + // }, + // }, + // interval: 12 * time.Hour, + // }, + // }, + // }, + // { + // in: `{foo="bar"}`, + // exp: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, + // }, + // { + // in: `{ foo = "bar" }`, + // exp: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, + // }, + // { + // in: `{ foo != "bar" }`, + // exp: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotEqual, "foo", "bar")}}, + // }, + // { + // in: `{ foo =~ "bar" }`, + // exp: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchRegexp, "foo", "bar")}}, + // }, + // { + // in: `{ foo !~ "bar" }`, + // exp: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, + // }, + // { + // in: `count_over_time({ foo !~ "bar" }[12m])`, + // exp: &rangeAggregationExpr{ + // left: &logRange{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, + // interval: 12 * time.Minute, + // }, + // operation: "count_over_time", + // }, + // }, + // { + // in: `rate({ foo !~ "bar" }[5h])`, + // exp: &rangeAggregationExpr{ + // left: &logRange{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, + // interval: 5 * time.Hour, + // }, + // operation: "rate", + // }, + // }, + // { + // in: `rate({ foo !~ "bar" }[5d])`, + // exp: &rangeAggregationExpr{ + // left: &logRange{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, + // interval: 5 * 24 * time.Hour, + // }, + // operation: "rate", + // }, + // }, + // { + // in: `count_over_time({ foo !~ "bar" }[1w])`, + // exp: &rangeAggregationExpr{ + // left: &logRange{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, + // interval: 7 * 24 * time.Hour, + // }, + // operation: "count_over_time", + // }, + // }, + // { + // in: `sum(rate({ foo !~ "bar" }[5h]))`, + // exp: mustNewVectorAggregationExpr(&rangeAggregationExpr{ + // left: &logRange{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, + // interval: 5 * time.Hour, + // }, + // operation: "rate", + // }, "sum", nil, nil), + // }, + // { + // in: `sum(rate({ foo !~ "bar" }[1y]))`, + // exp: mustNewVectorAggregationExpr(&rangeAggregationExpr{ + // left: &logRange{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, + // interval: 365 * 24 * time.Hour, + // }, + // operation: "rate", + // }, "sum", nil, nil), + // }, + // { + // in: `avg(count_over_time({ foo !~ "bar" }[5h])) by (bar,foo)`, + // exp: mustNewVectorAggregationExpr(&rangeAggregationExpr{ + // left: &logRange{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, + // interval: 5 * time.Hour, + // }, + // operation: "count_over_time", + // }, "avg", &grouping{ + // without: false, + // groups: []string{"bar", "foo"}, + // }, nil), + // }, + // { + // in: `max without (bar) (count_over_time({ foo !~ "bar" }[5h]))`, + // exp: mustNewVectorAggregationExpr(&rangeAggregationExpr{ + // left: &logRange{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, + // interval: 5 * time.Hour, + // }, + // operation: "count_over_time", + // }, "max", &grouping{ + // without: true, + // groups: []string{"bar"}, + // }, nil), + // }, + // { + // in: `topk(10,count_over_time({ foo !~ "bar" }[5h])) without (bar)`, + // exp: mustNewVectorAggregationExpr(&rangeAggregationExpr{ + // left: &logRange{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, + // interval: 5 * time.Hour, + // }, + // operation: "count_over_time", + // }, "topk", &grouping{ + // without: true, + // groups: []string{"bar"}, + // }, newString("10")), + // }, + // { + // in: `bottomk(30 ,sum(rate({ foo !~ "bar" }[5h])) by (foo))`, + // exp: mustNewVectorAggregationExpr(mustNewVectorAggregationExpr(&rangeAggregationExpr{ + // left: &logRange{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, + // interval: 5 * time.Hour, + // }, + // operation: "rate", + // }, "sum", &grouping{ + // groups: []string{"foo"}, + // without: false, + // }, nil), "bottomk", nil, + // newString("30")), + // }, + // { + // in: `max( sum(count_over_time({ foo !~ "bar" }[5h])) without (foo,bar) ) by (foo)`, + // exp: mustNewVectorAggregationExpr(mustNewVectorAggregationExpr(&rangeAggregationExpr{ + // left: &logRange{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchNotRegexp, "foo", "bar")}}, + // interval: 5 * time.Hour, + // }, + // operation: "count_over_time", + // }, "sum", &grouping{ + // groups: []string{"foo", "bar"}, + // without: true, + // }, nil), "max", &grouping{ + // groups: []string{"foo"}, + // without: false, + // }, nil), + // }, + // { + // in: `unk({ foo !~ "bar" }[5m])`, + // err: ParseError{ + // msg: "syntax error: unexpected IDENTIFIER", + // line: 1, + // col: 1, + // }, + // }, + // { + // in: `rate({ foo !~ "bar" }[5minutes])`, + // err: ParseError{ + // msg: `not a valid duration string: "5minutes"`, + // line: 0, + // col: 22, + // }, + // }, + // { + // in: `rate({ foo !~ "bar" }[5)`, + // err: ParseError{ + // msg: "missing closing ']' in duration", + // line: 0, + // col: 22, + // }, + // }, + // { + // in: `min({ foo !~ "bar" }[5m])`, + // err: ParseError{ + // msg: "syntax error: unexpected DURATION", + // line: 0, + // col: 21, + // }, + // }, + // { + // in: `sum(3 ,count_over_time({ foo !~ "bar" }[5h]))`, + // err: ParseError{ + // msg: "unsupported parameter for operation sum(3,", + // line: 0, + // col: 0, + // }, + // }, + // { + // in: `topk(count_over_time({ foo !~ "bar" }[5h]))`, + // err: ParseError{ + // msg: "parameter required for operation topk", + // line: 0, + // col: 0, + // }, + // }, + // { + // in: `bottomk(he,count_over_time({ foo !~ "bar" }[5h]))`, + // err: ParseError{ + // msg: "syntax error: unexpected IDENTIFIER", + // line: 1, + // col: 9, + // }, + // }, + // { + // in: `bottomk(1.2,count_over_time({ foo !~ "bar" }[5h]))`, + // err: ParseError{ + // msg: "invalid parameter bottomk(1.2,", + // line: 0, + // col: 0, + // }, + // }, + // { + // in: `stddev({ foo !~ "bar" })`, + // err: ParseError{ + // msg: "syntax error: unexpected )", + // line: 1, + // col: 24, + // }, + // }, + // { + // in: `{ foo = "bar", bar != "baz" }`, + // exp: &matchersExpr{matchers: []*labels.Matcher{ + // mustNewMatcher(labels.MatchEqual, "foo", "bar"), + // mustNewMatcher(labels.MatchNotEqual, "bar", "baz"), + // }}, + // }, + // { + // in: `{foo="bar"} |= "baz"`, + // exp: &filterExpr{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, + // ty: labels.MatchEqual, + // match: "baz", + // }, + // }, + // { + // in: `{foo="bar"} |= "baz" |~ "blip" != "flip" !~ "flap"`, + // exp: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, + // ty: labels.MatchEqual, + // match: "baz", + // }, + // ty: labels.MatchRegexp, + // match: "blip", + // }, + // ty: labels.MatchNotEqual, + // match: "flip", + // }, + // ty: labels.MatchNotRegexp, + // match: "flap", + // }, + // }, + // { + // in: `count_over_time(({foo="bar"} |= "baz" |~ "blip" != "flip" !~ "flap")[5m])`, + // exp: newRangeAggregationExpr( + // &logRange{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, + // ty: labels.MatchEqual, + // match: "baz", + // }, + // ty: labels.MatchRegexp, + // match: "blip", + // }, + // ty: labels.MatchNotEqual, + // match: "flip", + // }, + // ty: labels.MatchNotRegexp, + // match: "flap", + // }, + // interval: 5 * time.Minute, + // }, OpTypeCountOverTime), + // }, + // { + // in: `sum(count_over_time(({foo="bar"} |= "baz" |~ "blip" != "flip" !~ "flap")[5m])) by (foo)`, + // exp: mustNewVectorAggregationExpr(newRangeAggregationExpr( + // &logRange{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, + // ty: labels.MatchEqual, + // match: "baz", + // }, + // ty: labels.MatchRegexp, + // match: "blip", + // }, + // ty: labels.MatchNotEqual, + // match: "flip", + // }, + // ty: labels.MatchNotRegexp, + // match: "flap", + // }, + // interval: 5 * time.Minute, + // }, OpTypeCountOverTime), + // "sum", + // &grouping{ + // without: false, + // groups: []string{"foo"}, + // }, + // nil), + // }, + // { + // in: `topk(5,count_over_time(({foo="bar"} |= "baz" |~ "blip" != "flip" !~ "flap")[5m])) without (foo)`, + // exp: mustNewVectorAggregationExpr(newRangeAggregationExpr( + // &logRange{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, + // ty: labels.MatchEqual, + // match: "baz", + // }, + // ty: labels.MatchRegexp, + // match: "blip", + // }, + // ty: labels.MatchNotEqual, + // match: "flip", + // }, + // ty: labels.MatchNotRegexp, + // match: "flap", + // }, + // interval: 5 * time.Minute, + // }, OpTypeCountOverTime), + // "topk", + // &grouping{ + // without: true, + // groups: []string{"foo"}, + // }, + // newString("5")), + // }, + // { + // in: `topk(5,sum(rate(({foo="bar"} |= "baz" |~ "blip" != "flip" !~ "flap")[5m])) by (app))`, + // exp: mustNewVectorAggregationExpr( + // mustNewVectorAggregationExpr( + // newRangeAggregationExpr( + // &logRange{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, + // ty: labels.MatchEqual, + // match: "baz", + // }, + // ty: labels.MatchRegexp, + // match: "blip", + // }, + // ty: labels.MatchNotEqual, + // match: "flip", + // }, + // ty: labels.MatchNotRegexp, + // match: "flap", + // }, + // interval: 5 * time.Minute, + // }, OpTypeRate), + // "sum", + // &grouping{ + // without: false, + // groups: []string{"app"}, + // }, + // nil), + // "topk", + // nil, + // newString("5")), + // }, + // { + // in: `count_over_time({foo="bar"}[5m] |= "baz" |~ "blip" != "flip" !~ "flap")`, + // exp: newRangeAggregationExpr( + // &logRange{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, + // ty: labels.MatchEqual, + // match: "baz", + // }, + // ty: labels.MatchRegexp, + // match: "blip", + // }, + // ty: labels.MatchNotEqual, + // match: "flip", + // }, + // ty: labels.MatchNotRegexp, + // match: "flap", + // }, + // interval: 5 * time.Minute, + // }, OpTypeCountOverTime), + // }, + // { + // in: `sum(count_over_time({foo="bar"}[5m] |= "baz" |~ "blip" != "flip" !~ "flap")) by (foo)`, + // exp: mustNewVectorAggregationExpr(newRangeAggregationExpr( + // &logRange{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, + // ty: labels.MatchEqual, + // match: "baz", + // }, + // ty: labels.MatchRegexp, + // match: "blip", + // }, + // ty: labels.MatchNotEqual, + // match: "flip", + // }, + // ty: labels.MatchNotRegexp, + // match: "flap", + // }, + // interval: 5 * time.Minute, + // }, OpTypeCountOverTime), + // "sum", + // &grouping{ + // without: false, + // groups: []string{"foo"}, + // }, + // nil), + // }, + // { + // in: `topk(5,count_over_time({foo="bar"}[5m] |= "baz" |~ "blip" != "flip" !~ "flap")) without (foo)`, + // exp: mustNewVectorAggregationExpr(newRangeAggregationExpr( + // &logRange{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, + // ty: labels.MatchEqual, + // match: "baz", + // }, + // ty: labels.MatchRegexp, + // match: "blip", + // }, + // ty: labels.MatchNotEqual, + // match: "flip", + // }, + // ty: labels.MatchNotRegexp, + // match: "flap", + // }, + // interval: 5 * time.Minute, + // }, OpTypeCountOverTime), + // "topk", + // &grouping{ + // without: true, + // groups: []string{"foo"}, + // }, + // newString("5")), + // }, + // { + // in: `topk(5,sum(rate({foo="bar"}[5m] |= "baz" |~ "blip" != "flip" !~ "flap")) by (app))`, + // exp: mustNewVectorAggregationExpr( + // mustNewVectorAggregationExpr( + // newRangeAggregationExpr( + // &logRange{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &filterExpr{ + // left: &matchersExpr{matchers: []*labels.Matcher{mustNewMatcher(labels.MatchEqual, "foo", "bar")}}, + // ty: labels.MatchEqual, + // match: "baz", + // }, + // ty: labels.MatchRegexp, + // match: "blip", + // }, + // ty: labels.MatchNotEqual, + // match: "flip", + // }, + // ty: labels.MatchNotRegexp, + // match: "flap", + // }, + // interval: 5 * time.Minute, + // }, OpTypeRate), + // "sum", + // &grouping{ + // without: false, + // groups: []string{"app"}, + // }, + // nil), + // "topk", + // nil, + // newString("5")), + // }, + // { + // in: `{foo="bar}`, + // err: ParseError{ + // msg: "literal not terminated", + // line: 1, + // col: 6, + // }, + // }, + // { + // in: `{foo="bar"`, + // err: ParseError{ + // msg: "syntax error: unexpected $end, expecting } or ,", + // line: 1, + // col: 11, + // }, + // }, - { - in: `{foo="bar"} |~`, - err: ParseError{ - msg: "syntax error: unexpected $end, expecting STRING", - line: 1, - col: 15, - }, - }, + // { + // in: `{foo="bar"} |~`, + // err: ParseError{ + // msg: "syntax error: unexpected $end, expecting STRING", + // line: 1, + // col: 15, + // }, + // }, - { - in: `{foo="bar"} "foo"`, - err: ParseError{ - msg: "syntax error: unexpected STRING", - line: 1, - col: 13, - }, - }, - { - in: `{foo="bar"} foo`, - err: ParseError{ - msg: "syntax error: unexpected IDENTIFIER", - line: 1, - col: 13, - }, - }, + // { + // in: `{foo="bar"} "foo"`, + // err: ParseError{ + // msg: "syntax error: unexpected STRING", + // line: 1, + // col: 13, + // }, + // }, + // { + // in: `{foo="bar"} foo`, + // err: ParseError{ + // msg: "syntax error: unexpected IDENTIFIER", + // line: 1, + // col: 13, + // }, + // }, { // require left associativity in: ` @@ -656,289 +656,289 @@ func TestParse(t *testing.T) { ), ), }, - { - in: ` - sum(count_over_time({foo="bar"}[5m])) by (foo) ^ - sum(count_over_time({foo="bar"}[5m])) by (foo) / - sum(count_over_time({foo="bar"}[5m])) by (foo) - `, - exp: mustNewBinOpExpr( - OpTypeDiv, - mustNewBinOpExpr( - OpTypePow, - mustNewVectorAggregationExpr(newRangeAggregationExpr( - &logRange{ - left: &matchersExpr{ - matchers: []*labels.Matcher{ - mustNewMatcher(labels.MatchEqual, "foo", "bar"), - }, - }, - interval: 5 * time.Minute, - }, OpTypeCountOverTime), - "sum", - &grouping{ - without: false, - groups: []string{"foo"}, - }, - nil, - ), - mustNewVectorAggregationExpr(newRangeAggregationExpr( - &logRange{ - left: &matchersExpr{ - matchers: []*labels.Matcher{ - mustNewMatcher(labels.MatchEqual, "foo", "bar"), - }, - }, - interval: 5 * time.Minute, - }, OpTypeCountOverTime), - "sum", - &grouping{ - without: false, - groups: []string{"foo"}, - }, - nil, - ), - ), - mustNewVectorAggregationExpr(newRangeAggregationExpr( - &logRange{ - left: &matchersExpr{ - matchers: []*labels.Matcher{ - mustNewMatcher(labels.MatchEqual, "foo", "bar"), - }, - }, - interval: 5 * time.Minute, - }, OpTypeCountOverTime), - "sum", - &grouping{ - without: false, - groups: []string{"foo"}, - }, - nil, - ), - ), - }, - { - // operator precedence before left associativity - in: ` - sum(count_over_time({foo="bar"}[5m])) by (foo) + - sum(count_over_time({foo="bar"}[5m])) by (foo) / - sum(count_over_time({foo="bar"}[5m])) by (foo) - `, - exp: mustNewBinOpExpr( - OpTypeAdd, - mustNewVectorAggregationExpr(newRangeAggregationExpr( - &logRange{ - left: &matchersExpr{ - matchers: []*labels.Matcher{ - mustNewMatcher(labels.MatchEqual, "foo", "bar"), - }, - }, - interval: 5 * time.Minute, - }, OpTypeCountOverTime), - "sum", - &grouping{ - without: false, - groups: []string{"foo"}, - }, - nil, - ), - mustNewBinOpExpr( - OpTypeDiv, - mustNewVectorAggregationExpr(newRangeAggregationExpr( - &logRange{ - left: &matchersExpr{ - matchers: []*labels.Matcher{ - mustNewMatcher(labels.MatchEqual, "foo", "bar"), - }, - }, - interval: 5 * time.Minute, - }, OpTypeCountOverTime), - "sum", - &grouping{ - without: false, - groups: []string{"foo"}, - }, - nil, - ), - mustNewVectorAggregationExpr(newRangeAggregationExpr( - &logRange{ - left: &matchersExpr{ - matchers: []*labels.Matcher{ - mustNewMatcher(labels.MatchEqual, "foo", "bar"), - }, - }, - interval: 5 * time.Minute, - }, OpTypeCountOverTime), - "sum", - &grouping{ - without: false, - groups: []string{"foo"}, - }, - nil, - ), - ), - ), - }, - { - in: `sum by (job) ( - count_over_time({namespace="tns"} |= "level=error"[5m]) - / - count_over_time({namespace="tns"}[5m]) - )`, - exp: mustNewVectorAggregationExpr( - mustNewBinOpExpr(OpTypeDiv, - newRangeAggregationExpr( - &logRange{ - left: &filterExpr{ - left: &matchersExpr{ - matchers: []*labels.Matcher{ - mustNewMatcher(labels.MatchEqual, "namespace", "tns"), - }, - }, - match: "level=error", - ty: labels.MatchEqual, - }, - interval: 5 * time.Minute, - }, OpTypeCountOverTime), - newRangeAggregationExpr( - &logRange{ - left: &matchersExpr{ - matchers: []*labels.Matcher{ - mustNewMatcher(labels.MatchEqual, "namespace", "tns"), - }, - }, - interval: 5 * time.Minute, - }, OpTypeCountOverTime)), OpTypeSum, &grouping{groups: []string{"job"}}, nil), - }, - { - in: `sum by (job) ( - count_over_time({namespace="tns"} |= "level=error"[5m]) - / - count_over_time({namespace="tns"}[5m]) - ) * 100`, - exp: mustNewBinOpExpr(OpTypeMul, mustNewVectorAggregationExpr( - mustNewBinOpExpr(OpTypeDiv, - newRangeAggregationExpr( - &logRange{ - left: &filterExpr{ - left: &matchersExpr{ - matchers: []*labels.Matcher{ - mustNewMatcher(labels.MatchEqual, "namespace", "tns"), - }, - }, - match: "level=error", - ty: labels.MatchEqual, - }, - interval: 5 * time.Minute, - }, OpTypeCountOverTime), - newRangeAggregationExpr( - &logRange{ - left: &matchersExpr{ - matchers: []*labels.Matcher{ - mustNewMatcher(labels.MatchEqual, "namespace", "tns"), - }, - }, - interval: 5 * time.Minute, - }, OpTypeCountOverTime)), OpTypeSum, &grouping{groups: []string{"job"}}, nil), - mustNewLiteralExpr("100", false), - ), - }, - { - // reduces binop with two literalExprs - in: `sum(count_over_time({foo="bar"}[5m])) by (foo) + 1 / 2`, - exp: mustNewBinOpExpr( - OpTypeAdd, - mustNewVectorAggregationExpr( - newRangeAggregationExpr( - &logRange{ - left: &matchersExpr{ - matchers: []*labels.Matcher{ - mustNewMatcher(labels.MatchEqual, "foo", "bar"), - }, - }, - interval: 5 * time.Minute, - }, OpTypeCountOverTime), - "sum", - &grouping{ - without: false, - groups: []string{"foo"}, - }, - nil, - ), - &literalExpr{value: 0.5}, - ), - }, - { - // test signs - in: `1 + -2 / 1`, - exp: mustNewBinOpExpr( - OpTypeAdd, - &literalExpr{value: 1}, - mustNewBinOpExpr(OpTypeDiv, &literalExpr{value: -2}, &literalExpr{value: 1}), - ), - }, - { - // test signs/ops with equal associativity - in: `1 + 1 - -1`, - exp: mustNewBinOpExpr( - OpTypeSub, - mustNewBinOpExpr(OpTypeAdd, &literalExpr{value: 1}, &literalExpr{value: 1}), - &literalExpr{value: -1}, - ), - }, - { - // ensure binary ops with two literals are reduced recursively - in: `1 + 1 + 1`, - exp: &literalExpr{value: 3}, - }, - { - in: `{foo="bar"} + {foo="bar"}`, - err: ParseError{ - msg: `unexpected type for left leg of binary operation (+): *logql.matchersExpr`, - line: 0, - col: 0, - }, - }, - { - in: `sum(count_over_time({foo="bar"}[5m])) by (foo) - {foo="bar"}`, - err: ParseError{ - msg: `unexpected type for right leg of binary operation (-): *logql.matchersExpr`, - line: 0, - col: 0, - }, - }, - { - in: `{foo="bar"} / sum(count_over_time({foo="bar"}[5m])) by (foo)`, - err: ParseError{ - msg: `unexpected type for left leg of binary operation (/): *logql.matchersExpr`, - line: 0, - col: 0, - }, - }, - { - in: `sum(count_over_time({foo="bar"}[5m])) by (foo) or 1`, - err: ParseError{ - msg: `unexpected literal for right leg of logical/set binary operation (or): 1.000000`, - line: 0, - col: 0, - }, - }, - { - in: `1 unless sum(count_over_time({foo="bar"}[5m])) by (foo)`, - err: ParseError{ - msg: `unexpected literal for left leg of logical/set binary operation (unless): 1.000000`, - line: 0, - col: 0, - }, - }, - { - in: `sum(count_over_time({foo="bar"}[5m])) by (foo) + 1 or 1`, - err: ParseError{ - msg: `unexpected literal for right leg of logical/set binary operation (or): 1.000000`, - line: 0, - col: 0, - }, - }, + // { + // in: ` + // sum(count_over_time({foo="bar"}[5m])) by (foo) ^ + // sum(count_over_time({foo="bar"}[5m])) by (foo) / + // sum(count_over_time({foo="bar"}[5m])) by (foo) + // `, + // exp: mustNewBinOpExpr( + // OpTypeDiv, + // mustNewBinOpExpr( + // OpTypePow, + // mustNewVectorAggregationExpr(newRangeAggregationExpr( + // &logRange{ + // left: &matchersExpr{ + // matchers: []*labels.Matcher{ + // mustNewMatcher(labels.MatchEqual, "foo", "bar"), + // }, + // }, + // interval: 5 * time.Minute, + // }, OpTypeCountOverTime), + // "sum", + // &grouping{ + // without: false, + // groups: []string{"foo"}, + // }, + // nil, + // ), + // mustNewVectorAggregationExpr(newRangeAggregationExpr( + // &logRange{ + // left: &matchersExpr{ + // matchers: []*labels.Matcher{ + // mustNewMatcher(labels.MatchEqual, "foo", "bar"), + // }, + // }, + // interval: 5 * time.Minute, + // }, OpTypeCountOverTime), + // "sum", + // &grouping{ + // without: false, + // groups: []string{"foo"}, + // }, + // nil, + // ), + // ), + // mustNewVectorAggregationExpr(newRangeAggregationExpr( + // &logRange{ + // left: &matchersExpr{ + // matchers: []*labels.Matcher{ + // mustNewMatcher(labels.MatchEqual, "foo", "bar"), + // }, + // }, + // interval: 5 * time.Minute, + // }, OpTypeCountOverTime), + // "sum", + // &grouping{ + // without: false, + // groups: []string{"foo"}, + // }, + // nil, + // ), + // ), + // }, + // { + // // operator precedence before left associativity + // in: ` + // sum(count_over_time({foo="bar"}[5m])) by (foo) + + // sum(count_over_time({foo="bar"}[5m])) by (foo) / + // sum(count_over_time({foo="bar"}[5m])) by (foo) + // `, + // exp: mustNewBinOpExpr( + // OpTypeAdd, + // mustNewVectorAggregationExpr(newRangeAggregationExpr( + // &logRange{ + // left: &matchersExpr{ + // matchers: []*labels.Matcher{ + // mustNewMatcher(labels.MatchEqual, "foo", "bar"), + // }, + // }, + // interval: 5 * time.Minute, + // }, OpTypeCountOverTime), + // "sum", + // &grouping{ + // without: false, + // groups: []string{"foo"}, + // }, + // nil, + // ), + // mustNewBinOpExpr( + // OpTypeDiv, + // mustNewVectorAggregationExpr(newRangeAggregationExpr( + // &logRange{ + // left: &matchersExpr{ + // matchers: []*labels.Matcher{ + // mustNewMatcher(labels.MatchEqual, "foo", "bar"), + // }, + // }, + // interval: 5 * time.Minute, + // }, OpTypeCountOverTime), + // "sum", + // &grouping{ + // without: false, + // groups: []string{"foo"}, + // }, + // nil, + // ), + // mustNewVectorAggregationExpr(newRangeAggregationExpr( + // &logRange{ + // left: &matchersExpr{ + // matchers: []*labels.Matcher{ + // mustNewMatcher(labels.MatchEqual, "foo", "bar"), + // }, + // }, + // interval: 5 * time.Minute, + // }, OpTypeCountOverTime), + // "sum", + // &grouping{ + // without: false, + // groups: []string{"foo"}, + // }, + // nil, + // ), + // ), + // ), + // }, + // { + // in: `sum by (job) ( + // count_over_time({namespace="tns"} |= "level=error"[5m]) + // / + // count_over_time({namespace="tns"}[5m]) + // )`, + // exp: mustNewVectorAggregationExpr( + // mustNewBinOpExpr(OpTypeDiv, + // newRangeAggregationExpr( + // &logRange{ + // left: &filterExpr{ + // left: &matchersExpr{ + // matchers: []*labels.Matcher{ + // mustNewMatcher(labels.MatchEqual, "namespace", "tns"), + // }, + // }, + // match: "level=error", + // ty: labels.MatchEqual, + // }, + // interval: 5 * time.Minute, + // }, OpTypeCountOverTime), + // newRangeAggregationExpr( + // &logRange{ + // left: &matchersExpr{ + // matchers: []*labels.Matcher{ + // mustNewMatcher(labels.MatchEqual, "namespace", "tns"), + // }, + // }, + // interval: 5 * time.Minute, + // }, OpTypeCountOverTime)), OpTypeSum, &grouping{groups: []string{"job"}}, nil), + // }, + // { + // in: `sum by (job) ( + // count_over_time({namespace="tns"} |= "level=error"[5m]) + // / + // count_over_time({namespace="tns"}[5m]) + // ) * 100`, + // exp: mustNewBinOpExpr(OpTypeMul, mustNewVectorAggregationExpr( + // mustNewBinOpExpr(OpTypeDiv, + // newRangeAggregationExpr( + // &logRange{ + // left: &filterExpr{ + // left: &matchersExpr{ + // matchers: []*labels.Matcher{ + // mustNewMatcher(labels.MatchEqual, "namespace", "tns"), + // }, + // }, + // match: "level=error", + // ty: labels.MatchEqual, + // }, + // interval: 5 * time.Minute, + // }, OpTypeCountOverTime), + // newRangeAggregationExpr( + // &logRange{ + // left: &matchersExpr{ + // matchers: []*labels.Matcher{ + // mustNewMatcher(labels.MatchEqual, "namespace", "tns"), + // }, + // }, + // interval: 5 * time.Minute, + // }, OpTypeCountOverTime)), OpTypeSum, &grouping{groups: []string{"job"}}, nil), + // mustNewLiteralExpr("100", false), + // ), + // }, + // { + // // reduces binop with two literalExprs + // in: `sum(count_over_time({foo="bar"}[5m])) by (foo) + 1 / 2`, + // exp: mustNewBinOpExpr( + // OpTypeAdd, + // mustNewVectorAggregationExpr( + // newRangeAggregationExpr( + // &logRange{ + // left: &matchersExpr{ + // matchers: []*labels.Matcher{ + // mustNewMatcher(labels.MatchEqual, "foo", "bar"), + // }, + // }, + // interval: 5 * time.Minute, + // }, OpTypeCountOverTime), + // "sum", + // &grouping{ + // without: false, + // groups: []string{"foo"}, + // }, + // nil, + // ), + // &literalExpr{value: 0.5}, + // ), + // }, + // { + // // test signs + // in: `1 + -2 / 1`, + // exp: mustNewBinOpExpr( + // OpTypeAdd, + // &literalExpr{value: 1}, + // mustNewBinOpExpr(OpTypeDiv, &literalExpr{value: -2}, &literalExpr{value: 1}), + // ), + // }, + // { + // // test signs/ops with equal associativity + // in: `1 + 1 - -1`, + // exp: mustNewBinOpExpr( + // OpTypeSub, + // mustNewBinOpExpr(OpTypeAdd, &literalExpr{value: 1}, &literalExpr{value: 1}), + // &literalExpr{value: -1}, + // ), + // }, + // { + // // ensure binary ops with two literals are reduced recursively + // in: `1 + 1 + 1`, + // exp: &literalExpr{value: 3}, + // }, + // { + // in: `{foo="bar"} + {foo="bar"}`, + // err: ParseError{ + // msg: `unexpected type for left leg of binary operation (+): *logql.matchersExpr`, + // line: 0, + // col: 0, + // }, + // }, + // { + // in: `sum(count_over_time({foo="bar"}[5m])) by (foo) - {foo="bar"}`, + // err: ParseError{ + // msg: `unexpected type for right leg of binary operation (-): *logql.matchersExpr`, + // line: 0, + // col: 0, + // }, + // }, + // { + // in: `{foo="bar"} / sum(count_over_time({foo="bar"}[5m])) by (foo)`, + // err: ParseError{ + // msg: `unexpected type for left leg of binary operation (/): *logql.matchersExpr`, + // line: 0, + // col: 0, + // }, + // }, + // { + // in: `sum(count_over_time({foo="bar"}[5m])) by (foo) or 1`, + // err: ParseError{ + // msg: `unexpected literal for right leg of logical/set binary operation (or): 1.000000`, + // line: 0, + // col: 0, + // }, + // }, + // { + // in: `1 unless sum(count_over_time({foo="bar"}[5m])) by (foo)`, + // err: ParseError{ + // msg: `unexpected literal for left leg of logical/set binary operation (unless): 1.000000`, + // line: 0, + // col: 0, + // }, + // }, + // { + // in: `sum(count_over_time({foo="bar"}[5m])) by (foo) + 1 or 1`, + // err: ParseError{ + // msg: `unexpected literal for right leg of logical/set binary operation (or): 1.000000`, + // line: 0, + // col: 0, + // }, + // }, } { t.Run(tc.in, func(t *testing.T) { ast, err := ParseExpr(tc.in)