diff --git a/exporter/opensearchexporter/config_test.go b/exporter/opensearchexporter/config_test.go index d6840945c588..921ce1a00428 100644 --- a/exporter/opensearchexporter/config_test.go +++ b/exporter/opensearchexporter/config_test.go @@ -44,6 +44,13 @@ func TestLoadConfig(t *testing.T) { expected: sampleCfg, configValidateAssert: assert.NoError, }, + { + id: component.NewIDWithName(metadata.Type, "default"), + expected: withDefaultConfig(), + configValidateAssert: func(t assert.TestingT, err error, _ ...any) bool { + return assert.ErrorContains(t, err, "endpoint must be specified") + }, + }, { id: component.NewIDWithName(metadata.Type, "trace"), expected: &Config{ diff --git a/exporter/opensearchexporter/factory.go b/exporter/opensearchexporter/factory.go index a10073ca04ae..418987167a32 100644 --- a/exporter/opensearchexporter/factory.go +++ b/exporter/opensearchexporter/factory.go @@ -41,12 +41,10 @@ func newDefaultConfig() component.Config { func createTracesExporter(ctx context.Context, set exporter.Settings, - cfg component.Config) (exporter.Traces, error) { + cfg component.Config, +) (exporter.Traces, error) { c := cfg.(*Config) - te, e := newSSOTracesExporter(c, set) - if e != nil { - return nil, e - } + te := newSSOTracesExporter(c, set) return exporterhelper.NewTracesExporter(ctx, set, cfg, te.pushTraceData, @@ -58,12 +56,10 @@ func createTracesExporter(ctx context.Context, func createLogsExporter(ctx context.Context, set exporter.Settings, - cfg component.Config) (exporter.Logs, error) { + cfg component.Config, +) (exporter.Logs, error) { c := cfg.(*Config) - le, e := newLogExporter(c, set) - if e != nil { - return nil, e - } + le := newLogExporter(c, set) return exporterhelper.NewLogsExporter(ctx, set, cfg, le.pushLogData, diff --git a/exporter/opensearchexporter/factory_test.go b/exporter/opensearchexporter/factory_test.go index f64dd285231a..1f3ab8ccc31d 100644 --- a/exporter/opensearchexporter/factory_test.go +++ b/exporter/opensearchexporter/factory_test.go @@ -20,30 +20,6 @@ func TestCreateDefaultConfig(t *testing.T) { assert.NoError(t, componenttest.CheckConfigStruct(cfg)) } -func TestFactory_CreateMetricsExporter_Fail(t *testing.T) { - factory := NewFactory() - cfg := factory.CreateDefaultConfig() - params := exportertest.NewNopSettings() - _, err := factory.CreateMetricsExporter(context.Background(), params, cfg) - require.Error(t, err, "expected an error when creating a metrics exporter") -} - -func TestFactory_CreateTracesExporter_Fail(t *testing.T) { - factory := NewFactory() - cfg := factory.CreateDefaultConfig() - params := exportertest.NewNopSettings() - _, err := factory.CreateTracesExporter(context.Background(), params, cfg) - require.Error(t, err, "expected an error when creating a traces exporter") -} - -func TestFactory_CreateLogsExporter_Fail(t *testing.T) { - factory := NewFactory() - cfg := factory.CreateDefaultConfig() - params := exportertest.NewNopSettings() - _, err := factory.CreateLogsExporter(context.Background(), params, cfg) - require.Error(t, err, "expected an error when creating a logs exporter") -} - func TestFactory_CreateTracesExporter(t *testing.T) { factory := NewFactory() cfg := withDefaultConfig(func(cfg *Config) { diff --git a/exporter/opensearchexporter/sso_log_exporter.go b/exporter/opensearchexporter/sso_log_exporter.go index bfa34d90d1f1..fe3584f3e0f0 100644 --- a/exporter/opensearchexporter/sso_log_exporter.go +++ b/exporter/opensearchexporter/sso_log_exporter.go @@ -23,11 +23,7 @@ type logExporter struct { telemetry component.TelemetrySettings } -func newLogExporter(cfg *Config, set exporter.Settings) (*logExporter, error) { - if err := cfg.Validate(); err != nil { - return nil, err - } - +func newLogExporter(cfg *Config, set exporter.Settings) *logExporter { model := &encodeModel{ dedup: cfg.Dedup, dedot: cfg.Dedot, @@ -45,7 +41,7 @@ func newLogExporter(cfg *Config, set exporter.Settings) (*logExporter, error) { bulkAction: cfg.BulkAction, httpSettings: cfg.ClientConfig, model: model, - }, nil + } } func (l *logExporter) Start(ctx context.Context, host component.Host) error { diff --git a/exporter/opensearchexporter/sso_trace_exporter.go b/exporter/opensearchexporter/sso_trace_exporter.go index fdc6dab67e87..3c0f2e4b2211 100644 --- a/exporter/opensearchexporter/sso_trace_exporter.go +++ b/exporter/opensearchexporter/sso_trace_exporter.go @@ -25,11 +25,7 @@ type ssoTracesExporter struct { telemetry component.TelemetrySettings } -func newSSOTracesExporter(cfg *Config, set exporter.Settings) (*ssoTracesExporter, error) { - if err := cfg.Validate(); err != nil { - return nil, err - } - +func newSSOTracesExporter(cfg *Config, set exporter.Settings) *ssoTracesExporter { model := &encodeModel{ dataset: cfg.Dataset, namespace: cfg.Namespace, @@ -42,7 +38,7 @@ func newSSOTracesExporter(cfg *Config, set exporter.Settings) (*ssoTracesExporte bulkAction: cfg.BulkAction, model: model, httpSettings: cfg.ClientConfig, - }, nil + } } func (s *ssoTracesExporter) Start(ctx context.Context, host component.Host) error { diff --git a/exporter/opensearchexporter/testdata/config.yaml b/exporter/opensearchexporter/testdata/config.yaml index a187af23318e..2f967002ed96 100644 --- a/exporter/opensearchexporter/testdata/config.yaml +++ b/exporter/opensearchexporter/testdata/config.yaml @@ -7,6 +7,8 @@ opensearch: http: endpoint: https://opensearch.example.com:9200 +opensearch/default: + opensearch/empty_namespace: dataset: ngnix namespace: ""