Skip to content

Conversation

@amadeuszl
Copy link
Contributor

@amadeuszl amadeuszl commented Jan 29, 2026

Fix #7202

Microsoft Reviewers: Open in CodeFlow

Observations

for 1CPU, when it equals to weight 102, it will result in baseline for calculations on around ~1.0253, which means that previously reported utilization at 20% will be reported now as <20%, suggesting that we are getting more CPU

@amadeuszl amadeuszl marked this pull request as ready for review January 30, 2026 14:55
@amadeuszl amadeuszl requested a review from a team as a code owner January 30, 2026 14:55
Copilot AI review requested due to automatic review settings January 30, 2026 14:55
Copy link
Contributor

Copilot AI left a 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 pull request updates the CPU weight to CPU shares conversion formula for cgroup v2 in the ResourceMonitoring library. The change implements a new, more accurate conversion formula from Kubernetes that better reflects actual CPU allocations in modern container environments.

Changes:

  • Implemented new mathematical formula for converting cgroup v2 cpu.weight to cgroup v1 cpu.shares
  • Updated documentation in SystemResources.cs to reflect the new formula and reference Kubernetes blog post
  • Updated all affected tests with correct expected values based on the new formula
  • Updated verified test snapshots to reflect changed stack traces and calculation results

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationParserCgroupV2.cs Replaced old linear conversion formula with new logarithmic formula in ConvertCpuWeightToShares method
src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/SystemResources.cs Updated XML documentation to describe new formula with reference to Kubernetes blog post
test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs Updated test cases with new expected values; added new test method with proper formula documentation; removed duplicate test
test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs Updated test data (cpu.weight values) to match expected CPU units under new formula
test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Verified/*.verified.txt Updated verified test outputs for changed cpuRequest values and stack trace display class numbers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ResourceMonitoring - LinuxUtilizationParserCgroupV2.cs - Formula to calculate cpuUnits based on cpu.weight is outdated.

2 participants