Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate componenterror package, move to component #5383

Merged
merged 1 commit into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
### 🚩 Deprecations 🚩

- Deprecate `config.Config` and `config.Service`, use `service.Config*` (#4608)
- Deprecate `componenterror` package, move everything to `component` (#5383)

### 💡 Enhancements 💡

Expand Down
11 changes: 11 additions & 0 deletions component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,21 @@ package component // import "go.opentelemetry.io/collector/component"

import (
"context"
"errors"

"go.opentelemetry.io/collector/config"
)

var (
// ErrNilNextConsumer can be returned by receiver, or processor Start factory funcs that create the Component if the
// expected next Consumer is nil.
ErrNilNextConsumer = errors.New("nil next Consumer")

// ErrDataTypeIsNotSupported can be returned by receiver, exporter or processor factory funcs that create the
// Component if the particular telemetry data type is not supported by the receiver, exporter or processor.
ErrDataTypeIsNotSupported = errors.New("telemetry type is not supported")
)

// Component is either a receiver, exporter, processor, or an extension.
//
// A component's lifecycle has the following phases:
Expand Down
12 changes: 5 additions & 7 deletions component/componenterror/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
package componenterror // import "go.opentelemetry.io/collector/component/componenterror"

import (
"errors"
"go.opentelemetry.io/collector/component"
)

var (
// ErrNilNextConsumer indicates an error on nil next consumer.
ErrNilNextConsumer = errors.New("nil nextConsumer")
// Deprecated: use component.ErrNilNextConsumer
ErrNilNextConsumer = component.ErrNilNextConsumer

// 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")
// Deprecated: use component.ErrDataTypeIsNotSupported
ErrDataTypeIsNotSupported = component.ErrDataTypeIsNotSupported
)
3 changes: 1 addition & 2 deletions component/componenttest/shutdown_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ 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/consumer/consumertest"
"go.opentelemetry.io/collector/internal/testdata"
Expand All @@ -39,7 +38,7 @@ func verifyTracesProcessorDoesntProduceAfterShutdown(t *testing.T, factory compo
nextSink,
)
if err != nil {
if errors.Is(err, componenterror.ErrDataTypeIsNotSupported) {
if errors.Is(err, component.ErrDataTypeIsNotSupported) {
return
}
require.NoError(t, err)
Expand Down
7 changes: 3 additions & 4 deletions component/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package component // import "go.opentelemetry.io/collector/component"
import (
"context"

"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer"
)
Expand Down Expand Up @@ -102,7 +101,7 @@ type CreateTracesExporterFunc func(context.Context, ExporterCreateSettings, conf
// CreateTracesExporter implements ExporterFactory.CreateTracesExporter().
func (f CreateTracesExporterFunc) CreateTracesExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (TracesExporter, error) {
if f == nil {
return nil, componenterror.ErrDataTypeIsNotSupported
return nil, ErrDataTypeIsNotSupported
}
return f(ctx, set, cfg)
}
Expand All @@ -113,7 +112,7 @@ type CreateMetricsExporterFunc func(context.Context, ExporterCreateSettings, con
// CreateMetricsExporter implements ExporterFactory.CreateMetricsExporter().
func (f CreateMetricsExporterFunc) CreateMetricsExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (MetricsExporter, error) {
if f == nil {
return nil, componenterror.ErrDataTypeIsNotSupported
return nil, ErrDataTypeIsNotSupported
}
return f(ctx, set, cfg)
}
Expand All @@ -124,7 +123,7 @@ type CreateLogsExporterFunc func(context.Context, ExporterCreateSettings, config
// CreateLogsExporter implements ExporterFactory.CreateLogsExporter().
func (f CreateLogsExporterFunc) CreateLogsExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (LogsExporter, error) {
if f == nil {
return nil, componenterror.ErrDataTypeIsNotSupported
return nil, ErrDataTypeIsNotSupported
}
return f(ctx, set, cfg)
}
Expand Down
7 changes: 3 additions & 4 deletions component/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package component // import "go.opentelemetry.io/collector/component"
import (
"context"

"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer"
)
Expand Down Expand Up @@ -122,7 +121,7 @@ func (f CreateTracesProcessorFunc) CreateTracesProcessor(
cfg config.Processor,
nextConsumer consumer.Traces) (TracesProcessor, error) {
if f == nil {
return nil, componenterror.ErrDataTypeIsNotSupported
return nil, ErrDataTypeIsNotSupported
}
return f(ctx, set, cfg, nextConsumer)
}
Expand All @@ -138,7 +137,7 @@ func (f CreateMetricsProcessorFunc) CreateMetricsProcessor(
nextConsumer consumer.Metrics,
) (MetricsProcessor, error) {
if f == nil {
return nil, componenterror.ErrDataTypeIsNotSupported
return nil, ErrDataTypeIsNotSupported
}
return f(ctx, set, cfg, nextConsumer)
}
Expand All @@ -154,7 +153,7 @@ func (f CreateLogsProcessorFunc) CreateLogsProcessor(
nextConsumer consumer.Logs,
) (LogsProcessor, error) {
if f == nil {
return nil, componenterror.ErrDataTypeIsNotSupported
return nil, ErrDataTypeIsNotSupported
}
return f(ctx, set, cfg, nextConsumer)
}
Expand Down
7 changes: 3 additions & 4 deletions component/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package component // import "go.opentelemetry.io/collector/component"
import (
"context"

"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer"
)
Expand Down Expand Up @@ -154,7 +153,7 @@ func (f CreateTracesReceiverFunc) CreateTracesReceiver(
cfg config.Receiver,
nextConsumer consumer.Traces) (TracesReceiver, error) {
if f == nil {
return nil, componenterror.ErrDataTypeIsNotSupported
return nil, ErrDataTypeIsNotSupported
}
return f(ctx, set, cfg, nextConsumer)
}
Expand All @@ -170,7 +169,7 @@ func (f CreateMetricsReceiverFunc) CreateMetricsReceiver(
nextConsumer consumer.Metrics,
) (MetricsReceiver, error) {
if f == nil {
return nil, componenterror.ErrDataTypeIsNotSupported
return nil, ErrDataTypeIsNotSupported
}
return f(ctx, set, cfg, nextConsumer)
}
Expand All @@ -186,7 +185,7 @@ func (f CreateLogsReceiverFunc) CreateLogsReceiver(
nextConsumer consumer.Logs,
) (LogsReceiver, error) {
if f == nil {
return nil, componenterror.ErrDataTypeIsNotSupported
return nil, ErrDataTypeIsNotSupported
}
return f(ctx, set, cfg, nextConsumer)
}
Expand Down
3 changes: 1 addition & 2 deletions processor/processorhelper/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"go.opentelemetry.io/otel/trace"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/plog"
Expand Down Expand Up @@ -50,7 +49,7 @@ func NewLogsProcessor(
}

if nextConsumer == nil {
return nil, componenterror.ErrNilNextConsumer
return nil, component.ErrNilNextConsumer
}

eventOptions := spanAttributes(cfg.ID())
Expand Down
3 changes: 1 addition & 2 deletions processor/processorhelper/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/stretchr/testify/require"

"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/consumer"
Expand Down Expand Up @@ -61,7 +60,7 @@ func TestNewLogsProcessor_NilRequiredFields(t *testing.T) {
assert.Error(t, err)

_, err = NewLogsProcessor(&testLogsCfg, nil, newTestLProcessor(nil))
assert.Equal(t, componenterror.ErrNilNextConsumer, err)
assert.Equal(t, component.ErrNilNextConsumer, err)
}

func TestNewLogsProcessor_ProcessLogError(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions processor/processorhelper/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"go.opentelemetry.io/otel/trace"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/pmetric"
Expand Down Expand Up @@ -50,7 +49,7 @@ func NewMetricsProcessor(
}

if nextConsumer == nil {
return nil, componenterror.ErrNilNextConsumer
return nil, component.ErrNilNextConsumer
}

eventOptions := spanAttributes(cfg.ID())
Expand Down
3 changes: 1 addition & 2 deletions processor/processorhelper/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/stretchr/testify/require"

"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/consumer"
Expand Down Expand Up @@ -61,7 +60,7 @@ func TestNewMetricsProcessor_NilRequiredFields(t *testing.T) {
assert.Error(t, err)

_, err = NewMetricsProcessor(&testMetricsCfg, nil, newTestMProcessor(nil))
assert.Equal(t, componenterror.ErrNilNextConsumer, err)
assert.Equal(t, component.ErrNilNextConsumer, err)
}

func TestNewMetricsProcessor_ProcessMetricsError(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions processor/processorhelper/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"go.opentelemetry.io/otel/trace"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/ptrace"
Expand Down Expand Up @@ -50,7 +49,7 @@ func NewTracesProcessor(
}

if nextConsumer == nil {
return nil, componenterror.ErrNilNextConsumer
return nil, component.ErrNilNextConsumer
}

eventOptions := spanAttributes(cfg.ID())
Expand Down
3 changes: 1 addition & 2 deletions processor/processorhelper/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/stretchr/testify/require"

"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/consumer"
Expand Down Expand Up @@ -61,7 +60,7 @@ func TestNewTracesProcessor_NilRequiredFields(t *testing.T) {
assert.Error(t, err)

_, err = NewTracesProcessor(&testTracesCfg, nil, newTestTProcessor(nil))
assert.Equal(t, componenterror.ErrNilNextConsumer, err)
assert.Equal(t, component.ErrNilNextConsumer, err)
}

func TestNewTracesProcessor_ProcessTraceError(t *testing.T) {
Expand Down
7 changes: 3 additions & 4 deletions receiver/otlpreceiver/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"google.golang.org/grpc"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/consumer"
Expand Down Expand Up @@ -174,7 +173,7 @@ func (r *otlpReceiver) Shutdown(ctx context.Context) error {

func (r *otlpReceiver) registerTraceConsumer(tc consumer.Traces) error {
if tc == nil {
return componenterror.ErrNilNextConsumer
return component.ErrNilNextConsumer
}
r.traceReceiver = trace.New(r.cfg.ID(), tc, r.settings)
if r.httpMux != nil {
Expand All @@ -198,7 +197,7 @@ func (r *otlpReceiver) registerTraceConsumer(tc consumer.Traces) error {

func (r *otlpReceiver) registerMetricsConsumer(mc consumer.Metrics) error {
if mc == nil {
return componenterror.ErrNilNextConsumer
return component.ErrNilNextConsumer
}
r.metricsReceiver = metrics.New(r.cfg.ID(), mc, r.settings)
if r.httpMux != nil {
Expand All @@ -222,7 +221,7 @@ func (r *otlpReceiver) registerMetricsConsumer(mc consumer.Metrics) error {

func (r *otlpReceiver) registerLogsConsumer(lc consumer.Logs) error {
if lc == nil {
return componenterror.ErrNilNextConsumer
return component.ErrNilNextConsumer
}
r.logReceiver = logs.New(r.cfg.ID(), lc, r.settings)
if r.httpMux != nil {
Expand Down
3 changes: 1 addition & 2 deletions receiver/scraperhelper/scrapercontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ 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/consumer"
"go.opentelemetry.io/collector/obsreport"
Expand Down Expand Up @@ -97,7 +96,7 @@ func NewScraperControllerReceiver(
options ...ScraperControllerOption,
) (component.Receiver, error) {
if nextConsumer == nil {
return nil, componenterror.ErrNilNextConsumer
return nil, component.ErrNilNextConsumer
}

if cfg.CollectionInterval <= 0 {
Expand Down
2 changes: 1 addition & 1 deletion receiver/scraperhelper/scrapercontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestScrapeController(t *testing.T) {
name: "AddMetricsScrapers_NilNextConsumerError",
scrapers: 2,
nilNextConsumer: true,
expectedNewErr: "nil nextConsumer",
expectedNewErr: "nil next Consumer",
},
{
name: "AddMetricsScrapersWithCollectionInterval_InvalidCollectionIntervalError",
Expand Down
3 changes: 1 addition & 2 deletions service/internal/builder/exporters_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ 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/service/internal/components"
)
Expand Down Expand Up @@ -238,7 +237,7 @@ func buildExporter(
}

if err != nil {
if errors.Is(err, componenterror.ErrDataTypeIsNotSupported) {
if errors.Is(err, component.ErrDataTypeIsNotSupported) {
// Could not create because this exporter does not support this data type.
return nil, exporterTypeMismatchErr(cfg, pipelineID, dataType)
}
Expand Down
5 changes: 2 additions & 3 deletions service/internal/builder/receivers_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ 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/consumer"
"go.opentelemetry.io/collector/service/internal/components"
Expand Down Expand Up @@ -191,11 +190,11 @@ func attachReceiverToPipelines(
createdReceiver, err = factory.CreateLogsReceiver(ctx, set, cfg, junction)

default:
err = componenterror.ErrDataTypeIsNotSupported
err = component.ErrDataTypeIsNotSupported
}

if err != nil {
if errors.Is(err, componenterror.ErrDataTypeIsNotSupported) {
if errors.Is(err, component.ErrDataTypeIsNotSupported) {
return fmt.Errorf(
"receiver %v does not support %s but it was used in a %s pipeline",
id, dataType, dataType)
Expand Down