Skip to content

Commit

Permalink
[Serve] Deprecate RAY_SERVE_REQUEST_ID (ray-project#39943)
Browse files Browse the repository at this point in the history
  • Loading branch information
sihanwang41 authored Oct 3, 2023
1 parent d166024 commit 0b1cb70
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 27 deletions.
5 changes: 0 additions & 5 deletions python/ray/serve/_private/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 2 additions & 17 deletions python/ray/serve/_private/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
)
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 1 addition & 5 deletions python/ray/serve/tests/test_http_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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"}
)
Expand Down Expand Up @@ -99,7 +96,6 @@ def __call__(self):
resp = requests.get(
"http://localhost:8000",
headers={
RAY_SERVE_REQUEST_ID_HEADER: "123",
"X-Request-ID": "234",
},
)
Expand Down

0 comments on commit 0b1cb70

Please sign in to comment.