Skip to content

fix(metrics): cpu_stat deltaWaitRunSum uint64 underflow on cgroup counter reset#415

Open
wc4440222 wants to merge 1 commit into
ccfos:mainfrom
wc4440222:fix/cpu-stat-cputotal-underflow
Open

fix(metrics): cpu_stat deltaWaitRunSum uint64 underflow on cgroup counter reset#415
wc4440222 wants to merge 1 commit into
ccfos:mainfrom
wc4440222:fix/cpu-stat-cputotal-underflow

Conversation

@wc4440222

Copy link
Copy Markdown
Contributor

Fix

Fixes #414

Problem

In core/metrics/cpu_stat.go, deltaWaitRunSum is computed with a raw uint64 subtraction:

deltaWaitRunSum := deltaHierarchyWaitSum + stat.cpuTotal - cpu.cpuTotal

When a container's cgroup is recreated (e.g., container restart), stat.cpuTotal can be smaller than cpu.cpuTotal, causing the subtraction to underflow to a near-MaxUint64 value. This produces garbage values for all four wait-rate metrics derived from deltaWaitRunSum.

Fix

Reuse the already-safe deltaCpuUsage variable (computed with a counter-reset guard a few lines above) instead of repeating the raw subtraction:

deltaWaitRunSum := deltaHierarchyWaitSum + deltaCpuUsage

This is consistent with how waitSumDenom is already computed on line 144:

waitSumDenom := deltaWaitSum + deltaCpuUsage

Verification

  • go build ./core/metrics/ — pass
  • golangci-lint run ./core/metrics/... --timeout=5m --config .golangci.yaml — pass (no warnings)
  • Code review by sub-agent — pass

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.

fix(metrics): cpu_stat deltaWaitRunSum uint64 underflow on cgroup counter reset

1 participant