Skip to content

Commit

Permalink
Change default_service_config to google.protobuf.Struct
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
EdSchouten committed Jan 23, 2025
1 parent 7ebb551 commit 07366c6
Show file tree
Hide file tree
Showing 4 changed files with 317 additions and 303 deletions.
8 changes: 6 additions & 2 deletions pkg/grpc/base_client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,14 @@ func (cf baseClientFactory) NewClientFromConfiguration(config *configuration.Cli
}

// Optional: service config.
if serviceConfig := config.DefaultServiceConfig; serviceConfig != "" {
if serviceConfig := config.DefaultServiceConfig; serviceConfig != nil {
serviceConfigJSON, err := serviceConfig.MarshalJSON()
if err != nil {
return nil, util.StatusWrap(err, "Failed to marshal default service config")
}
dialOptions = append(
dialOptions,
grpc.WithDefaultServiceConfig(serviceConfig))
grpc.WithDefaultServiceConfig(string(serviceConfigJSON)))
}

dialOptions = append(
Expand Down
1 change: 1 addition & 0 deletions pkg/proto/configuration/grpc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ proto_library(
"//pkg/proto/configuration/tls:tls_proto",
"@protobuf//:duration_proto",
"@protobuf//:empty_proto",
"@protobuf//:struct_proto",
],
)

Expand Down
Loading

0 comments on commit 07366c6

Please sign in to comment.