Skip to content

Commit

Permalink
Return err for unsupported client configs
Browse files Browse the repository at this point in the history
  • Loading branch information
songy23 committed Mar 14, 2024
1 parent 49e21b7 commit 5f5d8a5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
34 changes: 34 additions & 0 deletions exporter/datadogexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down
23 changes: 23 additions & 0 deletions exporter/datadogexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion exporter/datadogexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5f5d8a5

Please sign in to comment.