Skip to content

fix(cgroup): avoid early return when cpu.pressure file is missing#275

Merged
orestisfl merged 4 commits intoelastic:mainfrom
orestisfl:fix-cgv2-cpu-pressure-early-return
Jan 16, 2026
Merged

fix(cgroup): avoid early return when cpu.pressure file is missing#275
orestisfl merged 4 commits intoelastic:mainfrom
orestisfl:fix-cgv2-cpu-pressure-early-return

Conversation

@orestisfl
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a bug in the cgroup v2 CPU subsystem where the Get method was returning early when the cpu.pressure file doesn't exist.

The change replaces return nil with err = 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 TestGetCPUEmpty that verifies the CPU subsystem correctly handles empty directories without errors.

Why is it important?

On systems where cpu.pressure is 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:

  1. Compile-time: Controlled by CONFIG_PSI in init/Kconfig:
  2. Boot-time disabled by default: With CONFIG_PSI_DEFAULT_DISABLED=y, PSI is off unless psi=1 is passed.
  3. Boot parameter: Can be disabled with cgroup_disable=pressure:

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • [ ] I have added an entry in CHANGELOG.md

Related issues

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.
@orestisfl orestisfl self-assigned this Dec 11, 2025
@orestisfl orestisfl requested a review from a team as a code owner December 11, 2025 14:51
@orestisfl orestisfl requested review from AndersonQ and rdner and removed request for a team December 11, 2025 14:51
@orestisfl orestisfl added bug Something isn't working Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team labels Dec 11, 2025
Copy link
Copy Markdown
Member

@AndersonQ AndersonQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@orestisfl orestisfl requested a review from AndersonQ January 16, 2026 10:25
@orestisfl orestisfl merged commit 5b3badf into elastic:main Jan 16, 2026
5 checks passed
@orestisfl orestisfl deleted the fix-cgv2-cpu-pressure-early-return branch January 16, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants