Skip to content

Fix reported CPU usage on Podman - #200

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

Fix reported CPU usage on Podman#200
MatthewCash wants to merge 3 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 more consistent readings.
    • CPU calculations now use elapsed sampling time for improved accuracy.
    • Added safeguards for counter resets, invalid timestamps, and incomplete statistics.

@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: ee0a434b-3f20-4b25-8da4-91bb7728cd6b

📥 Commits

Reviewing files that changed from the base of the PR and between 6e3ae2c and 00d6732.

📒 Files selected for processing (2)
  • environment/docker/stats.go
  • environment/docker/stats_test.go

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


📝 Walkthrough

Walkthrough

Resource polling now uses one CPU usage calculation based on CPU-time and elapsed sample-time deltas. Runtime detection, Podman state caching, and Docker SystemUsage handling were removed. Tests were updated for the unified calculation.

Changes

CPU statistics calculation

Layer / File(s) Summary
Unified CPU calculation and polling integration
environment/docker/stats.go
Polling calls the simplified helper. CPU usage uses CPU-time and elapsed sample-time deltas. Invalid timestamps and non-increasing CPU counters return zero.
CPU calculation test updates
environment/docker/stats_test.go
Tests use the single-argument helper, remove runtime-specific cases, update expected usage, and retain timestamped CPU sample construction.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 00d67

The change updates Podman CPU usage calculation while retaining Docker behavior; no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: alexevladgabriel, lancepioch, parkervcp

Poem

A rabbit measured time with care,
And found one CPU path there.
Old runtime checks hopped away,
While tests kept watch on each sample day.
Steady counters led the way.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. 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 identifies the primary user-facing change: correcting CPU usage reporting for Podman. The implementation also applies the calculation to Docker, but this does not make the title misl…
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.
Full details: Title check

Explanation

The title clearly identifies the primary user-facing change: correcting CPU usage reporting for Podman. The implementation also applies the calculation to Docker, but this does not make the title misleading.

  • Fix all pre-merge checks with AI
✨ 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.

@MatthewCash

Copy link
Copy Markdown
Author

Apologies for the delay. I've updated the changes to use wall clock time. Do you want this rebased and squashed?

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