Skip to content

Commit

Permalink
Support <selector> <range> <filters> for aggregation (#1526)
Browse files Browse the repository at this point in the history
Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
  • Loading branch information
codesome authored and cyriltovena committed Jan 15, 2020
1 parent 4d853b3 commit 1761db6
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 87 deletions.
9 changes: 9 additions & 0 deletions pkg/logql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ func newLogRange(left LogSelectorExpr, interval time.Duration) *logRange {
}
}

func addFilterToLogRangeExpr(left *logRange, ty labels.MatchType, match string) *logRange {
left.left = &filterExpr{
left: left.left,
ty: ty,
match: match,
}
return left
}

const (
OpTypeSum = "sum"
OpTypeAvg = "avg"
Expand Down
15 changes: 13 additions & 2 deletions pkg/logql/expr.y
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
Labels []string
LogExpr LogSelectorExpr
LogRangeExpr *logRange
LogRangeExprExt *logRange
Matcher *labels.Matcher
Matchers []*labels.Matcher
RangeAggregationExpr SampleExpr
Expand All @@ -33,6 +34,7 @@ import (
%type <Grouping> grouping
%type <Labels> labels
%type <LogExpr> logExpr
%type <LogRangeExprExt> logRangeExprExt
%type <LogRangeExpr> logRangeExpr
%type <Matcher> matcher
%type <Matchers> matchers
Expand Down Expand Up @@ -65,9 +67,18 @@ logExpr:
| logExpr error
;

logRangeExpr:
logExpr DURATION { $$ = newLogRange($1, $2) } // <selector> <filters> <range>
| logRangeExprExt { $$ = $1 } // <selector> <range> <filters>
;

logRangeExpr: logExpr DURATION { $$ = newLogRange($1, $2) };

logRangeExprExt:
selector DURATION { $$ = newLogRange(newMatcherExpr($1), $2)}
| logRangeExprExt filter STRING { $$ = addFilterToLogRangeExpr( $1, $2, $3 ) }
| OPEN_PARENTHESIS logRangeExprExt CLOSE_PARENTHESIS { $$ = $2 }
| logRangeExprExt filter error
| logRangeExprExt error
;

rangeAggregationExpr: rangeOp OPEN_PARENTHESIS logRangeExpr CLOSE_PARENTHESIS { $$ = newRangeAggregationExpr($3,$1) };

Expand Down
Loading

0 comments on commit 1761db6

Please sign in to comment.