Skip to content

Commit

Permalink
chore: follow receiver contract
Browse files Browse the repository at this point in the history
  • Loading branch information
VihasMakwana committed Oct 31, 2024
1 parent ed09990 commit 3fd45f9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
25 changes: 25 additions & 0 deletions .chloggen/awsfirehose-contract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: awsfirehosereceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Follow receiver contract based on type of error

# One or more tracking issues or pull requests related to the change
issues: [5909]

# (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:

# 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: []
6 changes: 5 additions & 1 deletion receiver/awsfirehosereceiver/logs_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"

"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/receiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsfirehosereceiver/internal/unmarshaler"
Expand Down Expand Up @@ -81,7 +82,10 @@ func (mc *logsConsumer) Consume(ctx context.Context, records [][]byte, commonAtt

err = mc.consumer.ConsumeLogs(ctx, md)
if err != nil {
return http.StatusInternalServerError, err
if consumererror.IsPermanent(err) {
return http.StatusBadRequest, err
}
return http.StatusServiceUnavailable, err
}
return http.StatusOK, nil
}
8 changes: 7 additions & 1 deletion receiver/awsfirehosereceiver/logs_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/receiver/receivertest"
Expand Down Expand Up @@ -79,9 +80,14 @@ func TestLogsConsumer(t *testing.T) {
wantStatus: http.StatusBadRequest,
wantErr: testErr,
},
"WithConsumerErrorPermanent": {
consumerErr: consumererror.NewPermanent(testErr),
wantStatus: http.StatusBadRequest,
wantErr: consumererror.NewPermanent(testErr),
},
"WithConsumerError": {
consumerErr: testErr,
wantStatus: http.StatusInternalServerError,
wantStatus: http.StatusServiceUnavailable,
wantErr: testErr,
},
"WithNoError": {
Expand Down
6 changes: 5 additions & 1 deletion receiver/awsfirehosereceiver/metrics_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"

"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/receiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsfirehosereceiver/internal/unmarshaler"
Expand Down Expand Up @@ -82,7 +83,10 @@ func (mc *metricsConsumer) Consume(ctx context.Context, records [][]byte, common

err = mc.consumer.ConsumeMetrics(ctx, md)
if err != nil {
return http.StatusInternalServerError, err
if consumererror.IsPermanent(err) {
return http.StatusBadRequest, err
}
return http.StatusServiceUnavailable, err
}
return http.StatusOK, nil
}
8 changes: 7 additions & 1 deletion receiver/awsfirehosereceiver/metrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/receiver/receivertest"
Expand Down Expand Up @@ -79,9 +80,14 @@ func TestMetricsConsumer(t *testing.T) {
wantStatus: http.StatusBadRequest,
wantErr: testErr,
},
"WithConsumerErrorPermanent": {
consumerErr: consumererror.NewPermanent(testErr),
wantStatus: http.StatusBadRequest,
wantErr: consumererror.NewPermanent(testErr),
},
"WithConsumerError": {
consumerErr: testErr,
wantStatus: http.StatusInternalServerError,
wantStatus: http.StatusServiceUnavailable,
wantErr: testErr,
},
"WithNoError": {
Expand Down

0 comments on commit 3fd45f9

Please sign in to comment.