Skip to content

Commit

Permalink
Remove old interfaces for processor component
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Aug 19, 2020
1 parent 0079740 commit 1f20ccf
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 326 deletions.
6 changes: 3 additions & 3 deletions component/factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Factories struct {
Receivers map[configmodels.Type]ReceiverFactory

// Processors maps processor type names in the config to the respective factory.
Processors map[configmodels.Type]ProcessorFactoryBase
Processors map[configmodels.Type]ProcessorFactory

// Exporters maps exporter type names in the config to the respective factory.
Exporters map[configmodels.Type]ExporterFactoryBase
Expand All @@ -53,8 +53,8 @@ func MakeReceiverFactoryMap(factories ...ReceiverFactory) (map[configmodels.Type
// MakeProcessorFactoryMap takes a list of processor 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.
func MakeProcessorFactoryMap(factories ...ProcessorFactoryBase) (map[configmodels.Type]ProcessorFactoryBase, error) {
fMap := map[configmodels.Type]ProcessorFactoryBase{}
func MakeProcessorFactoryMap(factories ...ProcessorFactory) (map[configmodels.Type]ProcessorFactory, error) {
fMap := map[configmodels.Type]ProcessorFactory{}
for _, f := range factories {
if _, ok := fMap[f.Type()]; ok {
return fMap, fmt.Errorf("duplicate processor factory %q", f.Type())
Expand Down
79 changes: 22 additions & 57 deletions component/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,16 @@ type Processor interface {
GetCapabilities() ProcessorCapabilities
}

// TraceProcessorBase is a common interface for TraceProcessor and TraceProcessorOld
type TraceProcessorBase interface {
Processor
}

// TraceProcessorOld is a processor that can consume old-style traces.
type TraceProcessorOld interface {
consumer.TraceConsumerOld
TraceProcessorBase
}

// TraceProcessor is a processor that can consume traces.
type TraceProcessor interface {
consumer.TraceConsumer
TraceProcessorBase
}

// MetricsProcessorBase is a common interface for MetricsProcessor and MetricsProcessorV2
type MetricsProcessorBase interface {
Processor
}

// MetricsProcessor is a processor that can consume old-style metrics.
type MetricsProcessorOld interface {
consumer.MetricsConsumerOld
MetricsProcessorBase
consumer.TraceConsumer
}

// MetricsProcessor is a processor that can consume metrics.
type MetricsProcessor interface {
Processor
consumer.MetricsConsumer
MetricsProcessorBase
}

// LogsProcessor is a processor that can consume logs.
Expand All @@ -82,37 +60,6 @@ type ProcessorCapabilities struct {
MutatesConsumedData bool
}

// ProcessorFactoryBase defines the common functions for all processor factories.
type ProcessorFactoryBase interface {
Factory

// CreateDefaultConfig creates the default configuration for the Processor.
// This method can be called multiple times depending on the pipeline
// configuration and should not cause side-effects that prevent the creation
// of multiple instances of the Processor.
// The object returned by this method needs to pass the checks implemented by
// 'configcheck.ValidateConfig'. It is recommended to have such check in the
// tests of any implementation of the Factory interface.
CreateDefaultConfig() configmodels.Processor
}

// ProcessorFactoryOld is factory interface for processors.
type ProcessorFactoryOld interface {
ProcessorFactoryBase

// CreateTraceProcessor creates a trace processor based on this config.
// If the processor type does not support tracing or if the config is not valid
// error will be returned instead.
CreateTraceProcessor(logger *zap.Logger, nextConsumer consumer.TraceConsumerOld,
cfg configmodels.Processor) (TraceProcessorOld, error)

// CreateMetricsProcessor creates a metrics processor based on this config.
// If the processor type does not support metrics or if the config is not valid
// error will be returned instead.
CreateMetricsProcessor(logger *zap.Logger, nextConsumer consumer.MetricsConsumerOld,
cfg configmodels.Processor) (MetricsProcessorOld, error)
}

// ProcessorCreateParams is passed to Create* functions in ProcessorFactory.
type ProcessorCreateParams struct {
// Logger that the factory can use during creation and can pass to the created
Expand All @@ -123,7 +70,16 @@ type ProcessorCreateParams struct {
// ProcessorFactory is factory interface for processors. This is the
// new factory type that can create new style processors.
type ProcessorFactory interface {
ProcessorFactoryBase
Factory

// CreateDefaultConfig creates the default configuration for the Processor.
// This method can be called multiple times depending on the pipeline
// configuration and should not cause side-effects that prevent the creation
// of multiple instances of the Processor.
// The object returned by this method needs to pass the checks implemented by
// 'configcheck.ValidateConfig'. It is recommended to have such check in the
// tests of any implementation of the Factory interface.
CreateDefaultConfig() configmodels.Processor

// CreateTraceProcessor creates a trace processor based on this config.
// If the processor type does not support tracing or if the config is not valid
Expand All @@ -140,7 +96,16 @@ type ProcessorFactory interface {

// LogsProcessorFactory can create LogsProcessor.
type LogsProcessorFactory interface {
ProcessorFactoryBase
Factory

// CreateDefaultConfig creates the default configuration for the Processor.
// This method can be called multiple times depending on the pipeline
// configuration and should not cause side-effects that prevent the creation
// of multiple instances of the Processor.
// The object returned by this method needs to pass the checks implemented by
// 'configcheck.ValidateConfig'. It is recommended to have such check in the
// tests of any implementation of the Factory interface.
CreateDefaultConfig() configmodels.Processor

// CreateLogsProcessor creates a processor based on the config.
// If the processor type does not support logs or if the config is not valid
Expand Down
16 changes: 8 additions & 8 deletions component/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package component

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"go.uber.org/zap"

"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/config/configmodels"
Expand All @@ -40,34 +40,34 @@ func (f *TestProcessorFactory) CreateDefaultConfig() configmodels.Processor {
}

// CreateTraceProcessor creates a trace processor based on this config.
func (f *TestProcessorFactory) CreateTraceProcessor(*zap.Logger, consumer.TraceConsumerOld, configmodels.Processor) (TraceProcessorOld, error) {
func (f *TestProcessorFactory) CreateTraceProcessor(context.Context, ProcessorCreateParams, consumer.TraceConsumer, configmodels.Processor) (TraceProcessor, error) {
return nil, configerror.ErrDataTypeIsNotSupported
}

// CreateMetricsProcessor creates a metrics processor based on this config.
func (f *TestProcessorFactory) CreateMetricsProcessor(*zap.Logger, consumer.MetricsConsumerOld, configmodels.Processor) (MetricsProcessorOld, error) {
func (f *TestProcessorFactory) CreateMetricsProcessor(context.Context, ProcessorCreateParams, consumer.MetricsConsumer, configmodels.Processor) (MetricsProcessor, error) {
return nil, configerror.ErrDataTypeIsNotSupported
}

func TestFactoriesBuilder(t *testing.T) {
type testCase struct {
in []ProcessorFactoryBase
out map[configmodels.Type]ProcessorFactoryBase
in []ProcessorFactory
out map[configmodels.Type]ProcessorFactory
}

testCases := []testCase{
{
in: []ProcessorFactoryBase{
in: []ProcessorFactory{
&TestProcessorFactory{"p1"},
&TestProcessorFactory{"p2"},
},
out: map[configmodels.Type]ProcessorFactoryBase{
out: map[configmodels.Type]ProcessorFactory{
"p1": &TestProcessorFactory{"p1"},
"p2": &TestProcessorFactory{"p2"},
},
},
{
in: []ProcessorFactoryBase{
in: []ProcessorFactory{
&TestProcessorFactory{"p1"},
&TestProcessorFactory{"p1"},
},
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func loadExporters(v *viper.Viper, factories map[configmodels.Type]component.Exp
return exporters, nil
}

func loadProcessors(v *viper.Viper, factories map[configmodels.Type]component.ProcessorFactoryBase) (configmodels.Processors, error) {
func loadProcessors(v *viper.Viper, factories map[configmodels.Type]component.ProcessorFactory) (configmodels.Processors, error) {
// Get the list of all "processors" sub vipers from config source.
processorsConfig := ViperSub(v, processorsKeyName)
expandEnvConfig(processorsConfig)
Expand Down
102 changes: 0 additions & 102 deletions processor/processortest/nop_processor.go

This file was deleted.

72 changes: 0 additions & 72 deletions processor/processortest/nop_processor_test.go

This file was deleted.

Loading

0 comments on commit 1f20ccf

Please sign in to comment.