From 0b1cb703a7b2920b5960557268e11f2e7c290d16 Mon Sep 17 00:00:00 2001 From: Sihan Wang Date: Tue, 3 Oct 2023 11:18:26 -0700 Subject: [PATCH] [Serve] Deprecate RAY_SERVE_REQUEST_ID (#39943) --- python/ray/serve/_private/constants.py | 5 ----- python/ray/serve/_private/proxy.py | 19 ++----------------- python/ray/serve/tests/test_http_headers.py | 6 +----- 3 files changed, 3 insertions(+), 27 deletions(-) diff --git a/python/ray/serve/_private/constants.py b/python/ray/serve/_private/constants.py index 7e5999d84d6a..b1fd54694956 100644 --- a/python/ray/serve/_private/constants.py +++ b/python/ray/serve/_private/constants.py @@ -193,11 +193,6 @@ # Serve HTTP request header key for routing requests. SERVE_MULTIPLEXED_MODEL_ID = "serve_multiplexed_model_id" -# Request ID used for logging. Can be provided as a request -# header and will always be returned as a response header. -# DEPRECATED: use `X-Request-Id` instead -RAY_SERVE_REQUEST_ID_HEADER = "RAY_SERVE_REQUEST_ID" - # Feature flag to enable new handle API. RAY_SERVE_ENABLE_NEW_HANDLE_API = ( os.environ.get("RAY_SERVE_ENABLE_NEW_HANDLE_API", "0") == "1" diff --git a/python/ray/serve/_private/proxy.py b/python/ray/serve/_private/proxy.py index bc8cf526f983..f9ba6c03adc0 100644 --- a/python/ray/serve/_private/proxy.py +++ b/python/ray/serve/_private/proxy.py @@ -29,7 +29,6 @@ DEFAULT_UVICORN_KEEP_ALIVE_TIMEOUT_S, PROXY_MIN_DRAINING_PERIOD_S, RAY_SERVE_HTTP_PROXY_CALLBACK_IMPORT_PATH, - RAY_SERVE_REQUEST_ID_HEADER, SERVE_LOGGER_NAME, SERVE_MULTIPLEXED_MODEL_ID, SERVE_NAMESPACE, @@ -998,12 +997,6 @@ def setup_request_context_and_handle( request_context_info["multiplexed_model_id"] = multiplexed_model_id if key.decode() == "x-request-id": request_context_info["request_id"] = value.decode() - if ( - key.decode() == RAY_SERVE_REQUEST_ID_HEADER.lower() - and "request_id" not in request_context_info - ): - # "x-request-id" has higher priority than "RAY_SERVE_REQUEST_ID". - request_context_info["request_id"] = value.decode() ray.serve.context._serve_request_context.set( ray.serve.context._RequestContext(**request_context_info) ) @@ -1143,27 +1136,19 @@ def __init__(self, app): async def __call__(self, scope, receive, send): headers = MutableHeaders(scope=scope) - if RAY_SERVE_REQUEST_ID_HEADER not in headers and "x-request-id" not in headers: - # If X-Request-ID and RAY_SERVE_REQUEST_ID_HEADER are both not set, we + if "x-request-id" not in headers: + # If X-Request-ID is not set, we # generate a new request ID. request_id = generate_request_id() headers.append("x-request-id", request_id) - headers.append(RAY_SERVE_REQUEST_ID_HEADER, request_id) elif "x-request-id" in headers: request_id = headers["x-request-id"] - else: - # TODO(Sihan) Deprecate RAY_SERVE_REQUEST_ID_HEADER - request_id = headers[RAY_SERVE_REQUEST_ID_HEADER] async def send_with_request_id(message: Dict): if message["type"] == "http.response.start": headers = MutableHeaders(scope=message) - # TODO(Sihan) Deprecate RAY_SERVE_REQUEST_ID_HEADER - headers.append(RAY_SERVE_REQUEST_ID_HEADER, request_id) headers.append("X-Request-ID", request_id) if message["type"] == "websocket.accept": - # TODO(Sihan) Deprecate RAY_SERVE_REQUEST_ID_HEADER - message[RAY_SERVE_REQUEST_ID_HEADER] = request_id message["X-Request-ID"] = request_id await send(message) diff --git a/python/ray/serve/tests/test_http_headers.py b/python/ray/serve/tests/test_http_headers.py index a7fb6d5577e8..603967bde34e 100644 --- a/python/ray/serve/tests/test_http_headers.py +++ b/python/ray/serve/tests/test_http_headers.py @@ -7,7 +7,6 @@ import ray from ray import serve -from ray.serve._private.constants import RAY_SERVE_REQUEST_ID_HEADER def test_request_id_header_by_default(serve_instance): @@ -22,8 +21,6 @@ def __call__(self): serve.run(Model.bind()) resp = requests.get("http://localhost:8000") assert resp.status_code == 200 - assert RAY_SERVE_REQUEST_ID_HEADER in resp.headers - assert resp.text == resp.headers[RAY_SERVE_REQUEST_ID_HEADER] assert resp.text == resp.headers["x-request-id"] def is_valid_uuid(num: str): @@ -38,7 +35,7 @@ def is_valid_uuid(num: str): class TestUserProvidedRequestIDHeader: def verify_result(self): - for header_attr in [RAY_SERVE_REQUEST_ID_HEADER, "X-Request-ID"]: + for header_attr in ["X-Request-ID"]: resp = requests.get( "http://localhost:8000", headers={header_attr: "123-234"} ) @@ -99,7 +96,6 @@ def __call__(self): resp = requests.get( "http://localhost:8000", headers={ - RAY_SERVE_REQUEST_ID_HEADER: "123", "X-Request-ID": "234", }, )