Skip to content

[configgrpc] Handle gRPC metadata generically #12307

@jade-guiton-dd

Description

@jade-guiton-dd

Problem:

configgrpc and confighttp both allow setting a headers section to set headers on client requests. However, while confighttp handles this internally, configgrpc does not, as there doesn't seem to be a way to set headers on the grpc.ClientConn struct it returns. The OTLP/gRPC exporter fills the gap by extracting the headers config, wrapping it in a metadata.MD, then later adding it to the Context passed to the gRPC call, which is then taken into account by the gRPC library.

This is not ideal, as it means the configgrpc.ClientConfig.Headers is a no-op by default, and components using a gRPC client must manually do this abstraction-leaking processing to take it into account.

Proposed solution:

I considered wrapping grpc.ClientConn to automatically add the metadata in Invoke calls, but because the code calling this method is generated by protogen and expects a grpc.ClientConn specifically, this does not seem possible.

My proposed solution is a new method on ClientConfig which adds the headers to a provided Context, and documenting that the Headers field requires calling this function and passing the resulting Context into the gRPC call.

Update: We can actually do it pretty simply with grpc.WithUnaryInterceptor.

Metadata

Metadata

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions