chore: do not shard log queries with empty filter (#13568)

pull/13598/head
Ashwanth 10 months ago committed by GitHub
parent 6631c0f01d
commit 65697676e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      pkg/logql/syntax/ast.go
  2. 17
      pkg/logql/syntax/ast_test.go

@ -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
}

@ -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"},

Loading…
Cancel
Save