Skip to content

Balance instrumentation test shards by splitting long test task chains - #13344

Open
PabloRzBo wants to merge 3 commits into
masterfrom
pablo/sdct-1444-shard-rebalance
Open

PabloRzBo wants to merge 3 commits into
masterfrom
pablo/sdct-1444-shard-rebalance

Conversation

@PabloRzBo

@PabloRzBo PabloRzBo commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Shortens full CI pipelines by about 12 minutes by splitting the longest chains of test tasks across test_inst shards. Every test still runs in exactly one shard, and muzzle checks stay in each project's own shard.

Motivation

Shards are assigned by path.hashCode() % slots, which balances the number of projects, not their duration. A project's test tasks run one after another, so a few projects set the length of the whole pipeline: since #13218, lettuce-5.0 runs about 25 minutes of tests in a row, followed by akka-http-10.0 and jdbc. On JVM 8 and 11 the slowest shard took 45–51 minutes while most took 20–30.

This change moves selected test tasks of lettuce-5.0, jdbc and akka-http-10.0 to light shards through a small override map keyed by slot count (8 only). Projects stay intact; each shard only selects which of their test tasks it runs. Unlisted tasks keep the hash slot, and test_inst_latest (/6), check (/4) and test_base (/4) are unchanged.

Additional Notes

Improvements

Each step was measured on DDCI against a control pipeline started at the same time (same base, a no-op buildSrc change so both run the full suite), one run per arm:

Step Slowest test_inst shard, JVM 11 / 8 Pipeline Control pipeline Delta
Hash slots (control) 48.3–50.8 / 43.4–51.6 min — 56.2–56.8 min —
lettuce-5.0 and jdbc split 44.4 / 40.1 min 50.4 min 56.8 min −6.4 min
+ akka-http-10.0 split (this PR) 30.2 / 32.9 min 43.6 min 56.2 min −12.6 min (−22%)
Guardrail This PR Control
Job-hours 54.8 h 56.4 h (−2.8%)
Slowest shard on JVM 17 / 21 / 25 / tip 27.0 / 29.9 / 25.0 / 30.6 min 44.5 / 40.1 / 40.3 / 38.0 min
Muzzle shards 5.8–7.8 min 6.2–7.5 min
Failed jobs 0 1, unrelated (maven-3.2.1 20-min task timeout in test_inst_latest)

The pipeline is now limited by test_inst_latest [8, 3/6] (about 37 min plus its build), which this PR does not change. Against the full-execution baseline (p50 54.5 min over 28 pipelines), the expected p50 is about 42–44 min; that needs data after merge to confirm.

Tests

Check Result
CIJobsExtensionsTest (new, JUnit 5) 6/6 pass: hash slot, unlisted tasks keep it, overrides move tasks, overrides only for their slot count, every override targets a valid other slot, no leak to projects sharing a path prefix
Dry run of every :instrumentationTest slot 884 test tasks, each in exactly one slot, none missing or duplicated
Dry run of every :runMuzzle slot 363 projects, each in exactly one slot, same sets as master
check (/4) and latestDep (/6) dry runs Same tasks as master
DDCI test results Same set of tests per task as the control on all 6 JVMs for lettuce-5.0, jdbc and akka-http-10.0
Configuration time About +0.3 s on a slotted dry run (noise level)

Advantages

  • About 12 minutes faster on every full pipeline (PRs touching shared code, merge queue, master), with no extra runner time.
  • Smaller, more even shards on every JVM, which also leaves more margin before the 1-hour job timeout.
  • No test or JVM removed; stale entries can never drop a test, only fall back to the hash slot.

Drawbacks

  • The map is hand-maintained. Each split exposed the next long project (lettuce, then akka-http). On master the slowest shard changed twice in six months, so the map needs a check every 1–3 months and after PRs that add suites to heavy modules; when stale, the balance degrades silently.
  • Non-standard sharding. Moving whole projects saves nothing here because the long chain moves with them, and Balance test_inst CI shards by measured duration instead of project-path hash #12822 found duration-weighted project assignment gains a minute or two. Splitting projects into virtual projects (Split Akka HTTP and Spring WebFlux tests across CI shards #12848) was rejected; this change keeps projects intact.
  • Only the 8-slot test_inst jobs benefit. Going further needs the same for test_inst_latest.
  • Duration-based test parallelization would remove the manual map, but Datadog Test Parallelization does not support Java yet.

Jira ticket: SDCT-1444

🤖 Generated with Claude Code

PabloRzBo and others added 2 commits November 10, 2026 12:37
The test tasks of one Gradle project run one after another. On JVM 8 and
11, lettuce-5.0 runs about 25 minutes of tests in a row and sets the
length of test_inst shard 6, and jdbc does the same for shard 5. Moving
whole projects to other slots cannot shorten those chains.

Move some of their test tasks to light slots with a small override map
keyed by the total slot count. A project with moved tasks joins every
slot that runs one of its tasks, and each slot aggregate runs only the
test tasks assigned to that slot. Unlisted tasks keep the hash slot.
Muzzle checks stay in each project's own hash slot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After the first split, akka-http-10.0 became the longest chain of test
tasks in a row (about 33 minutes on JVM 11, slot 2). Move its version101
tasks to slot 6 and its version102 tasks to slot 7, and move the
lettuce62 pair from slot 3 to slot 4, based on the per-slot durations
measured in the first treatment run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PabloRzBo PabloRzBo added tag: no release notes Changes to exclude from release notes type: refactoring comp: tooling Build & Tooling tag: ai generated Largely based on code generated by an AI or LLM labels Nov 10, 2026
@PabloRzBo
PabloRzBo marked this pull request as ready for review November 12, 2026 13:31
@PabloRzBo
PabloRzBo requested review from a team as code owners November 12, 2026 13:31
@PabloRzBo
PabloRzBo requested review from cecile75 and sarahchen6 and removed request for a team November 12, 2026 13:31
@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T13:36:13.932968Z 41dce11 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: 41dce11d88

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

} else {
// Run only the test tasks of the selected slot, as a project's tasks can be split across slots
val (selectedSlot, totalSlots) = slot
dependsOn(testTask.taskDependencies.getDependencies(testTask).filter { testTaskSlot(it.path, totalSlots) == selectedSlot })

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep coverage dependencies in the project's own slot

When instrumentationTest is run with both -Pslot=x/8 and -PcheckCoverage, split projects are selected in every override slot and this filter schedules only the assigned test tasks, but the subsequently added jacocoTestReport bypasses the filter: gradle/jacoco.gradle makes that report depend on test and forkedTestJacocoData. Because the Test.onlyIf predicate is project-wide, those own-slot tests execute again in each override slot (for example, lettuce's test and forkedTest run in slots 3, 4, and 6), violating the one-shard-per-test invariant and producing redundant coverage runs. Disable task overrides when coverage is requested, or add coverage/report dependencies only in the project's own slot.

Useful? React with 👍 / 👎.

@PabloRzBo PabloRzBo Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This can't happen with the current overrides, so I'm leaving the code as is:

  • All overridden tasks belong to :dd-java-agent:instrumentation:* projects (lettuce-5.0, jdbc, akka-http-10.0), and code coverage is never applied to those: gradle/java_no_deps.gradle excludes every :dd-java-agent:instrumentation path before applying gradle/jacoco.gradle. So findByName("jacocoTestReport") returns null for split projects and no coverage dependency is added.
  • Dry run on this branch: ./gradlew :instrumentationTest -Pslot=3/8 -PcheckCoverage -m schedules only the moved lettuce tasks in slot 3. No jacocoTestReport, and lettuce's own-slot test and forkedTest are not scheduled.
  • In CI, -PcheckCoverage is only set for :baseTest (4 slots) and :debuggerTest, and the overrides only apply to 8-slot instrumentation jobs.

If coverage is ever enabled for instrumentation projects, the coverage dependencies should follow the muzzle approach (isInOwnSlot). I'd rather not add that guard now, since it would never run.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

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

Bits Code Review: FAIL

Direct eight-slot test commands execute split-project tests in multiple shards because the execution guard still checks project membership. The new task filtering protects aggregate commands only.

Open Bits AI session

🤖 Bits Code Review · Commit 41dce11

)

projectSlot == selectedSlot
selectedSlot in projectSlots

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Direct slotted test commands execute split-project tests repeatedly

For direct commands such as ./gradlew test -Pslot=3/8, the existing Test.onlyIf guard still checks project.isInSelectedSlot. This predicate now enables lettuce-5.0 in slots 3, 4, and 6, so its ordinary test task runs in all three instead of only slot 6. The filtering in createRootTask does not protect direct test, check, or module-level allTests invocations. Apply task-level slot eligibility in the execution guard as well.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed in faa2034. The Test.onlyIf guard now checks the test task's own slot (new Task.isInSelectedTestSlot: its override slot, or else its project's slot) instead of whether the project runs in the slot. Projects without overrides behave as before.

Checked with real runs, since dry runs don't evaluate onlyIf:

  • lettuce-5.0 test with -Pslot=3/8, lettuce60Test with -Pslot=6/8 and forkedTest with -Pslot=4/8 are skipped (onlyIf 'Test task is in selected slot' is false).
  • lettuce60Test with -Pslot=3/8 and test with -Pslot=6/8 still execute.
  • :instrumentationTest -Pslot=3/8 still schedules the moved lettuce tasks, and the buildSrc tests pass.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

@bric3
bric3 self-requested a review November 12, 2026 14:40
The Test onlyIf guard checked whether the project ran in the selected
slot. A split project runs in several slots, so a direct command such as
`./gradlew test -Pslot=3/8` ran its own-slot tasks in every one of them.
Check the test task's own slot instead, so each test task runs in exactly
one slot however it is invoked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

Thank for this improvement.

I haven't reviewed it yet, the idea is indeed interesting, but I'm not sure on the maintainability.
A bare glance shows it's much much better than #12822.

I'm just marking a "request changes" preemptively to avoid early merge.

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

Bits Code Review: PASS

More details

The PR redistributes long instrumentation test chains across eight CI shards while keeping muzzle checks in each project’s original shard. The new task-level execution guard fixes duplicate test execution for direct slotted commands; no review findings remain open, though runtime validation remains unverified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit faa2034

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 59.63% (-0.00%)

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

@dd-octo-sts

dd-octo-sts Bot commented Nov 12, 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.95 s [-0.4%; +1.2%] (no difference)
startup:insecure-bank:tracing:Agent 12.92 s 12.90 s [-0.6%; +0.8%] (no difference)
startup:petclinic:appsec:Agent 17.09 s 16.93 s [+0.0%; +1.9%] (maybe worse)
startup:petclinic:iast:Agent 16.95 s 16.49 s [-1.6%; +7.1%] (no difference)
startup:petclinic:profiling:Agent 16.08 s 16.84 s [-8.7%; -0.3%] (maybe better)
startup:petclinic:sca:Agent 17.01 s 16.85 s [+0.2%; +1.7%] (maybe worse)
startup:petclinic:tracing:Agent 16.09 s 16.26 s [-2.0%; -0.1%] (maybe better)

Commit: faa20347 · 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.

@PabloRzBo PabloRzBo changed the title Balance instrumentation test shards by splitting long test task chains [SDCT-1444] Balance instrumentation test shards by splitting long test task chains Nov 12, 2026
@dd-octo-sts

dd-octo-sts Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Hi! 👋 Thanks for your pull request! 🎉

To help us review it, please make sure to:

  • Remove the tag from the pull request title

If you need help, please check our contributing guidelines.

@PabloRzBo PabloRzBo changed the title [SDCT-1444] Balance instrumentation test shards by splitting long test task chains Balance instrumentation test shards by splitting long test task chains Nov 12, 2026

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

comp: tooling Build & Tooling tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes type: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants