Skip to content

Commit

Permalink
Move configerror.ErrDataTypeIsNotSupported to componenterror.ErrDataT…
Browse files Browse the repository at this point in the history
…ypeIsNotSupported

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Apr 2, 2021
1 parent 53832b5 commit b889856
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 79 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- Remove `configtest.NewViperFromYamlFile()`, use `config.Parser.NewParserFromFile()` (#2806)
- Move `config.ViperSubExact()` to use `config.Parser.Sub()` (#2806)
- Update LoadReceiver signature to remove unused params (#2823)
- Move `configerror.ErrDataTypeIsNotSupported` to `componenterror.ErrDataTypeIsNotSupported` (#2886)

## 💡 Enhancements 💡

Expand Down
5 changes: 5 additions & 0 deletions component/componenterror/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ var (

// ErrNilNextConsumer indicates an error on nil next consumer.
ErrNilNextConsumer = errors.New("nil nextConsumer")

// ErrDataTypeIsNotSupported can be returned by receiver, exporter or processor
// factory methods that create the entity if the particular telemetry
// data type is not supported by the receiver, exporter or processor.
ErrDataTypeIsNotSupported = errors.New("telemetry type is not supported")
)
4 changes: 2 additions & 2 deletions component/componenttest/shutdown_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/internal/testdata"
)
Expand All @@ -39,7 +39,7 @@ func verifyTraceProcessorDoesntProduceAfterShutdown(t *testing.T, factory compon
nextSink,
)
if err != nil {
if err == configerror.ErrDataTypeIsNotSupported {
if err == componenterror.ErrDataTypeIsNotSupported {
return
}
require.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions component/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

"github.com/stretchr/testify/assert"

"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configerror"
)

type TestExporterFactory struct {
Expand All @@ -40,17 +40,17 @@ func (f *TestExporterFactory) CreateDefaultConfig() config.Exporter {

// CreateTraceExporter creates a trace exporter based on this config.
func (f *TestExporterFactory) CreateTracesExporter(context.Context, ExporterCreateParams, config.Exporter) (TracesExporter, error) {
return nil, configerror.ErrDataTypeIsNotSupported
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateMetricsExporter creates a metrics exporter based on this config.
func (f *TestExporterFactory) CreateMetricsExporter(context.Context, ExporterCreateParams, config.Exporter) (MetricsExporter, error) {
return nil, configerror.ErrDataTypeIsNotSupported
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateMetricsExporter creates a logs exporter based on this config.
func (f *TestExporterFactory) CreateLogsExporter(context.Context, ExporterCreateParams, config.Exporter) (LogsExporter, error) {
return nil, configerror.ErrDataTypeIsNotSupported
return nil, componenterror.ErrDataTypeIsNotSupported
}

func TestBuildExporters(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions component/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

"go.uber.org/zap"

"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/consumer"
)

Expand Down Expand Up @@ -139,17 +139,17 @@ func (b BaseProcessorFactory) CreateDefaultConfig() config.Processor {

// CreateTracesProcessor default implemented as not supported date type.
func (b BaseProcessorFactory) CreateTracesProcessor(context.Context, ProcessorCreateParams, config.Processor, consumer.Traces) (TracesProcessor, error) {
return nil, configerror.ErrDataTypeIsNotSupported
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateMetricsProcessor default implemented as not supported date type.
func (b BaseProcessorFactory) CreateMetricsProcessor(context.Context, ProcessorCreateParams, config.Processor, consumer.Metrics) (MetricsProcessor, error) {
return nil, configerror.ErrDataTypeIsNotSupported
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateLogsProcessor default implemented as not supported date type.
func (b BaseProcessorFactory) CreateLogsProcessor(context.Context, ProcessorCreateParams, config.Processor, consumer.Logs) (LogsProcessor, error) {
return nil, configerror.ErrDataTypeIsNotSupported
return nil, componenterror.ErrDataTypeIsNotSupported
}

func (b BaseProcessorFactory) unexportedProcessor() {}
14 changes: 7 additions & 7 deletions component/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

"github.com/stretchr/testify/assert"

"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/consumer/consumertest"
)

Expand Down Expand Up @@ -85,10 +85,10 @@ func TestBaseProcessorFactory(t *testing.T) {
bpf.CreateDefaultConfig()
})
assert.NotPanics(t, bpf.unexportedProcessor)
_, err := bpf.CreateTracesProcessor(context.Background(), ProcessorCreateParams{}, config.NewProcessorSettings("nop"), consumertest.NewTracesNop())
assert.ErrorIs(t, err, configerror.ErrDataTypeIsNotSupported)
_, err = bpf.CreateMetricsProcessor(context.Background(), ProcessorCreateParams{}, config.NewProcessorSettings("nop"), consumertest.NewMetricsNop())
assert.ErrorIs(t, err, configerror.ErrDataTypeIsNotSupported)
_, err = bpf.CreateLogsProcessor(context.Background(), ProcessorCreateParams{}, config.NewProcessorSettings("nop"), consumertest.NewLogsNop())
assert.ErrorIs(t, err, configerror.ErrDataTypeIsNotSupported)
_, err := bpf.CreateTracesProcessor(context.Background(), ProcessorCreateParams{}, config.NewProcessorSettings("nop"), consumertest.NewNop())
assert.ErrorIs(t, err, componenterror.ErrDataTypeIsNotSupported)
_, err = bpf.CreateMetricsProcessor(context.Background(), ProcessorCreateParams{}, config.NewProcessorSettings("nop"), consumertest.NewNop())
assert.ErrorIs(t, err, componenterror.ErrDataTypeIsNotSupported)
_, err = bpf.CreateLogsProcessor(context.Background(), ProcessorCreateParams{}, config.NewProcessorSettings("nop"), consumertest.NewNop())
assert.ErrorIs(t, err, componenterror.ErrDataTypeIsNotSupported)
}
8 changes: 4 additions & 4 deletions component/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

"github.com/stretchr/testify/assert"

"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/consumer"
)

Expand All @@ -41,17 +41,17 @@ func (f *TestReceiverFactory) CreateDefaultConfig() config.Receiver {

// CreateTraceReceiver creates a trace receiver based on this config.
func (f *TestReceiverFactory) CreateTracesReceiver(context.Context, ReceiverCreateParams, config.Receiver, consumer.Traces) (TracesReceiver, error) {
return nil, configerror.ErrDataTypeIsNotSupported
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateMetricsReceiver creates a metrics receiver based on this config.
func (f *TestReceiverFactory) CreateMetricsReceiver(context.Context, ReceiverCreateParams, config.Receiver, consumer.Metrics) (MetricsReceiver, error) {
return nil, configerror.ErrDataTypeIsNotSupported
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateMetricsReceiver creates a metrics receiver based on this config.
func (f *TestReceiverFactory) CreateLogsReceiver(context.Context, ReceiverCreateParams, config.Receiver, consumer.Logs) (LogsReceiver, error) {
return nil, configerror.ErrDataTypeIsNotSupported
return nil, componenterror.ErrDataTypeIsNotSupported
}

func TestBuildReceivers(t *testing.T) {
Expand Down
23 changes: 0 additions & 23 deletions config/configerror/configerror.go

This file was deleted.

8 changes: 4 additions & 4 deletions exporter/exporterhelper/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"github.com/spf13/viper"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configerror"
)

// FactoryOption apply changes to ExporterOptions.
Expand Down Expand Up @@ -115,7 +115,7 @@ func (f *factory) CreateTracesExporter(
if f.createTracesExporter != nil {
return f.createTracesExporter(ctx, params, cfg)
}
return nil, configerror.ErrDataTypeIsNotSupported
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateMetricsExporter creates a component.MetricsExporter based on this config.
Expand All @@ -126,7 +126,7 @@ func (f *factory) CreateMetricsExporter(
if f.createMetricsExporter != nil {
return f.createMetricsExporter(ctx, params, cfg)
}
return nil, configerror.ErrDataTypeIsNotSupported
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateLogsExporter creates a metrics processor based on this config.
Expand All @@ -138,7 +138,7 @@ func (f *factory) CreateLogsExporter(
if f.createLogsExporter != nil {
return f.createLogsExporter(ctx, params, cfg)
}
return nil, configerror.ErrDataTypeIsNotSupported
return nil, componenterror.ErrDataTypeIsNotSupported
}

var _ component.ConfigUnmarshaler = (*factoryWithUnmarshaler)(nil)
Expand Down
8 changes: 4 additions & 4 deletions exporter/exporterhelper/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/consumer/pdata"
)

Expand Down Expand Up @@ -56,11 +56,11 @@ func TestNewFactory(t *testing.T) {
_, ok := factory.(component.ConfigUnmarshaler)
assert.False(t, ok)
_, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, defaultCfg)
assert.Equal(t, configerror.ErrDataTypeIsNotSupported, err)
assert.Equal(t, componenterror.ErrDataTypeIsNotSupported, err)
_, err = factory.CreateMetricsExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, defaultCfg)
assert.Equal(t, configerror.ErrDataTypeIsNotSupported, err)
assert.Equal(t, componenterror.ErrDataTypeIsNotSupported, err)
_, err = factory.CreateLogsExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, defaultCfg)
assert.Equal(t, configerror.ErrDataTypeIsNotSupported, err)
assert.Equal(t, componenterror.ErrDataTypeIsNotSupported, err)
}

func TestNewFactory_WithConstructors(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions exporter/jaegerexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config/configcheck"
"go.opentelemetry.io/collector/config/configerror"
)

func TestCreateDefaultConfig(t *testing.T) {
Expand All @@ -39,7 +39,7 @@ func TestCreateMetricsExporter(t *testing.T) {

params := component.ExporterCreateParams{Logger: zap.NewNop()}
_, err := factory.CreateMetricsExporter(context.Background(), params, cfg)
assert.Error(t, err, configerror.ErrDataTypeIsNotSupported)
assert.Error(t, err, componenterror.ErrDataTypeIsNotSupported)
}

func TestCreateInstanceViaFactory(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions processor/attributesprocessor/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configcheck"
"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/processor/processorhelper"
)
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestFactory_CreateMetricsProcessor(t *testing.T) {

mp, err := factory.CreateMetricsProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, nil)
require.Nil(t, mp)
assert.Equal(t, err, configerror.ErrDataTypeIsNotSupported)
assert.Equal(t, err, componenterror.ErrDataTypeIsNotSupported)
}

func TestFactoryCreateLogsProcessor_EmptyActions(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions processor/spanprocessor/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configcheck"
"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/consumer/consumertest"
)

Expand Down Expand Up @@ -103,5 +103,5 @@ func TestFactory_CreateMetricProcessor(t *testing.T) {

mp, err := factory.CreateMetricsProcessor(context.Background(), component.ProcessorCreateParams{Logger: zap.NewNop()}, cfg, nil)
require.Nil(t, mp)
assert.Equal(t, err, configerror.ErrDataTypeIsNotSupported)
assert.Equal(t, err, componenterror.ErrDataTypeIsNotSupported)
}
6 changes: 3 additions & 3 deletions receiver/hostmetricsreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config/configcheck"
"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal"
)
Expand All @@ -43,15 +43,15 @@ func TestCreateReceiver(t *testing.T) {
cfg := factory.CreateDefaultConfig()

tReceiver, err := factory.CreateTracesReceiver(context.Background(), creationParams, cfg, consumertest.NewNop())
assert.Equal(t, err, configerror.ErrDataTypeIsNotSupported)
assert.Equal(t, err, componenterror.ErrDataTypeIsNotSupported)
assert.Nil(t, tReceiver)

mReceiver, err := factory.CreateMetricsReceiver(context.Background(), creationParams, cfg, consumertest.NewNop())
assert.NoError(t, err)
assert.NotNil(t, mReceiver)

tLogs, err := factory.CreateLogsReceiver(context.Background(), creationParams, cfg, consumertest.NewNop())
assert.Equal(t, err, configerror.ErrDataTypeIsNotSupported)
assert.Equal(t, err, componenterror.ErrDataTypeIsNotSupported)
assert.Nil(t, tLogs)
}

Expand Down
6 changes: 3 additions & 3 deletions receiver/jaegerreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configcheck"
"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/confignet"
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestCreateReceiver(t *testing.T) {
assert.NotNil(t, tReceiver, "receiver creation failed")

mReceiver, err := factory.CreateMetricsReceiver(context.Background(), params, cfg, nil)
assert.Equal(t, err, configerror.ErrDataTypeIsNotSupported)
assert.Equal(t, err, componenterror.ErrDataTypeIsNotSupported)
assert.Nil(t, mReceiver)
}

Expand All @@ -89,7 +89,7 @@ func TestCreateReceiverGeneralConfig(t *testing.T) {
assert.NotNil(t, tReceiver, "receiver creation failed")

mReceiver, err := factory.CreateMetricsReceiver(context.Background(), params, rCfg, nil)
assert.Equal(t, err, configerror.ErrDataTypeIsNotSupported)
assert.Equal(t, err, componenterror.ErrDataTypeIsNotSupported)
assert.Nil(t, mReceiver)
}

Expand Down
8 changes: 4 additions & 4 deletions receiver/receiverhelper/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"github.com/spf13/viper"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/consumer"
)

Expand Down Expand Up @@ -117,7 +117,7 @@ func (f *factory) CreateTracesReceiver(
if f.createTraceReceiver != nil {
return f.createTraceReceiver(ctx, params, cfg, nextConsumer)
}
return nil, configerror.ErrDataTypeIsNotSupported
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateMetricsReceiver creates a component.MetricsReceiver based on this config.
Expand All @@ -129,7 +129,7 @@ func (f *factory) CreateMetricsReceiver(
if f.createMetricsReceiver != nil {
return f.createMetricsReceiver(ctx, params, cfg, nextConsumer)
}
return nil, configerror.ErrDataTypeIsNotSupported
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateLogsReceiver creates a metrics processor based on this config.
Expand All @@ -142,7 +142,7 @@ func (f *factory) CreateLogsReceiver(
if f.createLogsReceiver != nil {
return f.createLogsReceiver(ctx, params, cfg, nextConsumer)
}
return nil, configerror.ErrDataTypeIsNotSupported
return nil, componenterror.ErrDataTypeIsNotSupported
}

var _ component.ConfigUnmarshaler = (*factoryWithUnmarshaler)(nil)
Expand Down
Loading

0 comments on commit b889856

Please sign in to comment.