Skip to content
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

Add GetServiceInfo to xds.GRPCServer #4507

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions xds/server.go
Expand Up @@ -73,6 +73,7 @@ type grpcServerInterface interface {
Serve(net.Listener) error
Stop()
GracefulStop()
GetServiceInfo() map[string]grpc.ServiceInfo
}

// GRPCServer wraps a gRPC server and provides server-side xDS functionality, by
Expand Down Expand Up @@ -145,6 +146,12 @@ func (s *GRPCServer) RegisterService(sd *grpc.ServiceDesc, ss interface{}) {
s.gs.RegisterService(sd, ss)
}

// GetServiceInfo returns a map from service names to ServiceInfo.
// Service names include the package names, in the form of <package>.<service>.
func (s *GRPCServer) GetServiceInfo() map[string]grpc.ServiceInfo {
return s.gs.GetServiceInfo()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@easwars We discussed embedding gs, do you remember why we decided to not do it eventually?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember exactly why we decided not to embed it. But I can see multiple reasons for it:

  • there are methods on grpc.Server which we don't want on xds.GRPCServer like ServeHTTP
  • we want the GRPCServer.gs field to be an interface instead of a concrete type to able to use a fake grpc.Server in some tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm .. actually we could embed an interface as well, not just a concrete type. So, that argument does not hold good. But the first point still makes sense.

Copy link
Contributor

@menghanl menghanl Jun 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only two methods it can inherit are Register and this new one. The others all need override to do something.
So the loss of readability probably doesn't justify the gain.

}

// initXDSClient creates a new xdsClient if there is no existing one available.
func (s *GRPCServer) initXDSClient() error {
s.clientMu.Lock()
Expand Down
4 changes: 4 additions & 0 deletions xds/server_test.go
Expand Up @@ -86,6 +86,10 @@ func (f *fakeGRPCServer) GracefulStop() {
f.gracefulStopCh.Send(nil)
}

func (f *fakeGRPCServer) GetServiceInfo() map[string]grpc.ServiceInfo {
panic("implement me")
}

func newFakeGRPCServer() *fakeGRPCServer {
return &fakeGRPCServer{
done: make(chan struct{}),
Expand Down