From 647ce4f91e0c010d7937ae481cc90eaceb870d65 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Fri, 6 Jan 2023 09:06:19 -0800 Subject: [PATCH] [chore] deprecate signalfxexporter max_connections warning (#17406) We now have a better way to set up the http client settings, but we need to finish deprecating the `max_connections` config option. This commit removes the use of MaxConnections and adds a warning if it is explicitly used. Co-authored-by: Dmitrii Anoshin --- exporter/signalfxexporter/README.md | 2 +- exporter/signalfxexporter/config_test.go | 9 ++++++--- exporter/signalfxexporter/exporter.go | 13 ++++++++----- exporter/signalfxexporter/factory.go | 14 ++++++++++---- exporter/signalfxexporter/testdata/config.yaml | 3 ++- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/exporter/signalfxexporter/README.md b/exporter/signalfxexporter/README.md index e51e2d76b679..41b4e6f7df26 100644 --- a/exporter/signalfxexporter/README.md +++ b/exporter/signalfxexporter/README.md @@ -243,7 +243,7 @@ exporters: dot.test: test realm: us1 timeout: 5s - max_connections: 80 + max_idle_conns: 80 ``` > :warning: When enabling the SignalFx receiver or exporter, configure both the `metrics` and `logs` pipelines. diff --git a/exporter/signalfxexporter/config_test.go b/exporter/signalfxexporter/config_test.go index fac3f9db4a0d..bc80c2517f8b 100644 --- a/exporter/signalfxexporter/config_test.go +++ b/exporter/signalfxexporter/config_test.go @@ -48,6 +48,8 @@ func TestLoadConfig(t *testing.T) { require.NoError(t, err) defaultCfg.TranslationRules = defaultTranslationRules + seventy := 70 + tests := []struct { id component.ID expected component.Config @@ -59,14 +61,15 @@ func TestLoadConfig(t *testing.T) { { id: component.NewIDWithName(typeStr, "allsettings"), expected: &Config{ - AccessToken: "testToken", - Realm: "us1", - MaxConnections: 70, + AccessToken: "testToken", + Realm: "us1", HTTPClientSettings: confighttp.HTTPClientSettings{Timeout: 2 * time.Second, Headers: map[string]configopaque.String{ "added-entry": "added value", "dot.test": "test", }, + MaxIdleConns: &seventy, + MaxIdleConnsPerHost: &seventy, }, RetrySettings: exporterhelper.RetrySettings{ Enabled: true, diff --git a/exporter/signalfxexporter/exporter.go b/exporter/signalfxexporter/exporter.go index 3a0412d5ca0f..7abc6c3fb91c 100644 --- a/exporter/signalfxexporter/exporter.go +++ b/exporter/signalfxexporter/exporter.go @@ -230,11 +230,14 @@ func (se *signalfxExporter) startLogs(_ context.Context, host component.Host) er func (se *signalfxExporter) createClient(host component.Host) (*http.Client, error) { se.config.HTTPClientSettings.TLSSetting = se.config.IngestTLSSettings - if se.config.HTTPClientSettings.MaxIdleConns == nil { - se.config.HTTPClientSettings.MaxIdleConns = &se.config.MaxConnections - } - if se.config.HTTPClientSettings.MaxIdleConnsPerHost == nil { - se.config.HTTPClientSettings.MaxIdleConnsPerHost = &se.config.MaxConnections + if se.config.MaxConnections != 0 && (se.config.MaxIdleConns == nil || se.config.HTTPClientSettings.MaxIdleConnsPerHost == nil) { + se.logger.Warn("You are using the deprecated `max_connections` option that will be removed soon; use `max_idle_conns` and/or `max_idle_conns_per_host` instead: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/signalfxexporter#advanced-configuration") + if se.config.HTTPClientSettings.MaxIdleConns == nil { + se.config.HTTPClientSettings.MaxIdleConns = &se.config.MaxConnections + } + if se.config.HTTPClientSettings.MaxIdleConnsPerHost == nil { + se.config.HTTPClientSettings.MaxIdleConnsPerHost = &se.config.MaxConnections + } } if se.config.HTTPClientSettings.IdleConnTimeout == nil { defaultIdleConnTimeout := 30 * time.Second diff --git a/exporter/signalfxexporter/factory.go b/exporter/signalfxexporter/factory.go index a58d8dc92274..842ef8b9a45b 100644 --- a/exporter/signalfxexporter/factory.go +++ b/exporter/signalfxexporter/factory.go @@ -42,6 +42,8 @@ const ( stability = component.StabilityLevelBeta defaultHTTPTimeout = time.Second * 5 + + defaultMaxConns = 100 ) // NewFactory creates a factory for SignalFx exporter. @@ -56,17 +58,21 @@ func NewFactory() exporter.Factory { } func createDefaultConfig() component.Config { + maxConnCount := defaultMaxConns return &Config{ - RetrySettings: exporterhelper.NewDefaultRetrySettings(), - QueueSettings: exporterhelper.NewDefaultQueueSettings(), - HTTPClientSettings: confighttp.HTTPClientSettings{Timeout: defaultHTTPTimeout}, + RetrySettings: exporterhelper.NewDefaultRetrySettings(), + QueueSettings: exporterhelper.NewDefaultQueueSettings(), + HTTPClientSettings: confighttp.HTTPClientSettings{ + Timeout: defaultHTTPTimeout, + MaxIdleConns: &maxConnCount, + MaxIdleConnsPerHost: &maxConnCount, + }, AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{ AccessTokenPassthrough: true, }, DeltaTranslationTTL: 3600, Correlation: correlation.DefaultConfig(), NonAlphanumericDimensionChars: "_-.", - MaxConnections: 100, } } diff --git a/exporter/signalfxexporter/testdata/config.yaml b/exporter/signalfxexporter/testdata/config.yaml index 8c61502b7186..5a620d971daf 100644 --- a/exporter/signalfxexporter/testdata/config.yaml +++ b/exporter/signalfxexporter/testdata/config.yaml @@ -4,7 +4,8 @@ signalfx/allsettings: access_token: testToken realm: "us1" timeout: 2s - max_connections: 70 + max_idle_conns: 70 + max_idle_conns_per_host: 70 sending_queue: enabled: true num_consumers: 2