Skip to content

perf(ci): enable full Go test caching (fixed ldflags + stable mtimes)#19618

Draft
davdhacs wants to merge 9 commits intomasterfrom
davdhacs/test-cache-combined-minimal
Draft

perf(ci): enable full Go test caching (fixed ldflags + stable mtimes)#19618
davdhacs wants to merge 9 commits intomasterfrom
davdhacs/test-cache-combined-minimal

Conversation

@davdhacs
Copy link
Copy Markdown
Contributor

@davdhacs davdhacs commented Mar 25, 2026

Description

Combined branch for demonstrating full Go test caching. Contains all three PRs:

Do not merge — this is a demo/evidence branch. Merge the individual PRs instead.

Results (warm run 23081726167)

Job Master This PR Speedup
go (GOTAGS="") 38m 6.9m 5.5x
go (GOTAGS=release) 34m 6.5m 5.2x
go-postgres (GOTAGS="") 31m 3.8m 8.2x
go-postgres (GOTAGS=release) 30m 4.0m 7.5x
sensor-integration 22m 5.3m 4.2x

Test cache hit rate: 78% (1946/2509).

Partially generated by AI.

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Mar 25, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The git ls-files | xargs touch mtime stabilization currently applies to every tracked file; consider narrowing this to files relevant to Go builds/tests (or excluding known problematic paths like large assets or build outputs) to avoid surprising other tools that rely on mtimes during the same workflow.
  • The hard-coded VERSION_PKG="github.com/stackrox/rox/pkg/version/internal" in go-tool.sh will silently break if the version package is moved/renamed; consider deriving this import path from go list or centralizing it in a single shared variable/source of truth.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `git ls-files | xargs touch` mtime stabilization currently applies to every tracked file; consider narrowing this to files relevant to Go builds/tests (or excluding known problematic paths like large assets or build outputs) to avoid surprising other tools that rely on mtimes during the same workflow.
- The hard-coded `VERSION_PKG="github.com/stackrox/rox/pkg/version/internal"` in `go-tool.sh` will silently break if the version package is moved/renamed; consider deriving this import path from `go list` or centralizing it in a single shared variable/source of truth.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@rhacs-bot
Copy link
Copy Markdown
Contributor

rhacs-bot commented Mar 25, 2026

Images are ready for the commit at 029b0e6.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.11.x-481-g029b0e60bc.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.37%. Comparing base (0737966) to head (029b0e6).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #19618   +/-   ##
=======================================
  Coverage   49.37%   49.37%           
=======================================
  Files        2743     2743           
  Lines      207037   207037           
=======================================
+ Hits       102223   102231    +8     
+ Misses      97228    97222    -6     
+ Partials     7586     7584    -2     
Flag Coverage Δ
go-unit-tests 49.37% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@davdhacs davdhacs force-pushed the davdhacs/test-cache-combined-minimal branch from fb71343 to b3de047 Compare March 26, 2026 04:36
davdhacs and others added 8 commits March 27, 2026 22:59
Tests don't need real version info. Use fixed version strings
(0.0.0-test) instead of git-describe values for test ldflags.
This makes link ActionIDs stable across commits, enabling Go's
test result cache to hit.

Also adds -buildvcs=false to stop Go 1.18+'s VCS stamping which
independently changes link ActionIDs on every commit.

Builds keep the current XDef/status.sh mechanism unchanged.

Verified locally: tests cache across commits with fixed ldflags.

Combined with the mtime fix (#19395), this enables full warm
test caching in CI (2.5-8.2x faster test jobs).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Go's test cache validates inputs by (path, size, mtime) — not content.
git checkout sets all file mtimes to the current time, which differs
between CI runs, causing test results to never be cached.

Fix: set all tracked file mtimes to a fixed date (2001-01-01) after
checkout and cache restore. This makes the test cache hit across runs
when file content hasn't changed.

Measured impact (from PR #19201):
- go unit tests: 35m → 8m (4.5x)
- go-postgres: 31m → 36s (52x)
- sensor-integration: 26m → 2.5m (11x)
- Test cache hit rate: 97.6% (681/698 packages)

Partially generated by AI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
git ls-files only outputs files, not directories. Tests that read
directories at runtime (os.ReadDir, filepath.Walk) check directory
mtimes for cache validation. Without stable dir mtimes, these tests
always miss the cache.

The helm chart tests (pkg/helm/charts/tests/*) use testdata directories
and were the largest uncached tests at 712s combined. This fix caches
them, dropping the Go Unit Tests step from 486s to 85s.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… entries

pre-build-go-binaries: default and prerelease (GOTAGS=release) share 93%
of cache entries (only 6 packages use release build tags). Separating them
doubles cache storage and causes the trim to delete shared entries. Keep
key-suffix only for race-condition-debug which uses -race/CGO_ENABLED=1
and has 39% unique entries.

build-and-push-operator: branding (RHACS vs STACKROX) is a runtime env
var, not a build tag. Compiled output is identical. Remove key-suffix
entirely.

Verified locally:
  default:    8911 entries (baseline)
  prerelease: +691 new (7% unique, 93% shared)
  race:       +6300 new (39% unique, 61% shared)
  branding:   +0 new (0% unique, 100% shared)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
unit-tests.yaml: go and go-postgres have GOTAGS matrix (""/ release)
sharing one cache key. With the GOCACHE trim, each variant deletes
the other's entries on every run, causing 3GB of churn. Add key-suffix
to give each variant its own cache.

scanner-build.yaml: pre-build-scanner-go-binary cross-compiles for
multiple architectures but doesn't set GOARCH on the cache step,
so all arches share one amd64-labeled cache key. Add env GOARCH.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Address sourcery-ai review: make GHA expression grouping explicit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The operator branding key-suffix is unnecessary for GOCACHE (0% unique
entries), but PR #19417 will unify operator builds entirely. Removing
the key-suffix here would create a merge conflict with that PR.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Address sourcery-ai feedback: clarify why only race-condition-debug
gets a separate cache key (39% unique entries from -race/CGO_ENABLED=1)
while default and prerelease share (93% overlap).

GOARCH is intentionally set only on the cache step, not job-level,
to avoid changing the default arch for other steps.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants