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

cmd/protoc-gen-go-grpc: revert to interface-based service registration #3911

Merged
merged 4 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading