44 "context"
55 "maps"
66
7- "github.com/buildbarn/bb-storage/pkg/program"
87 grpcpb "github.com/buildbarn/bb-storage/pkg/proto/configuration/grpc"
9- "github.com/buildbarn/bb-storage/pkg/util"
108 "github.com/jhump/protoreflect/v2/grpcreflect"
119 "github.com/jhump/protoreflect/v2/protoresolve"
1210 "google.golang.org/grpc/reflection/grpc_reflection_v1"
@@ -25,20 +23,26 @@ var _ reflection.ServiceInfoProvider = (*combinedServiceInfoProvider)(nil)
2523// GetServiceInfo returns the currently available services, which might have
2624// changed since the creation of this reflection server.
2725func (p * combinedServiceInfoProvider ) GetServiceInfo () map [string ]grpc.ServiceInfo {
28- services := make (map [string ]grpc.ServiceInfo )
26+ serverServiceInfo := p .server .GetServiceInfo ()
27+ services := make (map [string ]grpc.ServiceInfo , len (p .extraServices )+ len (serverServiceInfo ))
2928 maps .Copy (services , p .extraServices )
30- maps .Copy (services , p . server . GetServiceInfo () )
29+ maps .Copy (services , serverServiceInfo )
3130 return services
3231}
3332
34- // registerReflection registers the google.golang.org/grpc/reflection/ service
35- // on a grpc.Server and calls remote backends in case for relayed services. The
36- // connections to the backend will run with the backendCtx.
37- func registerReflection (backendCtx context.Context , s * grpc.Server , serverRelayConfiguration []* grpcpb.ServerRelayConfiguration , group program.Group , grpcClientFactory ClientFactory ) error {
33+ type serverRelayConfigWithGrpcClient struct {
34+ config * grpcpb.ServerRelayConfiguration
35+ grpcClient grpc.ClientConnInterface
36+ }
37+
38+ // registerReflectionServer registers the google.golang.org/grpc/reflection/
39+ // service on a grpc.Server and calls remote backends in case for relayed
40+ // services. The connections to the backend will run with the backendCtx.
41+ func registerReflectionServer (backendCtx context.Context , s * grpc.Server , serverRelayConfigurations []serverRelayConfigWithGrpcClient ) error {
3842 // Accumulate all the service names.
3943 relayServices := make (map [string ]grpc.ServiceInfo )
40- for _ , relay := range serverRelayConfiguration {
41- for _ , service := range relay .GetServices () {
44+ for _ , relay := range serverRelayConfigurations {
45+ for _ , service := range relay .config . GetServices () {
4246 // According to ServiceInfoProvider docs for ServerOptions.Services,
4347 // the reflection service is only interested in the service names.
4448 relayServices [service ] = grpc.ServiceInfo {}
@@ -47,12 +51,8 @@ func registerReflection(backendCtx context.Context, s *grpc.Server, serverRelayC
4751
4852 // Make a combined descriptor and extension resolver.
4953 reflectionBackends := []protoresolve.Resolver {}
50- for relayIdx , relay := range serverRelayConfiguration {
51- grpcClient , err := grpcClientFactory .NewClientFromConfiguration (relay .Endpoint , group )
52- if err != nil {
53- return util .StatusWrapf (err , "Failed to create relay RPC client %d" , relayIdx + 1 )
54- }
55- resolver := grpcreflect .NewClientAuto (backendCtx , grpcClient ).AsResolver ()
54+ for _ , relay := range serverRelayConfigurations {
55+ resolver := grpcreflect .NewClientAuto (backendCtx , relay .grpcClient ).AsResolver ()
5656 reflectionBackends = append (reflectionBackends , resolver )
5757 }
5858 combinedRemoteResolver := protoresolve .Combine (reflectionBackends ... )
0 commit comments