-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OTLP HTTP Exporter: Propagate HTTP 429s (#9905)
Changes otlphttp status code handling to propagate the error code as a grpc status code. This follows the logic that was implemented for the http receiver [here](https://github.com/open-telemetry/opentelemetry-collector/pull/9893/files). Fixes #9892 **Testing:** local tests were updated, going to test a local build.
- Loading branch information
1 parent
fcdfdaa
commit dc48d0e
Showing
9 changed files
with
161 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: bug_fix | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) | ||
component: otlphttpexporter | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Fixes a bug that was preventing the otlp http exporter from propagating status. | ||
|
||
# One or more tracking issues or pull requests related to the change | ||
issues: [9892] | ||
|
||
# (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: [user] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package httphelper // import "go.opentelemetry.io/collector/internal/httphelper" | ||
|
||
import ( | ||
"net/http" | ||
|
||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
// NewStatusFromMsgAndHTTPCode returns a gRPC status based on an error message string and a http status code. | ||
// This function is shared between the http receiver and http exporter for error propagation. | ||
func NewStatusFromMsgAndHTTPCode(errMsg string, statusCode int) *status.Status { | ||
var c codes.Code | ||
// Mapping based on https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md | ||
// 429 mapping to ResourceExhausted and 400 mapping to StatusBadRequest are exceptions. | ||
switch statusCode { | ||
case http.StatusBadRequest: | ||
c = codes.InvalidArgument | ||
case http.StatusUnauthorized: | ||
c = codes.Unauthenticated | ||
case http.StatusForbidden: | ||
c = codes.PermissionDenied | ||
case http.StatusNotFound: | ||
c = codes.Unimplemented | ||
case http.StatusTooManyRequests: | ||
c = codes.ResourceExhausted | ||
case http.StatusBadGateway, http.StatusServiceUnavailable, http.StatusGatewayTimeout: | ||
c = codes.Unavailable | ||
default: | ||
c = codes.Unknown | ||
} | ||
return status.New(c, errMsg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package httphelper | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func Test_ErrorMsgAndHTTPCodeToStatus(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
errMsg string | ||
statusCode int | ||
expected *status.Status | ||
}{ | ||
{ | ||
name: "Bad Request", | ||
errMsg: "test", | ||
statusCode: http.StatusBadRequest, | ||
expected: status.New(codes.InvalidArgument, "test"), | ||
}, | ||
{ | ||
name: "Unauthorized", | ||
errMsg: "test", | ||
statusCode: http.StatusUnauthorized, | ||
expected: status.New(codes.Unauthenticated, "test"), | ||
}, | ||
{ | ||
name: "Forbidden", | ||
errMsg: "test", | ||
statusCode: http.StatusForbidden, | ||
expected: status.New(codes.PermissionDenied, "test"), | ||
}, | ||
{ | ||
name: "Not Found", | ||
errMsg: "test", | ||
statusCode: http.StatusNotFound, | ||
expected: status.New(codes.Unimplemented, "test"), | ||
}, | ||
{ | ||
name: "Too Many Requests", | ||
errMsg: "test", | ||
statusCode: http.StatusTooManyRequests, | ||
expected: status.New(codes.ResourceExhausted, "test"), | ||
}, | ||
{ | ||
name: "Bad Gateway", | ||
errMsg: "test", | ||
statusCode: http.StatusBadGateway, | ||
expected: status.New(codes.Unavailable, "test"), | ||
}, | ||
{ | ||
name: "Service Unavailable", | ||
errMsg: "test", | ||
statusCode: http.StatusServiceUnavailable, | ||
expected: status.New(codes.Unavailable, "test"), | ||
}, | ||
{ | ||
name: "Gateway Timeout", | ||
errMsg: "test", | ||
statusCode: http.StatusGatewayTimeout, | ||
expected: status.New(codes.Unavailable, "test"), | ||
}, | ||
{ | ||
name: "Unsupported Media Type", | ||
errMsg: "test", | ||
statusCode: http.StatusUnsupportedMediaType, | ||
expected: status.New(codes.Unknown, "test"), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := NewStatusFromMsgAndHTTPCode(tt.errMsg, tt.statusCode) | ||
assert.Equal(t, tt.expected, result) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters