Skip to content

Commit

Permalink
Add support to handle 402, 413, 414, 431 http error code as permanent…
Browse files Browse the repository at this point in the history
… errors in OTLP exporter #5674 (#5685)

* Add support to handle 402 and 413 http error code in Otlp exporter #5674
 - added StatusRequestEntityTooLarge (413) and StatusPaymentRequired (402) as failure permanent

* Add support to handle 402 and 413 http error code in Otlp exporter #5674
 - added unit tests

* Add support to handle 402 and 413 http error code in Otlp exporter #5674
 - fixed code review comment

* Add support to handle 402 and 413 http error code in Otlp exporter #5674
 - added an entry in CHANGELOG.md

* Update CHANGELOG.md

Co-authored-by: Juraci Paixão Kröhling <[email protected]>

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

* Add support to handle 402, 413, 414, 431 http error code as permanent errors in OTLP exporter #5674
 - change ifs to a switch statement

* Add support to handle 402, 413, 414, 431 http error code as permanent errors in OTLP exporter #5674
 - fixed according to code review

* Add support to handle 402, 413, 414, 431 http error code as permanent errors in OTLP exporter #5674
 - fixed build-and-test  golangci-lint run

* Creates a signed commit

Co-authored-by: Juraci Paixão Kröhling <[email protected]>
  • Loading branch information
mcmho and jpkrohling authored Jul 25, 2022
1 parent 4395697 commit c769779
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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

0 comments on commit c769779

Please sign in to comment.