Skip to content

Conversation

@thaJeztah
Copy link

As outlined in the PR, usage_usec, user_usec, and system_use may always exist, but in situations where the files parsed do not exist, we shouldn't have to try to assign values (which would always be 0).

Split out parsing of these to separate functions, so make this more transparent.

return &metrics, nil
}

func readMemoryEvents(cgroupPath string) (*stats.MemoryEvents, error) {
Copy link
Author

Choose a reason for hiding this comment

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

Alternatively, this could be a method (instead of passing the path as argument);

Suggested change
func readMemoryEvents(cgroupPath string) (*stats.MemoryEvents, error) {
func (c *Manager) readMemoryEvents() (*stats.MemoryEvents, error) {

My consideration was that having it as a plain function could be easier to add unit tests for, but of course we could probably construct a Manager{path: "some custom path"}, so probably either way would work

As outlined in the PR, usage_usec, user_usec, and system_use may
always exist, but in situations where the files parsed do not
exist, we shouldn't have to try to assign values (which would always
be 0).

Split out parsing of these to separate functions, so make this more
transparent.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Copy link
Owner

@jay-mckay jay-mckay left a comment

Choose a reason for hiding this comment

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

LGTM

@jay-mckay jay-mckay merged commit 40b4a5f into jay-mckay:main Mar 11, 2025
@thaJeztah thaJeztah deleted the 348_suggestions branch March 11, 2025 19:58
jay-mckay pushed a commit that referenced this pull request Jul 8, 2025
As outlined in the PR, usage_usec, user_usec, and system_use may
always exist, but in situations where the files parsed do not
exist, we shouldn't have to try to assign values (which would always
be 0).

Split out parsing of these to separate functions, so make this more
transparent.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
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