Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Serve] allow gRPC deployment to use grpc context #41667

Merged
merged 15 commits into from
Dec 8, 2023
Prev Previous commit
Next Next commit
add more comments
Signed-off-by: Gene Su <e870252314@gmail.com>
  • Loading branch information
GeneDer committed Dec 7, 2023
commit 308a2bd7953df5d0f332f5c861c8c29c239ebf46
12 changes: 10 additions & 2 deletions python/ray/serve/_private/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,11 @@ async def unary_unary(
response = message

# Only the latest code and details will take effect. If the user already
# set them in the context, skip setting them with Serve's default values.
# set them to a truthy value in the context, skip setting them with Serve's
# default values. By default, if nothing is set, the code is 0 and the
# details is "", which both are falsy. So if the user did not set them or
# if they're explicitly set to falsy values, such as None, Serve will
# continue to set them with our default values.
if not context.code():
context.set_code(status.code)
if not context.details():
Expand Down Expand Up @@ -674,7 +678,11 @@ async def unary_stream(
yield message

# Only the latest code and details will take effect. If the user already
# set them in the context, skip setting them with Serve's default values.
# set them to a truthy value in the context, skip setting them with Serve's
# default values. By default, if nothing is set, the code is 0 and the
# details is "", which both are falsy. So if the user did not set them or
# if they're explicitly set to falsy values, such as None, Serve will
# continue to set them with our default values.
if not context.code():
context.set_code(status.code)
if not context.details():
Expand Down
5 changes: 5 additions & 0 deletions python/ray/serve/_private/proxy_request_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def __init__(
self.request_id = None
self.method_name = "__call__"
self.multiplexed_model_id = DEFAULT.VALUE
# ray_serve_grpc_context is a class implemented by us to be able to serialize
# the object and pass into the deployment.
GeneDer marked this conversation as resolved.
Show resolved Hide resolved
self.ray_serve_grpc_context = RayServegRPCContext(context)
self.setup_variables()

Expand Down Expand Up @@ -161,6 +163,9 @@ def user_request(self) -> bytes:
return self.request

def send_request_id(self, request_id: str):
# Setting the trailing metadata on the ray_serve_grpc_context object, so it's
# not overriding the ones set from the user and will be sent back to the
# client altogether.
self.ray_serve_grpc_context.set_trailing_metadata([("request_id", request_id)])

def request_object(self, proxy_handle: ActorHandle) -> gRPCRequest:
Expand Down
1 change: 1 addition & 0 deletions python/ray/serve/_private/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class RequestMetadata:
# The protocol to serve this request
_request_protocol: RequestProtocol = RequestProtocol.UNDEFINED

# Serve's gRPC context associated with this request for getting and setting metadata
grpc_context: Optional[RayServegRPCContext] = None
GeneDer marked this conversation as resolved.
Show resolved Hide resolved

@property
Expand Down
Loading