logql-parser 0.1.3

LogQL lexer and parser
Documentation
  • Coverage
  • 65.4%
    155 out of 237 items documented5 out of 41 items with examples
  • Size
  • Source code size: 174.7 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.5 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • cedricziel/signaldb
    7 0 34
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • cedricziel

logql-parser

A LogQL lexer, AST, and recursive-descent parser in Rust.

[dependencies]
logql-parser = "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 = logql::parse_query(r#"{service_name="api"} |= "error""#)?;

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