Skip to content

Commit

Permalink
[chore] [exporter/prometheusremotewrite] Use NewDefaultClientConfig i…
Browse files Browse the repository at this point in the history
…nstead of manually creating struct

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

**Link to tracking Issue:** open-telemetry#35457
  • Loading branch information
mackjmr committed Oct 2, 2024
1 parent a191550 commit 9db7ca8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 10 additions & 0 deletions exporter/prometheusremotewriteexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package prometheusremotewriteexporter

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

func TestLoadConfig(t *testing.T) {
defaultMaxIdleConns := http.DefaultTransport.(*http.Transport).MaxIdleConns
defaultMaxIdleConnsPerHost := http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost
defaultMaxConnsPerHost := http.DefaultTransport.(*http.Transport).MaxConnsPerHost
defaultIdleConnTimeout := http.DefaultTransport.(*http.Transport).IdleConnTimeout

t.Parallel()

cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
Expand Down Expand Up @@ -73,6 +79,10 @@ func TestLoadConfig(t *testing.T) {
Headers: map[string]configopaque.String{
"Prometheus-Remote-Write-Version": "0.1.0",
"X-Scope-OrgID": "234"},
MaxIdleConns: &defaultMaxIdleConns,
MaxIdleConnsPerHost: &defaultMaxIdleConnsPerHost,
MaxConnsPerHost: &defaultMaxConnsPerHost,
IdleConnTimeout: &defaultIdleConnTimeout,
},
ResourceToTelemetrySettings: resourcetotelemetry.Settings{Enabled: true},
TargetInfo: &TargetInfo{
Expand Down
16 changes: 7 additions & 9 deletions exporter/prometheusremotewriteexporter/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 Down Expand Up @@ -81,6 +80,12 @@ func createMetricsExporter(ctx context.Context, set exporter.Settings,
func createDefaultConfig() component.Config {
retrySettings := configretry.NewDefaultBackOffConfig()
retrySettings.InitialInterval = 50 * time.Millisecond
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = "http://some.url:9411/api/prom/push"
// We almost read 0 bytes, so no need to tune ReadBufferSize.
clientConfig.ReadBufferSize = 0
clientConfig.WriteBufferSize = 512 * 1024
clientConfig.Timeout = exporterhelper.NewDefaultTimeoutConfig().Timeout

return &Config{
Namespace: "",
Expand All @@ -90,14 +95,7 @@ func createDefaultConfig() component.Config {
BackOffConfig: retrySettings,
AddMetricSuffixes: true,
SendMetadata: false,
ClientConfig: confighttp.ClientConfig{
Endpoint: "http://some.url:9411/api/prom/push",
// We almost read 0 bytes, so no need to tune ReadBufferSize.
ReadBufferSize: 0,
WriteBufferSize: 512 * 1024,
Timeout: exporterhelper.NewDefaultTimeoutConfig().Timeout,
Headers: map[string]configopaque.String{},
},
ClientConfig: clientConfig,
// TODO(jbd): Adjust the default queue size.
RemoteWriteQueue: RemoteWriteQueue{
Enabled: true,
Expand Down

0 comments on commit 9db7ca8

Please sign in to comment.