diff --git a/exporter/datadogexporter/config.go b/exporter/datadogexporter/config.go index 25eddf084976..9ebd11698016 100644 --- a/exporter/datadogexporter/config.go +++ b/exporter/datadogexporter/config.go @@ -438,6 +438,10 @@ var _ component.Config = (*Config)(nil) // Validate the configuration for errors. This is required by component.Config. func (c *Config) Validate() error { + if err := validateClientConfig(c.ClientConfig); err != nil { + return err + } + if c.OnlyMetadata && (!c.HostMetadata.Enabled || c.HostMetadata.HostnameSource != HostnameSourceFirstResource) { return errNoMetadata } @@ -478,6 +482,36 @@ func (c *Config) Validate() error { return nil } +func validateClientConfig(cfg confighttp.ClientConfig) error { + var unsupported []string + if cfg.Auth != nil { + unsupported = append(unsupported, "auth") + } + if cfg.Endpoint != "" { + unsupported = append(unsupported, "endpoint") + } + if cfg.Compression != "" { + unsupported = append(unsupported, "compression") + } + if cfg.ProxyURL != "" { + unsupported = append(unsupported, "proxy_url") + } + if cfg.Headers != nil { + unsupported = append(unsupported, "headers") + } + if cfg.HTTP2ReadIdleTimeout != 0 { + unsupported = append(unsupported, "http2_read_idle_timeout") + } + if cfg.HTTP2PingTimeout != 0 { + unsupported = append(unsupported, "http2_ping_timeout") + } + + if len(unsupported) > 0 { + return fmt.Errorf("these confighttp client configs are currently not respected by Datadog exporter: %s", strings.Join(unsupported, ", ")) + } + return nil +} + var _ error = (*renameError)(nil) // renameError is an error related to a renamed setting. diff --git a/exporter/datadogexporter/config_test.go b/exporter/datadogexporter/config_test.go index ac062be2fb21..62d244f7ca03 100644 --- a/exporter/datadogexporter/config_test.go +++ b/exporter/datadogexporter/config_test.go @@ -8,7 +8,10 @@ import ( "time" "github.com/stretchr/testify/assert" + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config/configauth" "go.opentelemetry.io/collector/config/confighttp" + "go.opentelemetry.io/collector/config/configopaque" "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/collector/confmap" ) @@ -18,6 +21,9 @@ func TestValidate(t *testing.T) { maxIdleConn := 300 maxIdleConnPerHost := 150 maxConnPerHost := 250 + ty, err := component.NewType("ty") + assert.NoError(t, err) + auth := configauth.Authentication{AuthenticatorID: component.NewID(ty)} tests := []struct { name string @@ -139,6 +145,23 @@ func TestValidate(t *testing.T) { }, }, }, + + { + name: "unsupported confighttp client configs", + cfg: &Config{ + API: APIConfig{Key: "notnull"}, + ClientConfig: confighttp.ClientConfig{ + Endpoint: "endpoint", + Compression: "gzip", + ProxyURL: "proxy", + Auth: &auth, + Headers: map[string]configopaque.String{"key": "val"}, + HTTP2ReadIdleTimeout: 250, + HTTP2PingTimeout: 200, + }, + }, + err: "these confighttp client configs are currently not respected by Datadog exporter: auth, endpoint, compression, proxy_url, headers, http2_read_idle_timeout, http2_ping_timeout", + }, } for _, testInstance := range tests { t.Run(testInstance.name, func(t *testing.T) { diff --git a/exporter/datadogexporter/go.mod b/exporter/datadogexporter/go.mod index ed9ca4e376bd..9a8e953aec6c 100644 --- a/exporter/datadogexporter/go.mod +++ b/exporter/datadogexporter/go.mod @@ -36,6 +36,7 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.96.0 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/collector/component v0.96.1-0.20240306115632-b2693620eff6 + go.opentelemetry.io/collector/config/configauth v0.96.1-0.20240306115632-b2693620eff6 go.opentelemetry.io/collector/config/configcompression v0.96.1-0.20240306115632-b2693620eff6 go.opentelemetry.io/collector/config/confighttp v0.96.1-0.20240306115632-b2693620eff6 go.opentelemetry.io/collector/config/confignet v0.96.1-0.20240306115632-b2693620eff6 @@ -235,7 +236,6 @@ require ( github.com/zorkian/go-datadog-api v2.30.0+incompatible // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/collector v0.96.1-0.20240306115632-b2693620eff6 // indirect - go.opentelemetry.io/collector/config/configauth v0.96.1-0.20240306115632-b2693620eff6 // indirect go.opentelemetry.io/collector/config/configgrpc v0.96.1-0.20240306115632-b2693620eff6 // indirect go.opentelemetry.io/collector/config/configtelemetry v0.96.1-0.20240306115632-b2693620eff6 // indirect go.opentelemetry.io/collector/config/internal v0.96.1-0.20240306115632-b2693620eff6 // indirect