Skip to content

Commit

Permalink
[exporter] deprecate CreateSettings -> Settings
Browse files Browse the repository at this point in the history
This deprecates CreateSettings in favour of Settings. NewNopCreateSettings is also being deprecated in favour of NewNopSettings

Part of #9428

Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
codeboten committed Jun 5, 2024
1 parent fde83fb commit 77ad8bf
Show file tree
Hide file tree
Showing 31 changed files with 210 additions and 170 deletions.
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
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
4 changes: 2 additions & 2 deletions exporter/exporterhelper/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ type baseExporter struct {
marshaler exporterqueue.Marshaler[Request]
unmarshaler exporterqueue.Unmarshaler[Request]

set exporter.CreateSettings
set exporter.Settings
obsrep *ObsReport

// Message for the user to be added with an export failure message.
Expand All @@ -249,7 +249,7 @@ type baseExporter struct {
consumerOptions []consumer.Option
}

func newBaseExporter(set exporter.CreateSettings, signal component.DataType, osf obsrepSenderFactory, options ...Option) (*baseExporter, error) {
func newBaseExporter(set exporter.Settings, signal component.DataType, osf obsrepSenderFactory, options ...Option) (*baseExporter, error) {
obsReport, err := NewObsReport(ObsReportSettings{ExporterID: set.ID, ExporterCreateSettings: set})
if err != nil {
return nil, err
Expand Down
12 changes: 6 additions & 6 deletions exporter/exporterhelper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ var (
defaultType = component.MustNewType("test")
defaultDataType = component.DataTypeMetrics
defaultID = component.NewID(defaultType)
defaultSettings = func() exporter.CreateSettings {
set := exportertest.NewNopCreateSettings()
defaultSettings = func() exporter.Settings {
set := exportertest.NewNopSettings()
set.ID = defaultID
return set
}()
Expand Down Expand Up @@ -67,24 +67,24 @@ func checkStatus(t *testing.T, sd sdktrace.ReadOnlySpan, err error) {
}

func TestQueueOptionsWithRequestExporter(t *testing.T) {
bs, err := newBaseExporter(exportertest.NewNopCreateSettings(), defaultDataType, newNoopObsrepSender,
bs, err := newBaseExporter(exportertest.NewNopSettings(), defaultDataType, newNoopObsrepSender,
WithRetry(configretry.NewDefaultBackOffConfig()))
require.Nil(t, err)
require.Nil(t, bs.marshaler)
require.Nil(t, bs.unmarshaler)
_, err = newBaseExporter(exportertest.NewNopCreateSettings(), defaultDataType, newNoopObsrepSender,
_, err = newBaseExporter(exportertest.NewNopSettings(), defaultDataType, newNoopObsrepSender,
WithRetry(configretry.NewDefaultBackOffConfig()), WithQueue(NewDefaultQueueSettings()))
require.Error(t, err)

_, err = newBaseExporter(exportertest.NewNopCreateSettings(), defaultDataType, newNoopObsrepSender,
_, err = newBaseExporter(exportertest.NewNopSettings(), defaultDataType, newNoopObsrepSender,
withMarshaler(mockRequestMarshaler), withUnmarshaler(mockRequestUnmarshaler(&mockRequest{})),
WithRetry(configretry.NewDefaultBackOffConfig()),
WithRequestQueue(exporterqueue.NewDefaultConfig(), exporterqueue.NewMemoryQueueFactory[Request]()))
require.Error(t, err)
}

func TestBaseExporterLogging(t *testing.T) {
set := exportertest.NewNopCreateSettings()
set := exportertest.NewNopSettings()
logger, observed := observer.New(zap.DebugLevel)
set.Logger = zap.New(logger)
rCfg := configretry.NewDefaultBackOffConfig()
Expand Down
4 changes: 2 additions & 2 deletions exporter/exporterhelper/generated_component_telemetry_test.go

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

4 changes: 2 additions & 2 deletions exporter/exporterhelper/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type logsExporter struct {
// NewLogsExporter creates an exporter.Logs that records observability metrics and wraps every request with a Span.
func NewLogsExporter(
ctx context.Context,
set exporter.CreateSettings,
set exporter.Settings,
cfg component.Config,
pusher consumer.ConsumeLogsFunc,
options ...Option,
Expand Down Expand Up @@ -106,7 +106,7 @@ func requestFromLogs(pusher consumer.ConsumeLogsFunc) RequestFromLogsFunc {
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
func NewLogsRequestExporter(
_ context.Context,
set exporter.CreateSettings,
set exporter.Settings,
converter RequestFromLogsFunc,
options ...Option,
) (exporter.Logs, error) {
Expand Down
Loading

0 comments on commit 77ad8bf

Please sign in to comment.