Skip to content

chore(ci): M1 tooling groundwork and deterministic PromQL substitute names (#918) - #1059

Merged
rita7lopes merged 5 commits into
metrico:masterfrom
Guess-Who-sec:chore/m1-tooling
Nov 9, 2026
Merged

rita7lopes merged 5 commits into
metrico:masterfrom
Guess-Who-sec:chore/m1-tooling

Conversation

@Guess-Who-sec

@Guess-Who-sec Guess-Who-sec commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #918. Part of #917. Supersedes #925.

No dependencies: #1056, #1057 and #1058 are merged, and this branch is rebased onto master.

Five commits:

  1. chore(ci): M1 tooling groundwork and deterministic PromQL substitute names (#918)
  2. fix(ci): give lint a base commit on pushes: falls back to github.event.before when there is no pull request base commit, so lint keeps its "new issues only" rule once ci(release): publish preflight and CI trigger fixes (M3, #922) #1067 runs go.yml on pushes to master.
  3. chore(ci): drop arch-lint, pin golangci-lint in a tools module: the review changes (see "Review items" below).
  4. chore(ci): run golangci-lint@latest instead of a tools module and 5. chore(ci): point make lint, CI and docs at golangci-lint@latest: maintainer follow-up that replaces the tools/ module (see below).

What

Fix: deterministic PromQL substitute names

Pushdown substitutes were named __metric_subst__<rand.Int64()>, so the same query transpiled to a different residual expression on every run. Each parsed Expr now hands out names from its own counter (Expr.NextSubstituteName(), giving __metric_subst__1, __metric_subst__2, …).

Names only need to be unique within one query. That is the only scope they are looked up in:

  • each request parses its own Expr (prom_query_instant.go, prom_query_range.go)
  • each request gets its own queryable bound to that Expr (SetOidAndDB)
  • the ruler does not transpile, so it never names substitutes

TestTranspileIsDeterministic transpiles each query twice and requires a byte-identical residual expression and byte-identical SQL for every substitute.

The Makefile is the single entry point, and CI only runs recipes

Recipe Does
make fmt-check fails if gofmt -l . lists any file
make build builds the binary as CI always has
make test-unit go test -race ./...
make lint golangci-lint, only issues new since LINT_NEW_FROM_REV; CI passes the PR base commit
make fuzz HEAD=<head> [DURATION=60s] native fuzzing of one parser

make lint runs go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest, so nothing has to be installed first.

It is deliberately unpinned. A pinned version breaks when Go moves on: golangci-lint v2.13.1, the version first pinned for this PR, could not read Go 1.27.3's export data format V5 (go.dev/issue/81188):

cannot decode "internal/goarch", export data version 5 is greater than maximum supported version 4

@latest keeps up with new Go releases with nothing to bump by hand: no second go.mod, no second go version for go-version-sync to miss, no extra Dependabot stream. .golangci.yml lists the linters explicitly and --new-from-rev only fails on new issues, so a new release cannot flood old code.

Parser fuzzing

  • FuzzParse for LogQL, PromQL and TraceQL checks two things: parsing never panics, and any accepted query round-trips (render, parse the rendering, render again: same text).
  • Parser fuzz workflow: manual dispatch only, never a merge gate. It takes a parser and a duration (validated before use), runs make fuzz, and uploads any crasher as an artifact.
  • Crasher committed as a seed. The LogQL crasher the fuzzer found (fixed in fix(logql): render a label filter with a dangling and/or without panicking #1058) is committed under testdata/fuzz/FuzzParse/, so it replays as a plain test.

Review items from #925

  1. Parser AST-shape pins removed: the three parserpin_test.go files and reader/internal/parserpin.
  2. golangci-lint pin: v2.13.1 did not work on Go 1.27.3. It is now unpinned (@latest), as described above.

Review items from this PR

  1. Rebased onto master.
  2. arch-lint dropped: .go-arch-lint.yml, tools/archlint, the make arch-lint target, its CI job and its line in docs/contributing.md.
  3. golangci-lint unpinned: first moved into a tools/ module, then replaced by @latest in a maintainer follow-up, which removes tools/go.mod, tools/go.sum, the /tools Dependabot entry and the tools/go.sum CI cache path.
  4. Comments: the .golangci.yml header now says CI runs make lint with --new-from-rev (no golangci-lint-action / only-new-issues, no corpus work), and the three fuzz_test.go headers say the seed corpus runs under go test ./....

The rest of #918 is completed here as well: CI runs only Makefile recipes, the determinism test compares SQL, the fuzz targets round-trip, and there is a manual fuzz workflow.

Verification

On a fork, running this branch's CI (before the review changes, still stacked on #1056, #1057 and #1058):

Check Result
build: make fmt-check, make build, make test-unit pass, 3.2 min, no data races
lint: make lint 0 issues.
integration, CodeQL, k6 pass
Gigapipe CI Cluster: make e2e-ci pass, 4121 tests, 136 snapshots

The jobs run in parallel, so the merge gate takes 3.2 minutes.

After the review changes, locally on the rebased branch:

  • go test ./... and make test-unit (-race): 33 packages pass. go vet ./... is the same as master; gofmt clean; make build leaves go.mod/go.sum untouched.
  • The fuzz seeds, including the committed LogQL crasher, run under go test; make fuzz HEAD=logql DURATION=10s passes; make fuzz HEAD=nope is rejected.
  • actionlint: no findings on go.yml and fuzz.yml.

Earlier, locally:

  • TestTranspileIsDeterministic fails on master (random names differ between the two passes) and passes 10/10 here.
  • Transpile output compared for 10 PromQL queries, master vs this branch. The residual expressions and all 11 generated SQL statements are byte-identical; only the substitute names change.
  • make fuzz for 60s per parser: PromQL and TraceQL found nothing. LogQL found the crasher fixed in fix(logql): render a label filter with a dangling and/or without panicking #1058, then ran clean.
  • make test-unit passed 5/5 runs.

Notes

  • The Parser fuzz workflow has not been dispatched yet. GitHub only offers manual dispatch once the workflow is on the default branch. The make fuzz it runs is covered above.
  • A new golangci-lint release can add checks. make lint only reports issues new since the base commit, but a stricter check can still flag new code. If a release ever breaks lint, pin a version in the Makefile until upstream fixes it.
  • make build runs go mod tidy before building, as the CI build step always has.
  • Unrelated to this PR: GitHub warns that actions/checkout@v4 and actions/setup-go@v5 run on the deprecated Node.js 20. Dependabot now covers GitHub Actions (ci(dependabot): keep GitHub Actions up to date #1072), so it will open those updates.

@rita7lopes

Copy link
Copy Markdown
Contributor

Thanks, this looks good. A few things before merge:

  1. Please rebase onto master now that test(smart_buffer): deflake TestRAMChunk_ReleaseReusesBlocks #1056, fix(traceql): render an empty selector without panicking #1057 and fix(logql): render a label filter with a dangling and/or without panicking #1058 are in.
  2. Let's drop arch-lint for now. With every component on anyProjectDeps and continue-on-error it can't report anything, and tools/archlint isn't covered by Dependabot, so it would go stale. We can add it back when we have real boundaries to enforce.
  3. The golangci-lint pin in the Makefile has the same staleness problem. Could you move it into a tools/ module as a go tool (make lint → go -C tools tool golangci-lint run ...) and add a Dependabot entry for /tools with allow: [{dependency-type: all}]?
  4. In .golangci.yml, the header still mentions golangci-lint-action with only-new-issues and the dropped corpus work. In the three fuzz_test.go files, please note that the seed corpus does run under go test ./....

@rita7lopes rita7lopes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess-Who-sec and others added 3 commits November 9, 2026 13:00
…names (metrico#918)

Takes over metrico#925, keeping the scope agreed in its review, and completes
the rest of metrico#918.

Fix: PromQL pushdown substitutes were named with rand.Int64(), so the same
query transpiled to a different residual expression on every run. Each
parsed Expr now hands out names from its own counter
(Expr.NextSubstituteName). Names stay unique within a query, which is the
only scope prom_queryable looks them up in. TestTranspileIsDeterministic
transpiles twice and requires a byte-identical residual expression and
byte-identical SQL for every substitute.

Makefile as the single entry point; CI runs only recipes:
- fmt-check, build, test-unit (go test -race ./...), lint, arch-lint,
  fuzz HEAD=<head> [DURATION=60s]
- lint builds golangci-lint v2.14.0 from source and reports only issues
  new since LINT_NEW_FROM_REV (CI passes the PR base commit). v2.13.x
  cannot read the export data go1.27.3 writes (format V5 needs
  golang.org/x/tools >= v0.50.0)
- arch-lint runs go-arch-lint v1.19.0 from tools/archlint, which raises
  golang.org/x/tools to v0.50.0 for the same reason; no go-arch-lint
  release does yet. Report-only in CI (continue-on-error)

Parser fuzzing:
- FuzzParse for LogQL, PromQL and TraceQL asserts no panic and that any
  accepted query round-trips (render, parse, render gives the same text)
- "Parser fuzz" workflow, manually dispatched only, uploads crashers
- the LogQL crasher it found (dangling and/or in a label filter) is
  committed as a regression seed

Review changes on top of metrico#925:
- drop the parser AST-shape pins and the reader/internal/parserpin helper
- arch-lint reads the Go version from go.mod instead of pinning 1.26
- bump golangci-lint v2.13.1 -> v2.14.0 (see above)

Co-authored-by: Thiago Souza <122435+tsouza@users.noreply.github.com>
github.event.pull_request.base.sha is empty on a push, so once go.yml runs
on pushes to master, `make lint` gets no --new-from-rev and fails on every
pre-existing issue. Fall back to github.event.before, the commit before the
push, so a push is held to the same "new issues only" rule as a pull request.
Review follow-up for metrico#1059.

- Remove go-arch-lint (.go-arch-lint.yml, tools/archlint, the make target
  and CI job): with every component allowed every dependency and the job
  set to continue-on-error, it could not report anything.
- golangci-lint v2.14.0 is now a tool of a tools/ module, kept current by
  a Dependabot entry for /tools. make lint runs it from the repo root with
  go tool -modfile=tools/go.mod, so it lints gigapipe's packages.
- .golangci.yml header: CI runs make lint with --new-from-rev; drop the
  stale golangci-lint-action and corpus references.
- Fuzz targets: state that the seed corpus runs under go test ./....
@Guess-Who-sec

Copy link
Copy Markdown
Contributor Author

Thanks @rita7lopes. All four are in the new commit ea1ab58a:

  1. Rebased onto master. The three commits from test(smart_buffer): deflake TestRAMChunk_ReleaseReusesBlocks #1056, fix(traceql): render an empty selector without panicking #1057 and fix(logql): render a label filter with a dangling and/or without panicking #1058 are gone; the PR is now the two M1 commits plus the review commit.
  2. arch-lint dropped: .go-arch-lint.yml, tools/archlint, the make target, the CI job and the docs line.
  3. golangci-lint v2.14.0 is a go tool in tools/, with a Dependabot entry for /tools and allow: [{dependency-type: all}]. One change from your suggestion: go -C tools tool golangci-lint run runs golangci-lint inside tools/, so it lints nothing there (no go files to analyze), and a path back to the repo is refused (outside main module). make lint is therefore go tool -modfile=tools/go.mod golangci-lint run ... from the repo root: the tool comes from tools/go.mod, the packages linted are gigapipe's. On a planted ineffectual assignment it reports the same 3 issues as the old go run ...@v2.14.0, and 0 issues. on the branch.
  4. Comments: the .golangci.yml header now describes make lint with --new-from-rev, without golangci-lint-action, only-new-issues or the corpus work; the three fuzz_test.go headers say the seed corpus (and testdata/fuzz) runs under go test ./....

Locally: go test ./... and make test-unit 33/33, go vet same as master, gofmt clean, actionlint clean. The PR description is updated.

The tools/ module added a second go.mod with a hand-maintained go version
that go-version-sync does not update, plus a second Dependabot stream.
Run the latest golangci-lint release instead: nothing to bump, and it keeps
up with new Go releases. .golangci.yml lists the linters explicitly and
--new-from-rev only fails on new issues.
Completes the previous commit, which removed tools/ but left make lint,
the CI cache paths, the /tools Dependabot entry and the docs pointing at it.
@rita7lopes

Copy link
Copy Markdown
Contributor

@Guess-Who-sec heads-up: I pushed two commits to your branch, so pull before you push again.

Point 3 of my last review was a bad call on our side, sorry. The tools/ module added a second go.mod with a hand-maintained go 1.27.3 that our go-version-sync workflow never updates, plus 1,100 lines of go.sum and a second Dependabot stream. Merging golangci-lint into the root go.mod instead would raise some of the server's real dependencies (e.g. pelletier/go-toml/v2, spf13/afero), so that wasn't an option either.

What changed:

  • tools/go.mod and tools/go.sum are removed, along with the /tools Dependabot entry and the tools/go.sum CI cache path.
  • make lint is now go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest run --new-from-rev=.... It's unpinned on purpose: it keeps up with new Go releases with nothing to bump by hand, and .golangci.yml plus --new-from-rev keep a new release from flooding old code.
  • docs/contributing.md and the PR description are updated to match.

The first of the two commits only removed the files, and the second carries the Makefile, CI, Dependabot and docs changes. They squash into one on merge. CI is green on the new head: lint ran golangci-lint v2.15.0 and reported 0 issues.

Thanks for turning the review around so fast. Everything else in the PR is good to go.

@rita7lopes
rita7lopes merged commit af53668 into metrico:master Nov 9, 2026
10 checks passed
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.

M1 — Tooling groundwork + PromQL transpile-determinism fix

2 participants