Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgroup monitors: Add mem/disk/cpu usage metrics for V2 #16905

Merged
merged 7 commits into from
Sep 24, 2024

Conversation

adithyachakilam
Copy link
Contributor

Description

This PR add the support for cgroup monitors for v2. For now, only the usage of cpu/disk/memory are being supported.

Release note

New monitors for cgroups v2 are now available to track usage of cpu/disk/memory.


Key changed/added classes in this PR
  • CgroupV2CpuMonitor
  • CgroupV2DiskMonitor
  • CgroupV2MemoryMonitor

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

for (int i = 1; i < parts.length; i++) {
String[] keyValue = parts[i].split("=");
if (keyValue.length == 2) {
stats.put(keyValue[0], Long.parseLong(keyValue[1]));

Check notice

Code scanning / CodeQL

Missing catch of NumberFormatException Note

Potential uncaught 'java.lang.NumberFormatException'.
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment as the Cpu Monitor - if we use Longs.parseLong we will need to handle nulls when emitting the metrics

Copy link
Contributor Author

@adithyachakilam adithyachakilam Sep 23, 2024

Choose a reason for hiding this comment

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

There shouldn't be any nulls, it should either be a valid long value that should be obtained here or a exception thrown, catched at line 113. Am I missing anything ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I got confused here because it looks like if there is an issue with parsing metrics for any disk, no disk metrics are reported and that is perhaps what hte code scanning bot is complaining about.

public class CgroupV2CpuMonitorTest
{
@Rule
public ExpectedException expectedException = ExpectedException.none();

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
ExpectedException.none
should be avoided because it has been deprecated.
public class CgroupV2DiskMonitorTest
{
@Rule
public ExpectedException expectedException = ExpectedException.none();

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
ExpectedException.none
should be avoided because it has been deprecated.
public class CgroupV2MemoryMonitorTest
{
@Rule
public ExpectedException expectedException = ExpectedException.none();

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
ExpectedException.none
should be avoided because it has been deprecated.
@arunramani
Copy link
Contributor

The changes looks reasonable to me. My one ask would be to add some javadoc comments around what proc file is being parsed and what the expected format is supposed to be.

@adithyachakilam
Copy link
Contributor Author

Added the comments for io.stat and cpu.stat, memory is same as v1. Also, test cases implies the format of the files

private final long userUsec;
private final long systemUsec;

public Snapshot(long usageUsec, long userUsec, long systemUsec)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the constructor accept @Nullable Long objects instead so that we can distinguish between parse exceptions and 0s when reading the file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We basically skip emitting metrics on parse exceptions and would not end up creating this Snapshot object at all.

for (int i = 1; i < parts.length; i++) {
String[] keyValue = parts[i].split("=");
if (keyValue.length == 2) {
stats.put(keyValue[0], Long.parseLong(keyValue[1]));
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment as the Cpu Monitor - if we use Longs.parseLong we will need to handle nulls when emitting the metrics

Copy link
Contributor

@suneet-s suneet-s left a comment

Choose a reason for hiding this comment

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

Thanks for these new metrics @adithyachakilam !

@suneet-s suneet-s merged commit 8eaac2c into apache:master Sep 24, 2024
90 checks passed
@adarshsanjeev adarshsanjeev added this to the 32.0.0 milestone Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants