Skip to content

test(logql): LogQL parity harness against Loki (M4, #923) - #1117

Open
Guess-Who-sec wants to merge 7 commits into
metrico:masterfrom
Guess-Who-sec:test/m4-logql-parity
Open

Guess-Who-sec wants to merge 7 commits into
metrico:masterfrom
Guess-Who-sec:test/m4-logql-parity

Conversation

@Guess-Who-sec

@Guess-Who-sec Guess-Who-sec commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Part of #923 (M4): the LogQL parity harness, with its first query list and baseline.

Depends on #1061 (M2 seed) and #1112 (shared checker, which needs #1069): this branch is built on them, so its first 6 commits are theirs (#1061: 3, #1069: 2, #1112: 1). Merge those first; I'll rebase this one onto master then. Only the last commit is new here.

As you decided: the query list is written in-house from the LogQL docs, like the planned TraceQL list. Nothing comes from Loki's code or its logqlbench queries. Loki itself is used only as an unmodified Docker image to compare answers with.

What it does

make parity-logql starts a real Loki 3.7.10 (pinned by image digest) and gigapipe built from the tree, pushes the same logs to both, sends every query in compatibility/loki/queries.txt to both, and compares the answers. Same shape as the PromQL harness:

Data: the M2 seed fixture, 4 log streams (checkout p1, p2, p3 with 4, 7 and 1 lines; payments p1 with 5), 17 JSON lines with level, msg, latency_ms, seq. The test waits until both servers return all 17 lines before asking anything.

Queries: 67, each under the docs section it exercises (## log_queries > Line filter expression): stream selectors, line filters, the five parsers, label filters, line_format, label_format, drop, keep, log range aggregations, offset, unwrapped range aggregations, vector aggregations, vector(). go test ./compatibility/loki/ checks the file's format without any server.

Comparison: both answers are normalized the same way (run label value, timestamps as offsets, numbers compared as numbers, series sorted by labels except for sort/sort_desc) and compared exactly. Lines that share a timestamp inside one stream are sorted by text, because LogQL defines no order among them (see Verification). Error answers are compared by HTTP status only. Full answers of every differing query are saved to out/answers/ for triage.

Location: compatibility/loki/, in gigapipe's main module. Unlike the PromQL harness it needs no new dependencies, so there's no separate go.mod. The server test and the code that talks to the servers (server.go) have the build tag parity, so CI's normal go test ./... and make lint see only the query parser, the normalizer and their unit tests.

Reference Loki settings (a question for you)

loki.yaml turns off one Loki ingestion feature, discover_log_levels. With it, Loki adds a detected_level label to every line and splits each stream by level; gigapipe doesn't. Measured: with it on, 61 of 67 queries differ. discover_service_name stays at Loki's default: Loki then adds service_name from app, and so does gigapipe. Measured: with it off, 58 differ. Is turning off level detection OK, or should gigapipe's answers be compared with it on?

Result today: 44 agree, 23 differ

Every difference is recorded in baseline.json with what was measured; none is unclassified. Whether each one is a bug is your call. "not filed" means there is no issue yet.

Count What differs Issue
8 unwrap functions (sum, avg, max, min, first, last, quantile, rate over unwrap latency_ms): gigapipe keeps the latency_ms label; with it removed the answers are identical (checked, 17 series each) #1082
2 stddev/stdvar by (app): gigapipe leaves out payments, whose value is 0; the other group is equal #1081
2 sort, sort_desc: gigapipe HTTP 500, parse error not filed
2 stddev_over_time, stdvar_over_time on unwrap: gigapipe HTTP 500, "… is not supported for this query" not filed
1 | pattern: gigapipe HTTP 500, parse error not filed
1 | unpack: gigapipe HTTP 500, parse error not filed
1 label filters joined by a comma (docs: same as and): gigapipe HTTP 500, parse error not filed
1 … or vector(0): gigapipe HTTP 500, parse error not filed
1 {app=~"check"}: Loki matches the whole value (docs: fully anchored) and returns nothing; gigapipe matches part of it and returns checkout not filed
1 | logfmt on JSON lines: gigapipe adds labels made from the line text; Loki adds none not filed
1 label_format severity=level: Loki (docs: rename) drops level; gigapipe keeps it not filed
1 label_format kind="{{.level}}-{{.app}}": gigapipe returns the template text instead of filling it in not filed
1 sum_over_time(… unwrap …) by (app): Loki rejects it (HTTP 400, "grouping not allowed for sum_over_time"); gigapipe answers not filed

Should I open issues for the 13 "not filed" differences? (One issue per row, 11 issues in all; the two sort queries and the two stddev/stdvar_over_time queries would share one each.) Or would you rather some of them stay recorded only in the baseline, for example if gigapipe is not meant to support pattern or unpack?

Verification

  • Real runs (Docker, Loki 3.7.10 + gigapipe from this tree): make parity-logql-check 3 runs, all matches the baseline (67 queries); regenerating the baseline keeps every reason
  • A flaky query found and fixed: | json | keep app, level first differed in 1 of 3 full runs, and in 7 of 8 runs against one stack. Cause, checked on the saved answers: keep merges the three checkout pods into one stream, their lines share timestamps, and the two servers return lines with the same timestamp in different orders (same lines, same timestamp sequence). LogQL defines no order there, so the harness now sorts such ties; after that, 10 of 10 agree.
  • Planted change: making != behave like |= in planner_line_filter.go fails the check naming exactly the two != queries; reverted
  • Unit tests (with -race): the query file, malformed query lists, and normalization of streams, matrices, vectors, scalars, number formats, result order, and timestamp ties (ties sorted, different timestamps still compared)
  • gofmt, go vet with and without -tags parity (no new findings compared with the base), CGO_ENABLED=0 go build, root go test ./... (39 packages)
  • golangci-lint and staticcheck both without the tag (as CI's make lint runs) and with -tags parity: 0 issues each
  • shellcheck: no warnings; one info-level note (SC2329) that cleanup is never called, a false positive since trap cleanup EXIT calls it, and the PromQL harness's run.sh gets the same note

Potential risks

  • Not in CI. Only make parity-logql-check runs it, like the PromQL harness, so a regression is caught only when someone runs it. Adding it to CI would need Docker in the pipeline, about a minute per run. I'd leave that for later, unless you want it now.
  • Stacked on test(integration): seed package and write-read harness for logs (M2 2/4, #920) #1061 and test(prom): PromQL parity baseline and ratchet (M3, #922) #1112. If review changes them, especially the seed data in test(integration): seed package and write-read harness for logs (M2 2/4, #920) #1061, this branch has to be rebased and the baseline regenerated and rechecked.
  • Loki version pinned (3.7.10, by digest). That keeps results reproducible. Upgrading can change Loki's answers, and the check then fails even though gigapipe didn't change, until the baseline is rerun and the new differences reviewed.
  • The reference Loki's settings. The result depends on discover_log_levels being off (see the question above). If gigapipe should match Loki with its defaults, 61 of 67 queries differ today, not 23.
  • Errors are compared by HTTP status only. Error messages always differ in wording, so two 400s for different reasons count as agreeing. The error bodies are still saved for triage.
  • Ports 3100 and 3101. It can't run at the same time as the integration tests or the PromQL harness on one machine. That's an inconvenience, not a correctness problem.
  • 67 queries on 17 lines is a first list. "44 agree" means these queries on this data agree, not that gigapipe is 66% LogQL-compatible. More queries can be added by docs section.

Fixed settings (a question for you)

Like the PromQL harness, the settings are written into the code rather than configurable:

  • in run.sh: the Loki image, the Loki port, the container and stack names, and the wait and test timeouts
  • in the test: limit=1000, the query window (one minute before the data to three minutes after, instant queries at +2 minutes), the 30-second step, and the setup and HTTP timeouts
  • sort/sort_desc are recognised by the query text starting with sort

Today this is fine: the data is 17 lines ending at +60 seconds. But two of these settings would fail with a misleading message if the data grows past 1000 lines or past +3 minutes. The setup wait counts lines with the same limit and window, so it times out with "returns N of the M lines written". That reads like an ingestion bug and doesn't say which setting to change.

Should I make both harnesses (PromQL and LogQL) more configurable in a follow-up PR? That would mean:

  • environment overrides with today's values as defaults, for example LOKI_IMAGE=… make parity-logql-baseline to try an upgrade
  • the query settings collected in one place
  • setup checks that fail with a clear message when the data no longer fits the limit or the window

I left it out of this PR to keep the two harnesses alike and this PR focused.

metrico#920)

The integration workflow built, started and tested gigapipe with raw
commands. It now runs make build, make integration-start and
make test-integration, and test/integration/run.sh runs the same
make test-integration, so CI and local runs are the same commands.

integration-start waits up to 60s for /api/v1/status/buildinfo and prints
gigapipe.log if gigapipe never answers.
run.sh changed to the repository root before running the tests, but the
EXIT trap runs `docker compose -f docker-compose.yml` with a relative
path, so teardown failed (hidden by `|| true`) and left the gigapipe and
ClickHouse containers running after every run. Run the tests in a
subshell so the trap still runs from test/integration.
…/4, metrico#920)

Add test/integration/seed, a deterministic declaration of the data the
integration tests write: services and pods, from which every signal is
derived. Logs are generated with a fixed random seed, so the same fixture
always produces the same push body; Run only sets the m2_run label that
keeps one run's data apart from earlier runs.

TestLogsRoundTrip pushes the fixture through /loki/api/v1/push and checks
what the Loki read APIs return against it, one named case each: every line
per stream, a line filter, the json parser with a label filter,
count_over_time per pod, labels, label values and series.

The query_range, instant query, label values and series responses are also
compared with pinned copies under testdata/logs/, since that JSON is what
Grafana reads. Run-specific values (the run label, timestamps) are
normalized before the comparison. The pins are maintained by hand; there is
no regeneration mode.

gigapipe's labels endpoint ignores the query parameter Loki uses to narrow
it to a selector, so that case cannot be limited to one run; the series
case covers the label sets.
Run the PromQL compliance suite with a real Prometheus 3.15.1 as the
reference and gigapipe built from this tree as the target. Gigapipe
doesn't scrape, so its target scrapes the suite's replayer itself,
remote-writes the samples and proxies the queries. `make parity-prom`
prints how many queries agree; it is report-only for now.

The suite lives in its own module under compatibility/prometheus, so
gigapipe's go.mod and binary are unchanged.
baseline.json records the state of all 660 compliance queries (529 agree,
131 differ) and why each difference exists. `make parity-prom-check` fails
when a query changes state: a query that agreed now differs, a query that
differed now agrees, a baselined query didn't run, or a new query isn't in
the baseline. `make parity-prom-baseline` rewrites the file and keeps its
reasons. `make parity-prom` stays report-only.

run.sh now saves `go test -json` output and hands it to the checker in
compatibility/ratchet, which it builds before the suite runs. The checker
is in gigapipe's main module (standard library only) so the LogQL and
TraceQL parity harnesses can use it too; -test names the parity test whose
results it reads, TestPromQLParity by default.

Reasons for the 131 differences, facts only:
- 113: the target sends no native histograms
- 15: the reference Prometheus drops the 7 oldest replay snapshots
- 3: gigapipe disables negative offsets (PQRC001)
@socket-security

socket-security Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedgithub.com/​prometheus/​prometheus@​v0.315.17610010075100
Addedgithub.com/​prometheus/​common@​v0.72.2-0.20261027144952-e257672f3db69110010010080
Addedgithub.com/​prometheus/​compliance@​v0.0.0-20261029144141-6ae8d35df52c82100100100100

View full report

compatibility/loki sends the in-house LogQL queries in queries.txt,
written from the LogQL docs and grouped by docs section, to a real Loki
3.7.10 (pinned by image digest) and to gigapipe built from the tree, both
fed the M2 seed's 17 log lines, and compares the normalized answers.
`make parity-logql` reports, `make parity-logql-check` fails when a query
changes state since baseline.json (shared compatibility/ratchet,
-test TestLogQLParity), and `make parity-logql-baseline` rewrites it.

The reference Loki has discover_log_levels off: with it Loki adds a
detected_level label that gigapipe doesn't. service_name discovery stays
on, since gigapipe adds the same label.

Lines that share a timestamp within one stream are compared sorted by
text: LogQL defines no order among them, and `keep` merges streams whose
lines share timestamps.

Today 44 of 67 queries agree. The 23 differences are recorded with what
was measured: 8 unwrapped label kept (metrico#1082), 2 zero-valued group left
out (metrico#1081), 8 HTTP 500 from gigapipe (parse errors or unsupported), and
5 behaviour differences (regex anchoring, logfmt on JSON lines, two
label_format cases, sum_over_time grouping that Loki rejects).
@rita7lopes

Copy link
Copy Markdown
Contributor

Please don't hardcode versions in scripts or the README, I don't want to update them by hand. Put the Loki image in a compose file and have run.sh use it from there, with no version number in the README, so it's in one place. The Prometheus versions here come from #1069 and will be fixed there.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants