Skip to content

Fix reported CPU usage on Podman#200

Open
MatthewCash wants to merge 1 commit into
pelican-dev:mainfrom
MatthewCash:fix/podman-cpu-usage
Open

Fix reported CPU usage on Podman#200
MatthewCash wants to merge 1 commit into
pelican-dev: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

Run ID: 4e40d88d-4cec-4f97-ad30-a3ce72866ea5

📥 Commits

Reviewing files that changed from the base of the PR and between 70f3344 and 36f8ee8.

📒 Files selected for processing (2)
  • environment/docker/stats.go
  • environment/docker/stats_test.go
📜 Recent review details
🔇 Additional comments (2)
environment/docker/stats.go (1)

7-24: LGTM!

Also applies to: 63-68, 99-99, 136-173, 174-198

environment/docker/stats_test.go (1)

1-110: LGTM!


📝 Walkthrough

Walkthrough

Resource polling now caches Podman runtime detection and selects runtime-specific absolute CPU calculations. Docker uses SystemUsage deltas, while 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 flag 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; tests cover scaling, rounding, resets, timestamps, and version detection.

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

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 peeked at Podman’s name,
Then measured time in hopping frames.
Docker’s counters joined the play,
Tests watched each edge along the way.
CPU numbers now bloom bright—
Thump, thump, accurate day and night!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: correcting Podman CPU usage reporting.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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.

1 participant