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

Standarize Settings, Params and Parameters in Exporters #3164

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Move BigEndian helper functions in `tracetranslator` to an internal package.(#3298)
- Rename `configtest.LoadConfigFile` to `configtest.LoadConfigAndValidate` (#3306)
- Replace `ExtensionCreateParams` with `ExtensionCreateSettings` (#3294)
- Replace `ExporterCreateParams` with `ExporterCreateSettings` (#3164)

## 💡 Enhancements 💡

Expand Down
6 changes: 3 additions & 3 deletions component/componenttest/nop_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (f *nopExporterFactory) CreateDefaultConfig() config.Exporter {
// CreateTracesExporter implements component.ExporterFactory interface.
func (f *nopExporterFactory) CreateTracesExporter(
_ context.Context,
_ component.ExporterCreateParams,
_ component.ExporterCreateSettings,
_ config.Exporter,
) (component.TracesExporter, error) {
return nopExporterInstance, nil
Expand All @@ -61,7 +61,7 @@ func (f *nopExporterFactory) CreateTracesExporter(
// CreateMetricsExporter implements component.ExporterFactory interface.
func (f *nopExporterFactory) CreateMetricsExporter(
_ context.Context,
_ component.ExporterCreateParams,
_ component.ExporterCreateSettings,
_ config.Exporter,
) (component.MetricsExporter, error) {
return nopExporterInstance, nil
Expand All @@ -70,7 +70,7 @@ func (f *nopExporterFactory) CreateMetricsExporter(
// CreateLogsExporter implements component.ExporterFactory interface.
func (f *nopExporterFactory) CreateLogsExporter(
_ context.Context,
_ component.ExporterCreateParams,
_ component.ExporterCreateSettings,
_ config.Exporter,
) (component.LogsExporter, error) {
return nopExporterInstance, nil
Expand Down
6 changes: 3 additions & 3 deletions component/componenttest/nop_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ func TestNewNopExporterFactory(t *testing.T) {
cfg := factory.CreateDefaultConfig()
assert.Equal(t, &nopExporterConfig{ExporterSettings: config.NewExporterSettings(config.NewID("nop"))}, cfg)

traces, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateParams{}, cfg)
traces, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateSettings{}, cfg)
require.NoError(t, err)
assert.NoError(t, traces.Start(context.Background(), NewNopHost()))
assert.NoError(t, traces.ConsumeTraces(context.Background(), pdata.NewTraces()))
assert.NoError(t, traces.Shutdown(context.Background()))

metrics, err := factory.CreateMetricsExporter(context.Background(), component.ExporterCreateParams{}, cfg)
metrics, err := factory.CreateMetricsExporter(context.Background(), component.ExporterCreateSettings{}, cfg)
require.NoError(t, err)
assert.NoError(t, metrics.Start(context.Background(), NewNopHost()))
assert.NoError(t, metrics.ConsumeMetrics(context.Background(), pdata.NewMetrics()))
assert.NoError(t, metrics.Shutdown(context.Background()))

logs, err := factory.CreateLogsExporter(context.Background(), component.ExporterCreateParams{}, cfg)
logs, err := factory.CreateLogsExporter(context.Background(), component.ExporterCreateSettings{}, cfg)
require.NoError(t, err)
assert.NoError(t, logs.Start(context.Background(), NewNopHost()))
assert.NoError(t, logs.ConsumeLogs(context.Background(), pdata.NewLogs()))
Expand Down
10 changes: 5 additions & 5 deletions component/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ type LogsExporter interface {
consumer.Logs
}

// ExporterCreateParams configures Exporter creators.
type ExporterCreateParams struct {
// ExporterCreateSettings configures Exporter creators.
type ExporterCreateSettings struct {
// Logger that the factory can use during creation and can pass to the created
// component to be used later as well.
Logger *zap.Logger
Expand All @@ -73,18 +73,18 @@ type ExporterFactory interface {
// CreateTracesExporter creates a trace exporter based on this config.
// If the exporter type does not support tracing or if the config is not valid,
// an error will be returned instead.
CreateTracesExporter(ctx context.Context, params ExporterCreateParams,
CreateTracesExporter(ctx context.Context, set ExporterCreateSettings,
cfg config.Exporter) (TracesExporter, error)

// CreateMetricsExporter creates a metrics exporter based on this config.
// If the exporter type does not support metrics or if the config is not valid,
// an error will be returned instead.
CreateMetricsExporter(ctx context.Context, params ExporterCreateParams,
CreateMetricsExporter(ctx context.Context, set ExporterCreateSettings,
cfg config.Exporter) (MetricsExporter, error)

// CreateLogsExporter creates an exporter based on the config.
// If the exporter type does not support logs or if the config is not valid,
// an error will be returned instead.
CreateLogsExporter(ctx context.Context, params ExporterCreateParams,
CreateLogsExporter(ctx context.Context, set ExporterCreateSettings,
cfg config.Exporter) (LogsExporter, error)
}
6 changes: 3 additions & 3 deletions component/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ func (f *TestExporterFactory) CreateDefaultConfig() config.Exporter {
}

// CreateTracesExporter creates a trace exporter based on this config.
func (f *TestExporterFactory) CreateTracesExporter(context.Context, ExporterCreateParams, config.Exporter) (TracesExporter, error) {
func (f *TestExporterFactory) CreateTracesExporter(context.Context, ExporterCreateSettings, config.Exporter) (TracesExporter, error) {
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateMetricsExporter creates a metrics exporter based on this config.
func (f *TestExporterFactory) CreateMetricsExporter(context.Context, ExporterCreateParams, config.Exporter) (MetricsExporter, error) {
func (f *TestExporterFactory) CreateMetricsExporter(context.Context, ExporterCreateSettings, config.Exporter) (MetricsExporter, error) {
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateLogsExporter creates a logs exporter based on this config.
func (f *TestExporterFactory) CreateLogsExporter(context.Context, ExporterCreateParams, config.Exporter) (LogsExporter, error) {
func (f *TestExporterFactory) CreateLogsExporter(context.Context, ExporterCreateSettings, config.Exporter) (LogsExporter, error) {
return nil, componenterror.ErrDataTypeIsNotSupported
}

Expand Down
18 changes: 9 additions & 9 deletions exporter/exporterhelper/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ type FactoryOption func(o *factory)
type CreateDefaultConfig func() config.Exporter

// CreateTracesExporter is the equivalent of component.ExporterFactory.CreateTracesExporter()
type CreateTracesExporter func(context.Context, component.ExporterCreateParams, config.Exporter) (component.TracesExporter, error)
type CreateTracesExporter func(context.Context, component.ExporterCreateSettings, config.Exporter) (component.TracesExporter, error)

// CreateMetricsExporter is the equivalent of component.ExporterFactory.CreateMetricsExporter()
type CreateMetricsExporter func(context.Context, component.ExporterCreateParams, config.Exporter) (component.MetricsExporter, error)
type CreateMetricsExporter func(context.Context, component.ExporterCreateSettings, config.Exporter) (component.MetricsExporter, error)

// CreateLogsExporter is the equivalent of component.ExporterFactory.CreateLogsExporter()
type CreateLogsExporter func(context.Context, component.ExporterCreateParams, config.Exporter) (component.LogsExporter, error)
type CreateLogsExporter func(context.Context, component.ExporterCreateSettings, config.Exporter) (component.LogsExporter, error)

type factory struct {
cfgType config.Type
Expand Down Expand Up @@ -94,33 +94,33 @@ func (f *factory) CreateDefaultConfig() config.Exporter {
// CreateTracesExporter creates a component.TracesExporter based on this config.
func (f *factory) CreateTracesExporter(
ctx context.Context,
params component.ExporterCreateParams,
set component.ExporterCreateSettings,
cfg config.Exporter) (component.TracesExporter, error) {
if f.createTracesExporter != nil {
return f.createTracesExporter(ctx, params, cfg)
return f.createTracesExporter(ctx, set, cfg)
}
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateMetricsExporter creates a component.MetricsExporter based on this config.
func (f *factory) CreateMetricsExporter(
ctx context.Context,
params component.ExporterCreateParams,
set component.ExporterCreateSettings,
cfg config.Exporter) (component.MetricsExporter, error) {
if f.createMetricsExporter != nil {
return f.createMetricsExporter(ctx, params, cfg)
return f.createMetricsExporter(ctx, set, cfg)
}
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateLogsExporter creates a metrics processor based on this config.
func (f *factory) CreateLogsExporter(
ctx context.Context,
params component.ExporterCreateParams,
set component.ExporterCreateSettings,
cfg config.Exporter,
) (component.LogsExporter, error) {
if f.createLogsExporter != nil {
return f.createLogsExporter(ctx, params, cfg)
return f.createLogsExporter(ctx, set, cfg)
}
return nil, componenterror.ErrDataTypeIsNotSupported
}
18 changes: 9 additions & 9 deletions exporter/exporterhelper/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func TestNewFactory(t *testing.T) {
defaultConfig)
assert.EqualValues(t, typeStr, factory.Type())
assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig())
_, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, &defaultCfg)
_, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateSettings{Logger: zap.NewNop()}, &defaultCfg)
assert.Equal(t, componenterror.ErrDataTypeIsNotSupported, err)
_, err = factory.CreateMetricsExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, &defaultCfg)
_, err = factory.CreateMetricsExporter(context.Background(), component.ExporterCreateSettings{Logger: zap.NewNop()}, &defaultCfg)
assert.Equal(t, componenterror.ErrDataTypeIsNotSupported, err)
_, err = factory.CreateLogsExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, &defaultCfg)
_, err = factory.CreateLogsExporter(context.Background(), component.ExporterCreateSettings{Logger: zap.NewNop()}, &defaultCfg)
assert.Equal(t, componenterror.ErrDataTypeIsNotSupported, err)
}

Expand All @@ -66,15 +66,15 @@ func TestNewFactory_WithConstructors(t *testing.T) {
assert.EqualValues(t, typeStr, factory.Type())
assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig())

te, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, &defaultCfg)
te, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateSettings{Logger: zap.NewNop()}, &defaultCfg)
assert.NoError(t, err)
assert.Same(t, nopTracesExporter, te)

me, err := factory.CreateMetricsExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, &defaultCfg)
me, err := factory.CreateMetricsExporter(context.Background(), component.ExporterCreateSettings{Logger: zap.NewNop()}, &defaultCfg)
assert.NoError(t, err)
assert.Same(t, nopMetricsExporter, me)

le, err := factory.CreateLogsExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, &defaultCfg)
le, err := factory.CreateLogsExporter(context.Background(), component.ExporterCreateSettings{Logger: zap.NewNop()}, &defaultCfg)
assert.NoError(t, err)
assert.Same(t, nopLogsExporter, le)
}
Expand All @@ -83,14 +83,14 @@ func defaultConfig() config.Exporter {
return &defaultCfg
}

func createTracesExporter(context.Context, component.ExporterCreateParams, config.Exporter) (component.TracesExporter, error) {
func createTracesExporter(context.Context, component.ExporterCreateSettings, config.Exporter) (component.TracesExporter, error) {
return nopTracesExporter, nil
}

func createMetricsExporter(context.Context, component.ExporterCreateParams, config.Exporter) (component.MetricsExporter, error) {
func createMetricsExporter(context.Context, component.ExporterCreateSettings, config.Exporter) (component.MetricsExporter, error) {
return nopMetricsExporter, nil
}

func createLogsExporter(context.Context, component.ExporterCreateParams, config.Exporter) (component.LogsExporter, error) {
func createLogsExporter(context.Context, component.ExporterCreateSettings, config.Exporter) (component.LogsExporter, error) {
return nopLogsExporter, nil
}
12 changes: 6 additions & 6 deletions exporter/fileexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func createDefaultConfig() config.Exporter {

func createTracesExporter(
_ context.Context,
params component.ExporterCreateParams,
set component.ExporterCreateSettings,
cfg config.Exporter,
) (component.TracesExporter, error) {
fe := exporters.GetOrAdd(cfg, func() component.Component {
return &fileExporter{path: cfg.(*Config).Path}
})
return exporterhelper.NewTracesExporter(
cfg,
params.Logger,
set.Logger,
fe.Unwrap().(*fileExporter).ConsumeTraces,
exporterhelper.WithStart(fe.Start),
exporterhelper.WithShutdown(fe.Shutdown),
Expand All @@ -63,15 +63,15 @@ func createTracesExporter(

func createMetricsExporter(
_ context.Context,
params component.ExporterCreateParams,
set component.ExporterCreateSettings,
cfg config.Exporter,
) (component.MetricsExporter, error) {
fe := exporters.GetOrAdd(cfg, func() component.Component {
return &fileExporter{path: cfg.(*Config).Path}
})
return exporterhelper.NewMetricsExporter(
cfg,
params.Logger,
set.Logger,
fe.Unwrap().(*fileExporter).ConsumeMetrics,
exporterhelper.WithStart(fe.Start),
exporterhelper.WithShutdown(fe.Shutdown),
Expand All @@ -80,15 +80,15 @@ func createMetricsExporter(

func createLogsExporter(
_ context.Context,
params component.ExporterCreateParams,
set component.ExporterCreateSettings,
cfg config.Exporter,
) (component.LogsExporter, error) {
fe := exporters.GetOrAdd(cfg, func() component.Component {
return &fileExporter{path: cfg.(*Config).Path}
})
return exporterhelper.NewLogsExporter(
cfg,
params.Logger,
set.Logger,
fe.Unwrap().(*fileExporter).ConsumeLogs,
exporterhelper.WithStart(fe.Start),
exporterhelper.WithShutdown(fe.Shutdown),
Expand Down
6 changes: 3 additions & 3 deletions exporter/fileexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestCreateMetricsExporter(t *testing.T) {
cfg := createDefaultConfig()
exp, err := createMetricsExporter(
context.Background(),
component.ExporterCreateParams{Logger: zap.NewNop()},
component.ExporterCreateSettings{Logger: zap.NewNop()},
cfg)
assert.NoError(t, err)
require.NotNil(t, exp)
Expand All @@ -46,7 +46,7 @@ func TestCreateTracesExporter(t *testing.T) {
cfg := createDefaultConfig()
exp, err := createTracesExporter(
context.Background(),
component.ExporterCreateParams{Logger: zap.NewNop()},
component.ExporterCreateSettings{Logger: zap.NewNop()},
cfg)
assert.NoError(t, err)
require.NotNil(t, exp)
Expand All @@ -56,7 +56,7 @@ func TestCreateLogsExporter(t *testing.T) {
cfg := createDefaultConfig()
exp, err := createLogsExporter(
context.Background(),
component.ExporterCreateParams{Logger: zap.NewNop()},
component.ExporterCreateSettings{Logger: zap.NewNop()},
cfg)
assert.NoError(t, err)
require.NotNil(t, exp)
Expand Down
4 changes: 2 additions & 2 deletions exporter/jaegerexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func TestLoadConfig(t *testing.T) {
},
})

params := component.ExporterCreateParams{Logger: zap.NewNop()}
te, err := factory.CreateTracesExporter(context.Background(), params, e1)
set := component.ExporterCreateSettings{Logger: zap.NewNop()}
te, err := factory.CreateTracesExporter(context.Background(), set, e1)
require.NoError(t, err)
require.NotNil(t, te)
}
2 changes: 1 addition & 1 deletion exporter/jaegerexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func TestMutualTLS(t *testing.T) {
ServerName: "localhost",
},
}
exporter, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, cfg)
exporter, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateSettings{Logger: zap.NewNop()}, cfg)
require.NoError(t, err)
err = exporter.Start(context.Background(), componenttest.NewNopHost())
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions exporter/jaegerexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func createDefaultConfig() config.Exporter {

func createTracesExporter(
_ context.Context,
params component.ExporterCreateParams,
set component.ExporterCreateSettings,
config config.Exporter,
) (component.TracesExporter, error) {

Expand All @@ -64,5 +64,5 @@ func createTracesExporter(
expCfg.ID().String())
}

return newTracesExporter(expCfg, params.Logger)
return newTracesExporter(expCfg, set.Logger)
}
10 changes: 5 additions & 5 deletions exporter/jaegerexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func TestCreateMetricsExporter(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()

params := component.ExporterCreateParams{Logger: zap.NewNop()}
_, err := factory.CreateMetricsExporter(context.Background(), params, cfg)
set := component.ExporterCreateSettings{Logger: zap.NewNop()}
_, err := factory.CreateMetricsExporter(context.Background(), set, cfg)
assert.Error(t, err, componenterror.ErrDataTypeIsNotSupported)
}

Expand All @@ -49,16 +49,16 @@ func TestCreateInstanceViaFactory(t *testing.T) {

// Default config doesn't have default endpoint so creating from it should
// fail.
params := component.ExporterCreateParams{Logger: zap.NewNop()}
exp, err := factory.CreateTracesExporter(context.Background(), params, cfg)
set := component.ExporterCreateSettings{Logger: zap.NewNop()}
exp, err := factory.CreateTracesExporter(context.Background(), set, cfg)
assert.NotNil(t, err)
assert.Equal(t, "\"jaeger\" config requires a non-empty \"endpoint\"", err.Error())
assert.Nil(t, exp)

// Endpoint doesn't have a default value so set it directly.
expCfg := cfg.(*Config)
expCfg.Endpoint = "some.target.org:12345"
exp, err = factory.CreateTracesExporter(context.Background(), params, cfg)
exp, err = factory.CreateTracesExporter(context.Background(), set, cfg)
assert.NoError(t, err)
assert.NotNil(t, exp)

Expand Down
Loading