Skip to content

Instantly share code, notes, and snippets.

@kavirajk
Created March 31, 2024 20:14
Show Gist options
  • Save kavirajk/085d4a81b6e913fbb9a013b1e07644d4 to your computer and use it in GitHub Desktop.
Save kavirajk/085d4a81b6e913fbb9a013b1e07644d4 to your computer and use it in GitHub Desktop.
LogQL linefilters bug
package main
import (
"fmt"
"github.com/grafana/loki/pkg/logql/syntax"
)
func main() {
q := `{app="loki"}!= "foo" or "bar"` // with single linefilters
expr, err := syntax.ParseLogSelector(q, true)
if err != nil {
panic(err)
}
fmt.Printf("query=%v\nparsed=%v\n", q, expr.String())
fmt.Println("---------------------")
q2 := `{app="loki"}!= "test" != "foo" or "bar"` // with chain of linefilters
expr2, err := syntax.ParseLogSelector(q2, true)
if err != nil {
panic(err)
}
fmt.Printf("query=%v\nparsed=%v\n", q2, expr2.String())
}
// Output
// query={app="loki"}!= "foo" or "bar"
// parsed={app="loki"} != "foo" != "bar"
// ---------------------
// query={app="loki"}!= "test" != "foo" or "bar"
// parsed={app="loki"} != "test" != "bar"
// note `foo` is missing on the second query.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment