diff --git a/exporter/logzioexporter/config_test.go b/exporter/logzioexporter/config_test.go index 1152286347d4..bf16dbe27644 100644 --- a/exporter/logzioexporter/config_test.go +++ b/exporter/logzioexporter/config_test.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/confmap/confmaptest" "go.opentelemetry.io/collector/exporter/exporterhelper" @@ -40,15 +39,11 @@ func TestLoadConfig(t *testing.T) { expected.BackOffConfig.MaxInterval = 5 * time.Second expected.QueueSettings = exporterhelper.NewDefaultQueueConfig() expected.QueueSettings.Enabled = false - expected.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, - } + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Timeout = 30 * time.Second + clientConfig.Compression = configcompression.TypeGzip + clientConfig.WriteBufferSize = 512 * 1024 + expected.ClientConfig = clientConfig assert.Equal(t, expected, cfg) } @@ -67,19 +62,19 @@ func TestDefaultLoadConfig(t *testing.T) { } expected.BackOffConfig = configretry.NewDefaultBackOffConfig() expected.QueueSettings = exporterhelper.NewDefaultQueueConfig() - expected.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, - } + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Timeout = 30 * time.Second + clientConfig.Compression = configcompression.TypeGzip + clientConfig.WriteBufferSize = 512 * 1024 + expected.ClientConfig = clientConfig assert.Equal(t, expected, cfg) } func TestCheckAndWarnDeprecatedOptions(t *testing.T) { + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Timeout = 10 * time.Second + clientConfig.Compression = configcompression.TypeGzip + clientConfig.WriteBufferSize = 512 * 1024 // Config with legacy options actualCfg := &Config{ QueueSettings: exporterhelper.NewDefaultQueueConfig(), @@ -88,15 +83,7 @@ func TestCheckAndWarnDeprecatedOptions(t *testing.T) { CustomEndpoint: "https://api.example.com", QueueMaxLength: 10, DrainInterval: 10, - ClientConfig: confighttp.ClientConfig{ - Endpoint: "", - Timeout: 10 * 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, - }, + ClientConfig: clientConfig, } params := exportertest.NewNopSettings() logger := hclog2ZapLogger{ @@ -105,6 +92,12 @@ func TestCheckAndWarnDeprecatedOptions(t *testing.T) { } actualCfg.checkAndWarnDeprecatedOptions(&logger) + clientConfigEndpoint := confighttp.NewDefaultClientConfig() + clientConfigEndpoint.Timeout = 10 * time.Second + clientConfigEndpoint.Compression = configcompression.TypeGzip + clientConfigEndpoint.WriteBufferSize = 512 * 1024 + clientConfigEndpoint.Endpoint = "https://api.example.com" + expected := &Config{ Token: "logzioTESTtoken", CustomEndpoint: "https://api.example.com", @@ -112,15 +105,7 @@ func TestCheckAndWarnDeprecatedOptions(t *testing.T) { DrainInterval: 10, BackOffConfig: configretry.NewDefaultBackOffConfig(), QueueSettings: exporterhelper.NewDefaultQueueConfig(), - ClientConfig: confighttp.ClientConfig{ - Endpoint: "https://api.example.com", - Timeout: 10 * 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, - }, + ClientConfig: clientConfigEndpoint, } expected.QueueSettings.QueueSize = 10 assert.Equal(t, expected, actualCfg) diff --git a/exporter/logzioexporter/exporter_test.go b/exporter/logzioexporter/exporter_test.go index 9f71c49bf16d..fde5d753f365 100644 --- a/exporter/logzioexporter/exporter_test.go +++ b/exporter/logzioexporter/exporter_test.go @@ -186,12 +186,13 @@ func TestExportErrors(tester *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) { rw.WriteHeader(test.status) })) + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Endpoint = server.URL + cfg := &Config{ - Region: "", - Token: "token", - ClientConfig: confighttp.ClientConfig{ - Endpoint: server.URL, - }, + Region: "", + Token: "token", + ClientConfig: clientConfig, } td := newTestTracesWithAttributes() ld := testdata.GenerateLogs(10) @@ -240,13 +241,13 @@ func TestPushTraceData(tester *testing.T) { recordedRequests, _ = io.ReadAll(req.Body) rw.WriteHeader(http.StatusOK) })) + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Endpoint = server.URL + clientConfig.Compression = configcompression.TypeGzip cfg := Config{ - Token: "token", - Region: "", - ClientConfig: confighttp.ClientConfig{ - Endpoint: server.URL, - Compression: configcompression.TypeGzip, - }, + Token: "token", + Region: "", + ClientConfig: clientConfig, } defer server.Close() td := newTestTraces() @@ -273,13 +274,13 @@ func TestPushLogsData(tester *testing.T) { recordedRequests, _ = io.ReadAll(req.Body) rw.WriteHeader(http.StatusOK) })) + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Endpoint = server.URL + clientConfig.Compression = configcompression.TypeGzip cfg := Config{ - Token: "token", - Region: "", - ClientConfig: confighttp.ClientConfig{ - Endpoint: server.URL, - Compression: configcompression.TypeGzip, - }, + Token: "token", + Region: "", + ClientConfig: clientConfig, } defer server.Close() ld := generateLogsOneEmptyTimestamp() diff --git a/exporter/logzioexporter/factory.go b/exporter/logzioexporter/factory.go index f1d37dbd7dfe..3345e38dac23 100644 --- a/exporter/logzioexporter/factory.go +++ b/exporter/logzioexporter/factory.go @@ -15,7 +15,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/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" @@ -34,20 +33,18 @@ 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 return &Config{ Region: "", Token: "", BackOffConfig: configretry.NewDefaultBackOffConfig(), QueueSettings: exporterhelper.NewDefaultQueueConfig(), - 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, - }, + ClientConfig: clientConfig, } } diff --git a/exporter/logzioexporter/factory_test.go b/exporter/logzioexporter/factory_test.go index bdfd78833d2a..4d682b44dea1 100644 --- a/exporter/logzioexporter/factory_test.go +++ b/exporter/logzioexporter/factory_test.go @@ -60,12 +60,12 @@ func TestGenerateUrl(t *testing.T) { {"", "EU", "https://listener-eu.logz.io:8071/?token=token"}, } for _, test := range generateURLTests { + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Endpoint = test.endpoint cfg := &Config{ - Region: test.region, - Token: "token", - ClientConfig: confighttp.ClientConfig{ - Endpoint: test.endpoint, - }, + Region: test.region, + Token: "token", + ClientConfig: clientConfig, } output, _ := generateEndpoint(cfg) require.Equal(t, test.expected, output) diff --git a/exporter/logzioexporter/jsonlog_test.go b/exporter/logzioexporter/jsonlog_test.go index a3643a5dc81a..2e4962e20e55 100644 --- a/exporter/logzioexporter/jsonlog_test.go +++ b/exporter/logzioexporter/jsonlog_test.go @@ -83,13 +83,13 @@ func TestSetTimeStamp(t *testing.T) { })) defer func() { server.Close() }() ld := generateLogsOneEmptyTimestamp() + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Endpoint = server.URL + clientConfig.Compression = configcompression.TypeGzip cfg := &Config{ - Region: "us", - Token: "token", - ClientConfig: confighttp.ClientConfig{ - Endpoint: server.URL, - Compression: configcompression.TypeGzip, - }, + Region: "us", + Token: "token", + ClientConfig: clientConfig, } var err error params := exportertest.NewNopSettings()