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 97caba9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 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
10 changes: 6 additions & 4 deletions pkg/proto/configuration/grpc/grpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package buildbarn.configuration.grpc;

import "google/protobuf/duration.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/struct.proto";
import "pkg/proto/auth/auth.proto";
import "pkg/proto/configuration/jwt/jwt.proto";
import "pkg/proto/configuration/tls/tls.proto";
Expand Down Expand Up @@ -118,10 +119,11 @@ message ClientConfiguration {
// /google.bytestream.ByteStream/Read
map<string, TracingMethodConfiguration> tracing = 11;

// The gRPC connection's default service config. See grpc-go
// WithDefaultServiceConfig. Note that the address should use dns:/// schema
// when LB config is round-robin.
string default_service_config = 13;
// The gRPC connection's default service config. Note that the address
// should use dns:/// schema when LB config is round-robin.
//
// More details: https://grpc.io/docs/guides/service-config/
google.protobuf.Struct default_service_config = 13;
}

message ClientKeepaliveConfiguration {
Expand Down

0 comments on commit 97caba9

Please sign in to comment.