diff --git a/.chloggen/opencensus_receiver_no_error_msg_on_clean_shutdown.yaml b/.chloggen/opencensus_receiver_no_error_msg_on_clean_shutdown.yaml new file mode 100644 index 000000000000..c4a80c261813 --- /dev/null +++ b/.chloggen/opencensus_receiver_no_error_msg_on_clean_shutdown.yaml @@ -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: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: opencensusreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Do not report error message when OpenCensus receiver is shutdown cleanly. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [36622] + +# (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: + +# 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: [user] diff --git a/receiver/opencensusreceiver/opencensus.go b/receiver/opencensusreceiver/opencensus.go index ee2de0d033af..e5047c45cd93 100644 --- a/receiver/opencensusreceiver/opencensus.go +++ b/receiver/opencensusreceiver/opencensus.go @@ -146,19 +146,19 @@ func (ocr *ocReceiver) Start(ctx context.Context, host component.Host) error { defer ocr.stopWG.Done() startWG.Done() // Check for cmux.ErrServerClosed, because during the shutdown this is not properly close before closing the cmux, - if err := ocr.serverGRPC.Serve(grpcL); !errors.Is(err, grpc.ErrServerStopped) && !errors.Is(err, cmux.ErrServerClosed) && err != nil { + if err := ocr.serverGRPC.Serve(grpcL); err != nil && !errors.Is(err, grpc.ErrServerStopped) && !errors.Is(err, cmux.ErrServerClosed) { componentstatus.ReportStatus(host, componentstatus.NewFatalErrorEvent(err)) } }() go func() { startWG.Done() - if err := ocr.serverHTTP.Serve(httpL); !errors.Is(err, http.ErrServerClosed) && !errors.Is(err, cmux.ErrServerClosed) && err != nil { + if err := ocr.serverHTTP.Serve(httpL); err != nil && !errors.Is(err, http.ErrServerClosed) && !errors.Is(err, cmux.ErrServerClosed) { componentstatus.ReportStatus(host, componentstatus.NewFatalErrorEvent(err)) } }() go func() { startWG.Done() - if err := ocr.multiplexer.Serve(); !errors.Is(err, cmux.ErrServerClosed) && !errors.Is(err, cmux.ErrListenerClosed) && err != nil { + if err := ocr.multiplexer.Serve(); err != nil && !errors.Is(err, net.ErrClosed) { componentstatus.ReportStatus(host, componentstatus.NewFatalErrorEvent(err)) } }() diff --git a/receiver/opencensusreceiver/opencensus_test.go b/receiver/opencensusreceiver/opencensus_test.go index 003df32562c2..6781d846abb1 100644 --- a/receiver/opencensusreceiver/opencensus_test.go +++ b/receiver/opencensusreceiver/opencensus_test.go @@ -28,6 +28,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/component/componentstatus" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/confignet" @@ -774,6 +775,28 @@ func TestInvalidTLSCredentials(t *testing.T) { assert.Nil(t, srv) } +func TestStartShutdownShouldNotReportError(t *testing.T) { + addr := testutil.GetAvailableLocalAddress(t) + cfg := Config{ + ServerConfig: configgrpc.ServerConfig{ + NetAddr: confignet.AddrConfig{ + Endpoint: addr, + Transport: "tcp", + }, + }, + } + ocr := newOpenCensusReceiver(&cfg, new(consumertest.TracesSink), new(consumertest.MetricsSink), receivertest.NewNopSettings()) + require.NotNil(t, ocr) + + nopHostReporter := &nopHost{ + reportFunc: func(event *componentstatus.Event) { + assert.NoError(t, event.Err()) + }, + } + require.NoError(t, ocr.Start(context.Background(), nopHostReporter)) + require.NoError(t, ocr.Shutdown(context.Background())) +} + type errOrSinkConsumer struct { *consumertest.TracesSink *consumertest.MetricsSink @@ -829,3 +852,17 @@ func (esc *errOrSinkConsumer) Reset() { esc.MetricsSink.Reset() } } + +var _ componentstatus.Reporter = (*nopHost)(nil) + +type nopHost struct { + reportFunc func(event *componentstatus.Event) +} + +func (nh *nopHost) GetExtensions() map[component.ID]component.Component { + return nil +} + +func (nh *nopHost) Report(event *componentstatus.Event) { + nh.reportFunc(event) +}