Repository navigation
chore(ci): M1 tooling groundwork and deterministic PromQL substitute names (#918) - #1059
Conversation
|
Thanks, this looks good. A few things before merge:
|
…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 ./....
86d9931 to
ea1ab58
Compare
|
Thanks @rita7lopes. All four are in the new commit
Locally: |
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.
|
@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 What changed:
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 Thanks for turning the review around so fast. Everything else in the PR is good to go. |
Closes #918. Part of #917. Supersedes #925.
No dependencies: #1056, #1057 and #1058 are merged, and this branch is rebased onto
master.Five commits:
chore(ci): M1 tooling groundwork and deterministic PromQL substitute names (#918)fix(ci): give lint a base commit on pushes: falls back togithub.event.beforewhen 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 runsgo.ymlon pushes tomaster.chore(ci): drop arch-lint, pin golangci-lint in a tools module: the review changes (see "Review items" below).chore(ci): run golangci-lint@latest instead of a tools moduleand 5.chore(ci): point make lint, CI and docs at golangci-lint@latest: maintainer follow-up that replaces thetools/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 parsedExprnow 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:
Expr(prom_query_instant.go,prom_query_range.go)Expr(SetOidAndDB)TestTranspileIsDeterministictranspiles 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
make fmt-checkgofmt -l .lists any filemake buildmake test-unitgo test -race ./...make lintLINT_NEW_FROM_REV; CI passes the PR base commitmake fuzz HEAD=<head> [DURATION=60s]make lintrunsgo 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):
@latestkeeps up with new Go releases with nothing to bump by hand: no secondgo.mod, no secondgoversion forgo-version-syncto miss, no extra Dependabot stream..golangci.ymllists the linters explicitly and--new-from-revonly fails on new issues, so a new release cannot flood old code.Parser fuzzing
FuzzParsefor LogQL, PromQL and TraceQL checks two things: parsing never panics, and any accepted query round-trips (render, parse the rendering, render again: same text).make fuzz, and uploads any crasher as an artifact.testdata/fuzz/FuzzParse/, so it replays as a plain test.Review items from #925
parserpin_test.gofiles andreader/internal/parserpin.@latest), as described above.Review items from this PR
master..go-arch-lint.yml,tools/archlint, themake arch-linttarget, its CI job and its line indocs/contributing.md.tools/module, then replaced by@latestin a maintainer follow-up, which removestools/go.mod,tools/go.sum, the/toolsDependabot entry and thetools/go.sumCI cache path..golangci.ymlheader now says CI runsmake lintwith--new-from-rev(nogolangci-lint-action/only-new-issues, no corpus work), and the threefuzz_test.goheaders say the seed corpus runs undergo 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):
make fmt-check,make build,make test-unitmake lint0 issues.make e2e-ciThe jobs run in parallel, so the merge gate takes 3.2 minutes.
After the review changes, locally on the rebased branch:
go test ./...andmake test-unit(-race): 33 packages pass.go vet ./...is the same asmaster;gofmtclean;make buildleavesgo.mod/go.sumuntouched.go test;make fuzz HEAD=logql DURATION=10spasses;make fuzz HEAD=nopeis rejected.go.ymlandfuzz.yml.Earlier, locally:
TestTranspileIsDeterministicfails onmaster(random names differ between the two passes) and passes 10/10 here.mastervs this branch. The residual expressions and all 11 generated SQL statements are byte-identical; only the substitute names change.make fuzzfor 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-unitpassed 5/5 runs.Notes
make fuzzit runs is covered above.make lintonly 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 buildrunsgo mod tidybefore building, as the CI build step always has.actions/checkout@v4andactions/setup-go@v5run 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.