-
Notifications
You must be signed in to change notification settings - Fork 858
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
OTLP retry #3636
Closed
Closed
OTLP retry #3636
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
exporters/otlp/common/src/main/java/io/opentelemetry/RetryConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry; | ||
|
||
import io.opentelemetry.exporter.otlp.internal.ExponentialBackoffConfig; | ||
import java.time.Duration; | ||
|
||
@SuppressWarnings("InterfaceWithOnlyStatics") | ||
public interface RetryConfig { | ||
|
||
/** | ||
* Create a retry config representing an exponential backoff policy. | ||
* | ||
* @param maxAttempts the max number of retries | ||
* @param initialBackoff the wait period before attempting the first retry | ||
* @param maxBackoff the maximum wait period before retry attempts | ||
* @param backoffMultiplier the multiplication factor used to compute the delay between successive | ||
* failures | ||
* @param jitter the duration to randomly vary retry delays by | ||
*/ | ||
static RetryConfig exponentialBackoff( | ||
long maxAttempts, | ||
Duration initialBackoff, | ||
Duration maxBackoff, | ||
double backoffMultiplier, | ||
Duration jitter) { | ||
return ExponentialBackoffConfig.create( | ||
maxAttempts, initialBackoff, maxBackoff, backoffMultiplier, jitter); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...ommon/src/main/java/io/opentelemetry/exporter/otlp/internal/ExponentialBackoffConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.exporter.otlp.internal; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import io.opentelemetry.RetryConfig; | ||
import java.time.Duration; | ||
import javax.annotation.concurrent.Immutable; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
@AutoValue | ||
@Immutable | ||
public abstract class ExponentialBackoffConfig implements RetryConfig { | ||
|
||
public static ExponentialBackoffConfig create( | ||
long maxRetries, | ||
Duration initialBackoff, | ||
Duration maxBackoff, | ||
double backoffMultiplier, | ||
Duration jitter) { | ||
return new AutoValue_ExponentialBackoffConfig( | ||
maxRetries, initialBackoff, maxBackoff, backoffMultiplier, jitter); | ||
} | ||
|
||
/** The maximum number of retries. */ | ||
abstract long getMaxRetries(); | ||
|
||
/** The wait period before attempting the first retry. */ | ||
abstract Duration getInitialBackoff(); | ||
|
||
/** The maximum wait period before retry attempts. */ | ||
abstract Duration getMaxBackoff(); | ||
|
||
/** The multiplication factor used to compute the delay between successive failures. */ | ||
abstract double getBackoffMultiplier(); | ||
|
||
/** The duration to randomly vary retry delays by. */ | ||
abstract Duration getJitter(); | ||
|
||
ExponentialBackoffConfig() {} | ||
} |
65 changes: 65 additions & 0 deletions
65
exporters/otlp/common/src/main/java/io/opentelemetry/exporter/otlp/internal/RetryUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.exporter.otlp.internal; | ||
|
||
import static io.grpc.Status.Code.ABORTED; | ||
import static io.grpc.Status.Code.CANCELLED; | ||
import static io.grpc.Status.Code.DATA_LOSS; | ||
import static io.grpc.Status.Code.DEADLINE_EXCEEDED; | ||
import static io.grpc.Status.Code.OUT_OF_RANGE; | ||
import static io.grpc.Status.Code.RESOURCE_EXHAUSTED; | ||
import static io.grpc.Status.Code.UNAVAILABLE; | ||
|
||
import io.grpc.Status; | ||
import io.opentelemetry.RetryConfig; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import net.jodah.failsafe.RetryPolicy; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
public final class RetryUtil { | ||
|
||
private static final Set<Status.Code> RETRYABLE_CODES = | ||
Collections.unmodifiableSet( | ||
new HashSet<>( | ||
Arrays.asList( | ||
CANCELLED, | ||
DEADLINE_EXCEEDED, | ||
RESOURCE_EXHAUSTED, | ||
ABORTED, | ||
OUT_OF_RANGE, | ||
UNAVAILABLE, | ||
DATA_LOSS))); | ||
|
||
public static Set<Status.Code> retryableStatusCodes() { | ||
return RETRYABLE_CODES; | ||
} | ||
|
||
public static boolean hasRetryableStatusCode(Throwable throwable) { | ||
return RETRYABLE_CODES.contains(Status.fromThrowable(throwable).getCode()); | ||
} | ||
|
||
/** Convert the retry config to a retry policy. */ | ||
public static <T> RetryPolicy<T> toRetryPolicy(RetryConfig retryConfig) { | ||
ExponentialBackoffConfig exponentialBackoffConfig = (ExponentialBackoffConfig) retryConfig; | ||
return new RetryPolicy<T>() | ||
.withBackoff( | ||
exponentialBackoffConfig.getInitialBackoff().toMillis(), | ||
exponentialBackoffConfig.getMaxBackoff().toMillis(), | ||
ChronoUnit.MILLIS, | ||
exponentialBackoffConfig.getBackoffMultiplier()) | ||
.withMaxRetries((int) exponentialBackoffConfig.getMaxRetries()) | ||
.withJitter(exponentialBackoffConfig.getJitter()); | ||
} | ||
|
||
private RetryUtil() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heh. Let's not make it an interface, but a utility class. :)