Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the gRPC server utility by extracting the method handler override logic into a helper method and adding support for routing registered-method handlers through Ray Serve via add_registered_method_handlers. It also adds corresponding unit tests. The review feedback correctly identifies that add_registered_method_handlers is only supported in newer versions of grpcio (1.62.0+). To avoid compatibility issues and test failures on older versions, it is recommended to check for the existence of this method on the superclass before calling it, and to conditionally skip the new unit tests using @pytest.mark.skipif.
| def add_registered_method_handlers(self, service_name: str, method_handlers): | ||
| """Route grpcio's registered-method handlers through Serve as well.""" | ||
| if service_name in self._passthrough_service_names: | ||
| super().add_registered_method_handlers(service_name, method_handlers) | ||
| return |
There was a problem hiding this comment.
The add_registered_method_handlers method is only available in newer versions of grpcio (1.62.0+). Since Ray supports older versions of grpcio, calling super().add_registered_method_handlers directly will raise an AttributeError on environments with older grpcio installed. We should check if the superclass has this attribute before proceeding, and raise a clear AttributeError if it is missing.
def add_registered_method_handlers(self, service_name: str, method_handlers):
"""Route grpcio's registered-method handlers through Serve as well."""
if not hasattr(super(), "add_registered_method_handlers"):
raise AttributeError(
"The underlying grpcio library does not support add_registered_method_handlers."
)
if service_name in self._passthrough_service_names:
super().add_registered_method_handlers(service_name, method_handlers)
return| ) | ||
|
|
||
|
|
||
| def test_grpc_server_overrides_registered_method_handlers(monkeypatch): |
There was a problem hiding this comment.
On older versions of grpcio where Server does not have add_registered_method_handlers, monkeypatch.setattr will raise an AttributeError and fail the test suite. We should skip this test if the installed grpcio version does not support this method.
@pytest.mark.skipif(
not hasattr(Server, "add_registered_method_handlers"),
reason="grpcio version does not support add_registered_method_handlers",
)
def test_grpc_server_overrides_registered_method_handlers(monkeypatch):| assert handler.stream_stream() == f"stream_stream call from {service_method}".encode() | ||
|
|
||
|
|
||
| def test_grpc_server_registered_passthrough_handlers_are_unchanged(monkeypatch): |
There was a problem hiding this comment.
Similarly, this test should be skipped on older versions of grpcio where Server does not have add_registered_method_handlers to prevent monkeypatch.setattr from raising an AttributeError.
@pytest.mark.skipif(
not hasattr(Server, "add_registered_method_handlers"),
reason="grpcio version does not support add_registered_method_handlers",
)
def test_grpc_server_registered_passthrough_handlers_are_unchanged(monkeypatch):|
@XFDG microcheck is failing on lint. dco is failing too, because the commit has no sign-off. note for the serve team (separate from this PR): CI installs with requirements_compiled.txt, which pins grpcio to 1.75/1.76. setup.py leaves grpcio unbounded, so users get 1.84 while CI never runs it, and that's how this slipped through. It might be worth running at least the Serve gRPC tests against the latest grpcio so a version bump like this gets caught before users hit it. |
| """ | ||
| self._passthrough_service_names.add(service_name) | ||
|
|
||
| def _override_method_handler(self, service_method: str, method_handler): |
There was a problem hiding this comment.
nit: can we add types here?
def _override_method_handler(
self, service_method: str, method_handler: grpc.RpcMethodHandler
) -> grpc.RpcMethodHandler:
| self.generic_rpc_handlers.append(generic_rpc_handlers) | ||
| super().add_generic_rpc_handlers(generic_rpc_handlers) | ||
|
|
||
| def add_registered_method_handlers(self, service_name: str, method_handlers): |
There was a problem hiding this comment.
nit: method_handlers: Dict[str, grpc.RpcMethodHandler] to match add_generic_rpc_handlers
| def test_grpc_server_registered_passthrough_handlers_are_unchanged(monkeypatch): | ||
| registered = {} | ||
|
|
||
| def capture_registered_handlers(server, service_name, method_handlers): |
There was a problem hiding this comment.
nit: this capture setup is duplicated across both tests. Maybe pull it into a fixture?
|
Superseded by #66502. The replacement keeps this PR commit unchanged, adds DCO sign-off on all commits, and includes the grpcio compatibility/review updates. |
## Summary - Route grpcio registered-method handlers through the Ray Serve proxy while preserving passthrough services. - Gracefully handle grpcio versions without the registered-handler API; add a fallback test and skip API-specific tests when unavailable. - Fixes #66493. Supersedes #66494; the original pushed commit was left unchanged. ## Tests - Targeted gRPC utility tests: 5 passed, 11 deselected (grpcio 1.84.0). - Ruff check, Ruff format check, and git diff --check passed. - The target test module was run with --noconftest because the current source conftest imports an API absent from the installed Ray wheel. --------- Signed-off-by: zhaoye <[email protected]>
…6502) ## Summary - Route grpcio registered-method handlers through the Ray Serve proxy while preserving passthrough services. - Gracefully handle grpcio versions without the registered-handler API; add a fallback test and skip API-specific tests when unavailable. - Fixes ray-project#66493. Supersedes ray-project#66494; the original pushed commit was left unchanged. ## Tests - Targeted gRPC utility tests: 5 passed, 11 deselected (grpcio 1.84.0). - Ruff check, Ruff format check, and git diff --check passed. - The target test module was run with --noconftest because the current source conftest imports an API absent from the installed Ray wheel. --------- Signed-off-by: zhaoye <[email protected]>
Summary
Tests