diff --git a/.chloggen/any_balancer_name.yaml b/.chloggen/any_balancer_name.yaml new file mode 100644 index 00000000000..d97cc84d5ad --- /dev/null +++ b/.chloggen/any_balancer_name.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: configgrpc + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Allow any registered gRPC load balancer name to be used. + +# One or more tracking issues or pull requests related to the change +issues: [8262] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/config/configgrpc/configgrpc.go b/config/configgrpc/configgrpc.go index 7b643b046a3..f6da798f165 100644 --- a/config/configgrpc/configgrpc.go +++ b/config/configgrpc/configgrpc.go @@ -17,7 +17,7 @@ import ( "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" "go.opentelemetry.io/otel" "google.golang.org/grpc" - "google.golang.org/grpc/balancer/roundrobin" + "google.golang.org/grpc/balancer" "google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/encoding/gzip" @@ -38,9 +38,6 @@ import ( var errMetadataNotFound = errors.New("no request metadata found") -// Allowed balancer names to be set in grpclb_policy to discover the servers. -var allowedBalancerNames = []string{roundrobin.Name, grpc.PickFirstBalancerName} - // KeepaliveClientConfig exposes the keepalive.ClientParameters to be used by the exporter. // Refer to the original data-structure for the meaning of each parameter: // https://godoc.org/google.golang.org/grpc/keepalive#ClientParameters @@ -269,12 +266,7 @@ func (gcs *GRPCClientSettings) toDialOptions(host component.Host, settings compo } func validateBalancerName(balancerName string) bool { - for _, item := range allowedBalancerNames { - if item == balancerName { - return true - } - } - return false + return balancer.Get(balancerName) != nil } // ToListener returns the net.Listener constructed from the settings. diff --git a/config/configgrpc/configgrpc_test.go b/config/configgrpc/configgrpc_test.go index 38040261f75..175848a5ebf 100644 --- a/config/configgrpc/configgrpc_test.go +++ b/config/configgrpc/configgrpc_test.go @@ -18,6 +18,7 @@ import ( "go.uber.org/zap" "go.uber.org/zap/zaptest/observer" "google.golang.org/grpc" + "google.golang.org/grpc/balancer" "google.golang.org/grpc/metadata" "google.golang.org/grpc/peer" @@ -35,6 +36,21 @@ import ( "go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp" ) +// testBalancerBuilder facilitates testing validateBalancerName(). +type testBalancerBuilder struct{} + +func (testBalancerBuilder) Build(_ balancer.ClientConn, _ balancer.BuildOptions) balancer.Balancer { + return nil +} + +func (testBalancerBuilder) Name() string { + return "configgrpc_balancer_test" +} + +func init() { + balancer.Register(testBalancerBuilder{}) +} + func TestDefaultGrpcClientSettings(t *testing.T) { tt, err := obsreporttest.SetupTelemetry(component.NewID("component")) require.NoError(t, err) @@ -137,7 +153,7 @@ func TestAllGrpcClientSettings(t *testing.T) { ReadBufferSize: 1024, WriteBufferSize: 1024, WaitForReady: true, - BalancerName: "round_robin", + BalancerName: "configgrpc_balancer_test", Authority: "pseudo-authority", Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")}, },