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

Remove checks of ErrNilNextConsumer #31793

Merged
merged 7 commits into from
Mar 19, 2024
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
27 changes: 27 additions & 0 deletions .chloggen/remove_ErrNilNextConsumer_impl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: all

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Remove explicit checks in all receivers to check if the next consumer is nil

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [31793]

# (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: The nil check is now done by the pipeline builder.

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
4 changes: 0 additions & 4 deletions processor/tailsamplingprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ const (
// newTracesProcessor returns a processor.TracesProcessor that will perform tail sampling according to the given
// configuration.
func newTracesProcessor(ctx context.Context, settings component.TelemetrySettings, nextConsumer consumer.Traces, cfg Config) (processor.Traces, error) {
if nextConsumer == nil {
return nil, component.ErrNilNextConsumer
}

policyNames := map[string]bool{}
policies := make([]*policy, len(cfg.PolicyCfgs))
for i := range cfg.PolicyCfgs {
Expand Down
3 changes: 0 additions & 3 deletions receiver/awscontainerinsightreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ func newAWSContainerInsightReceiver(
settings component.TelemetrySettings,
config *Config,
nextConsumer consumer.Metrics) (receiver.Metrics, error) {
if nextConsumer == nil {
return nil, component.ErrNilNextConsumer
}

r := &awsContainerInsightReceiver{
settings: settings,
Expand Down
12 changes: 0 additions & 12 deletions receiver/awscontainerinsightreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,6 @@ func TestReceiver(t *testing.T) {
require.NoError(t, err)
}

func TestReceiverForNilConsumer(t *testing.T) {
cfg := createDefaultConfig().(*Config)
metricsReceiver, err := newAWSContainerInsightReceiver(
componenttest.NewNopTelemetrySettings(),
cfg,
nil,
)

require.Error(t, err)
require.Nil(t, metricsReceiver)
}

func TestCollectData(t *testing.T) {
cfg := createDefaultConfig().(*Config)
metricsReceiver, err := newAWSContainerInsightReceiver(
Expand Down
4 changes: 0 additions & 4 deletions receiver/awsecscontainermetricsreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ func newAWSECSContainermetrics(
config *Config,
nextConsumer consumer.Metrics,
rest ecsutil.RestClient) (receiver.Metrics, error) {
if nextConsumer == nil {
return nil, component.ErrNilNextConsumer
}

r := &awsEcsContainerMetricsReceiver{
logger: logger,
nextConsumer: nextConsumer,
Expand Down
13 changes: 0 additions & 13 deletions receiver/awsecscontainermetricsreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,6 @@ func TestReceiver(t *testing.T) {
require.NoError(t, err)
}

func TestReceiverForNilConsumer(t *testing.T) {
cfg := createDefaultConfig().(*Config)
metricsReceiver, err := newAWSECSContainermetrics(
zap.NewNop(),
cfg,
nil,
&fakeRestClient{},
)

require.Error(t, err)
require.Nil(t, metricsReceiver)
}

func TestCollectDataFromEndpoint(t *testing.T) {
cfg := createDefaultConfig().(*Config)
metricsReceiver, err := newAWSECSContainermetrics(
Expand Down
4 changes: 0 additions & 4 deletions receiver/awsfirehosereceiver/metrics_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"net/http"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"

Expand Down Expand Up @@ -35,9 +34,6 @@ func newMetricsReceiver(
unmarshalers map[string]unmarshaler.MetricsUnmarshaler,
nextConsumer consumer.Metrics,
) (receiver.Metrics, error) {
if nextConsumer == nil {
return nil, component.ErrNilNextConsumer
}

configuredUnmarshaler := unmarshalers[config.RecordType]
if configuredUnmarshaler == nil {
Expand Down
4 changes: 0 additions & 4 deletions receiver/awsxrayreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ func newReceiver(config *Config,
consumer consumer.Traces,
set receiver.CreateSettings) (receiver.Traces, error) {

if consumer == nil {
return nil, component.ErrNilNextConsumer
}

set.Logger.Info("Going to listen on endpoint for X-Ray segments",
zap.String(udppoller.Transport, config.Endpoint))
poller, err := udppoller.New(&udppoller.Config{
Expand Down
4 changes: 0 additions & 4 deletions receiver/carbonreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ func newMetricsReceiver(
nextConsumer consumer.Metrics,
) (receiver.Metrics, error) {

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

if config.Endpoint == "" {
return nil, errEmptyEndpoint
}
Expand Down
4 changes: 0 additions & 4 deletions receiver/cloudfoundryreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ func newCloudFoundryReceiver(
config Config,
nextConsumer consumer.Metrics) (receiver.Metrics, error) {

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

obsrecv, err := receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{
ReceiverID: settings.ID,
Transport: transport,
Expand Down
16 changes: 0 additions & 16 deletions receiver/cloudfoundryreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,3 @@ func TestDefaultValidReceiver(t *testing.T) {
err = receiver.Shutdown(ctx)
require.NoError(t, err)
}

// Test to make sure start fails with invalid consumer
func TestInvalidConsumer(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig().(*Config)
params := receivertest.NewNopCreateSettings()

receiver, err := newCloudFoundryReceiver(
params,
*cfg,
nil,
)

require.EqualError(t, err, "nil next Consumer")
require.Nil(t, receiver, "receiver creation failed")
}
3 changes: 0 additions & 3 deletions receiver/collectdreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ func newCollectdReceiver(
defaultAttrsPrefix string,
nextConsumer consumer.Metrics,
createSettings receiver.CreateSettings) (receiver.Metrics, error) {
if nextConsumer == nil {
return nil, component.ErrNilNextConsumer
}

r := &collectdReceiver{
logger: logger,
Expand Down
3 changes: 0 additions & 3 deletions receiver/datadogreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ type datadogReceiver struct {
}

func newDataDogReceiver(config *Config, nextConsumer consumer.Traces, params receiver.CreateSettings) (receiver.Traces, error) {
if nextConsumer == nil {
return nil, component.ErrNilNextConsumer
}

instance, err := receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{LongLivedCtx: false, ReceiverID: params.ID, Transport: "http", ReceiverCreateSettings: params})
if err != nil {
Expand Down
9 changes: 0 additions & 9 deletions receiver/googlecloudpubsubreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ func (factory *pubsubReceiverFactory) CreateTracesReceiver(
cfg component.Config,
consumer consumer.Traces) (receiver.Traces, error) {

if consumer == nil {
return nil, component.ErrNilNextConsumer
}
err := cfg.(*Config).validateForTrace()
if err != nil {
return nil, err
Expand All @@ -92,9 +89,6 @@ func (factory *pubsubReceiverFactory) CreateMetricsReceiver(
cfg component.Config,
consumer consumer.Metrics) (receiver.Metrics, error) {

if consumer == nil {
return nil, component.ErrNilNextConsumer
}
err := cfg.(*Config).validateForMetric()
if err != nil {
return nil, err
Expand All @@ -113,9 +107,6 @@ func (factory *pubsubReceiverFactory) CreateLogsReceiver(
cfg component.Config,
consumer consumer.Logs) (receiver.Logs, error) {

if consumer == nil {
return nil, component.ErrNilNextConsumer
}
err := cfg.(*Config).validateForLog()
if err != nil {
return nil, err
Expand Down
6 changes: 0 additions & 6 deletions receiver/googlecloudpubsubreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ func TestCreateTracesReceiver(t *testing.T) {
tReceiver, err := factory.CreateTracesReceiver(context.Background(), params, cfg, consumertest.NewNop())
assert.NoError(t, err)
assert.NotNil(t, tReceiver, "traces receiver creation failed")
_, err = factory.CreateTracesReceiver(context.Background(), params, cfg, nil)
assert.Error(t, err)
}

func TestCreateMetricsReceiver(t *testing.T) {
Expand All @@ -49,8 +47,6 @@ func TestCreateMetricsReceiver(t *testing.T) {
tReceiver, err := factory.CreateMetricsReceiver(context.Background(), params, cfg, consumertest.NewNop())
assert.NoError(t, err)
assert.NotNil(t, tReceiver, "metrics receiver creation failed")
_, err = factory.CreateMetricsReceiver(context.Background(), params, cfg, nil)
assert.Error(t, err)
}

func TestCreateLogsReceiver(t *testing.T) {
Expand All @@ -62,8 +58,6 @@ func TestCreateLogsReceiver(t *testing.T) {
tReceiver, err := factory.CreateLogsReceiver(context.Background(), params, cfg, consumertest.NewNop())
assert.NoError(t, err)
assert.NotNil(t, tReceiver, "logs receiver creation failed")
_, err = factory.CreateLogsReceiver(context.Background(), params, cfg, nil)
assert.Error(t, err)
}

func TestEnsureReceiver(t *testing.T) {
Expand Down
4 changes: 0 additions & 4 deletions receiver/lokireceiver/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ func newLokiReceiver(conf *Config, nextConsumer consumer.Logs, settings receiver
return nil, err
}

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

if conf.HTTP != nil {
r.httpMux = http.NewServeMux()
r.httpMux.HandleFunc("/loki/api/v1/push", func(resp http.ResponseWriter, req *http.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
agentmetricspb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/metrics/v1"
ocmetrics "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1"
resourcepb "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/receiverhelper"
Expand All @@ -29,9 +28,6 @@ type Receiver struct {

// New creates a new ocmetrics.Receiver reference.
func New(nextConsumer consumer.Metrics, set receiver.CreateSettings) (*Receiver, error) {
if nextConsumer == nil {
return nil, component.ErrNilNextConsumer
}
obsrecv, err := receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{
ReceiverID: set.ID,
Transport: receiverTransport,
Expand Down
4 changes: 0 additions & 4 deletions receiver/opencensusreceiver/internal/octrace/opencensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1"
agenttracepb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/trace/v1"
resourcepb "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/collector/receiver"
Expand All @@ -34,9 +33,6 @@ type Receiver struct {

// New creates a new opencensus.Receiver reference.
func New(nextConsumer consumer.Traces, set receiver.CreateSettings) (*Receiver, error) {
if nextConsumer == nil {
return nil, component.ErrNilNextConsumer
}

obsrecv, err := receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{
ReceiverID: set.ID,
Expand Down
12 changes: 3 additions & 9 deletions receiver/otelarrowreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ func createTraces(
return nil, err
}

if err = r.Unwrap().(*otelArrowReceiver).registerTraceConsumer(nextConsumer); err != nil {
return nil, err
}
r.Unwrap().(*otelArrowReceiver).registerTraceConsumer(nextConsumer)
return r, nil
}

Expand All @@ -89,9 +87,7 @@ func createMetrics(
return nil, err
}

if err = r.Unwrap().(*otelArrowReceiver).registerMetricsConsumer(consumer); err != nil {
return nil, err
}
r.Unwrap().(*otelArrowReceiver).registerMetricsConsumer(consumer)
return r, nil
}

Expand All @@ -111,9 +107,7 @@ func createLog(
return nil, err
}

if err = r.Unwrap().(*otelArrowReceiver).registerLogsConsumer(consumer); err != nil {
return nil, err
}
r.Unwrap().(*otelArrowReceiver).registerLogsConsumer(consumer)
return r, nil
}

Expand Down
18 changes: 3 additions & 15 deletions receiver/otelarrowreceiver/otelarrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,28 +170,16 @@ func (r *otelArrowReceiver) Shutdown(_ context.Context) error {
return err
}

func (r *otelArrowReceiver) registerTraceConsumer(tc consumer.Traces) error {
if tc == nil {
return component.ErrNilNextConsumer
}
func (r *otelArrowReceiver) registerTraceConsumer(tc consumer.Traces) {
r.tracesReceiver = trace.New(tc, r.obsrepGRPC)
return nil
}

func (r *otelArrowReceiver) registerMetricsConsumer(mc consumer.Metrics) error {
if mc == nil {
return component.ErrNilNextConsumer
}
func (r *otelArrowReceiver) registerMetricsConsumer(mc consumer.Metrics) {
r.metricsReceiver = metrics.New(mc, r.obsrepGRPC)
return nil
}

func (r *otelArrowReceiver) registerLogsConsumer(lc consumer.Logs) error {
if lc == nil {
return component.ErrNilNextConsumer
}
func (r *otelArrowReceiver) registerLogsConsumer(lc consumer.Logs) {
r.logsReceiver = logs.New(lc, r.obsrepGRPC)
return nil
}

var _ arrow.Consumers = &otelArrowReceiver{}
Expand Down
Loading
Loading