From a782f0a4f02d6b662ea8a48a1d46a7cf6491099a Mon Sep 17 00:00:00 2001 From: mackjmr Date: Tue, 1 Oct 2024 14:42:41 +0200 Subject: [PATCH] [exporter/influxdb] 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/influxdbexporter/config_test.go | 12 +++++++++--- exporter/influxdbexporter/factory.go | 13 +++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/exporter/influxdbexporter/config_test.go b/exporter/influxdbexporter/config_test.go index 7bcb99dff6f6..6df0e310b0e8 100644 --- a/exporter/influxdbexporter/config_test.go +++ b/exporter/influxdbexporter/config_test.go @@ -4,6 +4,7 @@ package influxdbexporter import ( + "net/http" "path/filepath" "testing" "time" @@ -22,6 +23,7 @@ import ( ) func TestLoadConfig(t *testing.T) { + defaultTransport := http.DefaultTransport.(*http.Transport) t.Parallel() cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) @@ -39,9 +41,13 @@ func TestLoadConfig(t *testing.T) { id: component.NewIDWithName(metadata.Type, "override-config"), expected: &Config{ ClientConfig: confighttp.ClientConfig{ - Endpoint: "http://localhost:8080", - Timeout: 500 * time.Millisecond, - Headers: map[string]configopaque.String{"User-Agent": "OpenTelemetry -> Influx"}, + Endpoint: "http://localhost:8080", + Timeout: 500 * time.Millisecond, + Headers: map[string]configopaque.String{"User-Agent": "OpenTelemetry -> Influx"}, + MaxIdleConns: &defaultTransport.MaxIdleConns, + MaxIdleConnsPerHost: &defaultTransport.MaxIdleConnsPerHost, + MaxConnsPerHost: &defaultTransport.MaxConnsPerHost, + IdleConnTimeout: &defaultTransport.IdleConnTimeout, }, QueueSettings: exporterhelper.QueueConfig{ Enabled: true, diff --git a/exporter/influxdbexporter/factory.go b/exporter/influxdbexporter/factory.go index 0c821d751b3c..38f27097895c 100644 --- a/exporter/influxdbexporter/factory.go +++ b/exporter/influxdbexporter/factory.go @@ -34,13 +34,14 @@ func NewFactory() exporter.Factory { } func createDefaultConfig() component.Config { + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Timeout = 5 * time.Second + clientConfig.Headers = map[string]configopaque.String{ + "User-Agent": "OpenTelemetry -> Influx", + } + return &Config{ - ClientConfig: confighttp.ClientConfig{ - Timeout: 5 * time.Second, - Headers: map[string]configopaque.String{ - "User-Agent": "OpenTelemetry -> Influx", - }, - }, + ClientConfig: clientConfig, QueueSettings: exporterhelper.NewDefaultQueueConfig(), BackOffConfig: configretry.NewDefaultBackOffConfig(), MetricsSchema: common.MetricsSchemaTelegrafPrometheusV1.String(),