Skip to content

Commit

Permalink
[chore][exporter/influxdb] Use NewDefaultClientConfig instead of manu…
Browse files Browse the repository at this point in the history
…ally creating struct (open-telemetry#35521)

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

**Link to tracking Issue:** open-telemetry#35457

---------

Co-authored-by: Ziqi Zhao <[email protected]>
  • Loading branch information
2 people authored and sbylica-splunk committed Dec 17, 2024
1 parent 0fa4f44 commit 4b5af88
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
10 changes: 5 additions & 5 deletions exporter/influxdbexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (
)

func TestLoadConfig(t *testing.T) {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = "http://localhost:8080"
clientConfig.Timeout = 500 * time.Millisecond
clientConfig.Headers = map[string]configopaque.String{"User-Agent": "OpenTelemetry -> Influx"}
t.Parallel()

cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
Expand All @@ -38,11 +42,7 @@ 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"},
},
ClientConfig: clientConfig,
QueueSettings: exporterhelper.QueueConfig{
Enabled: true,
NumConsumers: 3,
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
6 changes: 3 additions & 3 deletions exporter/influxdbexporter/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ func Test_influxHTTPWriterBatch_EnqueuePoint_emptyTagValue(t *testing.T) {
t.Cleanup(noopHTTPServer.Close)

nowTime := time.Unix(1000, 2000)
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = noopHTTPServer.URL

influxWriter, err := newInfluxHTTPWriter(
new(common.NoopLogger),
&Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: noopHTTPServer.URL,
},
ClientConfig: clientConfig,
},
componenttest.NewNopTelemetrySettings())
require.NoError(t, err)
Expand Down

0 comments on commit 4b5af88

Please sign in to comment.