Skip to content

Commit

Permalink
Move exporter Factory and types to exporter package (open-telemetry#6672
Browse files Browse the repository at this point in the history
)

Signed-off-by: Bogdan Drutu <[email protected]>

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
jaronoff97 committed Dec 14, 2022
1 parent d63042b commit 9278bee
Show file tree
Hide file tree
Showing 32 changed files with 408 additions and 275 deletions.
25 changes: 25 additions & 0 deletions .chloggen/deprecatecompexp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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: component

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate Exporter related types/funcs from component package in favor of exporter package.

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

# (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: |-
- `component.ExporterCreateSettings` -> `exporter.CreateSettings`
- `component.CreateTracesExporterFunc` -> `exporter.CreateTracesFunc`
- `component.CreateMetricsExporterFunc` -> `exporter.CreateMetricsFunc`
- `component.CreateLogsExporterFunc` -> `exporter.CreateLogsFunc`
- `component.ExporterFactory` -> `exporter.Factory`
- `component.NewExporterFactory` -> `exporter.NewFactory`
- `component.MakeExporterFactoryMap` -> `exporter.MakeFactoryMap`
- `componenttest.NewNopExporterCreateSettings` -> `exportertest.NewNopCreateSettings`
- `componenttest.NewNopExporterFactory` -> `exportertest.NewNopFactory`
23 changes: 12 additions & 11 deletions component/componenttest/nop_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/exporter"
)

// NewNopExporterCreateSettings returns a new nop settings for Create*Exporter functions.
func NewNopExporterCreateSettings() component.ExporterCreateSettings {
return component.ExporterCreateSettings{
func NewNopExporterCreateSettings() exporter.CreateSettings {
return exporter.CreateSettings{
TelemetrySettings: NewNopTelemetrySettings(),
BuildInfo: component.NewDefaultBuildInfo(),
}
Expand All @@ -34,30 +35,30 @@ type nopExporterConfig struct {
config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
}

// NewNopExporterFactory returns a component.ExporterFactory that constructs nop exporters.
func NewNopExporterFactory() component.ExporterFactory {
return component.NewExporterFactory(
// NewNopExporterFactory returns an exporter.Factory that constructs nop exporters.
func NewNopExporterFactory() exporter.Factory {
return exporter.NewFactory(
"nop",
func() component.Config {
return &nopExporterConfig{
ExporterSettings: config.NewExporterSettings(component.NewID("nop")),
}
},
component.WithTracesExporter(createTracesExporter, component.StabilityLevelStable),
component.WithMetricsExporter(createMetricsExporter, component.StabilityLevelStable),
component.WithLogsExporter(createLogsExporter, component.StabilityLevelStable),
exporter.WithTraces(createTracesExporter, component.StabilityLevelStable),
exporter.WithMetrics(createMetricsExporter, component.StabilityLevelStable),
exporter.WithLogs(createLogsExporter, component.StabilityLevelStable),
)
}

func createTracesExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.TracesExporter, error) {
func createTracesExporter(context.Context, exporter.CreateSettings, component.Config) (exporter.Traces, error) {
return nopExporterInstance, nil
}

func createMetricsExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.MetricsExporter, error) {
func createMetricsExporter(context.Context, exporter.CreateSettings, component.Config) (exporter.Metrics, error) {
return nopExporterInstance, nil
}

func createLogsExporter(context.Context, component.ExporterCreateSettings, component.Config) (component.LogsExporter, error) {
func createLogsExporter(context.Context, exporter.CreateSettings, component.Config) (exporter.Logs, error) {
return nopExporterInstance, nil
}

Expand Down
1 change: 1 addition & 0 deletions component/componenttest/nop_factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func NopFactories() (component.Factories, error) {
return component.Factories{}, err
}

//nolint:staticcheck
if factories.Exporters, err = component.MakeExporterFactoryMap(NewNopExporterFactory()); err != nil {
return component.Factories{}, err
}
Expand Down
29 changes: 13 additions & 16 deletions component/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ type ExporterConfig = Config
// Deprecated: [v0.67.0] use UnmarshalConfig.
var UnmarshalExporterConfig = UnmarshalConfig

// TracesExporter is an Exporter that can consume traces.
// Deprecated: [v0.67.0] use exporter.Traces.
type TracesExporter interface {
Component
consumer.Traces
}

// MetricsExporter is an Exporter that can consume metrics.
// Deprecated: [v0.67.0] use exporter.Metrics.
type MetricsExporter interface {
Component
consumer.Metrics
}

// LogsExporter is an Exporter that can consume logs.
// Deprecated: [v0.67.0] use exporter.Logs.
type LogsExporter interface {
Component
consumer.Logs
}

// ExporterCreateSettings configures Exporter creators.
// Deprecated: [v0.67.0] use exporter.CreateSettings.
type ExporterCreateSettings struct {
// ID returns the ID of the component that will be created.
ID ID
Expand All @@ -55,10 +55,7 @@ type ExporterCreateSettings struct {
BuildInfo BuildInfo
}

// ExporterFactory is factory interface for exporters.
//
// This interface cannot be directly implemented. Implementations must
// use the NewExporterFactory to implement it.
// Deprecated: [v0.67.0] use exporter.Factory.
type ExporterFactory interface {
Factory

Expand Down Expand Up @@ -87,7 +84,7 @@ type ExporterFactory interface {
LogsExporterStability() StabilityLevel
}

// ExporterFactoryOption apply changes to ExporterOptions.
// Deprecated: [v0.67.0] use exporter.FactoryOption.
type ExporterFactoryOption interface {
// applyExporterFactoryOption applies the option.
applyExporterFactoryOption(o *exporterFactory)
Expand All @@ -105,7 +102,7 @@ func (f exporterFactoryOptionFunc) applyExporterFactoryOption(o *exporterFactory
// Deprecated: [v0.67.0] use CreateDefaultConfigFunc.
type ExporterCreateDefaultConfigFunc = CreateDefaultConfigFunc

// CreateTracesExporterFunc is the equivalent of ExporterFactory.CreateTracesExporter().
// Deprecated: [v0.67.0] use exporter.CreateTracesFunc.
type CreateTracesExporterFunc func(context.Context, ExporterCreateSettings, Config) (TracesExporter, error)

// CreateTracesExporter implements ExporterFactory.CreateTracesExporter().
Expand All @@ -116,7 +113,7 @@ func (f CreateTracesExporterFunc) CreateTracesExporter(ctx context.Context, set
return f(ctx, set, cfg)
}

// CreateMetricsExporterFunc is the equivalent of ExporterFactory.CreateMetricsExporter().
// Deprecated: [v0.67.0] use exporter.CreateMetricsFunc.
type CreateMetricsExporterFunc func(context.Context, ExporterCreateSettings, Config) (MetricsExporter, error)

// CreateMetricsExporter implements ExporterFactory.CreateMetricsExporter().
Expand All @@ -127,7 +124,7 @@ func (f CreateMetricsExporterFunc) CreateMetricsExporter(ctx context.Context, se
return f(ctx, set, cfg)
}

// CreateLogsExporterFunc is the equivalent of ExporterFactory.CreateLogsExporter().
// Deprecated: [v0.67.0] use exporter.CreateLogsFunc.
type CreateLogsExporterFunc func(context.Context, ExporterCreateSettings, Config) (LogsExporter, error)

// CreateLogsExporter implements ExporterFactory.CreateLogsExporter().
Expand Down Expand Up @@ -160,31 +157,31 @@ func (e exporterFactory) LogsExporterStability() StabilityLevel {
return e.logsStabilityLevel
}

// WithTracesExporter overrides the default "error not supported" implementation for CreateTracesExporter and the default "undefined" stability level.
// Deprecated: [v0.67.0] use exporter.WithTraces.
func WithTracesExporter(createTracesExporter CreateTracesExporterFunc, sl StabilityLevel) ExporterFactoryOption {
return exporterFactoryOptionFunc(func(o *exporterFactory) {
o.tracesStabilityLevel = sl
o.CreateTracesExporterFunc = createTracesExporter
})
}

// WithMetricsExporter overrides the default "error not supported" implementation for CreateMetricsExporter and the default "undefined" stability level.
// Deprecated: [v0.67.0] use exporter.WithMetrics.
func WithMetricsExporter(createMetricsExporter CreateMetricsExporterFunc, sl StabilityLevel) ExporterFactoryOption {
return exporterFactoryOptionFunc(func(o *exporterFactory) {
o.metricsStabilityLevel = sl
o.CreateMetricsExporterFunc = createMetricsExporter
})
}

// WithLogsExporter overrides the default "error not supported" implementation for CreateLogsExporter and the default "undefined" stability level.
// Deprecated: [v0.67.0] use exporter.WithLogs.
func WithLogsExporter(createLogsExporter CreateLogsExporterFunc, sl StabilityLevel) ExporterFactoryOption {
return exporterFactoryOptionFunc(func(o *exporterFactory) {
o.logsStabilityLevel = sl
o.CreateLogsExporterFunc = createLogsExporter
})
}

// NewExporterFactory returns a ExporterFactory.
// Deprecated: [v0.67.0] use exporter.NewFactory.
func NewExporterFactory(cfgType Type, createDefaultConfig CreateDefaultConfigFunc, options ...ExporterFactoryOption) ExporterFactory {
f := &exporterFactory{
baseFactory: baseFactory{
Expand Down
80 changes: 0 additions & 80 deletions component/exporter_test.go

This file was deleted.

4 changes: 1 addition & 3 deletions component/factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ func MakeProcessorFactoryMap(factories ...ProcessorFactory) (map[Type]ProcessorF
return fMap, nil
}

// MakeExporterFactoryMap takes a list of exporter factories and returns a map
// with factory type as keys. It returns a non-nil error when more than one factories
// have the same type.
// Deprecated: [v0.67.0] use exporter.MakeFactoryMap
func MakeExporterFactoryMap(factories ...ExporterFactory) (map[Type]ExporterFactory, error) {
fMap := map[Type]ExporterFactory{}
for _, f := range factories {
Expand Down
38 changes: 0 additions & 38 deletions component/factories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,41 +95,3 @@ func TestMakeProcessorFactoryMap(t *testing.T) {
})
}
}

func TestMakeExporterFactoryMap(t *testing.T) {
type testCase struct {
name string
in []ExporterFactory
out map[Type]ExporterFactory
}

p1 := NewExporterFactory("p1", nil)
p2 := NewExporterFactory("p2", nil)
testCases := []testCase{
{
name: "different names",
in: []ExporterFactory{p1, p2},
out: map[Type]ExporterFactory{
p1.Type(): p1,
p2.Type(): p2,
},
},
{
name: "same name",
in: []ExporterFactory{p1, p2, NewExporterFactory("p1", nil)},
},
}

for i := range testCases {
tt := testCases[i]
t.Run(tt.name, func(t *testing.T) {
out, err := MakeExporterFactoryMap(tt.in...)
if tt.out == nil {
assert.Error(t, err)
return
}
assert.NoError(t, err)
assert.Equal(t, tt.out, out)
})
}
}
Loading

0 comments on commit 9278bee

Please sign in to comment.