Fix missing logger argument in cpu_stats error message - #213
Merged
Conversation
The _LOGGER.error() call logging the raw cpu_stats payload uses a three-placeholder format string but passes only two arguments, omitting self._instance. Every sibling call in this except block passes (self._instance, self._name, ...). When the KeyError path is hit, logging raises 'TypeError: not enough arguments for format string' internally, so instead of one diagnostic line the user gets '--- Logging error ---' plus two tracebacks and a full call stack.
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.
Problem
In
helpers.py, theexcept KeyErrorhandler for CPU stats logs the raw payload with a three-placeholder format string but passes only two arguments:self._instanceis missing. Every sibling_LOGGERcall in the same block passes(self._instance, self._name, ...), so this looks like a simple omission.Effect
Because the format string can't be rendered,
loggingraisesTypeError: not enough arguments for format stringwhile emitting the record. Instead of one diagnostic line, the log gets--- Logging error ---, theTypeErrortraceback, aDuring handling of the above exception...chain, and a fullCall stack:unwound back tosys.exit(main())— roughly 50 lines per occurrence.The practical impact is that the message intended to help diagnose a missing
cpu_statskey is itself unreadable, and the failure is noisiest exactly when something is already wrong.This is reachable in normal operation: Docker can return a
cpu_statsblock withoutsystem_cpu_usagefor a container that has just started or restarted, which triggers theKeyErrorpath.Fix
Pass
self._instance, matching the surrounding calls. No behaviour change beyond the message rendering correctly.Testing
Verified in production. The
KeyErrorbranch has executed several times since the patch was deployed, and now emits exactly the two intended lines:Before the fix, the same branch produced
--- Logging error ---, aTypeError: not enough arguments for format string, aDuring handling of the above exception, another exception occurred:chain, and a fullCall stack:unwound tosys.exit(main())— roughly 50 lines in place of those two.The trigger in my case is a monitored container that has just restarted: Docker returns a
cpu_statsblock with zeroedcpu_usageand nosystem_cpu_usagekey, as shown above.🤖 Generated with Claude Code