Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support byte sizes in label filters. #5

Merged
merged 3 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions pkg/logql/expr.y
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
VectorOp string
BinOpExpr SampleExpr
binOp string
bytes uint64
str string
duration time.Duration
LiteralExpr *literalExpr
Expand All @@ -34,9 +35,11 @@ import (
LineFilters *lineFilterExpr
PipelineExpr MultiPipelineExpr
PipelineStage PipelineExpr
BytesFilter labelfilter.Filterer
NumberFilter labelfilter.Filterer
DurationFilter labelfilter.Filterer
LabelFilter labelfilter.Filterer
UnitFilter labelfilter.Filterer
LineFormatExpr *lineFmtExpr
LabelFormatExpr *labelFmtExpr
LabelFormat labelFmt
Expand Down Expand Up @@ -67,6 +70,7 @@ import (
%type <LabelParser> labelParser
%type <PipelineExpr> pipelineExpr
%type <PipelineStage> pipelineStage
%type <BytesFilter> bytesFilter
%type <NumberFilter> numberFilter
%type <DurationFilter> durationFilter
%type <LabelFilter> labelFilter
Expand All @@ -76,7 +80,9 @@ import (
%type <LabelFormat> labelFormat
%type <LabelsFormat> labelsFormat
%type <UnwrapExpr> unwrapExpr
%type <UnitFilter> unitFilter

%token <bytes> BYTES
%token <str> IDENTIFIER STRING NUMBER
%token <duration> DURATION RANGE
%token <val> MATCHERS LABELS EQ RE NRE OPEN_BRACE CLOSE_BRACE OPEN_BRACKET CLOSE_BRACKET COMMA DOT PIPE_MATCH PIPE_EXACT
Expand Down Expand Up @@ -224,7 +230,7 @@ labelFormatExpr: LABEL_FMT labelsFormat { $$ = newLabelFmtExpr($2) };

labelFilter:
matcher { $$ = labelfilter.NewString($1) }
| durationFilter { $$ = $1 }
| unitFilter { $$ = $1 }
| numberFilter { $$ = $1 }
| OPEN_PARENTHESIS labelFilter CLOSE_PARENTHESIS { $$ = $2 }
| labelFilter labelFilter { $$ = labelfilter.NewAnd($1, $2 ) }
Expand All @@ -233,8 +239,12 @@ labelFilter:
| labelFilter OR labelFilter { $$ = labelfilter.NewOr($1, $3 ) }
;

unitFilter:
cyriltovena marked this conversation as resolved.
Show resolved Hide resolved
durationFilter { $$ = $1 }
| bytesFilter { $$ = $1 }

durationFilter:
IDENTIFIER GT DURATION { $$ = labelfilter.NewDuration(labelfilter.FilterGreaterThan, $1, $3) }
IDENTIFIER GT DURATION { $$ = labelfilter.NewDuration(labelfilter.FilterGreaterThan, $1, $3) }
| IDENTIFIER GTE DURATION { $$ = labelfilter.NewDuration(labelfilter.FilterGreaterThanOrEqual, $1, $3) }
| IDENTIFIER LT DURATION { $$ = labelfilter.NewDuration(labelfilter.FilterLesserThan, $1, $3) }
| IDENTIFIER LTE DURATION { $$ = labelfilter.NewDuration(labelfilter.FilterLesserThanOrEqual, $1, $3) }
Expand All @@ -243,6 +253,16 @@ durationFilter:
| IDENTIFIER CMP_EQ DURATION { $$ = labelfilter.NewDuration(labelfilter.FilterEqual, $1, $3) }
;

bytesFilter:
IDENTIFIER GT BYTES { $$ = labelfilter.NewBytes(labelfilter.FilterGreaterThan, $1, $3) }
jeschkies marked this conversation as resolved.
Show resolved Hide resolved
| IDENTIFIER GTE BYTES { $$ = labelfilter.NewBytes(labelfilter.FilterGreaterThanOrEqual, $1, $3) }
| IDENTIFIER LT BYTES { $$ = labelfilter.NewBytes(labelfilter.FilterLesserThan, $1, $3) }
| IDENTIFIER LTE BYTES { $$ = labelfilter.NewBytes(labelfilter.FilterLesserThanOrEqual, $1, $3) }
| IDENTIFIER NEQ BYTES { $$ = labelfilter.NewBytes(labelfilter.FilterNotEqual, $1, $3) }
| IDENTIFIER EQ BYTES { $$ = labelfilter.NewBytes(labelfilter.FilterEqual, $1, $3) }
| IDENTIFIER CMP_EQ BYTES { $$ = labelfilter.NewBytes(labelfilter.FilterEqual, $1, $3) }
;

numberFilter:
IDENTIFIER GT NUMBER { $$ = labelfilter.NewNumeric(labelfilter.FilterGreaterThan, $1, mustNewFloat($3))}
| IDENTIFIER GTE NUMBER { $$ = labelfilter.NewNumeric(labelfilter.FilterGreaterThanOrEqual, $1, mustNewFloat($3))}
Expand Down
Loading