-
Notifications
You must be signed in to change notification settings - Fork 195
Break PostResponse requestcontrol plugin into 3 separate plugins to add streamed request functionality
#1661
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
Break PostResponse requestcontrol plugin into 3 separate plugins to add streamed request functionality
#1661
Conversation
✅ Deploy Preview for gateway-api-inference-extension ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Hi @BenjaminBraunDev. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/ok-to-test |
|
Some smaller comments, overall looks good. Thanks! /approve |
pkg/epp/requestcontrol/director.go
Outdated
| } | ||
|
|
||
| // HandleResponseBodyStreaming is called every time a chunk of the response body is received. | ||
| func (d *Director) HandleResponseBodyStreaming(ctx context.Context, reqCtx *handlers.RequestContext, logger logr.Logger) (*handlers.RequestContext, error) { |
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.
please remove logger from the args, we don't use logr as argument to functions, we use contextual logging.
for example
log.FromContext(ctx).V(logutil.TRACE).Info(....)see for example here:
| loggerTrace := log.FromContext(ctx).V(logutil.TRACE) |
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 asked him to remove that, in the streaming case the high volume of instantiations of the logger will cause allocation/gc pressure. Luke mentioned this as an optimization during flow control benchmarking, and i think the same applies here b/c there will be multiple streaming calls per request.
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 log.FromContext(ctx).V(logutil.TRACE).Info(....) actually make another logger? I would think it takes the logger "from the context" given ctx has a logger. Does it actually allocate more memory? I would think that pretty inefficient.
From the FromContext() in go-logr package:
// FromContext returns a Logger from ctx or an error if no Logger is found.
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.
@nirrozenbaum @kfswain What is the desired state for this? I can revert it back or keep the changes
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 don't think it makes another logger.
that wouldn't make sense.
the desired state (at least in my opinion) is to remove logger from the args and use contextual logging if/when necessary.
we don't pass around logger in any part of the code. we pass ctx (which includes inside it the logger).
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'm slightly confused here, the FromContext in log.go always calls log.WithValues(keysAndValues...), it's the only way the function can return. Should I keep this logging regardless?
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 was checking now again. I see your point.
I’m still not sure about that, but anyway this looks to me like a system wide issue cause we’re using contextual logging in all places.
I suggest to move forward with current PR using Log.FromContext, open a dedicated issue to check about this issue, and if we decide to change, we need to update everywhere, not only in this function.
let me know if it makes sense.
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.
This PR has been open for a while, so I'm fine with whatever we do in the short term to keep this moving. This PR also needs a rebase, so when that is rebased we can update this to whatever. (Personally I think we leave it out here since this extension point is potentially called significantly more than any other). But don't feel strongly enough to hold up this PR further.
@BenjaminBraunDev pls ping me when this PR is rebased.
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.
+1; please revert and lets move forward with the PR and resolve the logging issue separately
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.
@kfswain Reverted and rebased! Should be ready for merge after tests finish.
|
@BenjaminBraunDev made another iteration on the PR. |
|
/approve Thanks Ben! Will let Nir give final stamp |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: BenjaminBraunDev, kfswain The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
2a25c1a to
f73ef27
Compare
…recieved, streaming, and complete
Co-authored-by: Nir Rozenbaum <[email protected]>
Co-authored-by: Nir Rozenbaum <[email protected]>
Co-authored-by: Nir Rozenbaum <[email protected]>
…ormat for plugins
9ec1c4f to
34a17a9
Compare
|
/lgtm Thanks! |
|
Thanks @BenjaminBraunDev! |
… add streamed request functionality (kubernetes-sigs#1661) * Break out PostResponse plugin into 3 constituent plugins for request recieved, streaming, and complete * Fix typo in variable names * Log typed name in director.go and remove redundant director nil check in response.go * Renamed the post response plugins to not include the word post. * Fix function comment and pass existing logger into HandleResponseBodyStreaming * Update pkg/epp/requestcontrol/plugins.go Co-authored-by: Nir Rozenbaum <[email protected]> * Update pkg/epp/requestcontrol/request_control_config.go Co-authored-by: Nir Rozenbaum <[email protected]> * Update pkg/epp/requestcontrol/director.go Co-authored-by: Nir Rozenbaum <[email protected]> * Fix comments andlogs, simplify Director defintion to take in config * Revert logging parameter addition, keeping consistent with existing format for plugins --------- Co-authored-by: Nir Rozenbaum <[email protected]>
/kind bug
/kind feature
What this PR does / why we need it:
PostResponse runs at the first chunk received instead of at the end of the request, however some PostResponse plugins would like to run only when a request is fully complete. This PR allows that flexibility by breaking out PostResponse into 3 separate requestcontrol plugin hooks for when the response is received, each chunk streamed, and fully complete respectively. The requestcontrol plugins are now the following:
Which issue(s) this PR fixes:
Fixes #1483
Does this PR introduce a user-facing change?: