Skip to content

Commit df80854

Browse files
committed
Add support for :authority pseudo-header in grpc client
This adds support for configuring authority dial option in grpc client
1 parent 81242fa commit df80854

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

.chloggen/otlp_with_authority.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: configgrpc
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Add support for :authority pseudo-header in grpc client"
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [8228]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: []

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)