Skip to content

Conversation

@DanielleMaywood
Copy link
Collaborator

@DanielleMaywood DanielleMaywood commented Nov 11, 2025

This PR abstracts a repeating parent lookup pattern in cgroupv2 using a generic helper function. Relates to #28 (comment)

Changes

  • Added generic helper - Handles parent cgroup lookups with customizable fallback behavior
  • Applied to 5 methods:
    • cpuQuota()
    • cpuPeriod()
    • memoryMaxBytes()
    • memoryCurrentBytes()
    • memoryInactiveFileBytes()

🤖 PR was written by Claude Sonnet 4.5 Thinking using Coder Mux and reviewed by a human 👩

- Add getFromParentOrDefault generic function to eliminate duplication
- Refactor cpuQuota() and memoryMaxBytes() to use helper
- Simplify error messages: 'read parent' instead of redundant context
- Rename getFromParentOrDefault to getFromParentOrFallback
- Change parameter from defaultValue to fallback function
- Apply helper to cpuPeriod, memoryCurrentBytes, memoryInactiveFileBytes
- Update function doc comment to reflect fallback function
- Standardize inline comments to 'try parent or [action]' pattern

The fallback function approach allows handling both default values and
error returns, making the abstraction applicable to all parent lookup
scenarios. This eliminates 40+ lines of boilerplate across 5 methods.
@DanielleMaywood DanielleMaywood changed the title Abstract parent lookup pattern in cgroupv2 🤖 chore: abstract parent lookup pattern in cgroupv2 Nov 11, 2025
@DanielleMaywood DanielleMaywood marked this pull request as ready for review November 11, 2025 13:13
@DanielleMaywood DanielleMaywood merged commit 0f14d87 into main Nov 11, 2025
30 checks passed
@DanielleMaywood DanielleMaywood deleted the danielle-abstract branch November 11, 2025 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants