From 2077e2ac3b1c71844f0fc25281faa85e27bf9cb0 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Fri, 22 Mar 2024 11:37:35 -0700 Subject: [PATCH] [carbonreceiver]: Do not report fatal error when closed normally (#31913) Signed-off-by: Bogdan Drutu --- .chloggen/carbonreceiver-error-closed.yaml | 22 +++++++++++++++++++ .../internal/transport/server.go | 2 ++ receiver/carbonreceiver/receiver.go | 3 ++- receiver/carbonreceiver/receiver_test.go | 4 ++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100755 .chloggen/carbonreceiver-error-closed.yaml diff --git a/.chloggen/carbonreceiver-error-closed.yaml b/.chloggen/carbonreceiver-error-closed.yaml new file mode 100755 index 000000000000..f2acc9a6a393 --- /dev/null +++ b/.chloggen/carbonreceiver-error-closed.yaml @@ -0,0 +1,22 @@ +# 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: carbonreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Do not report fatal error when closed normally + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [31913] + +# 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/carbonreceiver/internal/transport/server.go b/receiver/carbonreceiver/internal/transport/server.go index 0b6ba5440db3..cf2f08afc490 100644 --- a/receiver/carbonreceiver/internal/transport/server.go +++ b/receiver/carbonreceiver/internal/transport/server.go @@ -23,6 +23,8 @@ type Server interface { // ListenAndServe is a blocking call that starts to listen for client messages // on the specific transport, and prepares the message to be processed by // the Parser and passed to the next consumer. + // + // Returns net.ErrClosed when closed. ListenAndServe( p protocol.Parser, mc consumer.Metrics, diff --git a/receiver/carbonreceiver/receiver.go b/receiver/carbonreceiver/receiver.go index f9b4ade581e2..c59787b41e5a 100644 --- a/receiver/carbonreceiver/receiver.go +++ b/receiver/carbonreceiver/receiver.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + "net" "strings" "go.opentelemetry.io/collector/component" @@ -96,7 +97,7 @@ func (r *carbonReceiver) Start(_ context.Context, _ component.Host) error { } r.server = server go func() { - if err := r.server.ListenAndServe(r.parser, r.nextConsumer, r.reporter); err != nil { + if err := r.server.ListenAndServe(r.parser, r.nextConsumer, r.reporter); err != nil && !errors.Is(err, net.ErrClosed) { r.settings.ReportStatus(component.NewFatalErrorEvent(err)) } }() diff --git a/receiver/carbonreceiver/receiver_test.go b/receiver/carbonreceiver/receiver_test.go index 0a4ccf5cbfac..4777bde05ac4 100644 --- a/receiver/carbonreceiver/receiver_test.go +++ b/receiver/carbonreceiver/receiver_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/consumer" @@ -192,6 +193,9 @@ func Test_carbonreceiver_EndToEnd(t *testing.T) { rt := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(recorder)) cs := receivertest.NewNopCreateSettings() cs.TracerProvider = rt + cs.ReportStatus = func(event *component.StatusEvent) { + assert.NoError(t, event.Err()) + } rcv, err := newMetricsReceiver(cs, *cfg, sink) require.NoError(t, err) r := rcv.(*carbonReceiver)