Repository navigation
[Serve] Move shared replica methods from ReplicaBase to Replica, remove abstract base class - #60198
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the Replica class hierarchy by moving shared methods and logic from the Replica subclass into the ReplicaBase base class. This is a good change that improves code structure and enables better code reuse for other subclasses. A new extensibility hook _get_request_context_kwargs has been added to allow subclasses to easily extend the request context. Additionally, a comprehensive test suite for RPCSerializer has been added, which improves test coverage. My review includes a couple of suggestions to improve code quality and type safety.
This refactors the Replica class hierarchy to move shared methods into ReplicaBase, enabling better code reuse for subclasses. Changes: - Move _on_request_cancelled() and _on_request_failed() from Replica to ReplicaBase as concrete implementations (previously abstract) - Move _wrap_request() to ReplicaBase with new _get_request_context_kwargs() hook for subclasses to extend request context - Move gRPC handler methods (HandleRequest, HandleRequestStreaming, HandleRequestWithRejection, HandleRequestWithRejectionStreaming) to ReplicaBase - Add test_serialization.py for RPCSerializer coverage The Replica class now only implements _on_initialized() for gRPC servicer registration. Signed-off-by: Seiji Eicher <[email protected]>
9f8985a to
9632259
Compare
Signed-off-by: Seiji Eicher <[email protected]>
|
python/ray/serve/tests:test_serve_with_tracing is failing on |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
|
||
|
|
||
| @pytest.mark.timeout(60) | ||
| async def test_by_reference_false_raises_error(serve_instance): |
There was a problem hiding this comment.
Missing @pytest.mark.asyncio decorator on async test
Medium Severity
The async test function test_by_reference_false_raises_error is missing the @pytest.mark.asyncio decorator. Other async tests in this codebase (e.g., in test_handle_1.py and test_handle_2.py) consistently use this decorator. Without it, pytest-asyncio will not properly execute this as an async test, causing the test to fail or behave unexpectedly.
|
Needs the fix #60209 |
a092798 to
9f49dbd
Compare
|
This pull request has been automatically marked as stale because it has not had 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. |
|
This pull request has been automatically closed because there has been no more activity in the 14 days Please feel free to reopen or open a new pull request if you'd still like this to be addressed. Again, you can always ask for help on our discussion forum or Ray's public slack channel. Thanks again for your contribution! |
# Conflicts: # python/ray/serve/_private/replica.py
Signed-off-by: Seiji Eicher <[email protected]>
Signed-off-by: Seiji Eicher <[email protected]>
Signed-off-by: Seiji Eicher <[email protected]>
| @@ -1102,6 +1101,34 @@ def __init__( | |||
| # Silence spammy false positive errors from gRPC Python | |||
| self._event_loop.set_exception_handler(asyncio_grpc_exception_handler) | |||
|
|
|||
| try: | |||
| @@ -1253,6 +1280,13 @@ def _configure_logger_and_profilers( | |||
| } | |||
|
|
|||
| def _can_accept_request(self, request_metadata: RequestMetadata) -> bool: | |||
| @@ -1333,6 +1367,23 @@ def _record_errors_and_metrics( | |||
| exception_type=exception_type, | |||
| ) | |||
|
|
|||
| if is_span_recording(): | |||
| async def _on_initialized(self): | ||
| raise NotImplementedError | ||
| await self._maybe_start_direct_ingress_servers() |
| def _on_request_cancelled( | ||
| self, request_metadata: RequestMetadata, e: asyncio.CancelledError | ||
| ): | ||
| pass | ||
| """Recursively cancel child requests. | ||
|
|
| @@ -1772,13 +1853,34 @@ async def shutdown(self): | |||
| async def perform_graceful_shutdown(self): | |||
| self._shutting_down = True | |||
|
|
|||
| coros = [] | |||
| if ( | |||
| self._direct_ingress_http_server_task.cancel() | ||
| if self._direct_ingress_grpc_server_task: | ||
| self._direct_ingress_grpc_server_task.cancel() | ||
| async def send_http_response(message, status_code, send): |
Reverts the class collapse while preserving the metadata->request_metadata parameter rename in Replica._on_request_cancelled. Signed-off-by: Seiji Eicher <[email protected]>
Moves all Replica contents into ReplicaBase and removes the Replica subclass. ReplicaBase is now a concrete class that can be directly subclassed by users. Signed-off-by: Seiji Eicher <[email protected]>
Signed-off-by: Seiji Eicher <[email protected]>
414c36d to
f143ed5
Compare
…ve abstract base class (ray-project#60198) ## Why are these changes needed? This refactors the Replica class hierarchy to remove `ReplicaBase` in favor of `Replica` for unified gRPC and direct ingress handling. Reference PRs: - ray-project#60914 - ray-project#59908 - ray-project#60118 ## Related issue number N/A ## Checks - [x] I've signed off every commit (by using the -s flag) - [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 - [x] I've made sure the tests are passing - [ ] Testing Strategy - [x] Unit tests - [ ] Release tests - [ ] This PR is not tested :( ## Changes --------- Signed-off-by: Seiji Eicher <[email protected]>

Why are these changes needed?
This refactors the Replica class hierarchy to remove
ReplicaBasein favor ofReplicafor unified gRPC and direct ingress handling. Reference PRs:Related issue number
N/A
Checks
scripts/format.shto lint the changes in this PRChanges