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

[exporter] deprecate CreateSettings -> Settings #10335

Merged
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
28 changes: 28 additions & 0 deletions .chloggen/codeboten_create-settings-exporter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: deprecation

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: exporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate CreateSettings and NewNopCreateSettings

# One or more tracking issues or pull requests related to the change
issues: [9428]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
The following methods are being renamed:
- exporter.CreateSettings -> exporter.Settings
- exporter.NewNopCreateSettings -> exporter.NewNopSettings

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
2 changes: 1 addition & 1 deletion cmd/mdatagen/templates/component_telemetry_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type componentTestTelemetry struct {
meterProvider *sdkmetric.MeterProvider
}

{{- if isReceiver }}
{{- if (or isExporter isReceiver) }}
func (tt *componentTestTelemetry) NewSettings() {{ .Status.Class }}.Settings {
settings := {{ .Status.Class }}test.NewNopSettings()
settings.MeterProvider = tt.meterProvider
Expand Down
12 changes: 6 additions & 6 deletions cmd/mdatagen/templates/component_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,28 @@ func TestComponentLifecycle(t *testing.T) {

tests := []struct{
name string
createFn func(ctx context.Context, set exporter.CreateSettings, cfg component.Config) (component.Component, error)
createFn func(ctx context.Context, set exporter.Settings, cfg component.Config) (component.Component, error)
}{
{{ if supportsLogs }}
{
name: "logs",
createFn: func(ctx context.Context, set exporter.CreateSettings, cfg component.Config) (component.Component, error) {
createFn: func(ctx context.Context, set exporter.Settings, cfg component.Config) (component.Component, error) {
return factory.CreateLogsExporter(ctx, set, cfg)
},
},
{{ end }}
{{ if supportsMetrics }}
{
name: "metrics",
createFn: func(ctx context.Context, set exporter.CreateSettings, cfg component.Config) (component.Component, error) {
createFn: func(ctx context.Context, set exporter.Settings, cfg component.Config) (component.Component, error) {
return factory.CreateMetricsExporter(ctx, set, cfg)
},
},
{{ end }}
{{ if supportsTraces }}
{
name: "traces",
createFn: func(ctx context.Context, set exporter.CreateSettings, cfg component.Config) (component.Component, error) {
createFn: func(ctx context.Context, set exporter.Settings, cfg component.Config) (component.Component, error) {
return factory.CreateTracesExporter(ctx, set, cfg)
},
},
Expand All @@ -107,7 +107,7 @@ func TestComponentLifecycle(t *testing.T) {
for _, test := range tests {
{{- if not .Tests.SkipShutdown }}
t.Run(test.name + "-shutdown", func(t *testing.T) {
c, err := test.createFn(context.Background(), exportertest.NewNopCreateSettings(), cfg)
c, err := test.createFn(context.Background(), exportertest.NewNopSettings(), cfg)
require.NoError(t, err)
err = c.Shutdown(context.Background())
require.NoError(t, err)
Expand All @@ -116,7 +116,7 @@ func TestComponentLifecycle(t *testing.T) {

{{- if not .Tests.SkipLifecycle }}
t.Run(test.name + "-lifecycle", func(t *testing.T) {
c, err := test.createFn(context.Background(), exportertest.NewNopCreateSettings(), cfg)
c, err := test.createFn(context.Background(), exportertest.NewNopSettings(), cfg)
require.NoError(t, err)
host := componenttest.NewNopHost()
err = c.Start(context.Background(), host)
Expand Down
6 changes: 3 additions & 3 deletions exporter/debugexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func TestTracesExporterNoErrors(t *testing.T) {
lte, err := createTracesExporter(context.Background(), exportertest.NewNopCreateSettings(), createDefaultConfig())
lte, err := createTracesExporter(context.Background(), exportertest.NewNopSettings(), createDefaultConfig())
require.NotNil(t, lte)
assert.NoError(t, err)

Expand All @@ -32,7 +32,7 @@ func TestTracesExporterNoErrors(t *testing.T) {
}

func TestMetricsExporterNoErrors(t *testing.T) {
lme, err := createMetricsExporter(context.Background(), exportertest.NewNopCreateSettings(), createDefaultConfig())
lme, err := createMetricsExporter(context.Background(), exportertest.NewNopSettings(), createDefaultConfig())
require.NotNil(t, lme)
assert.NoError(t, err)

Expand All @@ -46,7 +46,7 @@ func TestMetricsExporterNoErrors(t *testing.T) {
}

func TestLogsExporterNoErrors(t *testing.T) {
lle, err := createLogsExporter(context.Background(), exportertest.NewNopCreateSettings(), createDefaultConfig())
lle, err := createLogsExporter(context.Background(), exportertest.NewNopSettings(), createDefaultConfig())
require.NotNil(t, lle)
assert.NoError(t, err)

Expand Down
6 changes: 3 additions & 3 deletions exporter/debugexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func createDefaultConfig() component.Config {
}
}

func createTracesExporter(ctx context.Context, set exporter.CreateSettings, config component.Config) (exporter.Traces, error) {
func createTracesExporter(ctx context.Context, set exporter.Settings, config component.Config) (exporter.Traces, error) {
cfg := config.(*Config)
exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger)
debugExporter := newDebugExporter(exporterLogger, cfg.Verbosity)
Expand All @@ -58,7 +58,7 @@ func createTracesExporter(ctx context.Context, set exporter.CreateSettings, conf
)
}

func createMetricsExporter(ctx context.Context, set exporter.CreateSettings, config component.Config) (exporter.Metrics, error) {
func createMetricsExporter(ctx context.Context, set exporter.Settings, config component.Config) (exporter.Metrics, error) {
cfg := config.(*Config)
exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger)
debugExporter := newDebugExporter(exporterLogger, cfg.Verbosity)
Expand All @@ -70,7 +70,7 @@ func createMetricsExporter(ctx context.Context, set exporter.CreateSettings, con
)
}

func createLogsExporter(ctx context.Context, set exporter.CreateSettings, config component.Config) (exporter.Logs, error) {
func createLogsExporter(ctx context.Context, set exporter.Settings, config component.Config) (exporter.Logs, error) {
cfg := config.(*Config)
exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger)
debugExporter := newDebugExporter(exporterLogger, cfg.Verbosity)
Expand Down
6 changes: 3 additions & 3 deletions exporter/debugexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestCreateMetricsExporter(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()

me, err := factory.CreateMetricsExporter(context.Background(), exportertest.NewNopCreateSettings(), cfg)
me, err := factory.CreateMetricsExporter(context.Background(), exportertest.NewNopSettings(), cfg)
assert.NoError(t, err)
assert.NotNil(t, me)
}
Expand All @@ -33,7 +33,7 @@ func TestCreateTracesExporter(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()

te, err := factory.CreateTracesExporter(context.Background(), exportertest.NewNopCreateSettings(), cfg)
te, err := factory.CreateTracesExporter(context.Background(), exportertest.NewNopSettings(), cfg)
assert.NoError(t, err)
assert.NotNil(t, te)
}
Expand All @@ -42,7 +42,7 @@ func TestCreateLogsExporter(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()

te, err := factory.CreateLogsExporter(context.Background(), exportertest.NewNopCreateSettings(), cfg)
te, err := factory.CreateLogsExporter(context.Background(), exportertest.NewNopSettings(), cfg)
assert.NoError(t, err)
assert.NotNil(t, te)
}
12 changes: 6 additions & 6 deletions exporter/debugexporter/generated_component_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 19 additions & 14 deletions exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ type Logs interface {
consumer.Logs
}

// CreateSettings configures exporter creators.
type CreateSettings struct {
// CreateSettings configures Exporter creators.
//
// Deprecated: [v0.103.0] Use exporter.Settings instead.
type CreateSettings = Settings

// Settings configures exporter creators.
type Settings struct {
// ID returns the ID of the component that will be created.
ID component.ID

Expand All @@ -52,23 +57,23 @@ type Factory interface {
// CreateTracesExporter creates a TracesExporter 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, set CreateSettings, cfg component.Config) (Traces, error)
CreateTracesExporter(ctx context.Context, set Settings, cfg component.Config) (Traces, error)

// TracesExporterStability gets the stability level of the TracesExporter.
TracesExporterStability() component.StabilityLevel

// CreateMetricsExporter creates a MetricsExporter 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, set CreateSettings, cfg component.Config) (Metrics, error)
CreateMetricsExporter(ctx context.Context, set Settings, cfg component.Config) (Metrics, error)

// MetricsExporterStability gets the stability level of the MetricsExporter.
MetricsExporterStability() component.StabilityLevel

// CreateLogsExporter creates a LogsExporter 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, set CreateSettings, cfg component.Config) (Logs, error)
CreateLogsExporter(ctx context.Context, set Settings, cfg component.Config) (Logs, error)

// LogsExporterStability gets the stability level of the LogsExporter.
LogsExporterStability() component.StabilityLevel
Expand All @@ -92,32 +97,32 @@ func (f factoryOptionFunc) applyExporterFactoryOption(o *factory) {
}

// CreateTracesFunc is the equivalent of Factory.CreateTraces.
type CreateTracesFunc func(context.Context, CreateSettings, component.Config) (Traces, error)
type CreateTracesFunc func(context.Context, Settings, component.Config) (Traces, error)

// CreateTracesExporter implements ExporterFactory.CreateTracesExporter().
func (f CreateTracesFunc) CreateTracesExporter(ctx context.Context, set CreateSettings, cfg component.Config) (Traces, error) {
func (f CreateTracesFunc) CreateTracesExporter(ctx context.Context, set Settings, cfg component.Config) (Traces, error) {
if f == nil {
return nil, component.ErrDataTypeIsNotSupported
}
return f(ctx, set, cfg)
}

// CreateMetricsFunc is the equivalent of Factory.CreateMetrics.
type CreateMetricsFunc func(context.Context, CreateSettings, component.Config) (Metrics, error)
type CreateMetricsFunc func(context.Context, Settings, component.Config) (Metrics, error)

// CreateMetricsExporter implements ExporterFactory.CreateMetricsExporter().
func (f CreateMetricsFunc) CreateMetricsExporter(ctx context.Context, set CreateSettings, cfg component.Config) (Metrics, error) {
func (f CreateMetricsFunc) CreateMetricsExporter(ctx context.Context, set Settings, cfg component.Config) (Metrics, error) {
if f == nil {
return nil, component.ErrDataTypeIsNotSupported
}
return f(ctx, set, cfg)
}

// CreateLogsFunc is the equivalent of Factory.CreateLogs.
type CreateLogsFunc func(context.Context, CreateSettings, component.Config) (Logs, error)
type CreateLogsFunc func(context.Context, Settings, component.Config) (Logs, error)

// CreateLogsExporter implements Factory.CreateLogsExporter().
func (f CreateLogsFunc) CreateLogsExporter(ctx context.Context, set CreateSettings, cfg component.Config) (Logs, error) {
func (f CreateLogsFunc) CreateLogsExporter(ctx context.Context, set Settings, cfg component.Config) (Logs, error) {
if f == nil {
return nil, component.ErrDataTypeIsNotSupported
}
Expand Down Expand Up @@ -214,7 +219,7 @@ func NewBuilder(cfgs map[component.ID]component.Config, factories map[component.
}

// CreateTraces creates a Traces exporter based on the settings and config.
func (b *Builder) CreateTraces(ctx context.Context, set CreateSettings) (Traces, error) {
func (b *Builder) CreateTraces(ctx context.Context, set Settings) (Traces, error) {
cfg, existsCfg := b.cfgs[set.ID]
if !existsCfg {
return nil, fmt.Errorf("exporter %q is not configured", set.ID)
Expand All @@ -230,7 +235,7 @@ func (b *Builder) CreateTraces(ctx context.Context, set CreateSettings) (Traces,
}

// CreateMetrics creates a Metrics exporter based on the settings and config.
func (b *Builder) CreateMetrics(ctx context.Context, set CreateSettings) (Metrics, error) {
func (b *Builder) CreateMetrics(ctx context.Context, set Settings) (Metrics, error) {
cfg, existsCfg := b.cfgs[set.ID]
if !existsCfg {
return nil, fmt.Errorf("exporter %q is not configured", set.ID)
Expand All @@ -246,7 +251,7 @@ func (b *Builder) CreateMetrics(ctx context.Context, set CreateSettings) (Metric
}

// CreateLogs creates a Logs exporter based on the settings and config.
func (b *Builder) CreateLogs(ctx context.Context, set CreateSettings) (Logs, error) {
func (b *Builder) CreateLogs(ctx context.Context, set Settings) (Logs, error) {
cfg, existsCfg := b.cfgs[set.ID]
if !existsCfg {
return nil, fmt.Errorf("exporter %q is not configured", set.ID)
Expand Down
22 changes: 11 additions & 11 deletions exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ func TestNewFactory(t *testing.T) {
func() component.Config { return &defaultCfg })
assert.EqualValues(t, testType, factory.Type())
assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig())
_, err := factory.CreateTracesExporter(context.Background(), CreateSettings{}, &defaultCfg)
_, err := factory.CreateTracesExporter(context.Background(), Settings{}, &defaultCfg)
assert.Error(t, err)
_, err = factory.CreateMetricsExporter(context.Background(), CreateSettings{}, &defaultCfg)
_, err = factory.CreateMetricsExporter(context.Background(), Settings{}, &defaultCfg)
assert.Error(t, err)
_, err = factory.CreateLogsExporter(context.Background(), CreateSettings{}, &defaultCfg)
_, err = factory.CreateLogsExporter(context.Background(), Settings{}, &defaultCfg)
assert.Error(t, err)
}

Expand All @@ -44,15 +44,15 @@ func TestNewFactoryWithOptions(t *testing.T) {
assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig())

assert.Equal(t, component.StabilityLevelDevelopment, factory.TracesExporterStability())
_, err := factory.CreateTracesExporter(context.Background(), CreateSettings{}, &defaultCfg)
_, err := factory.CreateTracesExporter(context.Background(), Settings{}, &defaultCfg)
assert.NoError(t, err)

assert.Equal(t, component.StabilityLevelAlpha, factory.MetricsExporterStability())
_, err = factory.CreateMetricsExporter(context.Background(), CreateSettings{}, &defaultCfg)
_, err = factory.CreateMetricsExporter(context.Background(), Settings{}, &defaultCfg)
assert.NoError(t, err)

assert.Equal(t, component.StabilityLevelDeprecated, factory.LogsExporterStability())
_, err = factory.CreateLogsExporter(context.Background(), CreateSettings{}, &defaultCfg)
_, err = factory.CreateLogsExporter(context.Background(), Settings{}, &defaultCfg)
assert.NoError(t, err)
}

Expand Down Expand Up @@ -220,20 +220,20 @@ type nopExporter struct {
consumertest.Consumer
}

func createTraces(context.Context, CreateSettings, component.Config) (Traces, error) {
func createTraces(context.Context, Settings, component.Config) (Traces, error) {
return nopInstance, nil
}

func createMetrics(context.Context, CreateSettings, component.Config) (Metrics, error) {
func createMetrics(context.Context, Settings, component.Config) (Metrics, error) {
return nopInstance, nil
}

func createLogs(context.Context, CreateSettings, component.Config) (Logs, error) {
func createLogs(context.Context, Settings, component.Config) (Logs, error) {
return nopInstance, nil
}

func createSettings(id component.ID) CreateSettings {
return CreateSettings{
func createSettings(id component.ID) Settings {
return Settings{
ID: id,
TelemetrySettings: componenttest.NewNopTelemetrySettings(),
BuildInfo: component.NewDefaultBuildInfo(),
Expand Down
2 changes: 1 addition & 1 deletion exporter/exporterhelper/batch_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type batchSender struct {
}

// newBatchSender returns a new batch consumer component.
func newBatchSender(cfg exporterbatcher.Config, set exporter.CreateSettings,
func newBatchSender(cfg exporterbatcher.Config, set exporter.Settings,
mf exporterbatcher.BatchMergeFunc[Request], msf exporterbatcher.BatchMergeSplitFunc[Request]) *batchSender {
bs := &batchSender{
activeBatch: newEmptyBatch(),
Expand Down
Loading
Loading