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 3 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
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
}

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
12 changes: 12 additions & 0 deletions exporter/otlphttpexporter/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,23 @@ 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: "419",
responseStatus: http.StatusTooManyRequests,
Expand Down