Skip to content

Commit 4355c53

Browse files
committed
add support for :authority pseudo-header for grpc client
This adds support for configuring `authority` dial option for grpc exporter
1 parent 81242fa commit 4355c53

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

config/configgrpc/configgrpc.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ type GRPCClientSettings struct {
8686
// https://github.com/grpc/grpc-go/blob/master/examples/features/load_balancing/README.md
8787
BalancerName string `mapstructure:"balancer_name"`
8888

89+
// WithAuthority parameter configures client to rewrite ":authority" header
90+
// (godoc.org/google.golang.org/grpc#WithAuthority)
91+
Authority string `mapstructure:"authority"`
92+
8993
// Auth configuration for outgoing RPCs.
9094
Auth *configauth.Authentication `mapstructure:"auth"`
9195
}
@@ -247,6 +251,10 @@ func (gcs *GRPCClientSettings) toDialOptions(host component.Host, settings compo
247251
opts = append(opts, grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"loadBalancingPolicy":"%s"}`, gcs.BalancerName)))
248252
}
249253

254+
if gcs.Authority != "" {
255+
opts = append(opts, grpc.WithAuthority(gcs.Authority))
256+
}
257+
250258
otelOpts := []otelgrpc.Option{
251259
otelgrpc.WithTracerProvider(settings.TracerProvider),
252260
otelgrpc.WithMeterProvider(settings.MeterProvider),

config/configgrpc/configgrpc_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
8080
WriteBufferSize: 1024,
8181
WaitForReady: true,
8282
BalancerName: "round_robin",
83+
Authority: "pseudo-authority",
8384
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")},
8485
},
8586
host: &mockHost{
@@ -108,6 +109,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
108109
WriteBufferSize: 1024,
109110
WaitForReady: true,
110111
BalancerName: "round_robin",
112+
Authority: "pseudo-authority",
111113
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")},
112114
},
113115
host: &mockHost{
@@ -136,6 +138,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
136138
WriteBufferSize: 1024,
137139
WaitForReady: true,
138140
BalancerName: "round_robin",
141+
Authority: "pseudo-authority",
139142
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")},
140143
},
141144
host: &mockHost{
@@ -149,7 +152,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
149152
t.Run(test.name, func(t *testing.T) {
150153
opts, err := test.settings.toDialOptions(test.host, tt.TelemetrySettings)
151154
assert.NoError(t, err)
152-
assert.Len(t, opts, 9)
155+
assert.Len(t, opts, 10)
153156
})
154157
}
155158
}

0 commit comments

Comments
 (0)