Standalone Go parser and AST for Grafana Loki's LogQL. Lifts the
upstream syntax, log, and logqlmodel packages out of grafana/loki with their runtime
dependencies (dskit, etcd, jaeger, the queryrange/push machinery) stripped away.
go get github.com/qualithm/logql-syntaximport "github.com/qualithm/logql-syntax/syntax"
expr, err := syntax.ParseExpr(`sum by (job) (rate({app="api"} |= "error" [5m]))`)
if err != nil {
return err
}
expr.Walk(func(e syntax.Expr) bool {
// inspect the AST
return true
})| Path | Source |
|---|---|
syntax/ |
github.com/grafana/loki/v3/pkg/logql/syntax |
log/ |
github.com/grafana/loki/v3/pkg/logql/log |
log/jsonexpr/ |
github.com/grafana/loki/v3/pkg/logql/log/jsonexpr |
log/logfmt/ |
github.com/grafana/loki/v3/pkg/logql/log/logfmt |
log/pattern/ |
github.com/grafana/loki/v3/pkg/logql/log/pattern |
logqlmodel/ |
trimmed extract of pkg/logqlmodel (errors + label constants only) |
internal/util/ |
three regex / matcher helpers from pkg/util |
The runtime Result and Streams types from logqlmodel are intentionally omitted because they
pull in loki/pkg/push and queryrange machinery.
Tracked against Loki v3.7.2.
To resync against a newer Loki release:
- Copy source files from
pkg/logql/{syntax,log}/...into the matching directories here. - Rewrite
github.com/grafana/loki/v3/pkg/...import paths togithub.com/qualithm/logql-syntax/...(see thesedinvocation in the project history). - Reconcile any new uses of
pkg/util,pkg/logqlmodel, orpkg/util/constants— extend the trimmed packages here as needed. go test ./...— the only known persistent failures are the two timestamp subtests inlog/that hardcode local-timezone dates upstream.
- Go 1.26+
make build
make test
make lintmake sync # defaults to LOKI_VERSION in the Makefile
LOKI_VERSION=v3.8.0 make sync # pin a specific upstream releaseGo 1.26+.
Apache-2.0. See LICENSE and NOTICE for upstream attribution.