Skip to content

Commit

Permalink
[receiver/opencensus] Do not report error message on clean shutdown (#…
Browse files Browse the repository at this point in the history
…36622)

#### Description
The receiver is reporting error on a clean shutdown because it is not
looking for the correct error. Besides logging a false-positive error
message this can end up in a deadlock during shutdown due to
open-telemetry/opentelemetry-collector#9824

#### Testing

Added a test specific for that. In principle, this should be part of the
generated tests, but, to do that it will be necessary to add support to
the `Reporter` interface.

#### Documentation

Changelog.
  • Loading branch information
pjanotti authored Dec 3, 2024
1 parent 622f4ca commit ac03e9f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
27 changes: 27 additions & 0 deletions .chloggen/opencensus_receiver_no_error_msg_on_clean_shutdown.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: 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]
6 changes: 3 additions & 3 deletions receiver/opencensusreceiver/opencensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}()
Expand Down
37 changes: 37 additions & 0 deletions receiver/opencensusreceiver/opencensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

0 comments on commit ac03e9f

Please sign in to comment.