fix(metrics): cpu_stat deltaWaitRunSum uint64 underflow on cgroup counter reset#415
Open
wc4440222 wants to merge 1 commit into
Open
fix(metrics): cpu_stat deltaWaitRunSum uint64 underflow on cgroup counter reset#415wc4440222 wants to merge 1 commit into
wc4440222 wants to merge 1 commit into
Conversation
Signed-off-by: wc4440222 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
Fixes #414
Problem
In
core/metrics/cpu_stat.go,deltaWaitRunSumis computed with a raw uint64 subtraction:When a container's cgroup is recreated (e.g., container restart),
stat.cpuTotalcan be smaller thancpu.cpuTotal, causing the subtraction to underflow to a near-MaxUint64value. This produces garbage values for all four wait-rate metrics derived fromdeltaWaitRunSum.Fix
Reuse the already-safe
deltaCpuUsagevariable (computed with a counter-reset guard a few lines above) instead of repeating the raw subtraction:This is consistent with how
waitSumDenomis already computed on line 144:Verification
go build ./core/metrics/— passgolangci-lint run ./core/metrics/... --timeout=5m --config .golangci.yaml— pass (no warnings)