-
Notifications
You must be signed in to change notification settings - Fork 2.2k
deps: bump cgroups to v0.0.3, fix a few regressions #4785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
11b933a to
f1abb32
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR bumps the cgroups dependency to v0.0.3 to address JSON incompatibility and CPU shares conversion issues. The changes include updating dependency versions in go.mod, revising the CPU shares to CPU weight conversion logic in the test helper, and adjusting corresponding tests accordingly.
Reviewed Changes
Copilot reviewed 4 out of 8 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/integration/update.bats | Updated test comments and assertion functions to reflect revised conversion logic. |
| tests/integration/helpers.bash | Modified CPU shares conversion, using a multi-line awk script to compute weight. |
| libcontainer/factory_linux.go | Added a safeguard to initialize Resources when nil for cgroup v1 compatibility. |
| go.mod | Bumped the dependency version for github.com/opencontainers/cgroups to v0.0.3. |
Since opencontainers/cgroups v0.0.2 (commit b206a01), all stuct Resources fields are annotated with "omitempty" attribute. As a result, the loaded configuration may have Resources == nil. It is totally OK (rootless containers may have no resources configured) except since commit 6c5441e, cgroup v1 fs manager requires Resources to be set in the call to NewManager (this is a cgroup v1 deficiency, or maybe our implementation deficiency, or both). To work around this, let's add code to ensure Resources is never nil after loading from state.json. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
For changelog, see https://github.com/opencontainers/cgroups/releases/tag/v0.0.3 This fixes two runc issues: 1. JSON incompatibility introduced in cgroups v0.0.2 (see opencontainers/cgroups#22). 2. Bad CPU shares to CPU weight conversion (see opencontainers#4772). Due to item 2, modify some tests accordingly. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
thaJeztah
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thx!
Signed-off-by: Jared Ledvina <jared.ledvina@datadoghq.com>
Signed-off-by: Jared Ledvina <jared.ledvina@datadoghq.com>
Signed-off-by: Jared Ledvina <jared.ledvina@datadoghq.com>
… >= 1.3.2 (#43760) ### What does this PR do? - Auto-detect which conversion formula the runtime uses by comparing the actual cgroup weight with expected values from Docker Inspect - Support both old (linear) and new (quadratic) formulas for backward compatibility - Use the geometric mean approach for the inverse formula to handle ceil() rounding New formula for shares to weight: ``` exponent = (l² + 125l) / 612 - 7/34; weight = ceil(10^exponent) ``` We are doing inverse formula to get shares from weight in this PR: See **cpuWeightToSharesNonLinear**(cpuWeight float64) function, same logic can be found in other reference: https://github.com/cloudfoundry/guardian/blob/main/rundmc/utils.go ### Motivation On cgroups v2 systems running runc >= 1.3.2 (or crun >= 1.23), the docker.cpu.shares metric reported incorrect values. For example, containers configured with the default --cpu-shares 1024 would show 2597 instead of 1024. Root cause: The container runtime changed its CPU shares-to-weight conversion formula from linear to quadratic (opencontainers/runc#4785), but the Agent was still using the old linear inverse formula. Old formula (linear): - weight = 1 + ((shares - 2) * 9999) / 262142 - 1024 shares → weight 39 (incorrect default mapping) New formula (quadratic): - Uses logarithmic function to ensure min, max, and default values align - 1024 shares → weight 100 (correct default mapping) The Datadog Agent was using the old formula's inverse to convert weight back to shares, causing: - With new runc: weight 100 → 2597 shares (should be 1024) ### Describe how you validated your changes unit test ### Additional Notes Co-authored-by: minyi.zhu <minyi.zhu@datadoghq.com>
For changelog, see https://github.com/opencontainers/cgroups/releases/tag/v0.0.3
This fixes three runc issues:
Since cgroups v0.0.2, Cgroups.Resources may be nil after loading, but cgroup v1 fs manager is not expecting it.
JSON incompatibility introduced in cgroups v0.0.2 (see Remove annotations from Resources cgroups#22).
Bad CPU shares to CPU weight conversion (see Conversion of cgroup v1 CPU shares to v2 CPU weight causes workloads to have low CPU priority #4772).
Due to item 3, modify some tests accordingly (see #4772).
Fixes: #4772