-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[confighttp, configgrpc] Replace host parameter by WithXExtensions option #14162
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
base: main
Are you sure you want to change the base?
[confighttp, configgrpc] Replace host parameter by WithXExtensions option #14162
Conversation
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (92.45%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #14162 +/- ##
==========================================
- Coverage 92.27% 92.22% -0.05%
==========================================
Files 657 658 +1
Lines 41093 41213 +120
==========================================
+ Hits 37917 38010 +93
- Misses 2174 2193 +19
- Partials 1002 1010 +8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
The unsatisfactory coverage seems to be because CodeCov doesn't understand the sealed interface pattern. |
mx-psi
left a comment
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 am a bit worried that component developers may forget to pass this option.
One thing that would help in that regard is if we could have an error message with a coda like:
No extensions were passed when building the server
(resp. client)
or soemthing else that makes it clear that this is a build-time/logic error, not something an end user did wrong
| type serverExtensionsOption struct { | ||
| extensions map[component.ID]component.Component | ||
| } | ||
|
|
||
| // WithServerExtensions is a [ToServerOption] which supplies the map of extensions to search for middlewares. | ||
| // | ||
| // Typically called with the output of host.GetExtensions(). | ||
| func WithServerExtensions(extensions map[component.ID]component.Component) ToServerOption { | ||
| return serverExtensionsOption{extensions: extensions} | ||
| } | ||
| func (serverExtensionsOption) isToServerOption() {} |
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.
What do you think about combining WithClientExtensions and WithServerExtensions, so it's just WithExtensions returning a type that implements both interfaces? The names feel a bit awkward, since there's no such thing as client and server extensions
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 tried doing that initially, but that would mean either exposing the underlying option type, or inventing a GenericOption interface that combines ToClientConnOption and ToServerOption.
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.
The latter is what I had in mind - I was thinking ToCommonOption FWIW
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.
Alright, I can try doing that.
The issue is: how would we deal with tests in that case? For the record, there is already a special error message if a |
I think As for which one to prefer, I could go either way assuming there are no major usability issues for either one. Ideally we take a |
My 2c: you have to be a bit more intentional about passing in
Is it even something that should be supported, components disabling support for middleware? If it is, and a user configures middleware, I think it should fail spectacularly rather than log and continue (if that's what you meant), so users don't get surprised that their config is ineffective. |
I don't think we should promote disabling middleware support, but I still think we need to handle a nil extensions map as an edge case. I mostly just called it out as what we would communicate to the user before exiting. The alternative would be to say it's likely a code issue and the user should file a bug report. I can see cases where e.g. a protocol is implemented on top of HTTP and standard middleware extensions won't work well, therefore a component author disables middleware support, but we may never hit that case.
Sorry, I could have been more clear. My intent was that passing |
|
Based on the previous discussion, I've created an alternate PR (was simpler than updating this one) where the map is passed as a positional parameter instead of an option: #14190 Will look into whether I need to update error messages to make it clearer that |
Description
Modifies the
ToServerandToClient(Conn)methods inconfighttpandconfiggrpcto no longer take ahost component.Hostparameter, replacing it with aWith(Client|Server)Extensionsoption, to be created with the result ofhost.GetExtensions.Link to tracking issue
Fixes #13640
Testing
Existing tests make extensive use of the option
Documentation
Added line in
ToServer/ToClient(Conn)documentation describing the intended use ofWithXExtensions.