Skip to content

Commit 07366c6

Browse files
committedJan 23, 2025
Change default_service_config to google.protobuf.Struct
The gRPC service config is based on a Protobuf message structure defined here: https://github.com/grpc/grpc-proto/blob/master/grpc/service_config/service_config.proto Ideally we'd just embed grpc.service_config.ServiceConfig into this message, but that's easier said than done. There is no canonical Go module containing the generated Protobuf source files. Furthermore, grpc-go ships with some copies of those, but has them placed inside internal/. This means that even if we were to generate those ourselves, we'd run into a Protobuf registration conflict at runtime. Use google.protobuf.Struct, so that we can at least embed these service configs without requiring excessive quoting. This is a continuation of #236.
1 parent 7ebb551 commit 07366c6

File tree

4 files changed

+317
-303
lines changed

4 files changed

+317
-303
lines changed
 

‎pkg/grpc/base_client_factory.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,14 @@ func (cf baseClientFactory) NewClientFromConfiguration(config *configuration.Cli
189189
}
190190

191191
// Optional: service config.
192-
if serviceConfig := config.DefaultServiceConfig; serviceConfig != "" {
192+
if serviceConfig := config.DefaultServiceConfig; serviceConfig != nil {
193+
serviceConfigJSON, err := serviceConfig.MarshalJSON()
194+
if err != nil {
195+
return nil, util.StatusWrap(err, "Failed to marshal default service config")
196+
}
193197
dialOptions = append(
194198
dialOptions,
195-
grpc.WithDefaultServiceConfig(serviceConfig))
199+
grpc.WithDefaultServiceConfig(string(serviceConfigJSON)))
196200
}
197201

198202
dialOptions = append(

‎pkg/proto/configuration/grpc/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ proto_library(
1212
"//pkg/proto/configuration/tls:tls_proto",
1313
"@protobuf//:duration_proto",
1414
"@protobuf//:empty_proto",
15+
"@protobuf//:struct_proto",
1516
],
1617
)
1718

0 commit comments

Comments
 (0)