diff --git a/.chloggen/awsfirehose-contract.yaml b/.chloggen/awsfirehose-contract.yaml new file mode 100644 index 000000000000..37c640c8a321 --- /dev/null +++ b/.chloggen/awsfirehose-contract.yaml @@ -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: [] diff --git a/receiver/awsfirehosereceiver/logs_receiver.go b/receiver/awsfirehosereceiver/logs_receiver.go index a7b8c0628525..fd730e15ca68 100644 --- a/receiver/awsfirehosereceiver/logs_receiver.go +++ b/receiver/awsfirehosereceiver/logs_receiver.go @@ -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" @@ -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 } diff --git a/receiver/awsfirehosereceiver/logs_receiver_test.go b/receiver/awsfirehosereceiver/logs_receiver_test.go index da448640ddb4..6739f8137929 100644 --- a/receiver/awsfirehosereceiver/logs_receiver_test.go +++ b/receiver/awsfirehosereceiver/logs_receiver_test.go @@ -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" @@ -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": { diff --git a/receiver/awsfirehosereceiver/metrics_receiver.go b/receiver/awsfirehosereceiver/metrics_receiver.go index db24595ccc48..0f3e30a6a7ba 100644 --- a/receiver/awsfirehosereceiver/metrics_receiver.go +++ b/receiver/awsfirehosereceiver/metrics_receiver.go @@ -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" @@ -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 } diff --git a/receiver/awsfirehosereceiver/metrics_receiver_test.go b/receiver/awsfirehosereceiver/metrics_receiver_test.go index 0952b12596e6..c415b50a9c12 100644 --- a/receiver/awsfirehosereceiver/metrics_receiver_test.go +++ b/receiver/awsfirehosereceiver/metrics_receiver_test.go @@ -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" @@ -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": {