Handle missing total_cache in check_docker.py#98
Closed
kamtec1 wants to merge 1 commit intotimdaman:release/v2-3-0from
Closed
Handle missing total_cache in check_docker.py#98kamtec1 wants to merge 1 commit intotimdaman:release/v2-3-0from
kamtec1 wants to merge 1 commit intotimdaman:release/v2-3-0from
Conversation
The fix: Changed line 523-524 from:
pythonadjusted_usage = inspection['memory_stats']['usage'] - inspection['memory_stats']['stats']['total_cache']
To:
pythoncache = inspection['memory_stats']['stats'].get('total_cache', 0)
adjusted_usage = inspection['memory_stats']['usage'] - cach
---
Root Cause:
Some Docker versions don't include the total_cache field in memory_stats['stats']. The script attempts to access this field directly without checking if it exists first.
Affected Docker/System:
AlmaLinux 9 / Python 3.12
Docker versions that don't provide total_cache in memory stats
Original Code (Lines 523-524):
python# Subtracting cache to match what `docker stats` does.
adjusted_usage = inspection['memory_stats']['usage'] - inspection['memory_stats']['stats']['total_cache']
Fixed Code (Lines 523-525):
python# Subtracting cache to match what `docker stats` does.
# Handle missing total_cache gracefully (some Docker versions don't provide it)
cache = inspection['memory_stats']['stats'].get('total_cache', 0)
adjusted_usage = inspection['memory_stats']['usage'] - cache
Change Summary:
Used .get('total_cache', 0) instead of direct dictionary access
Returns 0 if total_cache doesn't exist (no cache to subtract)
Maintains backward compatibility with Docker versions that do provide the field
Collaborator
|
This should be fixed with #82 I will include the fix in the next release |
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.
The fix: Changed line 523-524 from:
pythonadjusted_usage = inspection['memory_stats']['usage'] - inspection['memory_stats']['stats']['total_cache']
To:
pythoncache = inspection['memory_stats']['stats'].get('total_cache', 0) adjusted_usage = inspection['memory_stats']['usage'] - cach
Root Cause:
Some Docker versions don't include the total_cache field in memory_stats['stats']. The script attempts to access this field directly without checking if it exists first. Affected Docker/System:
AlmaLinux 9 / Python 3.12
Docker versions that don't provide total_cache in memory stats
Original Code (Lines 523-524):
python# Subtracting cache to match what
docker statsdoes. adjusted_usage = inspection['memory_stats']['usage'] - inspection['memory_stats']['stats']['total_cache'] Fixed Code (Lines 523-525):python# Subtracting cache to match what
docker statsdoes. # Handle missing total_cache gracefully (some Docker versions don't provide it) cache = inspection['memory_stats']['stats'].get('total_cache', 0) adjusted_usage = inspection['memory_stats']['usage'] - cache Change Summary:Used .get('total_cache', 0) instead of direct dictionary access Returns 0 if total_cache doesn't exist (no cache to subtract) Maintains backward compatibility with Docker versions that do provide the field