From afd826c5e68f5d0eeaadd480d32733a63c47e654 Mon Sep 17 00:00:00 2001 From: Stepan Rakitin Date: Tue, 5 Apr 2022 17:40:48 +0200 Subject: [PATCH] [exporter/otlp] Only retry on ResourceExhausted with retry info --- CHANGELOG.md | 1 + exporter/otlpexporter/otlp.go | 37 +++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 651f5e1192e..75b2a6d28da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 🚩 diff --git a/exporter/otlpexporter/otlp.go b/exporter/otlpexporter/otlp.go index e8adbf44417..a0dcf7539cc 100644 --- a/exporter/otlpexporter/otlp.go +++ b/exporter/otlpexporter/otlp.go @@ -141,26 +141,30 @@ 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, @@ -168,11 +172,18 @@ func shouldRetry(code codes.Code) bool { 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 {