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

[receiver/opencensus] Do not report error message on clean shutdown #36622

Merged
merged 4 commits into from
Dec 3, 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
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)
}
Loading