Skip to content

Commit

Permalink
cmd/protoc-gen-go-grpc: revert to interface-based service registration (
Browse files Browse the repository at this point in the history
  • Loading branch information
dfawley committed Sep 29, 2020
1 parent e6c98a4 commit 02cd07d
Show file tree
Hide file tree
Showing 68 changed files with 1,908 additions and 2,442 deletions.
102 changes: 39 additions & 63 deletions balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions balancer/grpclb/grpclb_test.go
Expand Up @@ -276,6 +276,8 @@ func (b *remoteBalancer) BalanceLoad(stream lbgrpc.LoadBalancer_BalanceLoadServe
}

type testServer struct {
testpb.UnimplementedTestServiceServer

addr string
fallback bool
}
Expand Down Expand Up @@ -304,11 +306,7 @@ func startBackends(sn string, fallback bool, lis ...net.Listener) (servers []*gr
sn: sn,
}
s := grpc.NewServer(grpc.Creds(creds))
ts := &testServer{addr: l.Addr().String(), fallback: fallback}
testpb.RegisterTestServiceService(s, &testpb.TestServiceService{
EmptyCall: ts.EmptyCall,
FullDuplexCall: ts.FullDuplexCall,
})
testpb.RegisterTestServiceServer(s, &testServer{addr: l.Addr().String(), fallback: fallback})
servers = append(servers, s)
go func(s *grpc.Server, l net.Listener) {
s.Serve(l)
Expand Down
100 changes: 40 additions & 60 deletions balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions balancer/roundrobin/roundrobin_test.go
Expand Up @@ -47,11 +47,15 @@ func Test(t *testing.T) {
grpctest.RunSubTests(t, s{})
}

func emptyCall(ctx context.Context, in *testpb.Empty) (*testpb.Empty, error) {
type testServer struct {
testpb.UnimplementedTestServiceServer
}

func (s *testServer) EmptyCall(ctx context.Context, in *testpb.Empty) (*testpb.Empty, error) {
return &testpb.Empty{}, nil
}

func fullDuplexCall(stream testpb.TestService_FullDuplexCallServer) error {
func (s *testServer) FullDuplexCall(stream testpb.TestService_FullDuplexCallServer) error {
return nil
}

Expand Down Expand Up @@ -81,10 +85,7 @@ func startTestServers(count int) (_ *test, err error) {
}

s := grpc.NewServer()
testpb.RegisterTestServiceService(s, &testpb.TestServiceService{
EmptyCall: emptyCall,
FullDuplexCall: fullDuplexCall,
})
testpb.RegisterTestServiceServer(s, &testServer{})
t.servers = append(t.servers, s)
t.addresses = append(t.addresses, lis.Addr().String())

Expand Down
23 changes: 5 additions & 18 deletions benchmark/benchmark.go
Expand Up @@ -61,14 +61,8 @@ func NewPayload(t testpb.PayloadType, size int) *testpb.Payload {
return p
}

type testServer struct{}

func (s *testServer) Svc() *testpb.BenchmarkServiceService {
return &testpb.BenchmarkServiceService{
UnaryCall: s.UnaryCall,
StreamingCall: s.StreamingCall,
UnconstrainedStreamingCall: s.UnconstrainedStreamingCall,
}
type testServer struct {
testpb.UnimplementedBenchmarkServiceServer
}

func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
Expand Down Expand Up @@ -150,17 +144,10 @@ func (s *testServer) UnconstrainedStreamingCall(stream testpb.BenchmarkService_U
// byteBufServer is a gRPC server that sends and receives byte buffer.
// The purpose is to benchmark the gRPC performance without protobuf serialization/deserialization overhead.
type byteBufServer struct {
testpb.UnimplementedBenchmarkServiceServer
respSize int32
}

func (s *byteBufServer) Svc() *testpb.BenchmarkServiceService {
return &testpb.BenchmarkServiceService{
UnaryCall: s.UnaryCall,
StreamingCall: s.StreamingCall,
UnconstrainedStreamingCall: s.UnconstrainedStreamingCall,
}
}

// UnaryCall is an empty function and is not used for benchmark.
// If bytebuf UnaryCall benchmark is needed later, the function body needs to be updated.
func (s *byteBufServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
Expand Down Expand Up @@ -224,13 +211,13 @@ func StartServer(info ServerInfo, opts ...grpc.ServerOption) func() {
s := grpc.NewServer(opts...)
switch info.Type {
case "protobuf":
testpb.RegisterBenchmarkServiceService(s, (&testServer{}).Svc())
testpb.RegisterBenchmarkServiceServer(s, &testServer{})
case "bytebuf":
respSize, ok := info.Metadata.(int32)
if !ok {
logger.Fatalf("failed to StartServer, invalid metadata: %v, for Type: %v", info.Metadata, info.Type)
}
testpb.RegisterBenchmarkServiceService(s, (&byteBufServer{respSize: respSize}).Svc())
testpb.RegisterBenchmarkServiceServer(s, &byteBufServer{respSize: respSize})
default:
logger.Fatalf("failed to StartServer, unknown Type: %v", info.Type)
}
Expand Down

0 comments on commit 02cd07d

Please sign in to comment.