Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove redundant config Validate call #35199

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions exporter/elasticsearchexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,7 @@ func TestConfig_Validate(t *testing.T) {

for name, tt := range tests {
t.Run(name, func(t *testing.T) {
err := tt.config.Validate()
assert.EqualError(t, err, tt.err)
assert.EqualError(t, component.ValidateConfig(tt.config), tt.err)
})
}
}
Expand All @@ -405,13 +404,13 @@ func TestConfig_Validate_Environment(t *testing.T) {
t.Run("valid", func(t *testing.T) {
t.Setenv("ELASTICSEARCH_URL", "http://test:9200")
config := withDefaultConfig()
err := config.Validate()
err := component.ValidateConfig(config)
require.NoError(t, err)
})
t.Run("invalid", func(t *testing.T) {
t.Setenv("ELASTICSEARCH_URL", "http://valid:9200, *:!")
config := withDefaultConfig()
err := config.Validate()
err := component.ValidateConfig(config)
assert.EqualError(t, err, `invalid endpoint "*:!": parse "*:!": first path segment in URL cannot contain colon`)
})
}
Expand Down
8 changes: 2 additions & 6 deletions exporter/elasticsearchexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ func newExporter(
set exporter.Settings,
index string,
dynamicIndex bool,
) (*elasticsearchExporter, error) {
if err := cfg.Validate(); err != nil {
return nil, err
}

) *elasticsearchExporter {
model := &encodeModel{
dedot: cfg.Mapping.Dedot,
mode: cfg.MappingMode(),
Expand All @@ -72,7 +68,7 @@ func newExporter(
model: model,
logstashFormat: cfg.LogstashFormat,
otel: otel,
}, nil
}
}

func (e *elasticsearchExporter) Start(ctx context.Context, host component.Host) error {
Expand Down
22 changes: 7 additions & 15 deletions exporter/elasticsearchexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package elasticsearchexporter // import "github.com/open-telemetry/opentelemetry

import (
"context"
"fmt"
"net/http"
"time"

Expand Down Expand Up @@ -113,10 +112,7 @@ func createLogsExporter(
}
logConfigDeprecationWarnings(cf, set.Logger)

exporter, err := newExporter(cf, set, index, cf.LogsDynamicIndex.Enabled)
if err != nil {
return nil, fmt.Errorf("cannot configure Elasticsearch exporter: %w", err)
}
exporter := newExporter(cf, set, index, cf.LogsDynamicIndex.Enabled)

return exporterhelper.NewLogsExporter(
ctx,
Expand All @@ -135,10 +131,8 @@ func createMetricsExporter(
cf := cfg.(*Config)
logConfigDeprecationWarnings(cf, set.Logger)

exporter, err := newExporter(cf, set, cf.MetricsIndex, cf.MetricsDynamicIndex.Enabled)
if err != nil {
return nil, fmt.Errorf("cannot configure Elasticsearch exporter: %w", err)
}
exporter := newExporter(cf, set, cf.MetricsIndex, cf.MetricsDynamicIndex.Enabled)

return exporterhelper.NewMetricsExporter(
ctx,
set,
Expand All @@ -150,15 +144,13 @@ func createMetricsExporter(

func createTracesExporter(ctx context.Context,
set exporter.Settings,
cfg component.Config) (exporter.Traces, error) {

cfg component.Config,
) (exporter.Traces, error) {
cf := cfg.(*Config)
logConfigDeprecationWarnings(cf, set.Logger)

exporter, err := newExporter(cf, set, cf.TracesIndex, cf.TracesDynamicIndex.Enabled)
if err != nil {
return nil, fmt.Errorf("cannot configure Elasticsearch exporter: %w", err)
}
exporter := newExporter(cf, set, cf.TracesIndex, cf.TracesDynamicIndex.Enabled)

return exporterhelper.NewTracesExporter(
ctx,
set,
Expand Down
18 changes: 0 additions & 18 deletions exporter/elasticsearchexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ func TestFactory_CreateLogsExporter(t *testing.T) {
require.NoError(t, exporter.Shutdown(context.Background()))
}

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")
assert.EqualError(t, err, "cannot configure Elasticsearch exporter: exactly one of [endpoint, endpoints, cloudid] must be specified")
}

func TestFactory_CreateMetricsExporter(t *testing.T) {
factory := NewFactory()
cfg := withDefaultConfig(func(cfg *Config) {
Expand All @@ -70,15 +61,6 @@ func TestFactory_CreateTracesExporter(t *testing.T) {
require.NoError(t, exporter.Shutdown(context.Background()))
}

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")
assert.EqualError(t, err, "cannot configure Elasticsearch exporter: exactly one of [endpoint, endpoints, cloudid] must be specified")
}

func TestFactory_CreateLogsAndTracesExporterWithDeprecatedIndexOption(t *testing.T) {
factory := NewFactory()
cfg := withDefaultConfig(func(cfg *Config) {
Expand Down
Loading