From c155b14c7cf0e658b4ad69c8469cef9255b36159 Mon Sep 17 00:00:00 2001 From: Mackenzie <63265430+mackjmr@users.noreply.github.com> Date: Thu, 26 Sep 2024 19:21:54 +0200 Subject: [PATCH] [exporter/otlphttpexporter] Use NewDefaultClientConfig instead of manually creating struct (#11273) #### Description This PR makes usage of `NewDefaultClientConfig` instead of manually creating the `confighttp.ClientConfig` struct. The updates to defaults are maintained (Timeout, Compression, WriteBufferSize) whereas the fields that match the default are not manually set anymore (Endpoint, Headers). It also sets to nil the fields that are set in default but weren't set previously (MaxIdleConns, MaxIdleConnsPerHost, MaxConnsPerHost, IdleConnTimeout) to retain the same behaviour. I am on the fence about this one, should we switch to using the defaults ? #### Link to tracking issue #11274 #### Testing #### Documentation --- exporter/otlphttpexporter/factory.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/exporter/otlphttpexporter/factory.go b/exporter/otlphttpexporter/factory.go index 8b7ec9dc807..1417f354a70 100644 --- a/exporter/otlphttpexporter/factory.go +++ b/exporter/otlphttpexporter/factory.go @@ -13,7 +13,6 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configcompression" "go.opentelemetry.io/collector/config/confighttp" - "go.opentelemetry.io/collector/config/configopaque" "go.opentelemetry.io/collector/config/configretry" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/exporter" @@ -33,19 +32,22 @@ func NewFactory() exporter.Factory { } func createDefaultConfig() component.Config { + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Timeout = 30 * time.Second + // Default to gzip compression + clientConfig.Compression = configcompression.TypeGzip + // We almost read 0 bytes, so no need to tune ReadBufferSize. + clientConfig.WriteBufferSize = 512 * 1024 + clientConfig.MaxIdleConns = nil + clientConfig.MaxIdleConnsPerHost = nil + clientConfig.MaxConnsPerHost = nil + clientConfig.IdleConnTimeout = nil + return &Config{ - RetryConfig: configretry.NewDefaultBackOffConfig(), - QueueConfig: exporterhelper.NewDefaultQueueConfig(), - Encoding: EncodingProto, - ClientConfig: confighttp.ClientConfig{ - Endpoint: "", - Timeout: 30 * time.Second, - Headers: map[string]configopaque.String{}, - // Default to gzip compression - Compression: configcompression.TypeGzip, - // We almost read 0 bytes, so no need to tune ReadBufferSize. - WriteBufferSize: 512 * 1024, - }, + RetryConfig: configretry.NewDefaultBackOffConfig(), + QueueConfig: exporterhelper.NewDefaultQueueConfig(), + Encoding: EncodingProto, + ClientConfig: clientConfig, } }