Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to handle 402, 413, 414, 431 http error code as permanent errors in OTLP exporter #5674 #5685

Merged
merged 12 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Expose `pcommon.NewSliceFromRaw` function (#5679)
- `loggingexporter`: create the exporter's logger from the service's logger (#5677)
- Add `otelcol_exporter_queue_capacity` metrics show the collector's exporter queue capacity (#5475)
- Add support to handle 402, 413, 414, 431 http error code as permanent errors in OTLP exporter (#5685)

### 🧰 Bug fixes 🧰

Expand Down
23 changes: 21 additions & 2 deletions exporter/otlphttpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,34 @@ func (e *exporter) export(ctx context.Context, url string, request []byte) error
return exporterhelper.NewThrottleRetry(formattedErr, time.Duration(retryAfter)*time.Second)
}

if resp.StatusCode == http.StatusBadRequest {
// Report the failure as permanent if the server thinks the request is malformed.
if isPermanentClientFailure(resp.StatusCode) {
// Do not retry; report the failure as permanent if the server thinks the request is malformed.
return consumererror.NewPermanent(formattedErr)
}

// All other errors are retryable, so don't wrap them in consumererror.NewPermanent().
return formattedErr
}

// Does the 'code' indicate a permanent error
func isPermanentClientFailure(code int) bool {
switch code {
case http.StatusBadRequest:
return true
case http.StatusPaymentRequired:
// 402 - payment required typically means that an auth token isn't valid anymore and as such, we deem it as permanent
return true
case http.StatusRequestEntityTooLarge:
return true
case http.StatusRequestURITooLong:
return true
case http.StatusRequestHeaderFieldsTooLarge:
return true
default:
return false
}
}

// Read the response and decode the status.Status from the body.
// Returns nil if the response is empty or cannot be decoded.
func readResponse(resp *http.Response) *status.Status {
Expand Down
24 changes: 24 additions & 0 deletions exporter/otlphttpexporter/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,35 @@ func TestErrorResponses(t *testing.T) {
responseBody: status.New(codes.InvalidArgument, "Bad field"),
isPermErr: true,
},
{
name: "402",
responseStatus: http.StatusPaymentRequired,
responseBody: status.New(codes.InvalidArgument, "Bad field"),
isPermErr: true,
},
{
name: "404",
responseStatus: http.StatusNotFound,
err: errors.New(errMsgPrefix + "404"),
},
{
name: "413",
responseStatus: http.StatusRequestEntityTooLarge,
responseBody: status.New(codes.InvalidArgument, "Bad field"),
isPermErr: true,
},
{
name: "414",
responseStatus: http.StatusRequestURITooLong,
responseBody: status.New(codes.InvalidArgument, "Bad field"),
isPermErr: true,
},
{
name: "431",
responseStatus: http.StatusRequestHeaderFieldsTooLarge,
responseBody: status.New(codes.InvalidArgument, "Bad field"),
isPermErr: true,
},
{
name: "419",
responseStatus: http.StatusTooManyRequests,
Expand Down