Skip to content

Commit 65478d4

Browse files
[Serve] Enable serve status when proxies disabled (ray-project#42286)
Serve proxies can be disabled by setting serve.start(..., proxy_location=ProxyLocation.Disabled). However, serve status currently fails when proxies are disabled. This change fixes the issue and lets serve status succeed even when proxy_location==ProxyLocation.Disabled. --------- Signed-off-by: Shreyas Krishnaswamy <shrekris@anyscale.com>
1 parent 96d0aab commit 65478d4

File tree

3 files changed

+65
-11
lines changed

3 files changed

+65
-11
lines changed

python/ray/serve/_private/controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
get_all_live_placement_group_names,
5555
get_head_node_id,
5656
)
57-
from ray.serve.config import HTTPOptions, gRPCOptions
57+
from ray.serve.config import HTTPOptions, ProxyLocation, gRPCOptions
5858
from ray.serve.generated.serve_pb2 import (
5959
ActorNameList,
6060
DeploymentArgs,
@@ -932,7 +932,7 @@ def get_serve_instance_details(self) -> Dict:
932932
return ServeInstanceDetails(
933933
target_capacity=self._target_capacity,
934934
controller_info=self._actor_details,
935-
proxy_location=http_config.location,
935+
proxy_location=ProxyLocation._from_deployment_mode(http_config.location),
936936
http_options=http_options,
937937
grpc_options=grpc_options,
938938
proxies=self.proxy_state_manager.get_proxy_details()

python/ray/serve/config.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,44 @@ class ProxyLocation(str, Enum):
150150
EveryNode = "EveryNode"
151151

152152
@classmethod
153-
def _to_deployment_mode(cls, v: Union["ProxyLocation", str]) -> DeploymentMode:
154-
if not isinstance(v, (cls, str)):
155-
raise TypeError(f"Must be a `ProxyLocation` or str, got: {type(v)}.")
156-
elif v == ProxyLocation.Disabled:
153+
def _to_deployment_mode(
154+
cls, proxy_location: Union["ProxyLocation", str]
155+
) -> DeploymentMode:
156+
if isinstance(proxy_location, str):
157+
proxy_location = ProxyLocation(proxy_location)
158+
elif not isinstance(proxy_location, ProxyLocation):
159+
raise TypeError(
160+
f"Must be a `ProxyLocation` or str, got: {type(proxy_location)}."
161+
)
162+
163+
if proxy_location == ProxyLocation.Disabled:
157164
return DeploymentMode.NoServer
158-
elif v == ProxyLocation.HeadOnly:
159-
return DeploymentMode.HeadOnly
160-
elif v == ProxyLocation.EveryNode:
161-
return DeploymentMode.EveryNode
162165
else:
163-
raise ValueError(f"Unrecognized `ProxyLocation`: {v}.")
166+
return DeploymentMode(proxy_location.value)
167+
168+
@classmethod
169+
def _from_deployment_mode(
170+
cls, deployment_mode: Optional[Union[DeploymentMode, str]]
171+
) -> Optional["ProxyLocation"]:
172+
"""Converts DeploymentMode enum into ProxyLocation enum.
173+
174+
DeploymentMode is a deprecated version of ProxyLocation that's still
175+
used internally throughout Serve.
176+
"""
177+
178+
if deployment_mode is None:
179+
return None
180+
elif isinstance(deployment_mode, str):
181+
deployment_mode = DeploymentMode(deployment_mode)
182+
elif not isinstance(deployment_mode, DeploymentMode):
183+
raise TypeError(
184+
f"Must be a `DeploymentMode` or str, got: {type(deployment_mode)}."
185+
)
186+
187+
if deployment_mode == DeploymentMode.NoServer:
188+
return ProxyLocation.Disabled
189+
else:
190+
return ProxyLocation(deployment_mode.value)
164191

165192

166193
@PublicAPI(stability="stable")

python/ray/serve/tests/unit/test_config.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,33 @@ def test_proxy_location_to_deployment_mode():
545545
ProxyLocation._to_deployment_mode({"some_other_obj"})
546546

547547

548+
def test_deployment_mode_to_proxy_location():
549+
assert ProxyLocation._from_deployment_mode(None) is None
550+
551+
assert (
552+
ProxyLocation._from_deployment_mode(DeploymentMode.NoServer)
553+
== ProxyLocation.Disabled
554+
)
555+
assert (
556+
ProxyLocation._from_deployment_mode(DeploymentMode.HeadOnly)
557+
== ProxyLocation.HeadOnly
558+
)
559+
assert (
560+
ProxyLocation._from_deployment_mode(DeploymentMode.EveryNode)
561+
== ProxyLocation.EveryNode
562+
)
563+
564+
assert ProxyLocation._from_deployment_mode("NoServer") == ProxyLocation.Disabled
565+
assert ProxyLocation._from_deployment_mode("HeadOnly") == ProxyLocation.HeadOnly
566+
assert ProxyLocation._from_deployment_mode("EveryNode") == ProxyLocation.EveryNode
567+
568+
with pytest.raises(ValueError):
569+
ProxyLocation._from_deployment_mode("Unknown")
570+
571+
with pytest.raises(TypeError):
572+
ProxyLocation._from_deployment_mode({"some_other_obj"})
573+
574+
548575
@pytest.mark.parametrize(
549576
"policy", [None, fake_policy, "ray.serve.tests.unit.test_config:fake_policy"]
550577
)

0 commit comments

Comments
 (0)