Skip to content

Fix reported CPU usage on Podman - #200

Open
MatthewCash wants to merge 2 commits into
pelican:mainfrom
MatthewCash:fix/podman-cpu-usage
Open

Fix reported CPU usage on Podman#200
MatthewCash wants to merge 2 commits into
pelican:mainfrom
MatthewCash:fix/podman-cpu-usage

Conversation

@MatthewCash

@MatthewCash MatthewCash commented Jul 19, 2026

Copy link
Copy Markdown

This fixes incorrect CPU usage reporting when Wings uses Podman. Podman does not provide Docker-equivalent system CPU values, so CPU usage is now calculated using elapsed wall time instead.
Docker retains its existing calculation, and the container runtime is detected automatically.

I added some tests to cover the Docker and Podman calculations, multi-core usage, counter resets, invalid timestamps, and runtime detection.

Summary by CodeRabbit

  • Bug Fixes
    • Improved container CPU usage reporting for Podman and Docker runtimes.
    • CPU calculations now use appropriate timing data for more accurate readings.
    • Added handling for counter resets, missing timestamps, and other edge cases.

@MatthewCash
MatthewCash requested a review from a team as a code owner July 19, 2026 18:19
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 23d82464-23c1-4ba0-b8d2-bd96f34edd20

📥 Commits

Reviewing files that changed from the base of the PR and between 36f8ee8 and 6e3ae2c.

📒 Files selected for processing (1)
  • environment/docker/stats.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • environment/docker/stats.go

Included review availability: Your plan includes up to 2 reviews per rolling hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

Resource polling caches Podman runtime detection and selects runtime-specific CPU calculations. Docker uses SystemUsage deltas. Podman uses elapsed sample wall time. Tests cover calculation variants, edge cases, and version detection.

Changes

Podman CPU statistics

Layer / File(s) Summary
Runtime detection and polling integration
environment/docker/stats.go
Polling detects and caches Podman from Docker Engine version components, then passes the runtime mode into CPU calculation.
Runtime-specific CPU calculation and validation
environment/docker/stats.go, environment/docker/stats_test.go
CPU usage uses wall-time deltas for Podman or SystemUsage deltas for Docker. The calculation guards against counter resets and invalid timestamps. Tests cover scaling, rounding, resets, timestamps, and version detection.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 6e3ae

The PR changes CPU usage calculation for Podman while retaining Docker behavior and adds targeted tests; no actionable merge-blocking risk remains.

Sequence Diagram(s)

sequenceDiagram
  participant ResourcePolling
  participant DockerAPI
  participant CPUCalculation
  ResourcePolling->>DockerAPI: detect runtime from Engine version
  DockerAPI-->>ResourcePolling: return version components
  ResourcePolling->>DockerAPI: read container stats
  DockerAPI-->>ResourcePolling: return stats sample
  ResourcePolling->>CPUCalculation: calculate absolute CPU with runtime flag
  CPUCalculation-->>ResourcePolling: return CPU usage
Loading

Poem

A rabbit checked the runtime name,
Then measured time and counters’ game.
Podman watched the wall clock run,
Docker tracked system totals spun.
Tests caught resets, edge cases too—
Accurate hops in every queue.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: correcting CPU usage reporting for Podman.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

parkervcp
parkervcp previously approved these changes Aug 13, 2026

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

LGTM

@parkervcp

Copy link
Copy Markdown
Member

@MatthewCash Can you fix the merge conflict here please?

# Conflicts:
#	environment/docker/stats.go
@lancepioch

Copy link
Copy Markdown
Member

I've fixed the merge conflict. But...

I think instead we should just do wall-time only, because Docker's formula effectively reduces to the same math anyway, so both runtimes would report identical numbers with one code path. That lets us delete the runtime detection entirely, which is where the real problems are, since the version probe holds a global lock across a network call and a transient failure would silently leave a server on the wrong formula.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants