Skip to content

Conversation

@zhuminyi
Copy link
Contributor

@zhuminyi zhuminyi commented Dec 3, 2025

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

@github-actions github-actions bot added the medium review PR review might take time label Dec 3, 2025
@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Dec 3, 2025

Static quality checks

✅ Please find below the results from static quality gates
Comparison made with ancestor 9f6f936

Successful checks

Info

Quality gate Delta On disk size (MiB) Delta On wire size (MiB)
agent_deb_amd64 $${+0.01}$$ $${705.45}$$ < $${706.32}$$ $${+0.02}$$ $${172.88}$$ < $${173.81}$$
agent_deb_amd64_fips $${+0}$$ $${700.79}$$ < $${701.16}$$ $${-0}$$ $${171.83}$$ < $${172.71}$$
agent_heroku_amd64 $${+0}$$ $${327.25}$$ < $${327.69}$$ $${-0.01}$$ $${87.24}$$ < $${88.19}$$
agent_msi $${+0.02}$$ $${568.82}$$ < $${982.08}$$ $${+0.03}$$ $${141.75}$$ < $${143.01}$$
agent_rpm_amd64 $${+0.01}$$ $${705.44}$$ < $${706.31}$$ $${+0.02}$$ $${175.92}$$ < $${176.86}$$
agent_rpm_amd64_fips $${+0}$$ $${700.78}$$ < $${701.15}$$ $${+0.03}$$ $${173.98}$$ < $${174.95}$$
agent_rpm_arm64 $${+0.01}$$ $${691.11}$$ < $${691.67}$$ $${-0.01}$$ $${159.68}$$ < $${160.7}$$
agent_rpm_arm64_fips $${+0}$$ $${687.33}$$ < $${687.54}$$ $${-0.01}$$ $${159.17}$$ < $${160.1}$$
agent_suse_amd64 $${+0.01}$$ $${705.44}$$ < $${706.31}$$ $${+0.02}$$ $${175.92}$$ < $${176.86}$$
agent_suse_amd64_fips $${+0}$$ $${700.78}$$ < $${701.15}$$ $${+0.03}$$ $${173.98}$$ < $${174.95}$$
agent_suse_arm64 $${+0.01}$$ $${691.11}$$ < $${691.67}$$ $${-0.01}$$ $${159.68}$$ < $${160.7}$$
agent_suse_arm64_fips $${+0}$$ $${687.33}$$ < $${687.54}$$ $${-0.01}$$ $${159.17}$$ < $${160.1}$$
docker_agent_amd64 $${+0.01}$$ $${767.78}$$ < $${768.66}$$ $${+0.01}$$ $${260.62}$$ < $${261.52}$$
docker_agent_arm64 $${+0.01}$$ $${777.72}$$ < $${778.35}$$ $${+0}$$ $${250.78}$$ < $${251.72}$$
docker_agent_jmx_amd64 $${+0.01}$$ $${958.66}$$ < $${959.54}$$ $${+0}$$ $${329.26}$$ < $${330.15}$$
docker_agent_jmx_arm64 $${+0.01}$$ $${957.32}$$ < $${957.95}$$ $${+0}$$ $${315.4}$$ < $${316.35}$$
docker_cluster_agent_amd64 $${0}$$ $${179.09}$$ < $${179.28}$$ $${+0}$$ $${63.24}$$ < $${63.96}$$
docker_cluster_agent_arm64 $${+0}$$ $${196.58}$$ < $${196.79}$$ $${-0}$$ $${59.96}$$ < $${60.69}$$
docker_cws_instrumentation_amd64 $${0}$$ $${7.07}$$ < $${7.12}$$ $${0}$$ $${2.95}$$ < $${3.29}$$
docker_cws_instrumentation_arm64 $${0}$$ $${6.69}$$ < $${6.92}$$ $${+0}$$ $${2.71}$$ < $${3.07}$$
docker_dogstatsd_amd64 $${0}$$ $${38.65}$$ < $${39.3}$$ $${+0}$$ $${14.93}$$ < $${15.76}$$
docker_dogstatsd_arm64 $${0}$$ $${37.3}$$ < $${37.94}$$ $${-0}$$ $${14.37}$$ < $${14.83}$$
dogstatsd_deb_amd64 $${0}$$ $${29.87}$$ < $${30.53}$$ $${-0}$$ $${7.87}$$ < $${8.75}$$
dogstatsd_deb_arm64 $${0}$$ $${28.38}$$ < $${29.11}$$ $${-0}$$ $${6.81}$$ < $${7.71}$$
dogstatsd_rpm_amd64 $${0}$$ $${29.87}$$ < $${30.53}$$ $${-0}$$ $${7.89}$$ < $${8.76}$$
dogstatsd_suse_amd64 $${0}$$ $${29.87}$$ < $${30.53}$$ $${-0}$$ $${7.89}$$ < $${8.76}$$
iot_agent_deb_amd64 $${0}$$ $${42.6}$$ < $${43.19}$$ $${-0}$$ $${11.13}$$ < $${11.98}$$
iot_agent_deb_arm64 $${0}$$ $${40.34}$$ < $${40.92}$$ $${+0}$$ $${9.58}$$ < $${10.45}$$
iot_agent_deb_armhf $${0}$$ $${40.24}$$ < $${40.86}$$ $${-0}$$ $${9.69}$$ < $${10.56}$$
iot_agent_rpm_amd64 $${0}$$ $${42.6}$$ < $${43.19}$$ $${-0}$$ $${11.14}$$ < $${12.0}$$
iot_agent_suse_amd64 $${0}$$ $${42.6}$$ < $${43.19}$$ $${-0}$$ $${11.14}$$ < $${12.0}$$

@cit-pr-commenter
Copy link

cit-pr-commenter bot commented Dec 3, 2025

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: 4fccadc5-eff1-4898-b141-848d5b58741f

Baseline: 9f6f936
Comparison: 2165b8e
Diff

Optimization Goals: ✅ No significant changes detected

Experiments ignored for regressions

Regressions in experiments with settings containing erratic: true are ignored.

perf experiment goal Δ mean % Δ mean % CI trials links
docker_containers_cpu % cpu utilization +5.39 [+2.22, +8.55] 1 Logs

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
docker_containers_cpu % cpu utilization +5.39 [+2.22, +8.55] 1 Logs
quality_gate_logs % cpu utilization +0.27 [-1.20, +1.73] 1 Logs bounds checks dashboard
quality_gate_idle_all_features memory utilization +0.22 [+0.18, +0.25] 1 Logs bounds checks dashboard
otlp_ingest_metrics memory utilization +0.20 [+0.05, +0.35] 1 Logs
ddot_metrics_sum_cumulative memory utilization +0.13 [-0.03, +0.29] 1 Logs
docker_containers_memory memory utilization +0.05 [-0.02, +0.12] 1 Logs
ddot_metrics memory utilization +0.05 [-0.17, +0.27] 1 Logs
file_to_blackhole_1000ms_latency egress throughput +0.03 [-0.38, +0.45] 1 Logs
file_to_blackhole_500ms_latency egress throughput +0.03 [-0.34, +0.41] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput +0.01 [-0.08, +0.09] 1 Logs
uds_dogstatsd_to_api ingress throughput -0.00 [-0.13, +0.12] 1 Logs
uds_dogstatsd_to_api_v3 ingress throughput -0.01 [-0.14, +0.12] 1 Logs
file_to_blackhole_0ms_latency egress throughput -0.03 [-0.44, +0.38] 1 Logs
otlp_ingest_logs memory utilization -0.04 [-0.14, +0.06] 1 Logs
ddot_metrics_sum_cumulativetodelta_exporter memory utilization -0.04 [-0.27, +0.18] 1 Logs
uds_dogstatsd_20mb_12k_contexts_20_senders memory utilization -0.05 [-0.10, +0.01] 1 Logs
file_to_blackhole_100ms_latency egress throughput -0.06 [-0.11, -0.01] 1 Logs
ddot_logs memory utilization -0.17 [-0.24, -0.10] 1 Logs
ddot_metrics_sum_delta memory utilization -0.38 [-0.60, -0.16] 1 Logs
quality_gate_idle memory utilization -0.41 [-0.45, -0.36] 1 Logs bounds checks dashboard
quality_gate_metrics_logs memory utilization -0.45 [-0.67, -0.23] 1 Logs bounds checks dashboard
file_tree memory utilization -0.82 [-0.91, -0.74] 1 Logs
tcp_syslog_to_blackhole ingress throughput -2.30 [-2.39, -2.21] 1 Logs

Bounds Checks: ❌ Failed

perf experiment bounds_check_name replicates_passed links
docker_containers_cpu simple_check_run 10/10
docker_containers_memory memory_usage 10/10
docker_containers_memory simple_check_run 10/10
file_to_blackhole_0ms_latency lost_bytes 10/10
file_to_blackhole_0ms_latency memory_usage 10/10
file_to_blackhole_1000ms_latency lost_bytes 10/10
file_to_blackhole_1000ms_latency memory_usage 10/10
file_to_blackhole_100ms_latency lost_bytes 10/10
file_to_blackhole_100ms_latency memory_usage 10/10
file_to_blackhole_500ms_latency lost_bytes 10/10
file_to_blackhole_500ms_latency memory_usage 10/10
quality_gate_idle intake_connections 10/10 bounds checks dashboard
quality_gate_idle memory_usage 10/10 bounds checks dashboard
quality_gate_idle_all_features intake_connections 10/10 bounds checks dashboard
quality_gate_idle_all_features memory_usage 9/10 bounds checks dashboard
quality_gate_logs intake_connections 10/10 bounds checks dashboard
quality_gate_logs lost_bytes 10/10 bounds checks dashboard
quality_gate_logs memory_usage 10/10 bounds checks dashboard
quality_gate_metrics_logs cpu_usage 10/10 bounds checks dashboard
quality_gate_metrics_logs intake_connections 10/10 bounds checks dashboard
quality_gate_metrics_logs lost_bytes 10/10 bounds checks dashboard
quality_gate_metrics_logs memory_usage 10/10 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

Failed. Some Quality Gates were violated.

  • quality_gate_idle_all_features, bounds check memory_usage: 9/10 replicas passed. Failed 1 which is > 0. Gate FAILED.
  • quality_gate_idle_all_features, bounds check intake_connections: 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 lost_bytes: 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 intake_connections: 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_logs, bounds check lost_bytes: 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.

@zhuminyi zhuminyi force-pushed the docker_cpu_share_fix_with_new_runc branch from 5fc7c2b to cb2d220 Compare December 3, 2025 10:10
@zhuminyi zhuminyi added this to the 7.75.0 milestone Dec 3, 2025
@zhuminyi zhuminyi force-pushed the docker_cpu_share_fix_with_new_runc branch 3 times, most recently from 5bdd064 to e5ceba9 Compare December 3, 2025 13:02
@zhuminyi zhuminyi changed the title support new cgroup v2 runc logic Support docker.cpu.shares metric on cgroups v2 with runc >= 1.3.2 Dec 3, 2025
@zhuminyi zhuminyi changed the title Support docker.cpu.shares metric on cgroups v2 with runc >= 1.3.2 [CONTP-1135] Support docker.cpu.shares metric on cgroups v2 with runc >= 1.3.2 Dec 3, 2025
@zhuminyi zhuminyi added qa/done QA done before merge and regressions are covered by tests team/container-platform The Container Platform Team labels Dec 3, 2025
@zhuminyi zhuminyi marked this pull request as ready for review December 3, 2025 13:20
@zhuminyi zhuminyi requested review from a team as code owners December 3, 2025 13:20
@zhuminyi zhuminyi force-pushed the docker_cpu_share_fix_with_new_runc branch from e5ceba9 to c15f909 Compare December 3, 2025 13:31
@zhuminyi zhuminyi force-pushed the docker_cpu_share_fix_with_new_runc branch from c15f909 to ad6af29 Compare December 8, 2025 16:06
Comment on lines -88 to -94
// - The value emitted by the check is not exactly the same as in
// Docker because of the rounding applied in the conversions. Example:
// - Run a container with 2048 shares in a system with cgroups v2.
// - The 2048 shares are converted to weight in cgroups v2:
// weight = (((shares - 2) * 9999) / 262142) + 1 = 79.04 (cgroups rounds to 79)
// - This check converts the weight to shares again to report the same as in docker:
// shares = (((weight - 1) * 262142) / 9999) + 2 = 2046.91 (will be rounded to 2047, instead of the original 2048).
Copy link
Member

Choose a reason for hiding this comment

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

This still applies right? At least with the old formula.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, deleted by mistake.

// formulas used to convert between shares and weights depend on the
// runtime version:
// - runc < 1.3.2 / crun < 1.23: linear mapping (old Kubernetes formula)
// - runc >= 1.3.2 / crun >= 1.23: quadratic mapping (PR #4785)
Copy link
Member

Choose a reason for hiding this comment

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

I think we should include the link. It's not obvious which repo you're referring to.

@zhuminyi zhuminyi force-pushed the docker_cpu_share_fix_with_new_runc branch from ad6af29 to 5747b0d Compare December 11, 2025 14:12
@zhuminyi zhuminyi force-pushed the docker_cpu_share_fix_with_new_runc branch 2 times, most recently from 9f7f1b8 to 610442f Compare December 11, 2025 18:35
@zhuminyi
Copy link
Contributor Author

/merge

@dd-devflow-routing-codex
Copy link

dd-devflow-routing-codex bot commented Dec 11, 2025

View all feedbacks in Devflow UI.

2025-12-11 20:39:40 UTC ℹ️ Start processing command /merge


2025-12-11 20:39:49 UTC ℹ️ MergeQueue: waiting for PR to be ready

This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts — but it could also be blocked by other repository rules or settings.
It will be added to the queue as soon as checks pass and/or get approvals.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2025-12-12 00:40:19 UTC ⚠️ MergeQueue: This merge request was unqueued

devflow unqueued this merge request: It did not become mergeable within the expected time

@zhuminyi zhuminyi force-pushed the docker_cpu_share_fix_with_new_runc branch from 206cbfa to 2165b8e Compare December 12, 2025 15:26
@zhuminyi
Copy link
Contributor Author

/merge

@dd-devflow-routing-codex
Copy link

dd-devflow-routing-codex bot commented Dec 15, 2025

View all feedbacks in Devflow UI.

2025-12-15 15:22:16 UTC ℹ️ Start processing command /merge


2025-12-15 15:22:22 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 44m (p90).


2025-12-15 15:39:09 UTC ℹ️ MergeQueue: This merge request was merged

@dd-mergequeue dd-mergequeue bot merged commit ad46512 into main Dec 15, 2025
299 checks passed
@dd-mergequeue dd-mergequeue bot deleted the docker_cpu_share_fix_with_new_runc branch December 15, 2025 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

medium review PR review might take time qa/done QA done before merge and regressions are covered by tests team/container-platform The Container Platform Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants