Skip to content

fix(ci): propagate CPU limits in Linux Bazel jobs (instead of 96 on x86_64) - #56994

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
regis.desgroppes/bazel-cpu-affinity-fix
Sep 29, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
regis.desgroppes/bazel-cpu-affinity-fix

Conversation

@rdesgroppes

@rdesgroppes rdesgroppes commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Pin Bazel, and everything it spawns, to KUBERNETES_CPU_LIMIT CPUs via taskset in tools/bazel, Linux only (as of today's setup).

Set the default on .bazel:defs:cache:progressive, the cache mixin every Bazel-invoking job extends, to KUBERNETES_CPU_REQUEST: 8 / KUBERNETES_CPU_LIMIT: 16, reaching every one of those jobs instead of the handful that previously declared their own KUBERNETES_CPU_LIMIT.

Double the limit relative to the request so jobs can opportunistically use idle node capacity, since taskset only binds our own process tree, not a cgroup guarantee.

Remove the per-job KUBERNETES_CPU_REQUEST/LIMIT overrides that just duplicated this default, and the now-redundant explicit --jobs=$KUBERNETES_CPU_REQUEST on bazel coverage/bazel test.

Drop the now-redundant --cpus $KUBERNETES_CPU_REQUEST from lint/{cross,linux}.yml and ebpf.yml's linter.go calls, since golangci-lint's own default concurrency, runtime.NumCPU(), already reads the taskset-restricted affinity mask on its own.

Halve go_e2e_test_binaries's KUBERNETES_MEMORY_REQUEST/LIMIT from 64Gi to 32Gi (we might even need less).

Motivation

Datadog's internal Kubernetes clusters, CI included, run job pods as Burstable QoS rather than Guaranteed, because sidecar containers like emissary don't declare a matching CPU request and limit, and Guaranteed is what actually triggers cpuset pinning and a CFS quota, see:
https://datadoghq.atlassian.net/wiki/spaces/cxg/pages/3473212607/Container+CPU+limits+in+internal+environments

Without either, cpu.max reads max no matter what KUBERNETES_CPU_LIMIT resolves to, so any cgroup-aware CPU auto-detection, Bazel's own --jobs=auto/--local_resources sizing included, sees the full host core count instead of what was granted, anywhere from 48 cores on an arm64 runner to 96 on x86_64, and so does every action Bazel spawns, since e.g. GoCompilePkg's own internal compiler concurrency defaults to runtime.GOMAXPROCS(0).

go_e2e_test_binaries is what actually surfaced this the most: it was OOM-killed ~110 times over 15 days in datadog-agent's own CI logs, still the single biggest source of these failures in the whole pipeline, because it moved from a Python thread pool, where KUBERNETES_CPU_LIMIT genuinely capped GOMAXPROCS, to a single bazel run call that never read that variable at all.

💡 taskset fixes this regardless of QoS class, because CPU affinity is inherited across fork/exec all the way down, unlike passing --jobs/--local_resources explicitly, which only bounds Bazel's own scheduling and leaves every spawned action to size itself off the same wrong host-wide number.

Describe how you validated your changes

Verified taskset reaches spawned actions, not just the Bazel server, with a stubbed $BAZEL_REAL and a grandchild process, and exercised the wraparound, fractional, and unset KUBERNETES_CPU_LIMIT cases under bash -n and real taskset invocations.

Compared durations against three recent main pipelines and retried each job at least once on the PR pipeline, for every job extending .bazel:defs:cache:progressive:

Job main (140981622) main (140982559) PR (140995231) PR (141017997)
bazel:mod-deps 1m19s 1m30s 1m18s 1m16s
bazel:mod-tidy 1m19s 1m23s 1m23s 1m17s
bazel:query-missing-manual-tags 1m41s 2m24s 1m31s 1m43s
bazel:run-buildifier-test 1m26s 1m33s 1m21s 1m20s
bazel:run-gazelle 1m59s 1m55s 1m31s 1m35s
bazel:run-go-mod-tidy 4m11s 4m58s 3m00s 3m40s
bazel:test:linux-amd64 12m16s 10m52s 8m59s 10m05s
bazel:test:linux-arm64 14m16s 12m06s 10m40s 11m24s
build_dogstatsd-binary_arm64 3m02s 2m23s 2m35s 2m13s
build_dogstatsd-binary_x64 1m58s 2m16s 1m51s 2m03s
build_dogstatsd_static-binary_arm64 2m28s 3m47s 2m09s 1m59s
build_dogstatsd_static-binary_x64 2m18s 1m46s 2m18s 2m13s
build_iot_agent-binary_arm64 3m15s 3m18s 2m47s 3m04s
build_iot_agent-binary_x64 2m54s 3m08s 3m10s 3m57s
build_system-probe-arm64 7m46s 7m25s 6m46s 6m48s
build_system-probe-x64 7m42s 7m28s 7m18s 6m54s
cluster_agent-build_amd64 4m00s 3m42s 4m01s 3m28s
cluster_agent-build_arm64 4m36s 5m29s 4m21s 4m13s
cluster_agent_cloudfoundry-build_amd64 3m09s 3m02s 2m38s 3m40s
cluster_agent_fips-build_amd64 4m13s 3m21s 3m29s 3m22s
cluster_agent_fips-build_arm64 6m10s 5m12s 6m20s 4m22s
cross_build_agent-binary_aix_ppc64 4m12s 4m07s 3m46s 3m48s
cross_build_trace_agent-binary_aix_ppc64 2m47s 2m18s 2m16s 2m41s
cws_instrumentation-build_amd64 2m10s 1m57s 2m40s 1m49s
cws_instrumentation-build_arm64 3m14s 2m16s 1m55s 1m57s
cws_instrumentation-build_injector_amd64 1m46s 1m46s 1m50s 1m44s
cws_instrumentation-build_injector_arm64 2m02s 2m13s 1m56s 1m52s
go_e2e_test_binaries 4m46s 4m38s 3m56s 3m39s
lint_cross_aix-ppc64 7m34s 8m41s 7m39s 7m38s
lint_cross_macos-arm64 10m20s 8m33s 9m02s 8m09s
lint_cross_macos-x64 8m21s 8m57s 8m32s 9m49s
lint_cross_windows-x64 8m39s 8m58s 9m22s 10m17s
lint_flavor_dogstatsd_linux-x64 9m09s 9m06s 11m18s 10m31s
lint_flavor_heroku_linux-x64 12m41s 10m11s 9m35s 16m14s
lint_flavor_iot_linux-x64 10m08s 9m19s 9m54s 11m11s
lint_linux-arm64 11m00s 11m00s 14m25s 15m04s
lint_linux-x64 10m08s 11m28s 12m17s 11m25s
new-e2e-unit-tests 8m18s 8m21s 8m25s 8m29s
secret_generic_connector-build_amd64 2m27s 2m05s 3m56s 1m50s
secret_generic_connector-build_arm64 2m34s 3m08s 2m12s 2m10s
secret_generic_connector_fips-build_amd64 2m20s 2m05s 1m50s 2m04s
secret_generic_connector_fips-build_arm64 2m22s 2m37s 2m06s 2m27s
security_go_generate_check 3m15s 2m50s 3m00s 3m05s
tests_ebpf_arm64 15m23s 14m40s 15m34s 14m57s
tests_ebpf_x64 14m28s 13m00s 15m30s 13m19s
tests_linux-arm64-py3 13m50s 11m51s 10m30s 10m58s
tests_linux-x64-py3 10m10s 10m15s 8m58s 9m55s
tests_serverless-init 3m50s 3m30s 3m33s 3m44s
tests_serverless-init-logs 2m29s 2m54s 2m48s 2m21s

Additional Notes

The PR doesn't address whether KUBERNETES_CPU_REQUEST could be unset (scheduling != capping).

@github-actions github-actions Bot added the medium review PR review might take time label Sep 28, 2026

@github-actions github-actions 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.

AI review by Codex (OpenAI) - workflow run

⚠️ Suspicious PR description: automated scanning withheld the description: “PR description withheld - it matched a secret/token or shell-canary pattern during automated scanning.”

^ ❓❓❓

The patch is incorrect: the new CPU-limit parser mishandles valid Kubernetes millicore quantities, defeating the intended concurrency limit.

(obsolete)

Comment thread tools/bazel Resolved
@dd-octo-sts

dd-octo-sts Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Gitlab CI Configuration Changes

⚠️ Diff too large to display on Github.

Changes Summary

Removed Modified Added Renamed
0 252 0 0

ℹ️ Diff available in the job log.

@rdesgroppes rdesgroppes added changelog/no-changelog No changelog entry needed qa/no-code-change No code change in Agent code requiring validation labels Sep 28, 2026
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 58.17% (+0.01%)

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

@dd-octo-sts

dd-octo-sts Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Files inventory check summary

File checks results against ancestor 4433f597:

Results for datadog-agent_7.85.0~devel.git.784.cc0ecf5.pipeline.140995231-1_amd64.deb:

No change detected

Results for datadog-iot-agent_7.85.0~devel.git.784.cc0ecf5.pipeline.140995231-1_amd64.deb:

No change detected

@rdesgroppes
rdesgroppes force-pushed the regis.desgroppes/bazel-cpu-affinity-fix branch 2 times, most recently from 0938d1f to 39b1512 Compare September 28, 2026 10:46
chatgpt-codex-connector[bot]

This comment was marked as outdated.

@rdesgroppes
rdesgroppes force-pushed the regis.desgroppes/bazel-cpu-affinity-fix branch from 39b1512 to 59b948d Compare September 28, 2026 12:40
@rdesgroppes rdesgroppes changed the title fix(ci): honor CPU limits in Bazel jobs fix(ci): propagate CPU limits in Linux Bazel jobs instead of 96 on x86_64 Sep 28, 2026
@rdesgroppes rdesgroppes changed the title fix(ci): propagate CPU limits in Linux Bazel jobs instead of 96 on x86_64 fix(ci): set CPU limits in Linux Bazel jobs (instead of 96 on x86_64) Sep 28, 2026
@rdesgroppes rdesgroppes changed the title fix(ci): set CPU limits in Linux Bazel jobs (instead of 96 on x86_64) fix(ci): propagate CPU limits in Linux Bazel jobs (instead of 96 on x86_64) Sep 28, 2026
@rdesgroppes
rdesgroppes force-pushed the regis.desgroppes/bazel-cpu-affinity-fix branch 4 times, most recently from 3531378 to a289657 Compare September 28, 2026 14:25
@JSGette

JSGette commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

I am not going to block this change but I don't think it's right to hide kubernetes specific logic inside of the wrapper that is used everywhere. I still think we should explicitly set CPU requests everywhere and just use --jobs= with the value read from requests or a similar approach.

First, it's somewhat "cloud native" approach when you set parameter from both ends - provider and consumer. Second, it makes it clearer what are the requirements towards compute to perform that chunk of work.

As I mentioned, I am not ready to die for it, just sharing my opinion.

@rdesgroppes
rdesgroppes force-pushed the regis.desgroppes/bazel-cpu-affinity-fix branch from a289657 to f8c8b5a Compare September 29, 2026 08:58
@rdesgroppes

rdesgroppes commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

@JSGette Fair point on the general principle, and I don't disagree that config coming from both ends (provider and consumer) is usually the right instinct.

However, I checked whether --jobs=/--local_resources= read from KUBERNETES_CPU_REQUEST would actually solve this though, and it unfortunately doesn't: neither flag propagates to what a spawned action itself sees.

With a minimal isolated Bazel workspace running a binary that just prints its own sched_getaffinity CPU count:

invocation spawned action's own CPU count
bazel run //:probe 14 (full host)
bazel run --jobs=2 //:probe 14
bazel run --local_resources=cpu=2 //:probe 14
taskset -c 0-1 bazel run //:probe 2

Both flags are Bazel's own internal action-scheduling bookkeeping: they don't touch a spawned process' environment or affinity mask.

=> taskset is the one mechanism that's inherited across fork/exec, which is why the OOM kills this PR fixes actually stop: GoCompilePkg/GoLink/golangci-lint each independently query runtime.NumCPU()/GOMAXPROCS, and only taskset changes what that returns.

On putting it in tools/bazel specifically: I counted the call sites, there are about 150 across the repo (~60 in tasks/*.py via the bazel() helper, ~90 direct bazel <verb> lines in .gitlab/**/*.yml, shell scripts, and omnibus/omnibus.rb).

=> tools/bazel is the one place all of them already funnel through today, before this PR, so it's the existing convention rather than a new hiding spot, and it's the only point reachable from every one of those ~150 sites without editing each one individually.

None of this rules out also setting KUBERNETES_CPU_REQUEST explicitly per job for scheduling purposes, most jobs already do, but that's a separate, complementary concern from what actually bounds the spawned actions' own concurrency.

@rdesgroppes
rdesgroppes force-pushed the regis.desgroppes/bazel-cpu-affinity-fix branch from f8c8b5a to 9ce9b38 Compare September 29, 2026 09:57
@rdesgroppes
rdesgroppes marked this pull request as ready for review September 29, 2026 10:01
@rdesgroppes
rdesgroppes requested review from a team as code owners September 29, 2026 10:01
@github-actions github-actions Bot deleted a comment from chatgpt-codex-connector Bot Sep 29, 2026

@github-actions github-actions 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.

AI review by Codex (OpenAI) - workflow run

⚠️ Suspicious PR description: automated scanning withheld the description: “PR description withheld - it matched a secret/token or shell-canary pattern during automated scanning.”

🚬 🚭

The patch is correct based on static review. No actionable issues were identified in the changed CI resource settings or Bazel CPU-affinity wrapper. CI execution was not validated.

@KevinFairise2 KevinFairise2 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for that change!
I do agree that it is not ideal to have logic that is very coupled to how our CI runners are made inside that wrapper. But in the other ends this is the best solution we have available that works for now. And I think it will drastically help us to have more predictable resource consumption for our jobs!

…6_64

### What does this PR do?

Pin Bazel, and everything it spawns, to `KUBERNETES_CPU_LIMIT` CPUs via
`taskset` in `tools/bazel`, Linux only.
Set the default on `.bazel:defs:cache:progressive`, the cache mixin
every Bazel-invoking job extends, to `KUBERNETES_CPU_REQUEST: 8` /
`KUBERNETES_CPU_LIMIT: 16`, reaching every one of those jobs instead of
the handful that previously declared their own `KUBERNETES_CPU_LIMIT`.
Double the limit relative to the request so jobs can opportunistically
use idle node capacity, since `taskset` only binds our own process tree,
not a cgroup guarantee.
Remove the per-job `KUBERNETES_CPU_REQUEST`/`LIMIT` overrides that just
duplicated this default, and the now-redundant explicit
`--jobs=$KUBERNETES_CPU_REQUEST` on `bazel coverage`/`bazel test`.
Drop the now-redundant `--cpus $KUBERNETES_CPU_REQUEST` from
`lint/{cross,linux}.yml` and `ebpf.yml`'s `linter.go` calls, since
golangci-lint's own default concurrency, `runtime.NumCPU()`, already
reads the `taskset`-restricted affinity mask on its own.
Halve `go_e2e_test_binaries`'s `KUBERNETES_MEMORY_REQUEST`/`LIMIT` from
64Gi to 32Gi.

### Motivation

Datadog's internal Kubernetes clusters, CI included, run job pods as
`Burstable` QoS rather than `Guaranteed`, because sidecar containers
like `emissary` don't declare a matching CPU request and limit, and
`Guaranteed` is what actually triggers `cpuset` pinning and a CFS quota.
https://datadoghq.atlassian.net/wiki/spaces/cxg/pages/3473212607/Container+CPU+limits+in+internal+environments
Without either, `cpu.max` reads `max` no matter what
`KUBERNETES_CPU_LIMIT` resolves to, so any cgroup-aware CPU
auto-detection, Bazel's own `--jobs=auto`/`--local_resources` sizing
included, sees the full host core count instead of what was granted,
anywhere from 48 cores on an arm64 runner to 96 on amd64, and so does
every action Bazel spawns, since e.g. `GoCompilePkg`'s own internal
compiler concurrency defaults to `runtime.GOMAXPROCS(0)`.
`go_e2e_test_binaries` is what actually surfaced this: it was OOM-killed
110 times over 15 days in datadog-agent's own CI logs, still the single
biggest source of these failures in the whole pipeline, because it moved
from a Python thread pool, where `KUBERNETES_CPU_LIMIT` genuinely capped
`GOMAXPROCS`, to a single `bazel run` call that never read that variable
at all.
`taskset` fixes this regardless of QoS class, because CPU affinity is
inherited across `fork`/`exec` all the way down, unlike passing
`--jobs`/`--local_resources` explicitly, which only bounds Bazel's own
scheduling and leaves every spawned action to size itself off the same
wrong host-wide number.

### Describe how you validated your changes

Verified `taskset` reaches spawned actions, not just the Bazel server,
with a stubbed `$BAZEL_REAL` and a grandchild process, and exercised the
wraparound, fractional, and unset `KUBERNETES_CPU_LIMIT` cases under
`bash -n` and real `taskset` invocations.
Compared durations against three recent `main` pipelines and retried
each job at least once on the PR pipeline, for every job extending
`.bazel:defs:cache:progressive`:

| Job | main 140467914 | main 140459135 | main 140451211 | PR baseline | PR retry |
|---|---|---|---|---|---|
| `bazel:coverage:linux-amd64` | 6m44s | 11m56s | 7m00s | 6m26s | 10m07s |
| `bazel:coverage:linux-arm64` | 9m44s | 9m55s | 9m52s | 8m40s | 10m46s |
| `bazel:test:linux-amd64` | 10m58s | 12m13s | 15m41s | 9m58s | 10m37s |
| `bazel:test:linux-arm64` | 14m00s | 13m18s | 15m00s | 23m18s | 9m39s |
| `bazel:mod-deps` | 1m17s | 1m25s | 3m07s | 1m09s | 1m18s |
| `bazel:mod-tidy` | 2m54s | 1m19s | 1m29s | 1m06s | 1m14s |
| `bazel:query-missing-manual-tags` | 4m09s | 2m00s | 1m54s | 4m52s | 1m45s |
| `bazel:run-buildifier-test` | 1m35s | 1m39s | 3m15s | 1m08s | 1m23s |
| `bazel:run-gazelle` | 3m47s | 2m16s | 1m52s | 1m31s | 1m41s |
| `bazel:run-go-mod-tidy` | 4m06s | 5m59s | 4m36s | 3m11s | 3m43s |
| `lint_cross_windows-x64` | 7m16s | 7m29s | 7m17s | 6m45s | 7m28s |
| `lint_cross_macos-x64` | 9m41s | 7m20s | 7m04s | 11m28s | 9m25s |
| `lint_cross_macos-arm64` | 6m51s | 7m37s | 6m33s | 8m23s | 7m55s |
| `lint_cross_aix-ppc64` | 6m38s | 6m36s | 5m56s | 5m52s | 6m22s |
| `lint_linux-x64` | 9m29s | 8m53s | 10m33s | 9m58s | 10m19s |
| `lint_linux-arm64` | 13m40s | 9m40s | 12m10s | 12m32s | 14m00s |
| `lint_flavor_iot_linux-x64` | 8m14s | 8m13s | 7m51s | 9m47s | 9m04s |
| `lint_flavor_dogstatsd_linux-x64` | 7m48s | 8m55s | 7m48s | 9m15s | 11m41s |
| `lint_flavor_heroku_linux-x64` | 9m46s | 8m19s | 8m02s | 10m58s | 8m38s |
| `cross_build_agent-binary_aix_ppc64` | 3m51s | 4m13s | 4m04s | 3m32s | 3m58s |
| `cross_build_trace_agent-binary_aix_ppc64` | 2m31s | 2m32s | 2m58s | 2m14s | 2m58s |
| `cluster_agent-build_amd64` | 3m45s | 3m45s | 3m49s | 3m15s | 3m32s |
| `cluster_agent-build_arm64` | 6m52s | 4m56s | 5m49s | 5m58s | 7m44s |
| `cluster_agent_fips-build_amd64` | 3m37s | 6m14s | 3m54s | 3m20s | 3m35s |
| `cluster_agent_fips-build_arm64` | 7m13s | 4m31s | 4m03s | 4m59s | 4m32s |
| `cluster_agent_cloudfoundry-build_amd64` | 2m47s | 3m19s | 4m23s | 2m47s | 2m36s |
| `cws_instrumentation-build_amd64` | 1m48s | 2m43s | 2m01s | 1m33s | 1m31s |
| `cws_instrumentation-build_arm64` | 2m11s | 2m06s | 3m37s | 1m46s | 2m10s |
| `cws_instrumentation-build_injector_amd64` | 1m59s | 1m51s | 1m54s | 1m29s | 1m43s |
| `cws_instrumentation-build_injector_arm64` | 4m38s | 2m08s | 2m08s | 1m56s | 1m46s |
| `build_dogstatsd_static-binary_x64` | 2m06s | 2m05s | 2m07s | 1m44s | 1m41s |
| `build_dogstatsd_static-binary_arm64` | 2m36s | 2m20s | 2m30s | 2m35s | 1m59s |
| `build_dogstatsd-binary_x64` | 2m16s | 2m09s | 4m01s | 1m42s | 1m56s |
| `build_dogstatsd-binary_arm64` | 7m14s | 2m34s | 2m23s | 2m12s | 2m19s |
| `build_iot_agent-binary_x64` | 3m19s | 2m46s | 2m36s | 2m41s | 2m17s |
| `build_iot_agent-binary_arm64` | 5m51s | 3m17s | 2m51s | 2m39s | 3m51s |
| `secret_generic_connector-build_amd64` | 1m53s | 2m15s | 2m20s | 1m39s | 1m46s |
| `secret_generic_connector-build_arm64` | 2m19s | 2m30s | 4m22s | 2m06s | 1m49s |
| `secret_generic_connector_fips-build_amd64` | 2m04s | 2m23s | 2m17s | 1m56s | 1m42s |
| `secret_generic_connector_fips-build_arm64` | 6m16s | 2m26s | 2m29s | 2m04s | 2m13s |
| `build_system-probe-x64` | 7m24s | 7m30s | 7m40s | 7m44s | 7m06s |
| `build_system-probe-arm64` | 7m30s | 8m02s | 6m07s | 6m40s | 6m43s |
| `tests_linux-x64-py3` | 22m23s | 21m56s | 21m47s | 9m55s | 10m48s |
| `tests_linux-arm64-py3` | 30m53s | 26m06s | 26m21s | 10m34s | 12m14s |
| `tests_serverless-init` | 4m31s | 3m32s | 3m51s | 3m13s | 3m16s |
| `tests_serverless-init-logs` | 2m40s | 2m21s | 2m47s | 2m34s | 2m16s |
| `new-e2e-unit-tests` | 7m27s | 8m46s | 7m32s | 7m28s | 7m17s |
| `tests_ebpf_x64` | 13m52s | 14m27s | 13m21s | 12m33s | 13m34s |
| `tests_ebpf_arm64` | 16m16s | 18m44s | 20m24s | 14m53s | 14m34s |
| `security_go_generate_check` | 3m09s | 3m15s | 3m06s | 3m00s | 2m44s |
| `go_e2e_test_binaries` | 6m50s | 5m06s | 5m11s | 3m51s | 4m26s |

The `bazel:test:linux-arm64` baseline outlier didn't reproduce on retry.
Every other job landed within its `main` range across all three
reference pipelines.

### Additional Notes

`.bazel:defs:cache:progressive` also covers jobs that never declared any
`KUBERNETES_CPU_REQUEST` at all (`cws_instrumentation`,
`secret_generic_connector`, plain Go unit tests, fuzzing), so they get
`taskset`-bounded for the first time too, at the plain default.
Jobs keeping their own lower `KUBERNETES_CPU_REQUEST` (`aix_cross`,
`cluster_agent`, `system_probe`, ...) still inherit the shared
`KUBERNETES_CPU_LIMIT: 16`, so they can opportunistically use more than
they reserve, same as the default case.
`invoke_unit_tests` inherits the new default too, but couldn't be
validated: its rule (`.on_invoke_tasks_changes`) never fired in this
diff or in any of the three reference pipelines.
The previous wraparound bound came from `getconf _NPROCESSORS_ONLN`, the
host's **raw** CPU count, not the set actually **allowed** to this
process.

A container that already excludes some CPUs, for example Kubernetes'
system-reserved ones, made `taskset` silently intersect that computed
range down to **fewer** CPUs than `KUBERNETES_CPU_LIMIT` requested.

A sweep of a real CI pipeline found this mismatch in about half of the
sampled jobs, one of them landing on a single usable CPU despite
requesting 16!

=> replace the `bash` and `awk` arithmetic with an embedded `python`
snippet that;
1. reads the real permitted set from `os.sched_getaffinity(0)`,
2. splits it at the last CPU this shell ran on via `bisect.bisect_left`,
3. rotates so the selection always starts from an actually allowed CPU.

This also drops the separate wraparound branch, since slicing the
rotated list naturally stops at however many CPUs are really available.
@rdesgroppes
rdesgroppes force-pushed the regis.desgroppes/bazel-cpu-affinity-fix branch from 9ce9b38 to cc0ecf5 Compare September 29, 2026 16:18
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 44858f6 into main Sep 29, 2026
678 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the regis.desgroppes/bazel-cpu-affinity-fix branch September 29, 2026 19:26
@github-actions github-actions Bot added this to the 7.85.0 milestone Sep 29, 2026
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Job ID: e76d794d-c89b-4a06-b348-503079ce6335

Baseline: 5ce35eb
Comparison: 44858f6
Diff

Optimization Goals: ✅ No significant changes detected

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
➖ quality_gate_metrics_logs memory utilization +1.42 [+1.19, +1.65] 1 Logs bounds checks dashboard
➖ dsd_uds_client_drop_detector_cpu % cpu utilization +1.32 [+0.83, +1.81] 1 Logs
➖ dsd_uds_10mb_3k_timestamped_contexts_memory memory utilization +0.78 [+0.56, +1.00] 1 Logs
➖ quality_gate_logs % cpu utilization +0.32 [-0.51, +1.16] 1 Logs bounds checks dashboard
➖ quality_gate_idle_all_features memory utilization +0.13 [+0.07, +0.19] 1 Logs bounds checks dashboard
➖ quality_gate_security_no_fs_load memory utilization +0.00 [-0.07, +0.08] 1 Logs bounds checks dashboard
➖ quality_gate_idle memory utilization -0.02 [-0.06, +0.02] 1 Logs bounds checks dashboard
➖ python_openmetrics % cpu utilization -0.06 [-0.74, +0.62] 1 Logs bounds checks dashboard
➖ quality_gate_security_idle memory utilization -0.25 [-0.29, -0.21] 1 Logs bounds checks dashboard
➖ quality_gate_private_action_runner memory utilization -0.25 [-0.38, -0.12] 1 Logs bounds checks dashboard
➖ quality_gate_security_mean_fs_load memory utilization -0.87 [-0.92, -0.83] 1 Logs bounds checks dashboard
➖ dsd_uds_10mb_3k_timestamped_contexts_cpu % cpu utilization -0.91 [-1.13, -0.68] 1 Logs

Bounds Checks: ✅ Passed

perf experiment bounds_check_name replicates_passed observed_value links
✅ python_openmetrics checks_execution_time 10/10 81.14 ≤ 100 bounds checks dashboard
✅ python_openmetrics cpu_usage 10/10 1335.58 ≤ 1500 bounds checks dashboard
✅ python_openmetrics memory_usage 10/10 4.32GiB ≤ 4.75GiB bounds checks dashboard
✅ quality_gate_idle intake_connections 10/10 4 ≤ 5 bounds checks dashboard
✅ quality_gate_idle memory_usage 10/10 176.55MiB ≤ 181MiB bounds checks dashboard
✅ quality_gate_idle total_bytes_received 10/10 761.67KiB ≤ 819.20KiB bounds checks dashboard
✅ quality_gate_idle_all_features intake_connections 10/10 2 ≤ 5 bounds checks dashboard
✅ quality_gate_idle_all_features memory_usage 10/10 464.54MiB ≤ 542MiB bounds checks dashboard
✅ quality_gate_idle_all_features total_bytes_received 10/10 1.12MiB ≤ 1.25MiB bounds checks dashboard
✅ quality_gate_logs intake_connections 10/10 18 ≤ 40 bounds checks dashboard
✅ quality_gate_logs memory_usage 10/10 212.37MiB ≤ 228MiB bounds checks dashboard
✅ quality_gate_logs missed_bytes 10/10 0B = 0B bounds checks dashboard
✅ quality_gate_logs total_bytes_received 10/10 263.50MiB ≤ 292MiB bounds checks dashboard
✅ quality_gate_metrics_logs cpu_usage 10/10 348.92 ≤ 2000 bounds checks dashboard
✅ quality_gate_metrics_logs intake_connections 10/10 19 ≤ 40 bounds checks dashboard
✅ quality_gate_metrics_logs memory_usage 10/10 431.88MiB ≤ 455MiB bounds checks dashboard
✅ quality_gate_metrics_logs missed_bytes 10/10 0B = 0B bounds checks dashboard
✅ quality_gate_metrics_logs total_bytes_received 10/10 0.93GiB ≤ 1.04GiB bounds checks dashboard
✅ quality_gate_private_action_runner memory_usage 10/10 72.83MiB ≤ 75MiB bounds checks dashboard
✅ quality_gate_security_idle cpu_usage 10/10 30.26 ≤ 100 bounds checks dashboard
✅ quality_gate_security_idle memory_usage 10/10 327.30MiB ≤ 357MiB bounds checks dashboard
✅ quality_gate_security_mean_fs_load cpu_usage 10/10 63.67 ≤ 200 bounds checks dashboard
✅ quality_gate_security_mean_fs_load memory_usage 10/10 307.56MiB ≤ 337MiB bounds checks dashboard
✅ quality_gate_security_no_fs_load cpu_usage 10/10 25.72 ≤ 100 bounds checks dashboard
✅ quality_gate_security_no_fs_load memory_usage 10/10 311.57MiB ≤ 348MiB bounds checks dashboard

Explanation

Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%

Performance changes are noted in the perf column of each table:

  • ✅ = significantly better comparison variant performance
  • ❌ = significantly worse comparison variant performance
  • ➖ = no significant change in performance

A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".

For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:

  1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.

  2. Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.

  3. Its configuration does not mark it "erratic".

CI Pass/Fail Decision

✅ Passed. All Quality Gates passed.

  • quality_gate_metrics_logs, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check missed_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_security_no_fs_load, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_no_fs_load, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check missed_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_private_action_runner, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_idle, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_mean_fs_load, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_mean_fs_load, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.

chouetz added a commit that referenced this pull request Oct 2, 2026
The gotest-custom build was the last direct OS-go invocation in e2e jobs,
bypassing the tools/bazel taskset CPU pin from #56994: it sized its
parallelism off the host core count (up to 96 on x86_64) instead of the
pod's CPU limit. Route it through the wrapper like every other go call in
these jobs (gotestsum runs via bazel run //internal/tools:gotestsum), so
CPU affinity is inherited all the way down.

Suggested-by: Régis Desgroppes <[email protected]>
gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Oct 5, 2026
### What does this PR do?

Route the `go build` of `gotest-custom` in `new-e2e-tests.run` through `bazel run //:go -- build …` instead of calling the OS-provided `go` directly.

### Motivation

It was the last direct OS-`go` invocation left in the e2e jobs — everything else (gotestsum, `go test`, the test binaries) already runs under `bazel run //internal/tools:gotestsum`. Going through the `tools/bazel` wrapper means the `taskset` CPU pin from #56994 is inherited by this build too, instead of sizing its parallelism off the host core count (up to 96 on x86_64) against the job's RAM limit.
https://datadoghq.atlassian.net/browse/ACIX-2077

Replaces the earlier GOMAXPROCS/GOMEMLIMIT approach from this PR, per the review discussion (thanks @rdesgroppes). Resource requests and limits are left untouched.

### Describe how you validated your changes

Smoke-tested the exact invocation (`bazel run //:go -- build -o … ./internal/tools/gotest-custom`) locally — it compiles and produces the binary.


Co-authored-by: nicolas.schweitzer <[email protected]>
gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Oct 5, 2026
…57555)

### What does this PR do?
Patch `rules_go` with bazel-contrib/rules_go#4727, which declares a 2048MB `resource_set` for `GoLink` instead of Bazel's 250MB default.

### Motivation
`go_e2e_test_binaries` OOM kills resurfaced on `main` ([#incident-61714](https://dd.enterprise.slack.com/archives/C0C6V8J63B3)) after #56683 bumped a constant in a package every e2e test depends on, forcing all test binaries to relink at once instead of hitting the remote cache, leading to either:
- `OOMKilled` ([example](https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/2108531979)):
```
ERROR: Job failed (system failure): Error in container build: exit code: 137, reason: 'OOMKilled'
```
- or `Segmentation fault` ([example](https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/2108458779)):
```
collect2: fatal error: ld terminated with signal 11 [Segmentation fault]
```
Bazel accounts 250MB per action and thus runs 16 of them at once, one per CPU granted since #56994, whereas a Go link peaks at up to 2490MB RSS, beyond the 32Gi memory limit (shared with Bazel's JVM, among others).

### Describe how you validated your changes
`//pkg/version:version_test` builds with the patch applied and `MODULE.bazel.lock` stays unchanged.

Co-authored-by: regis.desgroppes <[email protected]>
github-actions Bot pushed a commit that referenced this pull request Oct 5, 2026
…57555)

### What does this PR do?
Patch `rules_go` with bazel-contrib/rules_go#4727, which declares a 2048MB `resource_set` for `GoLink` instead of Bazel's 250MB default.

### Motivation
`go_e2e_test_binaries` OOM kills resurfaced on `main` ([#incident-61714](https://dd.enterprise.slack.com/archives/C0C6V8J63B3)) after #56683 bumped a constant in a package every e2e test depends on, forcing all test binaries to relink at once instead of hitting the remote cache, leading to either:
- `OOMKilled` ([example](https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/2108531979)):
```
ERROR: Job failed (system failure): Error in container build: exit code: 137, reason: 'OOMKilled'
```
- or `Segmentation fault` ([example](https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/2108458779)):
```
collect2: fatal error: ld terminated with signal 11 [Segmentation fault]
```
Bazel accounts 250MB per action and thus runs 16 of them at once, one per CPU granted since #56994, whereas a Go link peaks at up to 2490MB RSS, beyond the 32Gi memory limit (shared with Bazel's JVM, among others).

### Describe how you validated your changes
`//pkg/version:version_test` builds with the patch applied and `MODULE.bazel.lock` stays unchanged.

Co-authored-by: regis.desgroppes <[email protected]> 353a00a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/no-changelog No changelog entry needed internal Identify a non-fork PR medium review PR review might take time qa/no-code-change No code change in Agent code requiring validation team/agent-build team/agent-devx team/ebpf-platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants