logql-parser
A LogQL lexer, AST, and recursive-descent parser in Rust.
[]
= "0.1"
The package is logql-parser; the library is imported as logql, because a
bare logql on crates.io was taken in 2022 by an unrelated project.
let query = parse_query?;
What it does, and what it deliberately does not
It answers one question: is this LogQL, and what does it say? It lexes,
parses, and validates syntax, and its only dependency is thiserror — no
Arrow, no DataFusion, no database. Whether a query is valid is a property of
the query text, so answering it needs no catalog, no tenant, and no running
server.
It does not execute a query, plan one, or know anything about how logs are stored. Translating an AST into a plan is the caller's job.
Both query forms are covered: log queries (a stream selector plus a pipeline of
line filters, label filters, parser stages, and formatters) and metric queries
(range and vector aggregations, binary operations, label_replace).
Stability
Pre-1.0. The AST enums are #[non_exhaustive], so a release that teaches the
parser a new construct is additive for consumers — match with a fallback arm.
The AST structs are deliberately left constructible: building a query by hand
is a legitimate use of this crate.
Provenance
Extracted from SignalDB, which uses it for its Loki-compatible query interface. Licensed AGPL-3.0, matching Grafana Loki, whose language it implements.
Tests
cargo test -p logql-parser