Skip to content

Commit

Permalink
[exporter/otlp] Only retry on ResourceExhausted with retry info
Browse files Browse the repository at this point in the history
  • Loading branch information
svrakitin committed Apr 5, 2022
1 parent 46e9040 commit afd826c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Remove deprecated structs/funcs from previous versions (#5131)
- Do not set TraceProvider to global otel (#5138)
- Remove deprecated funcs from otlpgrpc (#5144)
- [exporter/otlp] Only retry on ResourceExhausted with retry info (#5145)

### 🚩 Deprecations 🚩

Expand Down
37 changes: 24 additions & 13 deletions exporter/otlpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,38 +141,49 @@ func processError(err error) error {
return nil
}

// Now, this is this a real error.
// Now, this is a real error.

if !shouldRetry(st.Code()) {
// It is not a retryable error, we should not retry.
// Check if error is permanent, in which case we shouldn't ever retry.
if shouldNeverRetry(st) {
return consumererror.NewPermanent(err)
}

// Need to retry.

// Check if server returned throttling information.
// Check if server returned throttling information in retry info.
throttleDuration := getThrottleDuration(st)
if throttleDuration != 0 {
return exporterhelper.NewThrottleRetry(err, throttleDuration)
}

return err
// Check if we should retry even without retry info.
if shouldAlwaysRetry(st) {
return err
}

// Do not retry, treat as permanent.
return consumererror.NewPermanent(err)
}

func shouldRetry(code codes.Code) bool {
switch code {
func shouldNeverRetry(status *status.Status) bool {
switch status.Code() {
case codes.Canceled,
codes.DeadlineExceeded,
codes.ResourceExhausted,
codes.Aborted,
codes.OutOfRange,
codes.Unavailable,
codes.DataLoss:
// These are retryable errors.
return true
return false
}
return true
}

func shouldAlwaysRetry(status *status.Status) bool {
switch status.Code() {
case codes.ResourceExhausted:
return false
default:
return !shouldNeverRetry(status)
}
// Don't retry on any other code.
return false
}

func getThrottleDuration(status *status.Status) time.Duration {
Expand Down

0 comments on commit afd826c

Please sign in to comment.