diff --git a/internal/gengapic/client_init.go b/internal/gengapic/client_init.go index e915dcc41..c9f22628a 100644 --- a/internal/gengapic/client_init.go +++ b/internal/gengapic/client_init.go @@ -61,10 +61,13 @@ func (g *generator) clientOptions(serv *descriptor.ServiceDescriptorProto, servN p(" option.WithEndpoint(%q),", host) p(" option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),") p(" option.WithScopes(DefaultAuthScopes()...),") + p(" option.WithGRPCDialOption(grpc.WithDefaultCallOptions(") + p(" grpc.MaxCallRecvMsgSize(math.MaxInt32))),") p(" }") p("}") p("") + g.imports[pbinfo.ImportSpec{Path: "math"}] = true g.imports[pbinfo.ImportSpec{Path: "google.golang.org/api/option"}] = true } @@ -72,6 +75,8 @@ func (g *generator) clientOptions(serv *descriptor.ServiceDescriptorProto, servN { sFQN := fmt.Sprintf("%s.%s", g.descInfo.ParentFile[serv].GetPackage(), serv.GetName()) policies := map[string]*conf.MethodConfig_RetryPolicy{} + reqLimits := map[string]int{} + resLimits := map[string]int{} var methCfgs []*conf.MethodConfig if g.grpcConf != nil { @@ -92,6 +97,15 @@ func (g *generator) clientOptions(serv *descriptor.ServiceDescriptorProto, servN if name.GetMethod() != "" { base = base + "." + name.GetMethod() policies[base] = mc.GetRetryPolicy() + + if maxReq := mc.GetMaxRequestMessageBytes(); maxReq != nil { + reqLimits[base] = int(maxReq.GetValue()) + } + + if maxRes := mc.GetMaxResponseMessageBytes(); maxRes != nil { + resLimits[base] = int(maxRes.GetValue()) + } + continue } @@ -99,9 +113,25 @@ func (g *generator) clientOptions(serv *descriptor.ServiceDescriptorProto, servN for _, m := range serv.GetMethod() { // build fully-qualified name fqn := base + "." + m.GetName() + + // set retry config if _, ok := policies[fqn]; !ok { policies[fqn] = mc.GetRetryPolicy() } + + // set max request size limit + if maxReq := mc.GetMaxRequestMessageBytes(); maxReq != nil { + if _, ok := reqLimits[fqn]; !ok { + reqLimits[fqn] = int(maxReq.GetValue()) + } + } + + // set max response size limit + if maxRes := mc.GetMaxResponseMessageBytes(); maxRes != nil { + if _, ok := resLimits[fqn]; !ok { + resLimits[fqn] = int(maxRes.GetValue()) + } + } } } } @@ -117,6 +147,15 @@ func (g *generator) clientOptions(serv *descriptor.ServiceDescriptorProto, servN for _, m := range serv.GetMethod() { mFQN := sFQN + "." + m.GetName() p("%s: []gax.CallOption{", m.GetName()) + + if maxReq, ok := reqLimits[mFQN]; ok { + p("gax.WithGRPCOptions(grpc.MaxCallSendMsgSize(%d)),", maxReq) + } + + if maxRes, ok := resLimits[mFQN]; ok { + p("gax.WithGRPCOptions(grpc.MaxCallRecvMsgSize(%d)),", maxRes) + } + if rp, ok := policies[mFQN]; ok && rp != nil { p("gax.WithRetry(func() gax.Retryer {") p(" return gax.OnCodes([]codes.Code{") diff --git a/internal/gengapic/client_init_test.go b/internal/gengapic/client_init_test.go index f91d07d30..c37cbaf70 100644 --- a/internal/gengapic/client_init_test.go +++ b/internal/gengapic/client_init_test.go @@ -26,6 +26,7 @@ import ( "github.com/googleapis/gapic-generator-go/internal/txtdiff" "google.golang.org/genproto/googleapis/api/annotations" code "google.golang.org/genproto/googleapis/rpc/code" + wrappers "github.com/golang/protobuf/ptypes/wrappers" ) func TestClientOpt(t *testing.T) { @@ -40,6 +41,8 @@ func TestClientOpt(t *testing.T) { Method: "Zip", }, }, + MaxRequestMessageBytes: &wrappers.UInt32Value{Value: 123456}, + MaxResponseMessageBytes: &wrappers.UInt32Value{Value: 123456}, RetryOrHedgingPolicy: &conf.MethodConfig_RetryPolicy_{ RetryPolicy: &conf.MethodConfig_RetryPolicy{ InitialBackoff: &duration.Duration{Nanos: 100000000}, @@ -57,6 +60,8 @@ func TestClientOpt(t *testing.T) { Service: "bar.FooService", }, }, + MaxRequestMessageBytes: &wrappers.UInt32Value{Value: 654321}, + MaxResponseMessageBytes: &wrappers.UInt32Value{Value: 654321}, RetryOrHedgingPolicy: &conf.MethodConfig_RetryPolicy_{ RetryPolicy: &conf.MethodConfig_RetryPolicy{ InitialBackoff: &duration.Duration{Nanos: 10000000}, diff --git a/internal/gengapic/paging.go b/internal/gengapic/paging.go index d299688f0..19b64c69a 100644 --- a/internal/gengapic/paging.go +++ b/internal/gengapic/paging.go @@ -199,7 +199,6 @@ func (g *generator) pagingCall(servName string, m *descriptor.MethodDescriptorPr p("}") p("") - g.imports[pbinfo.ImportSpec{Path: "math"}] = true g.imports[pbinfo.ImportSpec{Path: "github.com/golang/protobuf/proto"}] = true g.imports[pbinfo.ImportSpec{Path: "google.golang.org/api/iterator"}] = true g.imports[inSpec] = true diff --git a/internal/gengapic/testdata/empty_opt.want b/internal/gengapic/testdata/empty_opt.want index 9b301873d..1e88abd6b 100644 --- a/internal/gengapic/testdata/empty_opt.want +++ b/internal/gengapic/testdata/empty_opt.want @@ -10,12 +10,16 @@ func defaultClientOptions() []option.ClientOption { option.WithEndpoint("foo.bar.com:443"), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), } } func defaultCallOptions() *CallOptions { return &CallOptions{ Zip: []gax.CallOption{ + gax.WithGRPCOptions(grpc.MaxCallSendMsgSize(123456)), + gax.WithGRPCOptions(grpc.MaxCallRecvMsgSize(123456)), gax.WithRetry(func() gax.Retryer { return gax.OnCodes([]codes.Code{ codes.Unknown, @@ -27,6 +31,8 @@ func defaultCallOptions() *CallOptions { }), }, Zap: []gax.CallOption{ + gax.WithGRPCOptions(grpc.MaxCallSendMsgSize(654321)), + gax.WithGRPCOptions(grpc.MaxCallRecvMsgSize(654321)), gax.WithRetry(func() gax.Retryer { return gax.OnCodes([]codes.Code{ codes.Unknown, @@ -38,6 +44,8 @@ func defaultCallOptions() *CallOptions { }), }, Smack: []gax.CallOption{ + gax.WithGRPCOptions(grpc.MaxCallSendMsgSize(654321)), + gax.WithGRPCOptions(grpc.MaxCallRecvMsgSize(654321)), gax.WithRetry(func() gax.Retryer { return gax.OnCodes([]codes.Code{ codes.Unknown, diff --git a/internal/gengapic/testdata/foo_opt.want b/internal/gengapic/testdata/foo_opt.want index bed1cca77..1737d48dc 100644 --- a/internal/gengapic/testdata/foo_opt.want +++ b/internal/gengapic/testdata/foo_opt.want @@ -10,12 +10,16 @@ func defaultFooClientOptions() []option.ClientOption { option.WithEndpoint("foo.bar.com:443"), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), } } func defaultFooCallOptions() *FooCallOptions { return &FooCallOptions{ Zip: []gax.CallOption{ + gax.WithGRPCOptions(grpc.MaxCallSendMsgSize(123456)), + gax.WithGRPCOptions(grpc.MaxCallRecvMsgSize(123456)), gax.WithRetry(func() gax.Retryer { return gax.OnCodes([]codes.Code{ codes.Unknown, @@ -27,6 +31,8 @@ func defaultFooCallOptions() *FooCallOptions { }), }, Zap: []gax.CallOption{ + gax.WithGRPCOptions(grpc.MaxCallSendMsgSize(654321)), + gax.WithGRPCOptions(grpc.MaxCallRecvMsgSize(654321)), gax.WithRetry(func() gax.Retryer { return gax.OnCodes([]codes.Code{ codes.Unknown, @@ -38,6 +44,8 @@ func defaultFooCallOptions() *FooCallOptions { }), }, Smack: []gax.CallOption{ + gax.WithGRPCOptions(grpc.MaxCallSendMsgSize(654321)), + gax.WithGRPCOptions(grpc.MaxCallRecvMsgSize(654321)), gax.WithRetry(func() gax.Retryer { return gax.OnCodes([]codes.Code{ codes.Unknown, diff --git a/internal/gengapic/testdata/host_port_opt.want b/internal/gengapic/testdata/host_port_opt.want index 0d3f9b642..c7e77c645 100644 --- a/internal/gengapic/testdata/host_port_opt.want +++ b/internal/gengapic/testdata/host_port_opt.want @@ -8,6 +8,8 @@ func defaultBarClientOptions() []option.ClientOption { option.WithEndpoint("foo.bar.com:1234"), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), } }