Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .chloggen/no-host-in-configgrpc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: pkg/config/configgrpc

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Replace `component.Host` parameter of ToServer/ToClientConn by map of extensions

# One or more tracking issues or pull requests related to the change
issues: [13640]

# (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: |
Components must now pass the map obtained from the host's `GetExtensions` method
instead of the host itself.

Nil may be used in tests where no middleware or authentication extensions are used.

# 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: [api]
29 changes: 29 additions & 0 deletions .chloggen/no-host-in-confighttp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: pkg/config/confighttp

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Replace `component.Host` parameter of ToServer/ToClient by map of extensions

# One or more tracking issues or pull requests related to the change
issues: [13640]

# (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: |
Components must now pass the map obtained from the host's `GetExtensions` method
instead of the host itself.

Nil may be used in tests where no middleware or authentication extensions are used.

# 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: [api]
27 changes: 10 additions & 17 deletions config/configgrpc/client_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,8 @@ func TestClientMiddlewareOrdering(t *testing.T) {
},
}

// Create a test host with our mock extensions
host := &mockHost{ext: mockExt}

// Send a request using the client with middleware
resp, err := sendTestRequestWithHost(t, clientConfig, host)
resp, err := sendTestRequestWithExtensions(t, clientConfig, mockExt)
require.NoError(t, err)
assert.NotNil(t, resp)

Expand All @@ -147,16 +144,14 @@ func TestClientMiddlewareOrdering(t *testing.T) {
// specifically related to middleware resolution and API calls.
func TestClientMiddlewareToClientErrors(t *testing.T) {
tests := []struct {
name string
host component.Host
config ClientConfig
errText string
name string
extensions map[component.ID]component.Component
config ClientConfig
errText string
}{
{
name: "extension_not_found",
host: &mockHost{
ext: map[component.ID]component.Component{},
},
name: "extension_not_found",
extensions: map[component.ID]component.Component{},
config: ClientConfig{
Endpoint: "localhost:1234",
TLS: configtls.ClientConfig{
Expand All @@ -172,10 +167,8 @@ func TestClientMiddlewareToClientErrors(t *testing.T) {
},
{
name: "get_client_options_fails",
host: &mockHost{
ext: map[component.ID]component.Component{
component.MustNewID("errormw"): extensionmiddlewaretest.NewErr(errors.New("get options failed")),
},
extensions: map[component.ID]component.Component{
component.MustNewID("errormw"): extensionmiddlewaretest.NewErr(errors.New("get options failed")),
},
config: ClientConfig{
Endpoint: "localhost:1234",
Expand All @@ -195,7 +188,7 @@ func TestClientMiddlewareToClientErrors(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
// Test creating the client with middleware errors
_, err := tc.config.ToClientConn(context.Background(), tc.host, componenttest.NewNopTelemetrySettings())
_, err := tc.config.ToClientConn(context.Background(), tc.extensions, componenttest.NewNopTelemetrySettings())
require.Error(t, err)
assert.Contains(t, err.Error(), tc.errText)
})
Expand Down
30 changes: 19 additions & 11 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,17 @@ func (grpcDialOptionWrapper) isToClientConnOption() {}
// a non-blocking dial (the function won't wait for connections to be
// established, and connecting happens in the background). To make it a blocking
// dial, use the WithGrpcDialOption(grpc.WithBlock()) option.
//
// To allow the configuration to reference middleware or authentication extensions,
// the `extensions` argument should be the output of `host.GetExtensions()`.
// It may also be `nil` in tests where no such extension is expected to be used.
func (cc *ClientConfig) ToClientConn(
ctx context.Context,
host component.Host,
extensions map[component.ID]component.Component,
settings component.TelemetrySettings,
extraOpts ...ToClientConnOption,
) (*grpc.ClientConn, error) {
grpcOpts, err := cc.getGrpcDialOptions(ctx, host, settings, extraOpts)
grpcOpts, err := cc.getGrpcDialOptions(ctx, extensions, settings, extraOpts)
if err != nil {
return nil, err
}
Expand All @@ -299,7 +303,7 @@ func (cc *ClientConfig) addHeadersIfAbsent(ctx context.Context) context.Context

func (cc *ClientConfig) getGrpcDialOptions(
ctx context.Context,
host component.Host,
extensions map[component.ID]component.Component,
settings component.TelemetrySettings,
extraOpts []ToClientConnOption,
) ([]grpc.DialOption, error) {
Expand Down Expand Up @@ -343,11 +347,11 @@ func (cc *ClientConfig) getGrpcDialOptions(
}

if cc.Auth.HasValue() {
if host.GetExtensions() == nil {
if extensions == nil {
return nil, errors.New("no extensions configuration available")
}

grpcAuthenticator, cerr := cc.Auth.Get().GetGRPCClientAuthenticator(ctx, host.GetExtensions())
grpcAuthenticator, cerr := cc.Auth.Get().GetGRPCClientAuthenticator(ctx, extensions)
if cerr != nil {
return nil, cerr
}
Expand Down Expand Up @@ -389,7 +393,7 @@ func (cc *ClientConfig) getGrpcDialOptions(

// Apply middleware options. Note: OpenTelemetry could be registered as an extension.
for _, middleware := range cc.Middlewares {
middlewareOptions, err := middleware.GetGRPCClientOptions(ctx, host.GetExtensions())
middlewareOptions, err := middleware.GetGRPCClientOptions(ctx, extensions)
if err != nil {
return nil, fmt.Errorf("failed to get gRPC client options from middleware: %w", err)
}
Expand Down Expand Up @@ -437,13 +441,17 @@ func WithGrpcServerOption(opt grpc.ServerOption) ToServerOption {
func (grpcServerOptionWrapper) isToServerOption() {}

// ToServer returns a [grpc.Server] for the configuration.
//
// To allow the configuration to reference middleware or authentication extensions,
// the `extensions` argument should be the output of `host.GetExtensions()`.
// It may also be `nil` in tests where no such extension is expected to be used.
func (sc *ServerConfig) ToServer(
ctx context.Context,
host component.Host,
extensions map[component.ID]component.Component,
settings component.TelemetrySettings,
extraOpts ...ToServerOption,
) (*grpc.Server, error) {
grpcOpts, err := sc.getGrpcServerOptions(ctx, host, settings, extraOpts)
grpcOpts, err := sc.getGrpcServerOptions(ctx, extensions, settings, extraOpts)
if err != nil {
return nil, err
}
Expand All @@ -452,7 +460,7 @@ func (sc *ServerConfig) ToServer(

func (sc *ServerConfig) getGrpcServerOptions(
ctx context.Context,
host component.Host,
extensions map[component.ID]component.Component,
settings component.TelemetrySettings,
extraOpts []ToServerOption,
) ([]grpc.ServerOption, error) {
Expand Down Expand Up @@ -515,7 +523,7 @@ func (sc *ServerConfig) getGrpcServerOptions(
var sInterceptors []grpc.StreamServerInterceptor

if sc.Auth.HasValue() {
authenticator, err := sc.Auth.Get().GetServerAuthenticator(ctx, host.GetExtensions())
authenticator, err := sc.Auth.Get().GetServerAuthenticator(ctx, extensions)
if err != nil {
return nil, err
}
Expand All @@ -539,7 +547,7 @@ func (sc *ServerConfig) getGrpcServerOptions(

// Apply middleware options. Note: OpenTelemetry could be registered as an extension.
for _, middleware := range sc.Middlewares {
middlewareOptions, err := middleware.GetGRPCServerOptions(ctx, host.GetExtensions())
middlewareOptions, err := middleware.GetGRPCServerOptions(ctx, extensions)
if err != nil {
return nil, fmt.Errorf("failed to get gRPC server options from middleware: %w", err)
}
Expand Down
Loading
Loading