Skip to content

Commit

Permalink
[configgrpc] Change Headers field type to have opaque values (#6853)
Browse files Browse the repository at this point in the history
* [configgrpc] Change Headers field type to have opaque values

* Add changelog entry
  • Loading branch information
mx-psi authored Jan 20, 2023
1 parent 8fa8408 commit d97f1eb
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 11 deletions.
16 changes: 16 additions & 0 deletions .chloggen/mx-psi_configgrpc-opaque.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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: config/configgrpc

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Change configgrpc.GRPCClientSettings.Headers type to map[string]configopaque.String

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

# (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: Use `configopaque.String(str)` and `string(opaque)` to turn a string opaque/clear.
3 changes: 2 additions & 1 deletion config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"go.opentelemetry.io/collector/config/configauth"
"go.opentelemetry.io/collector/config/configcompression"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/config/internal"
"go.opentelemetry.io/collector/extension/auth"
Expand Down Expand Up @@ -90,7 +91,7 @@ type GRPCClientSettings struct {
WaitForReady bool `mapstructure:"wait_for_ready"`

// The headers associated with gRPC requests.
Headers map[string]string `mapstructure:"headers"`
Headers map[string]configopaque.String `mapstructure:"headers"`

// Sets the balancer in grpclb_policy to discover the servers. Default is pick_first.
// https://github.com/grpc/grpc-go/blob/master/examples/features/load_balancing/README.md
Expand Down
9 changes: 5 additions & 4 deletions config/configgrpc/configgrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"go.opentelemetry.io/collector/config/configauth"
"go.opentelemetry.io/collector/config/configcompression"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/extension/auth"
"go.opentelemetry.io/collector/extension/auth/authtest"
Expand Down Expand Up @@ -73,7 +74,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
{
name: "test all with gzip compression",
settings: GRPCClientSettings{
Headers: map[string]string{
Headers: map[string]configopaque.String{
"test": "test",
},
Endpoint: "localhost:1234",
Expand Down Expand Up @@ -101,7 +102,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
{
name: "test all with snappy compression",
settings: GRPCClientSettings{
Headers: map[string]string{
Headers: map[string]configopaque.String{
"test": "test",
},
Endpoint: "localhost:1234",
Expand Down Expand Up @@ -129,7 +130,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
{
name: "test all with zstd compression",
settings: GRPCClientSettings{
Headers: map[string]string{
Headers: map[string]configopaque.String{
"test": "test",
},
Endpoint: "localhost:1234",
Expand Down Expand Up @@ -272,7 +273,7 @@ func TestGRPCClientSettingsError(t *testing.T) {
{
err: "invalid balancer_name: test",
settings: GRPCClientSettings{
Headers: map[string]string{
Headers: map[string]configopaque.String{
"test": "test",
},
Endpoint: "localhost:1234",
Expand Down
3 changes: 2 additions & 1 deletion exporter/otlpexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configauth"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/confmaptest"
Expand Down Expand Up @@ -61,7 +62,7 @@ func TestUnmarshalConfig(t *testing.T) {
QueueSize: 10,
},
GRPCClientSettings: configgrpc.GRPCClientSettings{
Headers: map[string]string{
Headers: map[string]configopaque.String{
"can you have a . here?": "F0000000-0000-0000-0000-000000000000",
"header1": "234",
"another": "somevalue",
Expand Down
3 changes: 2 additions & 1 deletion exporter/otlpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configcompression"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand Down Expand Up @@ -47,7 +48,7 @@ func createDefaultConfig() component.Config {
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Headers: map[string]string{},
Headers: map[string]configopaque.String{},
// Default to gzip compression
Compression: configcompression.Gzip,
// We almost read 0 bytes, so no need to tune ReadBufferSize.
Expand Down
3 changes: 2 additions & 1 deletion exporter/otlpexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/configcompression"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/exporter/exportertest"
Expand Down Expand Up @@ -138,7 +139,7 @@ func TestCreateTracesExporter(t *testing.T) {
config: Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: endpoint,
Headers: map[string]string{
Headers: map[string]configopaque.String{
"hdr1": "val1",
"hdr2": "val2",
},
Expand Down
6 changes: 5 additions & 1 deletion exporter/otlpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ func (e *baseExporter) start(ctx context.Context, host component.Host) (err erro
e.traceExporter = ptraceotlp.NewGRPCClient(e.clientConn)
e.metricExporter = pmetricotlp.NewGRPCClient(e.clientConn)
e.logExporter = plogotlp.NewGRPCClient(e.clientConn)
e.metadata = metadata.New(e.config.GRPCClientSettings.Headers)
headers := map[string]string{}
for k, v := range e.config.GRPCClientSettings.Headers {
headers[k] = string(v)
}
e.metadata = metadata.New(headers)
e.callOptions = []grpc.CallOption{
grpc.WaitForReady(e.config.GRPCClientSettings.WaitForReady),
}
Expand Down
5 changes: 3 additions & 2 deletions exporter/otlpexporter/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (

"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exportertest"
Expand Down Expand Up @@ -223,7 +224,7 @@ func TestSendTraces(t *testing.T) {
TLSSetting: configtls.TLSClientSetting{
Insecure: true,
},
Headers: map[string]string{
Headers: map[string]configopaque.String{
"header": "header-value",
},
}
Expand Down Expand Up @@ -369,7 +370,7 @@ func TestSendMetrics(t *testing.T) {
TLSSetting: configtls.TLSClientSetting{
Insecure: true,
},
Headers: map[string]string{
Headers: map[string]configopaque.String{
"header": "header-value",
},
}
Expand Down

0 comments on commit d97f1eb

Please sign in to comment.