Skip to content

Introduce a Gradle S3 build cache - #12604

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 14 commits into
masterfrom
bdu/use-s3-gradle-build-cache
Nov 6, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 14 commits into
masterfrom
bdu/use-s3-gradle-build-cache

Conversation

@bric3

@bric3 bric3 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Enables S3 build cache for Gradle task outputs in GitLab CI. Eligible jobs can reuse matching outputs, while release pipelines use isolated, pipeline-specific namespaces. Dependency caches, plugin caches and job artifacts remain in GitLab. This should significantly improve Gradle job duration.

This effectively retire the old Gitlab based build cache.

Motivation

The existing pipeline-scoped GitLab cache transfers whole cache archives and limits reuse across pipelines. The S3 build cache lets jobs restore matching Gradle task outputs directly and share them across regular pipelines.

Follow-up

Additional Notes

It's important to understand that not all changes can benefit from the cache. Some changes impacts the whole build e.g. convention plugins, changing something in internal-api, reformatting code changing line numbers that land in class files, these kind impactful changes makes a different key, and require to be computed the first time they are encountered.

More precisely, the cost belongs to the first pipeline requesting each new cache key.

Example in such a PR:

  1. An author changes build-logic/ which produces new keys. Their PR pipeline needs to execute the affected tasks and stores their outputs.
  2. Meanwhile other PRs using the previous build-logic/ continue using the previous entries.
  3. The merge queue will run other jobs like ARM64 that need to execute the affected tasks as well, storing their output after success.
  4. After merging, other PRs can reuse the entries populated by the author's pipeline, wherever their task inputs match.

You can refer the doc and run book on our build cache.

Note

On master tests are still executed without relying on the build cache, the reason is to keep a steady signal for flaky tests.

Note

Smoke jobs restore build prerequisites, but their test results have zero reuse across the measured commits because the agent JAR includes the commit SHA.

Caution

If you are working on tasks that need caching ensure you read the gradle guide, in particular on having good inputs (for fingerprinting).

Scope and cache namespaces

This only affects GitLab CI. Dependency/plugin caches and job artifacts remain as big GitLab cache.

  • Shared: v1/<architecture>/<os>/
  • Tagged release: v1/release/<CI_PIPELINE_ID>/<architecture>/<os>/

Gradle appends the task cache key. Regular pipelines share entries across branches. Release entries are reused only within the same CI_PIPELINE_ID; no shared-cache fallback.

S3_BUILD_CACHE_PREFIX can override the full prefix.

Results and pipeline timings

The warm run reduced pipeline duration by 31.7% and median job duration by 20.3% across 200 matching cache-enabled Gradle jobs. System-test duration fell from 12m37s to 11m27s.

Snapshot: 2026-11-06, comparing the November 5 commit 50df1a0547 with the November 6 commit a19b40f110. Both passed and have identical source trees, using plugin 1.9.11 and Gradle 9.8.2. ARM64 test jobs remained manual in both pipelines.

Overall:

  • Parent pipeline duration: 45m27s -> 31m03s.
  • S3 build cache lookup hit rate: 83.23% -> 97.10%.
  • Misses: 20,936 -> 3,692.
  • Write operations: 21,048 -> 3,803.
  • Gradle actionable tasks restored: 41.77% -> 51.53%.

All times below are per-job medians. Arrows show the first pipeline followed by the second.

Job family S3 build cache lookup hits Test tasks restored, second run Gradle duration GitLab job duration
Instrumentation AMD64 88.74% -> 99.62% 98.8% 17m16s -> 3m37s 24m07s -> 10m00s
Latest dependencies AMD64 90.04% -> 99.92% 99.4% 14m13s -> 3m23s 23m02s -> 9m31s
Smoke AMD64 98.08% -> 98.17% 0% 9m10s -> 8m55s 16m07s -> 15m55s
Test compilation 44.94% -> 99.13% - 3m06s -> 2m10s 5m45s -> 4m36s
Muzzle 20.23% -> 83.88% - 4m59s -> 4m57s 7m15s -> 7m11s
Spotless 4.22% -> 58.69% - 3m37s -> 3m02s 5m08s -> 4m48s

- means test-task restoration is not applicable to that job family.

Measurement scope and limits

Cache metrics cover 200 cache-enabled parent-pipeline Gradle jobs in build and tests, excluding downstream system tests and validate_build: [false]. The analysis covers 402 Gradle job logs, including that uncached validation job in each pipeline. All 200 compared Gradle jobs passed; all 227 executed parent-job names match, with no retries. Median job duration change is calculated from each matched Gradle job's percentage change.

Pipeline duration includes non-Gradle jobs, merges job-running intervals, and excludes queues and retries. Job durations include runner overhead. System-test durations include the parent trigger's downstream wait; the separate GitHub Run system tests workflow is excluded. Duration calculation. Cache lookup rates use total hits/lookups. Restored/actionable task counts and Gradle durations use the invocation that emitted each S3 summary; unrelated nested-build summaries and follow-up validation commands are excluded. Test-task reuse excludes skipped, no-source and up-to-date tasks; FROM-CACHE can include local restoration.

The master GitLab-cache pipeline 150683126 below ran for commit 5a9bf74ccd, the master parent merged by 50df1a0547. It includes a broader JVM matrix, ARM64 and SSI smoke jobs, so the reported gains compare only the two S3 build cache pipelines. Runner load was not controlled; repeatability needs comparable runs across more commits.

Timelines span each group's first start to last finish, including gaps. Parallel rows are not additive; minor jobs are omitted. Time zero is the first parent job, excluding its initial queue. The master reference ends at 48m29s versus GitLab's 48m28s; the initial S3 run ends at 45m28s versus 45m27s, and the warm run at 31m09s versus 31m03s. Both S3 runs passed without retries.

Master GitLab-cache pipeline (2026-11-05)

=> pipeline 150683126

gantt
    title Master GitLab-cache run - pipeline 150683126
    dateFormat YYYY-MM-DD HH:mm:ss
    axisFormat %M:%S
    tickInterval 5minute
    todayMarker off

    section Parent pipeline
    Build and test compilation : 2000-01-01 00:00:36, 2000-01-01 00:12:11
    Instrumentation tests [144] : 2000-01-01 00:07:02, 2000-01-01 00:48:29
    Latest-dependency tests [54] : 2000-01-01 00:07:10, 2000-01-01 00:41:07
    Smoke tests [144] : 2000-01-01 00:07:16, 2000-01-01 00:41:17
    SSI smoke tests [144] : 2000-01-01 00:07:22, 2000-01-01 00:42:18
    Other Gradle tests and checks : 2000-01-01 00:00:03, 2000-01-01 00:34:02
    Packaging and system-test setup : 2000-01-01 00:06:54, 2000-01-01 00:13:28
    Startup benchmarks [2] : 2000-01-01 00:07:48, 2000-01-01 00:21:19
    Load and application benchmarks [6] : 2000-01-01 00:07:47, 2000-01-01 00:37:28
    Benchmark reporting and configuration validation : 2000-01-01 00:21:24, 2000-01-01 00:41:17

    section Downstream pipelines
    System tests : 2000-01-01 00:13:41, 2000-01-01 00:29:22
    Test-matrix generation : 2000-01-01 00:13:44, 2000-01-01 00:15:06
    SSI system tests : 2000-01-01 00:15:06, 2000-01-01 00:29:21

    section Comparison scale
    50-minute boundary :milestone, 2000-01-01 00:50:00, 0s
Loading

The last Gradle job, test_inst: [zulu8, 5/8], ran for 40m12s and finished at 48m29s. System tests finished at 29m22s.

Warm S3 build cache pipeline (hot cache, empty commit, best case scanario)

=> pipeline 150859060

gantt
    title Warm S3 build cache run - pipeline 150859060
    dateFormat YYYY-MM-DD HH:mm:ss
    axisFormat %M:%S
    tickInterval 5minute
    todayMarker off

    section Parent pipeline
    Build and test compilation : 2000-01-01 00:00:00, 2000-01-01 00:06:41
    Instrumentation tests [48] : 2000-01-01 00:04:17, 2000-01-01 00:16:38
    Latest-dependency tests [30] : 2000-01-01 00:04:37, 2000-01-01 00:18:10
    Smoke tests [48] : 2000-01-01 00:06:42, 2000-01-01 00:29:24
    Other Gradle tests and checks : 2000-01-01 00:00:01, 2000-01-01 00:19:29
    Packaging and system-test setup : 2000-01-01 00:05:16, 2000-01-01 00:11:43
    Startup benchmarks [2] : 2000-01-01 00:06:02, 2000-01-01 00:19:59
    Benchmark reporting and configuration validation : 2000-01-01 00:20:00, 2000-01-01 00:25:03
    Test-result aggregation and pipeline finalization : 2000-01-01 00:29:25, 2000-01-01 00:31:09

    section Downstream pipelines
    System tests : 2000-01-01 00:11:44, 2000-01-01 00:23:11
    Test-matrix generation : 2000-01-01 00:11:45, 2000-01-01 00:13:17
    SSI system tests : 2000-01-01 00:13:18, 2000-01-01 00:23:11

    section Comparison scale
    50-minute boundary :milestone, 2000-01-01 00:50:00, 0s
Loading

The last Gradle job, test_smoke: [17, 8/8], ran for 22m38s and finished at 29m24s. System tests finished at 23m11s.

Smoke tests were the last test group in the warm run, finishing at 29m24s. Instrumentation and latest-dependency tests finished at 16m38s and 18m10s; system tests finished at 23m11s, with benchmark reporting and configuration validation at 25m03s. Further instrumentation reductions save runner time.

Smoke tests cannot benefit from the Gradle S3 Build Cache ; in hot cache situation, smoke tests or child pipelines – like system tests – will determine the pipeline end.

Remaining cache misses

The warm run had 3,692 misses across 127,093 lookups (2.9%) and 3,803 writes (18.1% of the initial 21,048). Writes count operations, not unique cache keys.

Spotless: 1,157 writes. Muzzle's eight shards: 1,647 writes, including 283 in muzzle: [4/8]. Other jobs: 999 writes. Spotless and Muzzle account for 73.7% of writes. Both initial and warm jobs passed. Per-task key/input hashes were not retained, so remaining miss causes need targeted comparison.

Follow-up: analyze why they miss, by comparing keys with --info -Dorg.gradle.caching.debug=true, including dependencies, formatter state, toolchains, and path/ref-dependent inputs. Identical source trees can have different inputs. Cache-miss diagnostics.

Remaining tasks

Correctness checks before rollout

Other tasks

Test JVM

[!CAUTION]
Possibly need to track the JVM fingerprint, not only the JVM major version.

Container images

Tests having a moving version tag are a problem as they are not accounted in task's fingerprints. The following is a proposed solution to account for them.

Proposed build-logic DSL:

dependencies {
  testContainerImage(image("cassandra:4", "test.cassandra.image"))
}

The factory method image declares the reference and explicit system-property name; testContainerImage associates it with the consuming test suite. The plugin would:

  1. Apply Testcontainers image substitution, including TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX and JDBC's SQL Server mapping.
  2. Resolve the effective registry's digest before test fingerprinting; revalidate moving tags each build, including with configuration-cache reuse.
  3. Set test.cassandra.image to the full registry/repository@sha256:... reference on the consuming test tasks.

Tests then use System.getProperty("test.cassandra.image"), retaining any Testcontainers compatibility mapping. Both property name and value are Gradle task inputs. A changed digest changes the key. Resolution in doFirst would be too late.

This syntax can be supplied through DependencyHandler extensions; the plugin must provide the DSL and OCI resolver. No native Gradle OCI resolution is implied.

Moving test references found: WebSphere latest, Google Cloud CLI emulators, Cassandra 3/4, MySQL 8.0, PostgreSQL 16-alpine, implicit SQL Server latest, Oracle 23.5-slim-faststart, and Testcontainers' Alpine 3.17 helper. Apply digest tracking to release tags too: they can be republished. Resolve the effective CI mirror, whose contents can differ from upstream.

CI builders

Builder ci-* tags can move. Track the actual builder digest as an input to affected cacheable Gradle tasks, and retain architecture separation.

Test counts

The initial and warm aggregates match for all 172 counted jobs: 400,054 reported tests each. These include restored results by the build cache.

[!NOTE]
.gitlab/collect-result/* still runs after Gradle and processes restored XML normally. Existing counter limitations remain: retried failures are retained, and text matching can mistake log contents for XML errors.

Muzzle

The planner discovers dependency versions; the plugin registers per-version checks with stable names derived from pass/fail, dependency coordinates and the optional directive name. Discovery and planning are not cached by the S3 build cache. Artifact downloads use Gradle's separate dependency cache.

Each MuzzleTask is already cacheable. Reuse depends on its implementation, directive and instrumentation/tooling/dependency classpaths; a stable task name alone does not guarantee a hit. Each planned check has two build-cache outcomes:

  • Matching entry: restore reports/<task>.txt and skip the compatibility assertion.
  • No matching entry: run the assertion and cache its output on success. This can happen for a newly published or newly sampled dependency version, changed inputs, or an expired entry.

A warm run can therefore mix restored and executed checks: the planner is free to select versions whose results have not been cached. Random version sampling can change that selection between runs.

muzzle-end is not cacheable; it regenerates reports from both restored and newly produced result files.

[!CAUTION]
The actual validation JDK identity still needs tracking beyond the requested Java major.

Latest dependencies and scheduled locks

  • Same resolved classpath and other inputs: reuse is expected.
  • Changed resolved classpath: execute, unless that exact input combination is already cached.

The scheduled lock refresh does not change test dependency selection in this PR. It runs in build and validate_build, not in build_tests or test jobs, and the rewritten locks are not shared. build also uses -PskipTests, so it produces no cached test results against those refreshed locks.

Before and after the migration, test jobs resolve dependencies using their checked-in locks. The S3 build cache changes output reuse: matching results from earlier test jobs can now be restored across pipelines. Outputs built with refreshed dependencies are reusable only when the consuming task's fingerprints match. No lock-refresh or lock-handoff change is needed for this migration.

Remaining input checks

Standard sources, classpaths and test options are tracked. Check full JDK/native-tool versions, relevant environment variables, service state and dependencies resolved inside nested builds. Paths and moving labels do not identify their contents. The S3 build cache adds no inputs automatically.

Compare representative results with --no-build-cache --rerun-tasks. For untrackable external state, disable caching and up-to-date reuse on affected tasks. Keep release isolation and independent validate_build checks.

Identified bug post activation of the S3 build cache

Nightly cache warming

The POPULATE_CACHE populates dependency/plugin caches. Which is still useful, during build or tests. Moreover, running this nightly helps keeping the Gradle S3 Build Cache in a steady state.

Success measures and remaining work

Primary metrics: median/tail job duration, pipeline critical path, S3 build cache lookup hit rate and Gradle FROM-CACHE, split by job family and architecture. Also track writes/misses, transfer time/bytes, cache errors and actual test executions. The plugin's cumulative cache-time estimate is not pipeline wall time.

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 59.99% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 7db1179 | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.01 s 13.96 s [-0.3%; +1.0%] (no difference)
startup:insecure-bank:tracing:Agent 13.01 s 12.89 s [-0.0%; +1.9%] (no difference)
startup:petclinic:appsec:Agent 17.11 s 16.58 s [-1.2%; +7.7%] (no difference)
startup:petclinic:iast:Agent 17.07 s 17.07 s [-0.8%; +0.9%] (no difference)
startup:petclinic:profiling:Agent 16.77 s 16.96 s [-2.2%; +0.0%] (no difference)
startup:petclinic:sca:Agent 17.11 s 16.36 s [+0.4%; +8.8%] (maybe worse)
startup:petclinic:tracing:Agent 16.25 s 16.14 s [+0.0%; +1.4%] (maybe worse)

Commit: 7db1179c · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@sarahchen6 sarahchen6 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.

LGTM!! Though we should probably update the PR description based on results from the latest changes?

@bric3

bric3 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

@sarahchen6 Yes, I can do that tomorrow when all pipelines have run. I can push an empty commit.

@AlexeyKuznetsov-DD AlexeyKuznetsov-DD 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.

Can't wait to see it alive!
Left some minor notes.
Just for my understanding: cache expiration was configured in some external admin tool?

Comment thread settings.gradle.kts Resolved
Comment thread settings.gradle.kts Resolved
Comment thread settings.gradle.kts Resolved
@bric3

bric3 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Just for my understanding: cache expiration was configured in some external admin tool?

Yes

@sarahchen6
sarahchen6 marked this pull request as ready for review November 4, 2026 18:39
@sarahchen6
sarahchen6 requested review from a team as code owners November 4, 2026 18:39
@sarahchen6
sarahchen6 requested review from dougqh, jandro996 and randomanderson and removed request for a team November 4, 2026 18:39
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T18:47:35.658702Z ded8386 Draft marked ready
🔒 Security Review ✅ Completed 2026-11-04T18:46:53.544035Z ded8386 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ded8386885

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread settings.gradle.kts Resolved
Comment thread settings.gradle.kts Resolved
Comment thread settings.gradle.kts Resolved

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot 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.

Bits Code Review: PASS

More details

Default release cache namespaces isolate pipelines and separate architectures and operating systems; packaged dependency bytes participate in cache fingerprints. These safeguards were reviewed statically; live S3 operations and tagged-pipeline execution remain unverified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit ded8386

bric3 added 8 commits November 6, 2026 15:35
[ci: NON_DEFAULT_JVMS]
[ci: ARM64]
Cache hits restore earlier test results and provide no new executions
for flaky-test detection. Run selected Test tasks on master every time,
while keeping successful results eligible for cache writes and reuse by
other branches. Compilation and other build tasks keep normal caching.

Preserve the per-project rerun flag and log why task output reuse is
disabled.
@bric3
bric3 force-pushed the bdu/use-s3-gradle-build-cache branch from 13a2f36 to 7c16fea Compare November 6, 2026 14:36
@bric3

bric3 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Dooh had to rebase unsigned commits.

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 1508ea5 into master Nov 6, 2026
951 of 955 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the bdu/use-s3-gradle-build-cache branch November 6, 2026 18:46
@github-actions github-actions Bot added this to the 1.69.0 milestone Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: tooling Build & Tooling tag: no release notes Changes to exclude from release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants