Skip to content

Commit

Permalink
[serve] Fix get endpoint when autoscaling config is set (ray-project#…
Browse files Browse the repository at this point in the history
…34377)

If autoscaling config is set for a deployment, we can't set the num replicas when returning the deployment details of that deployment. Otherwise, it breaks the entirety of the get metadata endpoint.
  • Loading branch information
zcin authored and vitsai committed Apr 17, 2023
1 parent 825d9e3 commit b8c847e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
29 changes: 21 additions & 8 deletions dashboard/modules/serve/tests/test_serve_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,21 @@ def test_get_status(ray_start_stop):


@pytest.mark.skipif(sys.platform == "darwin", reason="Flaky on OSX.")
def test_get_serve_instance_details(ray_start_stop):
@pytest.mark.parametrize(
"f_deployment_options",
[
{"name": "f", "ray_actor_options": {"num_cpus": 0.2}},
{
"name": "f",
"autoscaling_config": {
"min_replicas": 1,
"initial_replicas": 3,
"max_replicas": 10,
},
},
],
)
def test_get_serve_instance_details(ray_start_stop, f_deployment_options):
world_import_path = "ray.serve.tests.test_config_files.world.DagNode"
fastapi_import_path = "ray.serve.tests.test_config_files.fastapi_deployment.node"
config1 = {
Expand All @@ -474,12 +488,7 @@ def test_get_serve_instance_details(ray_start_stop):
"name": "app1",
"route_prefix": "/app1",
"import_path": world_import_path,
"deployments": [
{
"name": "f",
"ray_actor_options": {"num_cpus": 0.2},
},
],
"deployments": [f_deployment_options],
},
{
"name": "app2",
Expand Down Expand Up @@ -553,7 +562,11 @@ def applications_running():
assert "route_prefix" not in deployment.deployment_config.dict(
exclude_unset=True
)
assert len(deployment.replicas) == deployment.deployment_config.num_replicas
if isinstance(deployment.deployment_config.num_replicas, int):
assert (
len(deployment.replicas)
== deployment.deployment_config.num_replicas
)

for replica in deployment.replicas:
assert replica.state == ReplicaState.RUNNING
Expand Down
11 changes: 8 additions & 3 deletions python/ray/serve/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,10 @@ def _deployment_info_to_schema(name: str, info: DeploymentInfo) -> DeploymentSch
codepath)
"""

return DeploymentSchema(
schema = DeploymentSchema(
name=name,
num_replicas=info.deployment_config.num_replicas,
max_concurrent_queries=info.deployment_config.max_concurrent_queries,
user_config=info.deployment_config.user_config,
autoscaling_config=info.deployment_config.autoscaling_config,
graceful_shutdown_wait_loop_s=(
info.deployment_config.graceful_shutdown_wait_loop_s
),
Expand All @@ -287,6 +285,13 @@ def _deployment_info_to_schema(name: str, info: DeploymentInfo) -> DeploymentSch
is_driver_deployment=info.is_driver_deployment,
)

if info.deployment_config.autoscaling_config is not None:
schema.autoscaling_config = info.deployment_config.autoscaling_config
else:
schema.num_replicas = info.deployment_config.num_replicas

return schema


@PublicAPI(stability="beta")
class ServeApplicationSchema(BaseModel, extra=Extra.forbid):
Expand Down

0 comments on commit b8c847e

Please sign in to comment.