Skip to content

Commit

Permalink
[carbonreceiver]: Do not report fatal error when closed normally (#31913
Browse files Browse the repository at this point in the history
)

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Mar 22, 2024
1 parent 941d873 commit 2077e2a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .chloggen/carbonreceiver-error-closed.yaml
Original file line number Diff line number Diff line change
@@ -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]
2 changes: 2 additions & 0 deletions receiver/carbonreceiver/internal/transport/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion receiver/carbonreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"net"
"strings"

"go.opentelemetry.io/collector/component"
Expand Down Expand Up @@ -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))
}
}()
Expand Down
4 changes: 4 additions & 0 deletions receiver/carbonreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2077e2a

Please sign in to comment.