Skip to content

Commit

Permalink
Do not report error message on clean shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanotti committed Dec 2, 2024
1 parent dc74f03 commit a0e00ab
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
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 a0e00ab

Please sign in to comment.