Skip to content

Commit

Permalink
[exporter/alertmanager] Use NewDefaultClientConfig instead of manuall…
Browse files Browse the repository at this point in the history
…y creating struct

This PR makes usage of NewDefaultClientConfig instead of manually creating the confighttp.ClientConfig struct.

Issue: open-telemetry#35457
  • Loading branch information
mackjmr committed Oct 1, 2024
1 parent da9d94c commit c18ed36
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
12 changes: 9 additions & 3 deletions exporter/alertmanagerexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package alertmanagerexporter

import (
"net/http"
"path/filepath"
"testing"
"time"
Expand All @@ -23,6 +24,7 @@ import (
)

func TestLoadConfig(t *testing.T) {
defaultTransport := http.DefaultTransport.(*http.Transport)
t.Parallel()

cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
Expand Down Expand Up @@ -74,9 +76,13 @@ func TestLoadConfig(t *testing.T) {
CAFile: "/var/lib/mycert.pem",
},
},
ReadBufferSize: 0,
WriteBufferSize: 524288,
Timeout: time.Second * 10,
ReadBufferSize: 0,
WriteBufferSize: 524288,
Timeout: time.Second * 10,
MaxIdleConns: &defaultTransport.MaxIdleConns,
MaxIdleConnsPerHost: &defaultTransport.MaxIdleConnsPerHost,
MaxConnsPerHost: &defaultTransport.MaxConnsPerHost,
IdleConnTimeout: &defaultTransport.IdleConnTimeout,
},
},
},
Expand Down
13 changes: 6 additions & 7 deletions exporter/alertmanagerexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand All @@ -27,18 +26,18 @@ func NewFactory() exporter.Factory {
}

func createDefaultConfig() component.Config {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = "http://localhost:9093"
clientConfig.Timeout = 30 * time.Second
clientConfig.WriteBufferSize = 512 * 1024

return &Config{
GeneratorURL: "opentelemetry-collector",
DefaultSeverity: "info",
TimeoutSettings: exporterhelper.NewDefaultTimeoutConfig(),
BackoffConfig: configretry.NewDefaultBackOffConfig(),
QueueSettings: exporterhelper.NewDefaultQueueConfig(),
ClientConfig: confighttp.ClientConfig{
Endpoint: "http://localhost:9093",
Timeout: 30 * time.Second,
Headers: map[string]configopaque.String{},
WriteBufferSize: 512 * 1024,
},
ClientConfig: clientConfig,
}
}

Expand Down

0 comments on commit c18ed36

Please sign in to comment.