-
Notifications
You must be signed in to change notification settings - Fork 850
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Autoconfigure experimental OTLP retry (#3791)
* Add retry policy class and wire into autoconfigure * Wire up otlp retry for DefaultGrpcExporter * Add documentation to autoconfigure readme * Add more tests * Move delegate accessor to :exporters:otlp:common * Use jackson for json serialization * PR feedback
- Loading branch information
Showing
29 changed files
with
713 additions
and
152 deletions.
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
48 changes: 48 additions & 0 deletions
48
exporters/otlp/common/src/main/java/io/opentelemetry/exporter/otlp/internal/RetryPolicy.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,48 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.exporter.otlp.internal; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import java.time.Duration; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
@AutoValue | ||
public abstract class RetryPolicy { | ||
|
||
private static final RetryPolicy DEFAULT = new RetryPolicyBuilder().build(); | ||
|
||
RetryPolicy() {} | ||
|
||
/** Return the default {@link RetryPolicy}. */ | ||
public static RetryPolicy getDefault() { | ||
return DEFAULT; | ||
} | ||
|
||
/** Returns a new {@link RetryPolicyBuilder} to construct a {@link RetryPolicy}. */ | ||
public static RetryPolicyBuilder builder() { | ||
return new RetryPolicyBuilder(); | ||
} | ||
|
||
/** Returns the max number of attempts, including the original request. */ | ||
public abstract int getMaxAttempts(); | ||
|
||
/** Returns the initial backoff. */ | ||
public abstract Duration getInitialBackoff(); | ||
|
||
/** Returns the max backoff. */ | ||
public abstract Duration getMaxBackoff(); | ||
|
||
/** Returns the backoff multiplier. */ | ||
public abstract double getBackoffMultiplier(); | ||
|
||
static RetryPolicy create( | ||
int maxAttempts, Duration initialBackoff, Duration maxBackoff, double backoffMultiplier) { | ||
return new AutoValue_RetryPolicy(maxAttempts, initialBackoff, maxBackoff, backoffMultiplier); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...otlp/common/src/main/java/io/opentelemetry/exporter/otlp/internal/RetryPolicyBuilder.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,69 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.exporter.otlp.internal; | ||
|
||
import static io.opentelemetry.api.internal.Utils.checkArgument; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.time.Duration; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
public final class RetryPolicyBuilder { | ||
|
||
private static final int DEFAULT_MAX_ATTEMPTS = 5; | ||
private static final Duration DEFAULT_INITIAL_BACKOFF = Duration.ofSeconds(1); | ||
private static final Duration DEFAULT_MAX_BACKOFF = Duration.ofSeconds(5); | ||
private static final double DEFAULT_BACKOFF_MULTIPLIER = 1.5; | ||
|
||
private int maxAttempts = DEFAULT_MAX_ATTEMPTS; | ||
private Duration initialBackoff = DEFAULT_INITIAL_BACKOFF; | ||
private Duration maxBackoff = DEFAULT_MAX_BACKOFF; | ||
private double backoffMultiplier = DEFAULT_BACKOFF_MULTIPLIER; | ||
|
||
RetryPolicyBuilder() {} | ||
|
||
/** | ||
* Set the maximum number of attempts, including the original request. Must be greater than 1 and | ||
* less than 6. | ||
*/ | ||
public RetryPolicyBuilder setMaxAttempts(int maxAttempts) { | ||
checkArgument( | ||
maxAttempts > 1 && maxAttempts < 6, "maxAttempts must be greater than 1 and less than 6"); | ||
this.maxAttempts = maxAttempts; | ||
return this; | ||
} | ||
|
||
/** Set the initial backoff. Must be greater than 0. */ | ||
public RetryPolicyBuilder setInitialBackoff(Duration initialBackoff) { | ||
requireNonNull(initialBackoff, "initialBackoff"); | ||
checkArgument(initialBackoff.toNanos() > 0, "initialBackoff must be greater than 0"); | ||
this.initialBackoff = initialBackoff; | ||
return this; | ||
} | ||
|
||
/** Set the maximum backoff. Must be greater than 0. */ | ||
public RetryPolicyBuilder setMaxBackoff(Duration maxBackoff) { | ||
requireNonNull(maxBackoff, "maxBackoff"); | ||
checkArgument(maxBackoff.toNanos() > 0, "maxBackoff must be greater than 0"); | ||
this.maxBackoff = maxBackoff; | ||
return this; | ||
} | ||
|
||
/** Set the backoff multiplier. Must be greater than 0.0. */ | ||
public RetryPolicyBuilder setBackoffMultiplier(double backoffMultiplier) { | ||
checkArgument(backoffMultiplier > 0, "backoffMultiplier must be greater than 0"); | ||
this.backoffMultiplier = backoffMultiplier; | ||
return this; | ||
} | ||
|
||
/** Build and return a {@link RetryPolicy} with the values of this builder. */ | ||
public RetryPolicy build() { | ||
return RetryPolicy.create(maxAttempts, initialBackoff, maxBackoff, backoffMultiplier); | ||
} | ||
} |
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
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
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.