Skip to content

[SPARK-52776][CORE] Do not split the comm field in ProcfsMetricsGetter #51457

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

Closed
wants to merge 2 commits into from

Conversation

max2718281
Copy link

@max2718281 max2718281 commented Jul 11, 2025

What changes were proposed in this pull request?

We are fixing an issue in ProcfsMetricsGetter when parsing the /proc/<pid>/stat file. The current implementation will split the comm field by spaces if it contains them, thereby causing subsequent numbers to be shifted. The comm field, and only the comm field, is in parentheses so we can resolve this issue by ignoring everything between the first open parenthesis and last closing parenthesis when splitting the stat file.

Why are the changes needed?

These changes are needed to prevent a comm field with spaces from causing incorrect calculations for vmem/rssmem metrics. Please see JIRA for details.

Does this PR introduce any user-facing change?

No

How was this patch tested?

Added a unit test to test for irregular characters in the comm field

Was this patch authored or co-authored using generative AI tooling?

No

@github-actions github-actions bot added the CORE label Jul 11, 2025
@max2718281 max2718281 marked this pull request as ready for review July 11, 2025 23:46
Copy link
Contributor

@robreeves robreeves 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 open sourcing the fix!

Copy link
Contributor

@mridulm mridulm left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@mridulm mridulm closed this in cf097a5 Jul 14, 2025
mridulm pushed a commit that referenced this pull request Jul 14, 2025
### What changes were proposed in this pull request?

We are fixing an issue in `ProcfsMetricsGetter` when parsing the `/proc/<pid>/stat` file. The current implementation will split the comm field by spaces if it contains them, thereby causing subsequent numbers to be shifted. The comm field, and only the comm field, is in parentheses so we can resolve this issue by ignoring everything between the first open parenthesis and last closing parenthesis when splitting the stat file.

### Why are the changes needed?

These changes are needed to prevent a comm field with spaces from causing incorrect calculations for vmem/rssmem metrics. Please see [JIRA](https://issues.apache.org/jira/projects/SPARK/issues/SPARK-52776) for details.

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

Added a unit test to test for irregular characters in the comm field

### Was this patch authored or co-authored using generative AI tooling?

No

Closes #51457 from max2718281/procfs.

Authored-by: Maxime Xu <[email protected]>
Signed-off-by: Mridul Muralidharan <mridul<at>gmail.com>
(cherry picked from commit cf097a5)
Signed-off-by: Mridul Muralidharan <mridulatgmail.com>
@mridulm
Copy link
Contributor

mridulm commented Jul 14, 2025

Merged to master and 4.0.
Thanks for contributing @max2718281 !

Can you create a backport for 3.5 please ? Looks like there are some conflicts

max2718281 pushed a commit to max2718281/spark that referenced this pull request Jul 14, 2025
We are fixing an issue in `ProcfsMetricsGetter` when parsing the `/proc/<pid>/stat` file. The current implementation will split the comm field by spaces if it contains them, thereby causing subsequent numbers to be shifted. The comm field, and only the comm field, is in parentheses so we can resolve this issue by ignoring everything between the first open parenthesis and last closing parenthesis when splitting the stat file.

These changes are needed to prevent a comm field with spaces from causing incorrect calculations for vmem/rssmem metrics. Please see [JIRA](https://issues.apache.org/jira/projects/SPARK/issues/SPARK-52776) for details.

No

Added a unit test to test for irregular characters in the comm field

No

Closes apache#51457 from max2718281/procfs.

Authored-by: Maxime Xu <[email protected]>
Signed-off-by: Mridul Muralidharan <mridul<at>gmail.com>
(cherry picked from commit cf097a5)
@max2718281
Copy link
Author

Merged to master and 4.0. Thanks for contributing @max2718281 !

Can you create a backport for 3.5 please ? Looks like there are some conflicts

Created #51481

mridulm pushed a commit that referenced this pull request Jul 16, 2025
…Getter

### What changes were proposed in this pull request?

This is a backport of #51457.

We are fixing an issue in `ProcfsMetricsGetter` when parsing the `/proc/<pid>/stat` file. The current implementation will split the comm field by spaces if it contains them, thereby causing subsequent numbers to be shifted. The comm field, and only the comm field, is in parentheses so we can resolve this issue by ignoring everything between the first open parenthesis and last closing parenthesis when splitting the stat file.

### Why are the changes needed?

These changes are needed to prevent a comm field with spaces from causing incorrect calculations for vmem/rssmem metrics. Please see [JIRA](https://issues.apache.org/jira/projects/SPARK/issues/SPARK-52776) for details.

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

Added a unit test to test for irregular characters in the comm field

### Was this patch authored or co-authored using generative AI tooling?

No

### Original PR Info

Closes #51457 from max2718281/procfs.

Authored-by: Maxime Xu <maxxulinkedin.com>

(cherry picked from commit cf097a5)

Closes #51481 from max2718281/procfs-3.5.

Authored-by: Maxime Xu <[email protected]>
Signed-off-by: Mridul Muralidharan <mridul<at>gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants