Skip to content

Commit

Permalink
chore: do not shard log queries with empty filter (#13568)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwanthgoli authored Jul 19, 2024
1 parent 6631c0f commit 6569767
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/logql/syntax/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,14 @@ func (e *PipelineExpr) Pipeline() (log.Pipeline, error) {
// HasFilter returns true if the pipeline contains stage that can filter out lines.
func (e *PipelineExpr) HasFilter() bool {
for _, p := range e.MultiStages {
switch p.(type) {
case *LineFilterExpr, *LabelFilterExpr:
switch v := p.(type) {
case *LabelFilterExpr:
return true
case *LineFilterExpr:
// ignore empty matchers as they match everything
if !((v.Ty == log.LineMatchEqual || v.Ty == log.LineMatchRegexp) && v.Match == "") {
return true
}
default:
continue
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/logql/syntax/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,23 @@ func TestParseLargeQuery(t *testing.T) {
require.NoError(t, err)
}

func TestLogSelectorExprHasFilter(t *testing.T) {
for query, hasFilter := range map[string]bool{
`{foo="bar"} |= ""`: false,
`{foo="bar"} |= "" |= ""`: false,
`{foo="bar"} |~ ""`: false,
`{foo="bar"} |= "notempty"`: true,
`{foo="bar"} |= "" |= "notempty"`: true,
`{foo="bar"} != ""`: true,
`{foo="bar"} | lbl="notempty"`: true,
`{foo="bar"} |= "" | lbl="notempty"`: true,
} {
expr, err := ParseExpr(query)
require.NoError(t, err)
require.Equal(t, hasFilter, expr.(LogSelectorExpr).HasFilter())
}
}

func TestGroupingString(t *testing.T) {
g := Grouping{
Groups: []string{"a", "b"},
Expand Down

0 comments on commit 6569767

Please sign in to comment.