Skip to content

Commit

Permalink
[receiver/signalfx] follow receiver contract (#36376)
Browse files Browse the repository at this point in the history
This PR enables awsfirehose to follow [the receiver
contract](https://github.com/open-telemetry/opentelemetry-collector/blob/df3c9e38a80ccc3b14705462be2e2e51c628a3b3/receiver/doc.go#L10)
and maintain the correct order of operations. The status code returned
by the receiver should be dependent upon type of error (i.e.
permanent/non-permanent error).

Also, updates the helpers to improve readability.

---------

Co-authored-by: Dmitrii Anoshin <[email protected]>
  • Loading branch information
VihasMakwana and dmitryax authored Nov 20, 2024
1 parent 99df805 commit f1b6311
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
24 changes: 24 additions & 0 deletions .chloggen/signalfx-contract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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
component: signalfxreceiver

# 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: Use 503 error code for retryable and 400 error code for not-retryable errors instead of responding with a 500 unconditionally.

# 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: []
12 changes: 11 additions & 1 deletion internal/coreinternal/errorutil/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ func HTTPError(w http.ResponseWriter, err error) {
if err == nil {
return
}
http.Error(w, err.Error(), GetHTTPStatusCodeFromError(err))
}

func GetHTTPStatusCodeFromError(err error) int {
// See requirements for receviers
// https://github.com/open-telemetry/opentelemetry-collector/blob/8e522ad950de6326a0841d7e1bef808bbc0d3537/receiver/doc.go#L10-L29

// See https://github.com/open-telemetry/opentelemetry-proto/blob/main/docs/specification.md#failures-1
// to see a list of retryable http status codes.

// non-retryable status
status := http.StatusBadRequest
if !consumererror.IsPermanent(err) {
// retryable status
status = http.StatusServiceUnavailable
}
http.Error(w, err.Error(), status)
return status
}
2 changes: 1 addition & 1 deletion receiver/signalfxreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/gorilla/mux v1.8.1
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter v0.114.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.114.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.114.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk v0.114.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.114.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/signalfx v0.114.0
Expand Down Expand Up @@ -57,7 +58,6 @@ require (
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.114.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/batchperresourceattr v0.114.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata v0.114.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.114.0 // indirect
Expand Down
3 changes: 2 additions & 1 deletion receiver/signalfxreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"go.opentelemetry.io/collector/receiver/receiverhelper"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/errorutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/signalfx"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/signalfxreceiver/internal/metadata"
Expand Down Expand Up @@ -195,7 +196,7 @@ func (r *sfxReceiver) readBody(ctx context.Context, resp http.ResponseWriter, re

func (r *sfxReceiver) writeResponse(ctx context.Context, resp http.ResponseWriter, err error) {
if err != nil {
r.failRequest(ctx, resp, http.StatusInternalServerError, errNextConsumerRespBody, err)
r.failRequest(ctx, resp, errorutil.GetHTTPStatusCodeFromError(err), errNextConsumerRespBody, err)
return
}

Expand Down

0 comments on commit f1b6311

Please sign in to comment.