Skip to content

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

Merged
suneet-s merged 7 commits intoapache:masterfrom
ac9817:cgroups-v2
Sep 24, 2024
Merged

cgroup monitors: Add mem/disk/cpu usage metrics for V2#16905
suneet-s merged 7 commits intoapache:masterfrom
ac9817:cgroups-v2

Conversation

@ac9817
Copy link
Copy Markdown
Contributor

@ac9817 ac9817 commented Aug 16, 2024

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

Potential uncaught 'java.lang.NumberFormatException'.
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

@ac9817 ac9817 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
Copy Markdown
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

Invoking [ExpectedException.none](1) 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

Invoking [ExpectedException.none](1) 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

Invoking [ExpectedException.none](1) should be avoided because it has been deprecated.
@arunramani
Copy link
Copy Markdown
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.

@ac9817
Copy link
Copy Markdown
Contributor Author

ac9817 commented Aug 20, 2024

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

Comment thread docs/configuration/index.md Outdated
private final long userUsec;
private final long systemUsec;

public Snapshot(long usageUsec, long userUsec, long systemUsec)
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@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.

5 participants