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
Prev Previous commit
Next Next commit
Add support to handle 402 and 413 http error code in Otlp exporter #5674


 - fixed code review comment
  • Loading branch information
mcmho committed Jul 19, 2022
commit d2863e656ffff663326700a427a49fb81a5af101
25 changes: 21 additions & 4 deletions exporter/otlphttpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,34 @@ func (e *exporter) export(ctx context.Context, url string, request []byte) error
return exporterhelper.NewThrottleRetry(formattedErr, time.Duration(retryAfter)*time.Second)
}

// do not retry these errors
if resp.StatusCode == http.StatusBadRequest || resp.StatusCode == http.StatusRequestEntityTooLarge ||
resp.StatusCode == http.StatusPaymentRequired {
// 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
}

func isPermanentClientFailure(code int) bool {
// 400 - bad request
if code == http.StatusBadRequest {
return true
}

// 402 - payment required typically means that an auth token isn't valid anymore and as such, we deem it as permanent
if code == http.StatusPaymentRequired {
return true
}

// 413 - request size is too large
if code == http.StatusRequestEntityTooLarge {
return true
}

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