diff --git a/exporter/lokiexporter/config_test.go b/exporter/lokiexporter/config_test.go index caf6ee5a120e..f9ee4470fc63 100644 --- a/exporter/lokiexporter/config_test.go +++ b/exporter/lokiexporter/config_test.go @@ -24,6 +24,22 @@ import ( ) func TestLoadConfigNewExporter(t *testing.T) { + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Headers = map[string]configopaque.String{ + "X-Custom-Header": "loki_rocks", + } + clientConfig.Endpoint = "https://loki:3100/loki/api/v1/push" + clientConfig.TLSSetting = configtls.ClientConfig{ + Config: configtls.Config{ + CAFile: "/var/lib/mycert.pem", + CertFile: "certfile", + KeyFile: "keyfile", + }, + Insecure: true, + } + clientConfig.ReadBufferSize = 123 + clientConfig.WriteBufferSize = 345 + clientConfig.Timeout = time.Second * 10 t.Parallel() cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) @@ -36,23 +52,7 @@ func TestLoadConfigNewExporter(t *testing.T) { { id: component.NewIDWithName(metadata.Type, "allsettings"), expected: &Config{ - ClientConfig: confighttp.ClientConfig{ - Headers: map[string]configopaque.String{ - "X-Custom-Header": "loki_rocks", - }, - Endpoint: "https://loki:3100/loki/api/v1/push", - TLSSetting: configtls.ClientConfig{ - Config: configtls.Config{ - CAFile: "/var/lib/mycert.pem", - CertFile: "certfile", - KeyFile: "keyfile", - }, - Insecure: true, - }, - ReadBufferSize: 123, - WriteBufferSize: 345, - Timeout: time.Second * 10, - }, + ClientConfig: clientConfig, BackOffConfig: configretry.BackOffConfig{ Enabled: true, InitialInterval: 10 * time.Second, @@ -92,6 +92,8 @@ func TestLoadConfigNewExporter(t *testing.T) { } func TestConfigValidate(t *testing.T) { + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Endpoint = "https://loki.example.com" testCases := []struct { desc string cfg *Config @@ -110,9 +112,7 @@ func TestConfigValidate(t *testing.T) { { desc: "Config is valid", cfg: &Config{ - ClientConfig: confighttp.ClientConfig{ - Endpoint: "https://loki.example.com", - }, + ClientConfig: clientConfig, }, err: nil, }, diff --git a/exporter/lokiexporter/exporter_test.go b/exporter/lokiexporter/exporter_test.go index 19033b9ab2bc..37f29f29d3da 100644 --- a/exporter/lokiexporter/exporter_test.go +++ b/exporter/lokiexporter/exporter_test.go @@ -75,10 +75,10 @@ func TestPushLogData(t *testing.T) { })) defer ts.Close() + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Endpoint = ts.URL cfg := &Config{ - ClientConfig: confighttp.ClientConfig{ - Endpoint: ts.URL, - }, + ClientConfig: clientConfig, } f := NewFactory() @@ -254,10 +254,11 @@ func TestLogsToLokiRequestWithGroupingByTenant(t *testing.T) { })) defer ts.Close() + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Endpoint = ts.URL + cfg := &Config{ - ClientConfig: confighttp.ClientConfig{ - Endpoint: ts.URL, - }, + ClientConfig: clientConfig, } f := NewFactory() diff --git a/exporter/lokiexporter/factory.go b/exporter/lokiexporter/factory.go index 05fc68c776a3..95af89096af3 100644 --- a/exporter/lokiexporter/factory.go +++ b/exporter/lokiexporter/factory.go @@ -11,7 +11,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" @@ -29,14 +28,12 @@ func NewFactory() exporter.Factory { } func createDefaultConfig() component.Config { + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Timeout = 30 * time.Second + // We almost read 0 bytes, so no need to tune ReadBufferSize. + clientConfig.WriteBufferSize = 512 * 1024 return &Config{ - ClientConfig: confighttp.ClientConfig{ - Endpoint: "", - Timeout: 30 * time.Second, - Headers: map[string]configopaque.String{}, - // We almost read 0 bytes, so no need to tune ReadBufferSize. - WriteBufferSize: 512 * 1024, - }, + ClientConfig: clientConfig, BackOffConfig: configretry.NewDefaultBackOffConfig(), QueueSettings: exporterhelper.NewDefaultQueueConfig(), DefaultLabelsEnabled: map[string]bool{ diff --git a/exporter/lokiexporter/factory_test.go b/exporter/lokiexporter/factory_test.go index 3ca0bd9c7eec..c24650045877 100644 --- a/exporter/lokiexporter/factory_test.go +++ b/exporter/lokiexporter/factory_test.go @@ -18,11 +18,12 @@ const ( ) func TestExporter_new(t *testing.T) { + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Endpoint = validEndpoint + t.Run("with valid config", func(t *testing.T) { config := &Config{ - ClientConfig: confighttp.ClientConfig{ - Endpoint: validEndpoint, - }, + ClientConfig: clientConfig, } exp, err := newExporter(config, componenttest.NewNopTelemetrySettings()) require.NoError(t, err) @@ -31,10 +32,11 @@ func TestExporter_new(t *testing.T) { } func TestExporter_startReturnsNillWhenValidConfig(t *testing.T) { + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Endpoint = validEndpoint + config := &Config{ - ClientConfig: confighttp.ClientConfig{ - Endpoint: validEndpoint, - }, + ClientConfig: clientConfig, } exp, err := newExporter(config, componenttest.NewNopTelemetrySettings()) require.NoError(t, err) @@ -43,16 +45,17 @@ func TestExporter_startReturnsNillWhenValidConfig(t *testing.T) { } func TestExporter_startReturnsErrorWhenInvalidHttpClientSettings(t *testing.T) { - config := &Config{ - ClientConfig: confighttp.ClientConfig{ - Endpoint: "", - TLSSetting: configtls.ClientConfig{ - Config: configtls.Config{ - MinVersion: "invalid", - }, - }, + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Endpoint = "" + clientConfig.TLSSetting = configtls.ClientConfig{ + Config: configtls.Config{ + MinVersion: "invalid", }, } + + config := &Config{ + ClientConfig: clientConfig, + } exp, err := newExporter(config, componenttest.NewNopTelemetrySettings()) require.NoError(t, err) require.NotNil(t, exp) @@ -60,10 +63,11 @@ func TestExporter_startReturnsErrorWhenInvalidHttpClientSettings(t *testing.T) { } func TestExporter_stopAlwaysReturnsNil(t *testing.T) { + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Endpoint = validEndpoint + config := &Config{ - ClientConfig: confighttp.ClientConfig{ - Endpoint: validEndpoint, - }, + ClientConfig: clientConfig, } exp, err := newExporter(config, componenttest.NewNopTelemetrySettings()) require.NoError(t, err)