From c961731471f2f4108223be26bb1204480a15d858 Mon Sep 17 00:00:00 2001 From: Vihas Makwana <121151420+VihasMakwana@users.noreply.github.com> Date: Sat, 30 Nov 2024 02:01:39 +0530 Subject: [PATCH] [receiver/awsfirehose] follow receiver contract (#36124) --- .chloggen/awsfirehose-contract.yaml | 25 +++++++++++++++++++ receiver/awsfirehosereceiver/go.mod | 2 +- receiver/awsfirehosereceiver/logs_receiver.go | 6 ++++- .../awsfirehosereceiver/logs_receiver_test.go | 8 +++++- .../awsfirehosereceiver/metrics_receiver.go | 6 ++++- .../metrics_receiver_test.go | 8 +++++- 6 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 .chloggen/awsfirehose-contract.yaml diff --git a/.chloggen/awsfirehose-contract.yaml b/.chloggen/awsfirehose-contract.yaml new file mode 100644 index 000000000000..32c4fa039026 --- /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: breaking + +# 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/go.mod b/receiver/awsfirehosereceiver/go.mod index 018c9220cd77..3748359a80cd 100644 --- a/receiver/awsfirehosereceiver/go.mod +++ b/receiver/awsfirehosereceiver/go.mod @@ -14,6 +14,7 @@ require ( go.opentelemetry.io/collector/config/configtls v1.20.0 go.opentelemetry.io/collector/confmap v1.20.0 go.opentelemetry.io/collector/consumer v0.114.0 + go.opentelemetry.io/collector/consumer/consumererror v0.114.0 go.opentelemetry.io/collector/consumer/consumertest v0.114.0 go.opentelemetry.io/collector/pdata v1.20.0 go.opentelemetry.io/collector/receiver v0.114.0 @@ -50,7 +51,6 @@ require ( go.opentelemetry.io/collector/config/configcompression v1.20.0 // indirect go.opentelemetry.io/collector/config/configtelemetry v0.114.0 // indirect go.opentelemetry.io/collector/config/internal v0.114.0 // indirect - go.opentelemetry.io/collector/consumer/consumererror v0.114.0 // indirect go.opentelemetry.io/collector/consumer/consumerprofiles v0.114.0 // indirect go.opentelemetry.io/collector/extension v0.114.0 // indirect go.opentelemetry.io/collector/extension/auth v0.114.0 // indirect diff --git a/receiver/awsfirehosereceiver/logs_receiver.go b/receiver/awsfirehosereceiver/logs_receiver.go index 2bf02f3bd400..570e6cf1e745 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" @@ -80,7 +81,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 e1eb841f4c4b..4a5128583ac0 100644 --- a/receiver/awsfirehosereceiver/metrics_receiver.go +++ b/receiver/awsfirehosereceiver/metrics_receiver.go @@ -9,6 +9,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 efe6bf7ccbd3..d32ec4efc8a5 100644 --- a/receiver/awsfirehosereceiver/metrics_receiver_test.go +++ b/receiver/awsfirehosereceiver/metrics_receiver_test.go @@ -12,6 +12,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" @@ -80,9 +81,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": {