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
reflection: accept interface instead of grpc.Server struct in Register() #4340
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 this important for you?
I'm thinking about another option, to take a
map
instead offunc() map
.It has the advantage that the result will be fixed (instead of dynamic when
queryServices()
is called). But it also loses some flexibility.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 that's fine. I did it this way only so it worked more like the other version, which let you provide the server before it was done accumulating all of the registered services.
Under-the-hood, I think it will need the function and delayed query, just to support the other entry-point.
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.
Changed. Let me know what you think.
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, right. Sorry, I forgot that
*grpc.Server.GetServiceInfo()
needs to be delayed. Then maybe what you had was better. Or, option 3 is to make it another interface.But let's wait for @dfawley's opinion on this (he's out this week, and will be back next Monday).
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.
And in your use case, are you able to generate a complete list of
map[string]grpc.ServiceInfo
before all the services are registered?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 throwing yet another idea here:
The interface method can be
GetServiceInfo(string) grpc.ServiceInfo
.This gives the implementation a chance to intercept the lookup.
While in the old way, the server cannot intercept the map lookup (they cannot overload
[]
).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.
Instead of intercepting map lookup, the simpler interface I described allows a custom impl to intercept the map retrieval -- like modify the map or produce a different/derivative one. Also, your proposed method alone is insufficient -- how does the caller know what string names to use? You'd also have to have a method that provides the list of services exposed.
Finally, if it has the same name (
GetServiceInfo
) then*grpc.Server
cannot implement it without a backwards incompatible change. So we'd also have to add an adapter type in this package, just to adapt the server to whatever new interface is used.I personally think sticking with the interface already exposed by
*grpc.Server
would be best.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.
@menghanl or @dfawley, any other thoughts about this?
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.
Whoops, didn't see this thread in the "files changed" view.
I agree with your last comment, @jhump. @easwars what are the benefits of adding this to the grpc package? That seems counter to Go design ideals - the only reason
ServiceRegistrar
is there is because we didn't want it to be in every single generated code package for...reasons... I disagreed with them, but went along with 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.
I think I got confused with supporting the
xds.GRPCServer
and got it wrong here. Yes, no good reason to define it in thegrpc
package.