Skip to content

Commit

Permalink
[exporter/influxdb] Use NewDefaultClientConfig instead of manually cr…
Browse files Browse the repository at this point in the history
…eating struct

**Description:**
This PR makes usage of `NewDefaultClientConfig` instead of manually creating the confighttp.ClientConfig struct.

**Link to tracking Issue:** #35457
  • Loading branch information
mackjmr committed Oct 1, 2024
1 parent df53fdb commit a782f0a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
12 changes: 9 additions & 3 deletions exporter/influxdbexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package influxdbexporter

import (
"net/http"
"path/filepath"
"testing"
"time"
Expand All @@ -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"))
Expand All @@ -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,
Expand Down
13 changes: 7 additions & 6 deletions exporter/influxdbexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit a782f0a

Please sign in to comment.