Skip to content

[serve] Include custom metrics method and report to controller - #56005

Merged
zcin merged 23 commits into
ray-project:masterfrom
arcyleung:serve-custom-metrics
Sep 18, 2025
Merged

zcin merged 23 commits into
ray-project:masterfrom
arcyleung:serve-custom-metrics

Conversation

@arcyleung

@arcyleung arcyleung commented Aug 27, 2025 •

Copy link
Copy Markdown
Contributor

Why are these changes needed?

Required by
https://docs.google.com/document/d/1KtMUDz1O3koihG6eh-QcUqudZjNAX3NsqqOMYh3BoWA/edit?tab=t.0#heading=h.jo7hyr9zpyw
image

Allows each replica to call a method record_autoscaling_stats and sends the resultant custom metrics to the controller.

Related issue number

Checks

@arcyleung
arcyleung requested a review from a team as a code owner August 27, 2025 17:41
@arcyleung arcyleung changed the title [serve] Include custom metrics method and report to controller [Draft] [serve] Include custom metrics method and report to controller Aug 27, 2025

@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 introduces a mechanism for replicas to report custom autoscaling metrics to the controller. The changes look good overall, enabling more flexible autoscaling strategies. My review includes suggestions to refactor the state management for these new metrics to improve clarity and maintainability, fixes for a few incorrect type hints, and a recommendation to make timestamping more robust. Most importantly, the new tests for this feature are currently placeholders and need to be fully implemented to ensure the functionality is working as expected.

Comment thread python/ray/serve/_private/replica.py Resolved
@ray-gardener ray-gardener Bot added serve Ray Serve Related Issue docs An issue or change related to documentation community-contribution Contributed by the community labels Aug 27, 2025
@arcyleung
arcyleung force-pushed the serve-custom-metrics branch from 2caab7b to 2520d98 Compare August 31, 2025 20:10
@arcyleung arcyleung changed the title [Draft] [serve] Include custom metrics method and report to controller [serve] Include custom metrics method and report to controller Sep 1, 2025
Comment thread python/ray/serve/_private/replica.py Resolved
Comment thread python/ray/serve/_private/controller.py Resolved
Comment thread python/ray/serve/_private/replica.py Resolved
Comment thread python/ray/serve/_private/replica.py Resolved
Comment thread python/ray/serve/_private/constants.py Resolved
Comment thread python/ray/serve/_private/replica.py Resolved
@arcyleung
arcyleung force-pushed the serve-custom-metrics branch 8 times, most recently from 22aa476 to bc9180b Compare September 11, 2025 12:56
Comment thread python/ray/serve/_private/replica.py Resolved
Comment thread python/ray/serve/_private/replica.py Resolved
Comment thread python/ray/serve/_private/replica.py Resolved
Comment thread python/ray/serve/_private/replica.py Resolved
Comment thread python/ray/serve/_private/replica.py Resolved
Comment thread python/ray/serve/_private/replica.py Resolved
Comment thread python/ray/serve/_private/replica.py Resolved
@abrarsheikh abrarsheikh added the go add ONLY when ready to merge, run all tests label Sep 15, 2025

@abrarsheikh abrarsheikh 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.

one comment but looks good to me

@arcyleung
arcyleung force-pushed the serve-custom-metrics branch 2 times, most recently from 043270c to da71014 Compare September 16, 2025 01:15
Signed-off-by: Arthur Leung <[email protected]>
Signed-off-by: Arthur Leung <[email protected]>
@arcyleung
arcyleung requested a review from zcin September 18, 2025 04:59
Signed-off-by: Arthur Leung <[email protected]>
@zcin
zcin merged commit 570a9d1 into ray-project:master Sep 18, 2025
zma2 pushed a commit to zma2/ray that referenced this pull request Sep 23, 2025
…roject#56005)

## Why are these changes needed?
Required by

https://docs.google.com/document/d/1KtMUDz1O3koihG6eh-QcUqudZjNAX3NsqqOMYh3BoWA/edit?tab=t.0#heading=h.jo7hyr9zpyw
<img width="1563" height="901" alt="image"
src="https://github.com/user-attachments/assets/f6405710-2622-41d3-b5a5-b2440b705ddd"
/>

Allows each replica to call a method `record_autoscaling_stats` and
sends the resultant custom metrics to the controller.

## Related issue number

<!-- For example: "Closes ray-project#1234" -->

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run `scripts/format.sh` to lint the changes in this PR.
- [ ] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [ ] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [x] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Arthur Leung <[email protected]>
Co-authored-by: Arthur Leung <[email protected]>
Signed-off-by: Zhiqiang Ma <[email protected]>
ZacAttack pushed a commit to ZacAttack/ray that referenced this pull request Sep 24, 2025
…roject#56005)

## Why are these changes needed?
Required by

https://docs.google.com/document/d/1KtMUDz1O3koihG6eh-QcUqudZjNAX3NsqqOMYh3BoWA/edit?tab=t.0#heading=h.jo7hyr9zpyw
<img width="1563" height="901" alt="image"
src="https://github.com/user-attachments/assets/f6405710-2622-41d3-b5a5-b2440b705ddd"
/>

Allows each replica to call a method `record_autoscaling_stats` and
sends the resultant custom metrics to the controller.

## Related issue number

<!-- For example: "Closes ray-project#1234" -->

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run `scripts/format.sh` to lint the changes in this PR.
- [ ] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [ ] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [x] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Arthur Leung <[email protected]>
Co-authored-by: Arthur Leung <[email protected]>
Signed-off-by: zac <[email protected]>
elliot-barn pushed a commit that referenced this pull request Sep 24, 2025
## Why are these changes needed?
Required by

https://docs.google.com/document/d/1KtMUDz1O3koihG6eh-QcUqudZjNAX3NsqqOMYh3BoWA/edit?tab=t.0#heading=h.jo7hyr9zpyw
<img width="1563" height="901" alt="image"
src="https://github.com/user-attachments/assets/f6405710-2622-41d3-b5a5-b2440b705ddd"
/>

Allows each replica to call a method `record_autoscaling_stats` and
sends the resultant custom metrics to the controller.

## Related issue number

<!-- For example: "Closes #1234" -->

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run `scripts/format.sh` to lint the changes in this PR.
- [ ] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [ ] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [x] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Arthur Leung <[email protected]>
Co-authored-by: Arthur Leung <[email protected]>
Signed-off-by: elliot-barn <[email protected]>
marcostephan pushed a commit to marcostephan/ray that referenced this pull request Sep 24, 2025
…roject#56005)

## Why are these changes needed?
Required by

https://docs.google.com/document/d/1KtMUDz1O3koihG6eh-QcUqudZjNAX3NsqqOMYh3BoWA/edit?tab=t.0#heading=h.jo7hyr9zpyw
<img width="1563" height="901" alt="image"
src="https://github.com/user-attachments/assets/f6405710-2622-41d3-b5a5-b2440b705ddd"
/>

Allows each replica to call a method `record_autoscaling_stats` and
sends the resultant custom metrics to the controller.

## Related issue number

<!-- For example: "Closes ray-project#1234" -->

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run `scripts/format.sh` to lint the changes in this PR.
- [ ] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [ ] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [x] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Arthur Leung <[email protected]>
Co-authored-by: Arthur Leung <[email protected]>
Signed-off-by: Marco Stephan <[email protected]>
elliot-barn pushed a commit that referenced this pull request Sep 27, 2025
## Why are these changes needed?
Required by

https://docs.google.com/document/d/1KtMUDz1O3koihG6eh-QcUqudZjNAX3NsqqOMYh3BoWA/edit?tab=t.0#heading=h.jo7hyr9zpyw
<img width="1563" height="901" alt="image"
src="https://github.com/user-attachments/assets/f6405710-2622-41d3-b5a5-b2440b705ddd"
/>

Allows each replica to call a method `record_autoscaling_stats` and
sends the resultant custom metrics to the controller.

## Related issue number

<!-- For example: "Closes #1234" -->

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run `scripts/format.sh` to lint the changes in this PR.
- [ ] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [ ] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [x] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Arthur Leung <[email protected]>
Co-authored-by: Arthur Leung <[email protected]>
Signed-off-by: elliot-barn <[email protected]>
dstrodtman pushed a commit to dstrodtman/ray that referenced this pull request Oct 6, 2025
…roject#56005)

## Why are these changes needed?
Required by

https://docs.google.com/document/d/1KtMUDz1O3koihG6eh-QcUqudZjNAX3NsqqOMYh3BoWA/edit?tab=t.0#heading=h.jo7hyr9zpyw
<img width="1563" height="901" alt="image"
src="https://github.com/user-attachments/assets/f6405710-2622-41d3-b5a5-b2440b705ddd"
/>

Allows each replica to call a method `record_autoscaling_stats` and
sends the resultant custom metrics to the controller.

## Related issue number

<!-- For example: "Closes ray-project#1234" -->

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run `scripts/format.sh` to lint the changes in this PR.
- [ ] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [ ] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [x] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Arthur Leung <[email protected]>
Co-authored-by: Arthur Leung <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
snorkelopstesting1-a11y pushed a commit to snorkel-marlin-repos/ray-project_ray_pr_56005_88d9466a-0611-46d8-b978-1b015005f3d2 that referenced this pull request Oct 11, 2025
snorkelopstesting1-a11y added a commit to snorkel-marlin-repos/ray-project_ray_pr_56005_88d9466a-0611-46d8-b978-1b015005f3d2 that referenced this pull request Oct 11, 2025
…rt to controller

Merged from original PR #56005
Original: ray-project/ray#56005
snorkelopstesting1-a11y pushed a commit to snorkel-marlin-repos/ray-project_ray_pr_56005_a7c4be8c-a6e2-4aac-8af9-a2f347b474a0 that referenced this pull request Oct 11, 2025
snorkelopstesting1-a11y added a commit to snorkel-marlin-repos/ray-project_ray_pr_56005_a7c4be8c-a6e2-4aac-8af9-a2f347b474a0 that referenced this pull request Oct 11, 2025
…rt to controller

Merged from original PR #56005
Original: ray-project/ray#56005
snorkelopstesting4-web pushed a commit to snorkel-marlin-repos/ray-project_ray_pr_56005_1f64f249-9bbc-4b3e-8106-afd8a3b1cb58 that referenced this pull request Oct 22, 2025
snorkelopstesting4-web added a commit to snorkel-marlin-repos/ray-project_ray_pr_56005_1f64f249-9bbc-4b3e-8106-afd8a3b1cb58 that referenced this pull request Oct 22, 2025
…rt to controller

Merged from original PR #56005
Original: ray-project/ray#56005
landscapepainter pushed a commit to landscapepainter/ray that referenced this pull request Nov 17, 2025
…roject#56005)

## Why are these changes needed?
Required by

https://docs.google.com/document/d/1KtMUDz1O3koihG6eh-QcUqudZjNAX3NsqqOMYh3BoWA/edit?tab=t.0#heading=h.jo7hyr9zpyw
<img width="1563" height="901" alt="image"
src="https://github.com/user-attachments/assets/f6405710-2622-41d3-b5a5-b2440b705ddd"
/>

Allows each replica to call a method `record_autoscaling_stats` and
sends the resultant custom metrics to the controller.

## Related issue number

<!-- For example: "Closes ray-project#1234" -->

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run `scripts/format.sh` to lint the changes in this PR.
- [ ] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [ ] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [x] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Arthur Leung <[email protected]>
Co-authored-by: Arthur Leung <[email protected]>
Future-Outlier pushed a commit to Future-Outlier/ray that referenced this pull request Dec 7, 2025
…roject#56005)

## Why are these changes needed?
Required by

https://docs.google.com/document/d/1KtMUDz1O3koihG6eh-QcUqudZjNAX3NsqqOMYh3BoWA/edit?tab=t.0#heading=h.jo7hyr9zpyw
<img width="1563" height="901" alt="image"
src="https://github.com/user-attachments/assets/f6405710-2622-41d3-b5a5-b2440b705ddd"
/>

Allows each replica to call a method `record_autoscaling_stats` and
sends the resultant custom metrics to the controller.

## Related issue number

<!-- For example: "Closes #1234" -->

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run `scripts/format.sh` to lint the changes in this PR.
- [ ] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [ ] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [x] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Arthur Leung <[email protected]>
Co-authored-by: Arthur Leung <[email protected]>
Signed-off-by: Future-Outlier <[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 docs An issue or change related to documentation go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants