Skip to content

Commit b4c6107

Browse files
committed
[serve] Fix bug with 'proxy_location' set for 'serve run' CLI command
Signed-off-by: axreldable <aleksei.starikov.ax@gmail.com>
1 parent d978d26 commit b4c6107

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

python/ray/serve/scripts.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
SERVE_DEFAULT_APP_NAME,
2828
SERVE_NAMESPACE,
2929
)
30-
from ray.serve.config import DeploymentMode, ProxyLocation, gRPCOptions
30+
from ray.serve.api import _prepare_http_options
31+
from ray.serve.config import DeploymentMode, HTTPOptions, ProxyLocation, gRPCOptions
3132
from ray.serve.deployment import Application, deployment_to_schema
3233
from ray.serve.schema import (
3334
LoggingConfig,
@@ -529,13 +530,16 @@ def run(
529530
"need to call `ray.init` in your code when using `serve run`."
530531
)
531532

532-
http_options = {"location": "EveryNode"}
533+
proxy_location = None
534+
http_options = None
533535
grpc_options = gRPCOptions()
534536
# Merge http_options and grpc_options with the ones on ServeDeploySchema.
535537
if is_config and isinstance(config, ServeDeploySchema):
536-
http_options = {**config.http_options.dict(), **http_options}
538+
proxy_location = config.proxy_location
539+
http_options = HTTPOptions(**config.http_options.dict())
537540
grpc_options = gRPCOptions(**config.grpc_options.dict())
538541

542+
http_options = _prepare_http_options(proxy_location, http_options)
539543
client = _private_api.serve_start(
540544
http_options=http_options,
541545
grpc_options=grpc_options,

python/ray/serve/tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
check_ray_stopped,
2222
start_telemetry_app,
2323
)
24-
from ray.serve.config import HTTPOptions, gRPCOptions
24+
from ray.serve.config import HTTPOptions, ProxyLocation, gRPCOptions
2525
from ray.serve.context import _get_global_client
2626
from ray.tests.conftest import ( # noqa
2727
external_redis,
@@ -148,6 +148,7 @@ def _shared_serve_instance():
148148
_system_config={"metrics_report_interval_ms": 1000, "task_retry_delay_ms": 50},
149149
)
150150
serve.start(
151+
proxy_location=ProxyLocation.HeadOnly,
151152
http_options={"host": "0.0.0.0"},
152153
grpc_options={
153154
"port": 9000,

python/ray/serve/tests/test_cli_3.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import subprocess
55
import sys
66
import time
7+
from typing import Union
78

89
import httpx
910
import pytest
@@ -138,6 +139,60 @@ def build_echo_app_typed(args: TypedArgs):
138139

139140

140141
class TestRun:
142+
@pytest.mark.skipif(
143+
sys.platform == "win32", reason="File path incorrect on Windows."
144+
)
145+
@pytest.mark.parametrize(
146+
"proxy_location,expected",
147+
[
148+
(
149+
None,
150+
"EveryNode",
151+
), # default ProxyLocation `EveryNode` is used as http_options.location is not specified
152+
("EveryNode", "EveryNode"),
153+
("HeadOnly", "HeadOnly"),
154+
("Disabled", "Disabled"),
155+
],
156+
)
157+
def test_proxy_location(self, ray_start_stop, tmp_path, proxy_location, expected):
158+
# when the `serve run` cli command is executed
159+
# without serve already running (for the first time)
160+
# `proxy_location` should be set from the config file if specified
161+
def is_proxy_location_correct(expected_proxy_location: str) -> bool:
162+
try:
163+
response = httpx.get(
164+
"http://localhost:8265/api/serve/applications/"
165+
).text
166+
response_json = json.loads(response)
167+
print("response_json")
168+
print(response_json)
169+
return response_json["proxy_location"] == expected_proxy_location
170+
except httpx.HTTPError:
171+
return False
172+
173+
def arithmetic_config(with_proxy_location: Union[str, None]) -> str:
174+
config_file_name = os.path.join(
175+
os.path.dirname(__file__), "test_config_files", "arithmetic.yaml"
176+
)
177+
with open(config_file_name, "r") as config_file:
178+
arithmetic_config_dict = yaml.safe_load(config_file)
179+
180+
config_path = tmp_path / "config.yaml"
181+
if proxy_location:
182+
arithmetic_config_dict["proxy_location"] = with_proxy_location
183+
with open(config_path, "w") as f:
184+
yaml.dump(arithmetic_config_dict, f)
185+
return str(config_path)
186+
187+
config_path = arithmetic_config(with_proxy_location=proxy_location)
188+
p = subprocess.Popen(["serve", "run", config_path])
189+
wait_for_condition(
190+
lambda: is_proxy_location_correct(expected_proxy_location=expected),
191+
timeout=10,
192+
)
193+
p.send_signal(signal.SIGINT)
194+
p.wait()
195+
141196
@pytest.mark.parametrize("number_of_kill_signals", (1, 2))
142197
@pytest.mark.skipif(
143198
sys.platform == "win32", reason="File path incorrect on Windows."

python/ray/serve/tests/test_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def autoscaling_app():
124124
"worker_id": controller_details.worker_id,
125125
"log_file_path": controller_details.log_file_path,
126126
},
127-
"proxy_location": "EveryNode",
127+
"proxy_location": "HeadOnly",
128128
"http_options": {"host": "0.0.0.0"},
129129
"grpc_options": {
130130
"port": 9000,

0 commit comments

Comments
 (0)