-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Serve] Expose serve request id from http request/resp #35789
Conversation
@@ -191,3 +191,6 @@ class ServeHandleType(str, Enum): | |||
|
|||
# Serve HTTP request header key for routing requests. | |||
SERVE_MULTIPLEXED_MODEL_ID = "serve_multiplexed_model_id" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, should this one be all-caps as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think headers are typically case-insensitive, but might as well be consistent...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, good point, I can push a fix in the master (since headers are case insensitive, I will not do cherry-pick in this case)
@@ -164,6 +165,12 @@ async def _send_request_to_handle(handle, scope, receive, send) -> str: | |||
return "500" | |||
|
|||
if isinstance(result, (starlette.responses.Response, RawASGIResponse)): | |||
if isinstance(result, starlette.responses.Response): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm this makes me realize that my PR will complicate this a bit...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will let your pr checked in and then revisit here.
# Set request id. | ||
self.raw_headers.append( | ||
[ | ||
RAY_SERVE_REQUEST_ID, | ||
ray.serve.context._serve_request_context.get().request_id, | ||
] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to do this only in the HTTP proxy instead of modifying the three separate codepaths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will rebase after your pr landed. and restructure the code. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you 🙏
Signed-off-by: sihanwang41 <sihanwang41@gmail.com>
b1d4037
to
6f3de23
Compare
@edoakes i put the request id into the constructor of the Response & RawASGIResponse.
|
@sihanwang41 this approach won't work for wrapped |
Signed-off-by: Sihan Wang <sihanwang41@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks reasonable; as discussed offline let's just make it a middleware, should be cleaner
@@ -207,6 +207,10 @@ class ServeHandleType(str, Enum): | |||
os.environ.get("RAY_SERVE_ENABLE_EXPERIMENTAL_STREAMING", "0") == "1" | |||
) | |||
|
|||
# Request ID used for logging. Can be provided as a request | |||
# header and will always be returned as a response header. | |||
RAY_SERVE_REQUEST_ID = "RAY_SERVE_REQUEST_ID" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RAY_SERVE_REQUEST_ID = "RAY_SERVE_REQUEST_ID" | |
RAY_SERVE_REQUEST_ID_HEADER = "RAY_SERVE_REQUEST_ID" |
async def send_with_request_id(message): | ||
if message["type"] == "http.response.start": | ||
request_id = ray.serve.context._serve_request_context.get().request_id | ||
headers = MutableHeaders(scope=message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this update the underlying scope
passed in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure i understand the question, I assume all headers information for http.response.start
is under the message directly.
The MutableHeaders
will only extract headers from the message https://github.com/encode/starlette/blob/2168e47052239da5df35d5353bb986f760c51cef/starlette/datastructures.py#L534
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I'm just confused because you're never modifying the message
here, does headers.append(RAY_SERVE_REQUEST_ID, request_id)
do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, yes. the headers
object hold the message header Dict ref. and whenever you update the headers
, it will update the message. It is same as you update the message header directly, but this is more standard instead of updating raw dict by yourself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect thanks for explaining
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating the tests! :)
ping for merge @edoakes , test failure is unrelated. |
…5789) User can inject request id: ``` @serve.deployment class Model: def __call__(self) -> int: return 1 serve.run(Model.bind()) resp = requests.get("http://localhost:8000", headers={"RAY_SERVE_REQUEST_ID": "123-234"}) ``` Signed-off-by: e428265 <arvind.chandramouli@lmco.com>
Why are these changes needed?
User can inject request id:
Related issue number
Closes: #35785
Checks
git commit -s
) in this PR.scripts/format.sh
to lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/
under thecorresponding
.rst
file.