fix(cgroup): avoid early return when cpu.pressure file is missing#275
Merged
orestisfl merged 4 commits intoelastic:mainfrom Jan 16, 2026
Merged
Conversation
When cpu.pressure file doesn't exist, the code was returning early, skipping the remaining CPU stats retrieval. Now it clears the error and continues execution to properly fetch all available stats.
AndersonQ
requested changes
Dec 12, 2025
Member
AndersonQ
left a comment
There was a problem hiding this comment.
I run the test you added on main and it passes. I believe a better test would be to have a mock cpu.stat file. Then you can call CPUSubsystem.Get point to the folder with this file and assert it retruns the data of the file even though the cpu.pressure isn't there.
AndersonQ
approved these changes
Jan 16, 2026
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.
What does this PR do?
Fixes a bug in the cgroup v2 CPU subsystem where the
Getmethod was returning early when thecpu.pressurefile doesn't exist.The change replaces
return nilwitherr = nil, allowing the function to continue execution and fetch the remaining CPU stats (usage, system time, etc.) even when pressure stats are unavailable.Also adds a new test
TestGetCPUEmptythat verifies the CPU subsystem correctly handles empty directories without errors.Why is it important?
On systems where
cpu.pressureis not available, the previous code would silently return without populating any CPU statistics. This meant that valid CPU metrics like usage and system time were being lost even though they were available in other files in the cgroup path.PSI can be disabled for linux in a number of ways:
CONFIG_PSIininit/Kconfig:CONFIG_PSI_DEFAULT_DISABLED=y, PSI is off unlesspsi=1is passed.cgroup_disable=pressure:Checklist
[ ] I have added an entry inCHANGELOG.mdRelated issues