From cb0d4b45578679345b926b0687ae8ec540d5ed01 Mon Sep 17 00:00:00 2001 From: mackjmr Date: Tue, 1 Oct 2024 13:56:01 +0200 Subject: [PATCH 1/3] [exporter/datadogexporter] Use NewDefaultClientConfig instead of manually creating struct **Description:** This PR makes usage of `NewDefaultClientConfig` instead of manually creating the confighttp.ClientConfig struct. **Link to tracking Issue:** #35457 --- exporter/datadogexporter/factory.go | 7 +++---- pkg/datadog/config/config.go | 7 +++---- .../mockdatasenders/mockdatadogagentexporter/factory.go | 6 +++++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/exporter/datadogexporter/factory.go b/exporter/datadogexporter/factory.go index ec13fbbd63d0..371666c298ad 100644 --- a/exporter/datadogexporter/factory.go +++ b/exporter/datadogexporter/factory.go @@ -190,10 +190,9 @@ func NewFactory() exporter.Factory { } func defaultClientConfig() confighttp.ClientConfig { - // do not use NewDefaultClientConfig for backwards-compatibility - return confighttp.ClientConfig{ - Timeout: 15 * time.Second, - } + client := confighttp.NewDefaultClientConfig() + client.Timeout = 15 * time.Second + return client } // createDefaultConfig creates the default exporter configuration diff --git a/pkg/datadog/config/config.go b/pkg/datadog/config/config.go index 43001935ab63..cac40a97bb3e 100644 --- a/pkg/datadog/config/config.go +++ b/pkg/datadog/config/config.go @@ -281,10 +281,9 @@ func (c *Config) Unmarshal(configMap *confmap.Conf) error { } func defaultClientConfig() confighttp.ClientConfig { - // do not use NewDefaultClientConfig for backwards-compatibility - return confighttp.ClientConfig{ - Timeout: 15 * time.Second, - } + client := confighttp.NewDefaultClientConfig() + client.Timeout = 15 * time.Second + return client } // CreateDefaultConfig creates the default exporter configuration diff --git a/testbed/mockdatasenders/mockdatadogagentexporter/factory.go b/testbed/mockdatasenders/mockdatadogagentexporter/factory.go index c328c3e06985..9e99edb730b9 100644 --- a/testbed/mockdatasenders/mockdatadogagentexporter/factory.go +++ b/testbed/mockdatasenders/mockdatadogagentexporter/factory.go @@ -30,8 +30,12 @@ func NewFactory() exporter.Factory { // CreateDefaultConfig creates the default configuration for DDAPM Exporter func createDefaultConfig() component.Config { + client := confighttp.NewDefaultClientConfig() + client.Endpoint = "localhost:8126" + return client + return &Config{ - ClientConfig: confighttp.ClientConfig{Endpoint: "localhost:8126"}, + ClientConfig: client, } } From 6405474001429070b9548a2e156e00cfa3430e79 Mon Sep 17 00:00:00 2001 From: mackjmr Date: Tue, 1 Oct 2024 14:02:32 +0200 Subject: [PATCH 2/3] fix test --- pkg/datadog/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/datadog/config/config.go b/pkg/datadog/config/config.go index cac40a97bb3e..60542c785993 100644 --- a/pkg/datadog/config/config.go +++ b/pkg/datadog/config/config.go @@ -147,7 +147,7 @@ func validateClientConfig(cfg confighttp.ClientConfig) error { if cfg.Compression != "" { unsupported = append(unsupported, "compression") } - if cfg.Headers != nil { + if len(cfg.Headers) > 0 { unsupported = append(unsupported, "headers") } if cfg.HTTP2ReadIdleTimeout != 0 { From de7686bf44c512d28e146378f5a1703d76221baf Mon Sep 17 00:00:00 2001 From: mackjmr Date: Tue, 1 Oct 2024 14:56:44 +0200 Subject: [PATCH 3/3] feedback --- testbed/mockdatasenders/mockdatadogagentexporter/factory.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/testbed/mockdatasenders/mockdatadogagentexporter/factory.go b/testbed/mockdatasenders/mockdatadogagentexporter/factory.go index 9e99edb730b9..d0a00a5659ea 100644 --- a/testbed/mockdatasenders/mockdatadogagentexporter/factory.go +++ b/testbed/mockdatasenders/mockdatadogagentexporter/factory.go @@ -33,10 +33,6 @@ func createDefaultConfig() component.Config { client := confighttp.NewDefaultClientConfig() client.Endpoint = "localhost:8126" return client - - return &Config{ - ClientConfig: client, - } } func CreateTracesExporter(