Skip to content

[Data] Make distribution metric export directly testable - #65750

Merged
bveeramani merged 1 commit into
ray-project:masterfrom
viiccwen:data/refactor-distribution-metric-export
Sep 17, 2026
Merged

bveeramani merged 1 commit into
ray-project:masterfrom
viiccwen:data/refactor-distribution-metric-export

Conversation

@viiccwen

@viiccwen viiccwen commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

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 [Data] Export task USS distribution metrics #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.

@viiccwen
viiccwen requested a review from a team as a code owner August 27, 2026 09:10

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request refactors Prometheus metric creation and recording in Ray Data. It introduces helper functions _create_prometheus_metric and _record_prometheus_metric to handle different metric types (Gauge, Histogram, Counter, and Distribution) and defines a new DistributionStats TypedDict along with corresponding type aliases. Unit tests are also added to verify these helpers. The reviewer identified a potential runtime TypeError in _record_prometheus_metric when value is None, suggesting an early return guard to prevent passing None to the underlying Prometheus client.

Comment thread python/ray/data/_internal/stats.py Resolved
@ray-gardener ray-gardener Bot added data Ray Data-related issues community-contribution Contributed by the community labels Aug 27, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Sep 10, 2026
@bveeramani bveeramani self-assigned this Sep 15, 2026
@github-actions github-actions Bot added unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Sep 16, 2026

@bveeramani bveeramani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice ty

Comment thread python/ray/data/tests/test_stats.py Resolved
@bveeramani
bveeramani enabled auto-merge (squash) September 17, 2026 02:54
@github-actions github-actions Bot added the go add ONLY when ready to merge, run all tests label Sep 17, 2026
auto-merge was automatically disabled September 17, 2026 03:43

Head branch was pushed to by a user without write access

@viiccwen
viiccwen force-pushed the data/refactor-distribution-metric-export branch from 1d0a87d to 132d0a6 Compare September 17, 2026 03:43
@bveeramani
bveeramani merged commit cfe4725 into ray-project:master Sep 17, 2026
6 checks passed
@viiccwen
viiccwen deleted the data/refactor-distribution-metric-export branch September 24, 2026 02:42
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community data Ray Data-related issues go add ONLY when ready to merge, run all tests unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants