Repository navigation
[Data] Export task USS distribution metrics - #65666
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new Distribution metric type to track task metrics like max_uss_bytes (with both mean and max statistics) instead of just a single average value. It updates the Prometheus exporter, Grafana dashboard panels, and high memory detector to support these distribution metrics, while removing the deprecated average_max_uss_per_task metric. The review feedback suggests improving the early-return guard in _record for dictionary-based metrics to ensure that metrics without a num_samples key are not accidentally ignored.
| if value.get("num_samples", 0) == 0: | ||
| return |
There was a problem hiding this comment.
Using value.get('num_samples', 0) == 0 to guard against empty distributions will cause the function to return early and silently ignore any future dictionary-based metrics that do not contain a 'num_samples' key (since it defaults to 0).
To make this more robust and future-proof, consider explicitly checking if 'num_samples' is present in the dictionary and is equal to 0 before returning early.
| if value.get("num_samples", 0) == 0: | |
| return | |
| if 'num_samples' in value and value['num_samples'] == 0: | |
| return |
|
|
||
|
|
||
| def test_stats_actor_exports_distribution_metrics(): | ||
| actor = _StatsActor.__ray_metadata__.modified_class() |
There was a problem hiding this comment.
What does this statement do/what's it intent?
I've never seen either __ray_metadata__ or modified_class()
There was a problem hiding this comment.
Bcz _StatsActor is wrapped by @ray.remote, so it can't be instantiated locally like a regular python class. I found __ray_metadata__ gives the underlying python class, and () create a local instance so we can patch and verify the Gauges at same time.
This follow the same pattern like:
ray/python/ray/data/tests/test_stats.py
Lines 2027 to 2044 in 2560f86
If needed, I can add a comment to explain it, Instantiate the Python class wrapped by @ray.remote locally.
There was a problem hiding this comment.
__ray_metadata__ is a private dunder attribute that seems extremely brittle. The test_stats example was contributed by an external contributor, but even if it were contributed by a Ray committer, I think we should strongly avoid magic attributes in our tests because they're hard to read and maintain
Could we remove this for now, and re-add tests if we refactor the source code to make it more testable?
Since this is non-critical piece of code (a chart for observability), I would rather err on the side of less coverage + readable tests than more coverage + brittle tests
| assert update_fn.call_args_list[-1].args[2] is None | ||
|
|
||
|
|
||
| def test_stats_actor_exports_distribution_metrics(): |
There was a problem hiding this comment.
I had difficulty reading this test and confirming that this will effectively verify the behavior we care about.
Is there an easier way to test the same logic? I know StatsActor isn't really testable to begin with, so there might not be an easy way
There was a problem hiding this comment.
Agreed. This test verifies 3 things,
- the actor creates
mean/maxGauges - empty distribution snapshots don't overwrite them
- non-empty snapshots update both Gauges with the expected tags.
I could add comments to explain it, WDYT?
And I explain the initialize way of StatsActor above.
|
|
||
|
|
||
| def test_stats_actor_exports_distribution_metrics(): | ||
| actor = _StatsActor.__ray_metadata__.modified_class() |
There was a problem hiding this comment.
__ray_metadata__ is a private dunder attribute that seems extremely brittle. The test_stats example was contributed by an external contributor, but even if it were contributed by a Ray committer, I think we should strongly avoid magic attributes in our tests because they're hard to read and maintain
Could we remove this for now, and re-add tests if we refactor the source code to make it more testable?
Since this is non-critical piece of code (a chart for observability), I would rather err on the side of less coverage + readable tests than more coverage + brittle tests
Signed-off-by: viiccwen <[email protected]>
Signed-off-by: viiccwen <[email protected]>
Signed-off-by: viiccwen <[email protected]>
Signed-off-by: viiccwen <[email protected]>
2b3e72c to
1edae2d
Compare
## Description Refactor Ray Data's Prometheus metric export logic so distribution metrics can be tested without accessing the private `__ray_metadata__` attribute of the remote StatsActor. The changes: - Define the dictionary schema returned by `DistributionTracker.as_dict()`. - Extract Prometheus metric creation and recording into helper functions. - Add direct tests for creating and updating distribution Gauges. This is a follow-up to #65666. - Use real `Gauge` instances in the metric creation test and inspect their public `info` property. ## Duplicate work This PR is a focused follow-up to #65666 and does not duplicate another implementation. ## Tests - `pytest python/ray/data/tests/test_stats.py -q -k 'test_create_distribution_prometheus_metric or test_record_distribution_prometheus_metric'` — 2 passed, 108 deselected. - `pre-commit run --files python/ray/data/tests/test_stats.py` — passed. AI assistance was used. The submitter reviewed the changes and test results. Signed-off-by: viiccwen <[email protected]>
## Description Expose the existing `OpRuntimeMetrics.max_uss_bytes` distribution as the Prometheus Gauges `ray_data_max_uss_bytes_mean` and `ray_data_max_uss_bytes_max`, and add a "Max Task USS Memory per Operator" chart to the Ray Data dashboard's Tasks row. Ray Data already records each completed task's peak unique set size (USS) in a `DistributionTracker`, but this distribution was marked as unsupported for Prometheus export. Consequently, users couldn't query the operator-level maximum from Prometheus or visualize it in the Data dashboard. This change introduces `MetricsType.Distribution`. A distribution metric declares which summary statistics to export through the existing `metrics_args` metadata; `_StatsActor` creates one Gauge per statistic and updates those Gauges from the serialized distribution snapshot. `max_uss_bytes` exports `mean` and `max`. The previous scalar `average_max_uss_per_task` property is removed. The `issue_detector` now reads `max_uss_bytes.mean` directly. ## Additional information <img width="1440" height="778" alt="image" src="https://github.com/user-attachments/assets/d9dc583e-6db3-42a2-b12d-dc9a8e490b27" /> --------- Signed-off-by: viiccwen <[email protected]>
…#65750) ## Description Refactor Ray Data's Prometheus metric export logic so distribution metrics can be tested without accessing the private `__ray_metadata__` attribute of the remote StatsActor. The changes: - Define the dictionary schema returned by `DistributionTracker.as_dict()`. - Extract Prometheus metric creation and recording into helper functions. - Add direct tests for creating and updating distribution Gauges. This is a follow-up to ray-project#65666. - Use real `Gauge` instances in the metric creation test and inspect their public `info` property. ## Duplicate work This PR is a focused follow-up to ray-project#65666 and does not duplicate another implementation. ## Tests - `pytest python/ray/data/tests/test_stats.py -q -k 'test_create_distribution_prometheus_metric or test_record_distribution_prometheus_metric'` — 2 passed, 108 deselected. - `pre-commit run --files python/ray/data/tests/test_stats.py` — passed. AI assistance was used. The submitter reviewed the changes and test results. Signed-off-by: viiccwen <[email protected]>
Add a nomination under `fellowship/ray/` Suggested level: 30k Highlights from 2026-09-01 to 2026-10-11: - [Contribution](https://github.com/opensource4you/readme/blob/main/fellowship/ray/fellow-contribution/viiccwen/September/report.md) - Merged 10 Ray Data PRs and filed 8 issues in 6 weeks - Made shuffle tasks up to 12.84x faster by pinning the fused map function, so large UDF closures are no longer serialized again for every shuffle task ([#65480](ray-project/ray#65480)) - Built a memory observability series to help users avoid OOM: exported task peak USS and logical memory metrics with Grafana charts ([#65666](ray-project/ray#65666), [#66044](ray-project/ray#66044)), added a warning with a suggested memory value when it is set below 1.25x max USS ([#65512](ray-project/ray#65512)), and updated the OOM prevention docs ([#65509](ray-project/ray#65509)) - Found, reported and fixed silent data loss in hash-shuffle (V2) anti joins, where rows were dropped when the other side was empty and had an unknown schema ([#66126](ray-project/ray#66126)) - Reviewed other fellows' PRs with suggestions ([#66878](ray-project/ray#66878)) - Merged the most PRs and filed the most issues of all Ray Fellowship participants - Solid work for an early contributor
Description
Expose the existing
OpRuntimeMetrics.max_uss_bytesdistribution as the Prometheus Gaugesray_data_max_uss_bytes_meanandray_data_max_uss_bytes_max, and add a "Max Task USS Memory per Operator" chart to the Ray Data dashboard's Tasks row.Ray Data already records each completed task's peak unique set size (USS) in a
DistributionTracker, but this distribution was marked as unsupported for Prometheus export. Consequently, users couldn't query the operator-level maximum from Prometheus or visualize it in the Data dashboard.This change introduces
MetricsType.Distribution. A distribution metric declares which summary statistics to export through the existingmetrics_argsmetadata;_StatsActorcreates one Gauge per statistic and updates those Gauges from the serialized distribution snapshot.max_uss_bytesexportsmeanandmax.The previous scalar
average_max_uss_per_taskproperty is removed. Theissue_detectornow readsmax_uss_bytes.meandirectly.Additional information