Skip to content

Commit

Permalink
Deprecate New*ProcessorWithCreateSettings, update New*Processor to th…
Browse files Browse the repository at this point in the history
…e new API (#5915)

Signed-off-by: Bogdan <bogdandrutu@gmail.com>

Signed-off-by: Bogdan <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Aug 15, 2022
1 parent e91aa95 commit 9e90e25
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 39 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
## Unreleased

### 🛑 Breaking changes 🛑

- Replace `processorhelper.New[Traces|Metrics|Logs]Exporter` with `processorhelper.New[Traces|Metrics|Logs]ProcessorWithCreateSettings` definition (#5915)

- Replace `exporterhelper.New[Traces|Metrics|Logs]Exporter` with `exporterhelper.New[Traces|Metrics|Logs]ExporterWithContext` definition (#5914)

### 🚩 Deprecations 🚩

- Deprecate `processorhelper.New[Traces|Metrics|Logs]ProcessorWithCreateSettings` in favor of `processorhelper.New[Traces|Metrics|Logs]Exporter` (#5915)
- Deprecates `LogRecord.Flags()` and `LogRecord.SetFlags()` in favor of `LogRecord.FlagsStruct()`. (#5866)
- Deprecate `exporterhelper.New[Traces|Metrics|Logs]ExporterWithContext` in favor of `exporterhelper.New[Traces|Metrics|Logs]Exporter` (#5914)

Expand Down
6 changes: 3 additions & 3 deletions processor/memorylimiterprocessor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (f *factory) createTracesProcessor(
if err != nil {
return nil, err
}
return processorhelper.NewTracesProcessorWithCreateSettings(ctx, set, cfg, nextConsumer,
return processorhelper.NewTracesProcessor(ctx, set, cfg, nextConsumer,
memLimiter.processTraces,
processorhelper.WithCapabilities(processorCapabilities),
processorhelper.WithStart(memLimiter.start),
Expand All @@ -86,7 +86,7 @@ func (f *factory) createMetricsProcessor(
if err != nil {
return nil, err
}
return processorhelper.NewMetricsProcessorWithCreateSettings(ctx, set, cfg, nextConsumer,
return processorhelper.NewMetricsProcessor(ctx, set, cfg, nextConsumer,
memLimiter.processMetrics,
processorhelper.WithCapabilities(processorCapabilities),
processorhelper.WithStart(memLimiter.start),
Expand All @@ -103,7 +103,7 @@ func (f *factory) createLogsProcessor(
if err != nil {
return nil, err
}
return processorhelper.NewLogsProcessorWithCreateSettings(ctx, set, cfg, nextConsumer,
return processorhelper.NewLogsProcessor(ctx, set, cfg, nextConsumer,
memLimiter.processLogs,
processorhelper.WithCapabilities(processorCapabilities),
processorhelper.WithStart(memLimiter.start),
Expand Down
6 changes: 3 additions & 3 deletions processor/memorylimiterprocessor/memorylimiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestMetricsMemoryPressureResponse(t *testing.T) {
obsrep: newObsReport(),
logger: zap.NewNop(),
}
mp, err := processorhelper.NewMetricsProcessorWithCreateSettings(
mp, err := processorhelper.NewMetricsProcessor(
context.Background(),
componenttest.NewNopProcessorCreateSettings(),
&Config{
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestTraceMemoryPressureResponse(t *testing.T) {
obsrep: newObsReport(),
logger: zap.NewNop(),
}
tp, err := processorhelper.NewTracesProcessorWithCreateSettings(
tp, err := processorhelper.NewTracesProcessor(
context.Background(),
componenttest.NewNopProcessorCreateSettings(),
&Config{
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestLogMemoryPressureResponse(t *testing.T) {
obsrep: newObsReport(),
logger: zap.NewNop(),
}
lp, err := processorhelper.NewLogsProcessorWithCreateSettings(
lp, err := processorhelper.NewLogsProcessor(
context.Background(),
componenttest.NewNopProcessorCreateSettings(),
&Config{
Expand Down
12 changes: 7 additions & 5 deletions processor/processorhelper/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@ type logProcessor struct {
consumer.Logs
}

// Deprecated: [v0.58.0] use version with NewLogsProcessorWithCreateSettings.
func NewLogsProcessor(
// Deprecated: [v0.58.0] use version with NewLogsProcessor.
func NewLogsProcessorWithCreateSettings(
ctx context.Context,
set component.ProcessorCreateSettings,
cfg config.Processor,
nextConsumer consumer.Logs,
logsFunc ProcessLogsFunc,
options ...Option,
) (component.LogsProcessor, error) {
return NewLogsProcessorWithCreateSettings(context.Background(), component.ProcessorCreateSettings{}, cfg, nextConsumer, logsFunc, options...)
return NewLogsProcessor(ctx, set, cfg, nextConsumer, logsFunc, options...)
}

// NewLogsProcessorWithCreateSettings creates a LogsProcessor that ensure context propagation and the right tags are set.
func NewLogsProcessorWithCreateSettings(
// NewLogsProcessor creates a component.LogsProcessor that ensure context propagation and the right tags are set.
func NewLogsProcessor(
_ context.Context,
_ component.ProcessorCreateSettings,
cfg config.Processor,
Expand Down
12 changes: 6 additions & 6 deletions processor/processorhelper/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
var testLogsCfg = config.NewProcessorSettings(config.NewComponentID("test"))

func TestNewLogsProcessor(t *testing.T) {
lp, err := NewLogsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), newTestLProcessor(nil))
lp, err := NewLogsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), newTestLProcessor(nil))
require.NoError(t, err)

assert.True(t, lp.Capabilities().MutatesData)
Expand All @@ -44,7 +44,7 @@ func TestNewLogsProcessor(t *testing.T) {

func TestNewLogsProcessor_WithOptions(t *testing.T) {
want := errors.New("my_error")
lp, err := NewLogsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), newTestLProcessor(nil),
lp, err := NewLogsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), newTestLProcessor(nil),
WithStart(func(context.Context, component.Host) error { return want }),
WithShutdown(func(context.Context) error { return want }),
WithCapabilities(consumer.Capabilities{MutatesData: false}))
Expand All @@ -56,22 +56,22 @@ func TestNewLogsProcessor_WithOptions(t *testing.T) {
}

func TestNewLogsProcessor_NilRequiredFields(t *testing.T) {
_, err := NewLogsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), nil)
_, err := NewLogsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), nil)
assert.Error(t, err)

_, err = NewLogsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, nil, newTestLProcessor(nil))
_, err = NewLogsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, nil, newTestLProcessor(nil))
assert.Equal(t, component.ErrNilNextConsumer, err)
}

func TestNewLogsProcessor_ProcessLogError(t *testing.T) {
want := errors.New("my_error")
lp, err := NewLogsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), newTestLProcessor(want))
lp, err := NewLogsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), newTestLProcessor(want))
require.NoError(t, err)
assert.Equal(t, want, lp.ConsumeLogs(context.Background(), plog.NewLogs()))
}

func TestNewLogsProcessor_ProcessLogsErrSkipProcessingData(t *testing.T) {
lp, err := NewLogsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), newTestLProcessor(ErrSkipProcessingData))
lp, err := NewLogsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testLogsCfg, consumertest.NewNop(), newTestLProcessor(ErrSkipProcessingData))
require.NoError(t, err)
assert.Equal(t, nil, lp.ConsumeLogs(context.Background(), plog.NewLogs()))
}
Expand Down
12 changes: 7 additions & 5 deletions processor/processorhelper/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@ type metricsProcessor struct {
consumer.Metrics
}

// Deprecated: [v0.58.0] use version with NewMetricsProcessorWithCreateSettings.
func NewMetricsProcessor(
// Deprecated: [v0.58.0] use version with NewMetricsProcessor.
func NewMetricsProcessorWithCreateSettings(
ctx context.Context,
set component.ProcessorCreateSettings,
cfg config.Processor,
nextConsumer consumer.Metrics,
metricsFunc ProcessMetricsFunc,
options ...Option,
) (component.MetricsProcessor, error) {
return NewMetricsProcessorWithCreateSettings(context.Background(), component.ProcessorCreateSettings{}, cfg, nextConsumer, metricsFunc, options...)
return NewMetricsProcessor(ctx, set, cfg, nextConsumer, metricsFunc, options...)
}

// NewMetricsProcessorWithCreateSettings creates a MetricsProcessor that ensure context propagation and the right tags are set.
func NewMetricsProcessorWithCreateSettings(
// NewMetricsProcessor creates a component.MetricsProcessor that ensure context propagation and the right tags are set.
func NewMetricsProcessor(
_ context.Context,
_ component.ProcessorCreateSettings,
cfg config.Processor,
Expand Down
12 changes: 6 additions & 6 deletions processor/processorhelper/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
var testMetricsCfg = config.NewProcessorSettings(config.NewComponentID("test"))

func TestNewMetricsProcessor(t *testing.T) {
mp, err := NewMetricsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), newTestMProcessor(nil))
mp, err := NewMetricsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), newTestMProcessor(nil))
require.NoError(t, err)

assert.True(t, mp.Capabilities().MutatesData)
Expand All @@ -44,7 +44,7 @@ func TestNewMetricsProcessor(t *testing.T) {

func TestNewMetricsProcessor_WithOptions(t *testing.T) {
want := errors.New("my_error")
mp, err := NewMetricsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), newTestMProcessor(nil),
mp, err := NewMetricsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), newTestMProcessor(nil),
WithStart(func(context.Context, component.Host) error { return want }),
WithShutdown(func(context.Context) error { return want }),
WithCapabilities(consumer.Capabilities{MutatesData: false}))
Expand All @@ -56,22 +56,22 @@ func TestNewMetricsProcessor_WithOptions(t *testing.T) {
}

func TestNewMetricsProcessor_NilRequiredFields(t *testing.T) {
_, err := NewMetricsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), nil)
_, err := NewMetricsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), nil)
assert.Error(t, err)

_, err = NewMetricsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, nil, newTestMProcessor(nil))
_, err = NewMetricsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, nil, newTestMProcessor(nil))
assert.Equal(t, component.ErrNilNextConsumer, err)
}

func TestNewMetricsProcessor_ProcessMetricsError(t *testing.T) {
want := errors.New("my_error")
mp, err := NewMetricsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), newTestMProcessor(want))
mp, err := NewMetricsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), newTestMProcessor(want))
require.NoError(t, err)
assert.Equal(t, want, mp.ConsumeMetrics(context.Background(), pmetric.NewMetrics()))
}

func TestNewMetricsProcessor_ProcessMetricsErrSkipProcessingData(t *testing.T) {
mp, err := NewMetricsProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), newTestMProcessor(ErrSkipProcessingData))
mp, err := NewMetricsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testMetricsCfg, consumertest.NewNop(), newTestMProcessor(ErrSkipProcessingData))
require.NoError(t, err)
assert.Equal(t, nil, mp.ConsumeMetrics(context.Background(), pmetric.NewMetrics()))
}
Expand Down
12 changes: 7 additions & 5 deletions processor/processorhelper/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@ type tracesProcessor struct {
consumer.Traces
}

// Deprecated: [v0.58.0] use version with NewTracesProcessorWithCreateSettings.
func NewTracesProcessor(
// Deprecated: [v0.58.0] use version with NewTracesProcessor.
func NewTracesProcessorWithCreateSettings(
ctx context.Context,
set component.ProcessorCreateSettings,
cfg config.Processor,
nextConsumer consumer.Traces,
tracesFunc ProcessTracesFunc,
options ...Option,
) (component.TracesProcessor, error) {
return NewTracesProcessorWithCreateSettings(context.Background(), component.ProcessorCreateSettings{}, cfg, nextConsumer, tracesFunc, options...)
return NewTracesProcessor(ctx, set, cfg, nextConsumer, tracesFunc, options...)
}

// NewTracesProcessorWithCreateSettings creates a TracesProcessor that ensure context propagation and the right tags are set.
func NewTracesProcessorWithCreateSettings(
// NewTracesProcessor creates a component.TracesProcessor that ensure context propagation and the right tags are set.
func NewTracesProcessor(
_ context.Context,
_ component.ProcessorCreateSettings,
cfg config.Processor,
Expand Down
12 changes: 6 additions & 6 deletions processor/processorhelper/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
var testTracesCfg = config.NewProcessorSettings(config.NewComponentID("test"))

func TestNewTracesProcessor(t *testing.T) {
tp, err := NewTracesProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), newTestTProcessor(nil))
tp, err := NewTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), newTestTProcessor(nil))
require.NoError(t, err)

assert.True(t, tp.Capabilities().MutatesData)
Expand All @@ -44,7 +44,7 @@ func TestNewTracesProcessor(t *testing.T) {

func TestNewTracesProcessor_WithOptions(t *testing.T) {
want := errors.New("my_error")
tp, err := NewTracesProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), newTestTProcessor(nil),
tp, err := NewTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), newTestTProcessor(nil),
WithStart(func(context.Context, component.Host) error { return want }),
WithShutdown(func(context.Context) error { return want }),
WithCapabilities(consumer.Capabilities{MutatesData: false}))
Expand All @@ -56,22 +56,22 @@ func TestNewTracesProcessor_WithOptions(t *testing.T) {
}

func TestNewTracesProcessor_NilRequiredFields(t *testing.T) {
_, err := NewTracesProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), nil)
_, err := NewTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), nil)
assert.Error(t, err)

_, err = NewTracesProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, nil, newTestTProcessor(nil))
_, err = NewTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, nil, newTestTProcessor(nil))
assert.Equal(t, component.ErrNilNextConsumer, err)
}

func TestNewTracesProcessor_ProcessTraceError(t *testing.T) {
want := errors.New("my_error")
tp, err := NewTracesProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), newTestTProcessor(want))
tp, err := NewTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), newTestTProcessor(want))
require.NoError(t, err)
assert.Equal(t, want, tp.ConsumeTraces(context.Background(), ptrace.NewTraces()))
}

func TestNewTracesProcessor_ProcessTracesErrSkipProcessingData(t *testing.T) {
tp, err := NewTracesProcessorWithCreateSettings(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), newTestTProcessor(ErrSkipProcessingData))
tp, err := NewTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), &testTracesCfg, consumertest.NewNop(), newTestTProcessor(ErrSkipProcessingData))
require.NoError(t, err)
assert.Equal(t, nil, tp.ConsumeTraces(context.Background(), ptrace.NewTraces()))
}
Expand Down

0 comments on commit 9e90e25

Please sign in to comment.