Skip to content

Commit

Permalink
[Serve] Enable serve status when proxies disabled (ray-project#42286)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
shrekris-anyscale authored and vickytsang committed Jan 12, 2024
1 parent 76412b2 commit fef42ea
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 11 deletions.
4 changes: 2 additions & 2 deletions python/ray/serve/_private/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
get_all_live_placement_group_names,
get_head_node_id,
)
from ray.serve.config import HTTPOptions, gRPCOptions
from ray.serve.config import HTTPOptions, ProxyLocation, gRPCOptions
from ray.serve.generated.serve_pb2 import (
ActorNameList,
DeploymentArgs,
Expand Down Expand Up @@ -932,7 +932,7 @@ def get_serve_instance_details(self) -> Dict:
return ServeInstanceDetails(
target_capacity=self._target_capacity,
controller_info=self._actor_details,
proxy_location=http_config.location,
proxy_location=ProxyLocation._from_deployment_mode(http_config.location),
http_options=http_options,
grpc_options=grpc_options,
proxies=self.proxy_state_manager.get_proxy_details()
Expand Down
45 changes: 36 additions & 9 deletions python/ray/serve/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,44 @@ class ProxyLocation(str, Enum):
EveryNode = "EveryNode"

@classmethod
def _to_deployment_mode(cls, v: Union["ProxyLocation", str]) -> DeploymentMode:
if not isinstance(v, (cls, str)):
raise TypeError(f"Must be a `ProxyLocation` or str, got: {type(v)}.")
elif v == ProxyLocation.Disabled:
def _to_deployment_mode(
cls, proxy_location: Union["ProxyLocation", str]
) -> DeploymentMode:
if isinstance(proxy_location, str):
proxy_location = ProxyLocation(proxy_location)
elif not isinstance(proxy_location, ProxyLocation):
raise TypeError(
f"Must be a `ProxyLocation` or str, got: {type(proxy_location)}."
)

if proxy_location == ProxyLocation.Disabled:
return DeploymentMode.NoServer
elif v == ProxyLocation.HeadOnly:
return DeploymentMode.HeadOnly
elif v == ProxyLocation.EveryNode:
return DeploymentMode.EveryNode
else:
raise ValueError(f"Unrecognized `ProxyLocation`: {v}.")
return DeploymentMode(proxy_location.value)

@classmethod
def _from_deployment_mode(
cls, deployment_mode: Optional[Union[DeploymentMode, str]]
) -> Optional["ProxyLocation"]:
"""Converts DeploymentMode enum into ProxyLocation enum.
DeploymentMode is a deprecated version of ProxyLocation that's still
used internally throughout Serve.
"""

if deployment_mode is None:
return None
elif isinstance(deployment_mode, str):
deployment_mode = DeploymentMode(deployment_mode)
elif not isinstance(deployment_mode, DeploymentMode):
raise TypeError(
f"Must be a `DeploymentMode` or str, got: {type(deployment_mode)}."
)

if deployment_mode == DeploymentMode.NoServer:
return ProxyLocation.Disabled
else:
return ProxyLocation(deployment_mode.value)


@PublicAPI(stability="stable")
Expand Down
27 changes: 27 additions & 0 deletions python/ray/serve/tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,33 @@ def test_proxy_location_to_deployment_mode():
ProxyLocation._to_deployment_mode({"some_other_obj"})


def test_deployment_mode_to_proxy_location():
assert ProxyLocation._from_deployment_mode(None) is None

assert (
ProxyLocation._from_deployment_mode(DeploymentMode.NoServer)
== ProxyLocation.Disabled
)
assert (
ProxyLocation._from_deployment_mode(DeploymentMode.HeadOnly)
== ProxyLocation.HeadOnly
)
assert (
ProxyLocation._from_deployment_mode(DeploymentMode.EveryNode)
== ProxyLocation.EveryNode
)

assert ProxyLocation._from_deployment_mode("NoServer") == ProxyLocation.Disabled
assert ProxyLocation._from_deployment_mode("HeadOnly") == ProxyLocation.HeadOnly
assert ProxyLocation._from_deployment_mode("EveryNode") == ProxyLocation.EveryNode

with pytest.raises(ValueError):
ProxyLocation._from_deployment_mode("Unknown")

with pytest.raises(TypeError):
ProxyLocation._from_deployment_mode({"some_other_obj"})


@pytest.mark.parametrize(
"policy", [None, fake_policy, "ray.serve.tests.unit.test_config:fake_policy"]
)
Expand Down

0 comments on commit fef42ea

Please sign in to comment.