Stabilize RetryPolicy API for OTLP exporters (#5524)
This commit is contained in:
parent
b5b02eb044
commit
7bd06ef189
|
@ -1,2 +1,19 @@
|
|||
Comparing source compatibility of against
|
||||
No changes.
|
||||
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder (not serializable)
|
||||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
|
||||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder setRetryPolicy(io.opentelemetry.sdk.common.export.RetryPolicy)
|
||||
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder (not serializable)
|
||||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
|
||||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder setRetryPolicy(io.opentelemetry.sdk.common.export.RetryPolicy)
|
||||
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder (not serializable)
|
||||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
|
||||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder setRetryPolicy(io.opentelemetry.sdk.common.export.RetryPolicy)
|
||||
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder (not serializable)
|
||||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
|
||||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder setRetryPolicy(io.opentelemetry.sdk.common.export.RetryPolicy)
|
||||
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder (not serializable)
|
||||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
|
||||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder setRetryPolicy(io.opentelemetry.sdk.common.export.RetryPolicy)
|
||||
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder (not serializable)
|
||||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
|
||||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder setRetryPolicy(io.opentelemetry.sdk.common.export.RetryPolicy)
|
||||
|
|
|
@ -1,2 +1,18 @@
|
|||
Comparing source compatibility of against
|
||||
No changes.
|
||||
+++ NEW CLASS: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.common.export.RetryPolicy (not serializable)
|
||||
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
|
||||
+++ NEW SUPERCLASS: java.lang.Object
|
||||
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.common.export.RetryPolicy$RetryPolicyBuilder builder()
|
||||
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) double getBackoffMultiplier()
|
||||
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.common.export.RetryPolicy getDefault()
|
||||
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.time.Duration getInitialBackoff()
|
||||
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) int getMaxAttempts()
|
||||
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.time.Duration getMaxBackoff()
|
||||
+++ NEW CLASS: PUBLIC(+) ABSTRACT(+) STATIC(+) io.opentelemetry.sdk.common.export.RetryPolicy$RetryPolicyBuilder (not serializable)
|
||||
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
|
||||
+++ NEW SUPERCLASS: java.lang.Object
|
||||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.common.export.RetryPolicy build()
|
||||
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.common.export.RetryPolicy$RetryPolicyBuilder setBackoffMultiplier(double)
|
||||
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.common.export.RetryPolicy$RetryPolicyBuilder setInitialBackoff(java.time.Duration)
|
||||
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.common.export.RetryPolicy$RetryPolicyBuilder setMaxAttempts(int)
|
||||
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.common.export.RetryPolicy$RetryPolicyBuilder setMaxBackoff(java.time.Duration)
|
||||
|
|
|
@ -18,7 +18,7 @@ import io.opentelemetry.exporter.internal.TlsConfigHelper;
|
|||
import io.opentelemetry.exporter.internal.marshal.Marshaler;
|
||||
import io.opentelemetry.exporter.internal.okhttp.OkHttpUtil;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryInterceptor;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
|
|
|
@ -9,9 +9,9 @@ import static java.util.stream.Collectors.toList;
|
|||
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.sdk.common.CompletableResultCode;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
|
|
@ -11,7 +11,7 @@ import io.opentelemetry.exporter.internal.ExporterBuilderUtil;
|
|||
import io.opentelemetry.exporter.internal.TlsConfigHelper;
|
||||
import io.opentelemetry.exporter.internal.auth.Authenticator;
|
||||
import io.opentelemetry.exporter.internal.marshal.Marshaler;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
package io.opentelemetry.exporter.internal.http;
|
||||
|
||||
import io.opentelemetry.exporter.internal.auth.Authenticator;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
import javax.annotation.Nullable;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
package io.opentelemetry.exporter.internal.retry;
|
||||
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import java.io.IOException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.Locale;
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.exporter.internal.retry;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.exporter.internal.retry;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -5,10 +5,7 @@
|
|||
|
||||
package io.opentelemetry.exporter.internal.retry;
|
||||
|
||||
import io.opentelemetry.exporter.internal.grpc.GrpcExporterBuilder;
|
||||
import io.opentelemetry.exporter.internal.grpc.GrpcStatusUtil;
|
||||
import io.opentelemetry.exporter.internal.http.HttpExporterBuilder;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
@ -47,29 +44,4 @@ public class RetryUtil {
|
|||
public static Set<Integer> retryableHttpResponseCodes() {
|
||||
return RETRYABLE_HTTP_STATUS_CODES;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reflectively access a {@link GrpcExporterBuilder}, or {@link HttpExporterBuilder} instance in
|
||||
* field called "delegate" of the instance, and set the {@link RetryPolicy}.
|
||||
*
|
||||
* @throws IllegalArgumentException if the instance does not contain a field called "delegate" of
|
||||
* a supported type.
|
||||
*/
|
||||
public static void setRetryPolicyOnDelegate(Object instance, RetryPolicy retryPolicy) {
|
||||
try {
|
||||
Field field = instance.getClass().getDeclaredField("delegate");
|
||||
field.setAccessible(true);
|
||||
Object value = field.get(instance);
|
||||
if (value instanceof GrpcExporterBuilder) {
|
||||
((GrpcExporterBuilder<?>) value).setRetryPolicy(retryPolicy);
|
||||
} else if (value instanceof HttpExporterBuilder) {
|
||||
((HttpExporterBuilder<?>) value).setRetryPolicy(retryPolicy);
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"delegate field is not type DefaultGrpcExporterBuilder or OkHttpGrpcExporterBuilder");
|
||||
}
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
throw new IllegalArgumentException("Unable to access delegate reflectively.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import static org.assertj.core.api.Assertions.assertThatCode;
|
|||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.skyscreamer.jsonassert.JSONAssert;
|
||||
|
|
|
@ -21,6 +21,7 @@ import static org.mockito.internal.verification.VerificationModeFactory.times;
|
|||
import com.linecorp.armeria.common.HttpResponse;
|
||||
import com.linecorp.armeria.common.HttpStatus;
|
||||
import com.linecorp.armeria.testing.junit5.server.mock.MockWebServerExtension;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import java.io.IOException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.time.Duration;
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.exporter.internal.retry;
|
||||
|
||||
import static org.assertj.core.api.Assertions.as;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import io.opentelemetry.exporter.internal.grpc.GrpcExporter;
|
||||
import io.opentelemetry.exporter.internal.grpc.GrpcExporterBuilder;
|
||||
import io.opentelemetry.exporter.internal.http.HttpExporterBuilder;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import org.assertj.core.api.InstanceOfAssertFactories;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class RetryUtilTest {
|
||||
|
||||
@Test
|
||||
void setRetryPolicyOnDelegate_GrpcExporterBuilder() throws URISyntaxException {
|
||||
RetryPolicy retryPolicy = RetryPolicy.getDefault();
|
||||
GrpcExporterBuilder<?> builder =
|
||||
GrpcExporter.builder(
|
||||
"otlp", "test", 0, new URI("http://localhost"), () -> (u1, u2) -> null, "/test");
|
||||
|
||||
RetryUtil.setRetryPolicyOnDelegate(new WithDelegate(builder), retryPolicy);
|
||||
|
||||
assertThat(builder)
|
||||
.extracting("retryPolicy", as(InstanceOfAssertFactories.type(RetryPolicy.class)))
|
||||
.isEqualTo(retryPolicy);
|
||||
}
|
||||
|
||||
@Test
|
||||
void setRetryPolicyOnDelegate_OkHttpExporterBuilder() {
|
||||
RetryPolicy retryPolicy = RetryPolicy.getDefault();
|
||||
HttpExporterBuilder<?> builder =
|
||||
new HttpExporterBuilder<>("otlp", "test", "http://localhost:4318/test");
|
||||
RetryUtil.setRetryPolicyOnDelegate(new WithDelegate(builder), retryPolicy);
|
||||
|
||||
assertThat(builder)
|
||||
.extracting("retryPolicy", as(InstanceOfAssertFactories.type(RetryPolicy.class)))
|
||||
.isEqualTo(retryPolicy);
|
||||
}
|
||||
|
||||
@Test
|
||||
void setRetryPolicyOnDelegate_InvalidUsage() {
|
||||
assertThatThrownBy(
|
||||
() -> RetryUtil.setRetryPolicyOnDelegate(new Object(), RetryPolicy.getDefault()))
|
||||
.hasMessageContaining("Unable to access delegate reflectively");
|
||||
assertThatThrownBy(
|
||||
() ->
|
||||
RetryUtil.setRetryPolicyOnDelegate(
|
||||
new WithDelegate(new Object()), RetryPolicy.getDefault()))
|
||||
.hasMessageContaining(
|
||||
"delegate field is not type DefaultGrpcExporterBuilder or OkHttpGrpcExporterBuilder");
|
||||
}
|
||||
|
||||
@SuppressWarnings({"UnusedVariable", "FieldCanBeLocal"})
|
||||
private static class WithDelegate {
|
||||
private final Object delegate;
|
||||
|
||||
private WithDelegate(Object delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ import io.opentelemetry.api.metrics.MeterProvider;
|
|||
import io.opentelemetry.exporter.internal.http.HttpExporterBuilder;
|
||||
import io.opentelemetry.exporter.internal.otlp.logs.LogsRequestMarshaler;
|
||||
import io.opentelemetry.exporter.otlp.internal.OtlpUserAgent;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
@ -113,6 +114,17 @@ public final class OtlpHttpLogRecordExporterBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ses the retry policy. Retry is disabled by default.
|
||||
*
|
||||
* @since 1.28.0
|
||||
*/
|
||||
public OtlpHttpLogRecordExporterBuilder setRetryPolicy(RetryPolicy retryPolicy) {
|
||||
requireNonNull(retryPolicy, "retryPolicy");
|
||||
delegate.setRetryPolicy(retryPolicy);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link MeterProvider} to use to collect metrics related to export. If not set, uses
|
||||
* {@link GlobalOpenTelemetry#getMeterProvider()}.
|
||||
|
|
|
@ -12,6 +12,7 @@ import io.opentelemetry.api.metrics.MeterProvider;
|
|||
import io.opentelemetry.exporter.internal.http.HttpExporterBuilder;
|
||||
import io.opentelemetry.exporter.internal.otlp.metrics.MetricsRequestMarshaler;
|
||||
import io.opentelemetry.exporter.otlp.internal.OtlpUserAgent;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import io.opentelemetry.sdk.metrics.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.export.AggregationTemporalitySelector;
|
||||
import io.opentelemetry.sdk.metrics.export.DefaultAggregationSelector;
|
||||
|
@ -157,6 +158,17 @@ public final class OtlpHttpMetricExporterBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ses the retry policy. Retry is disabled by default.
|
||||
*
|
||||
* @since 1.28.0
|
||||
*/
|
||||
public OtlpHttpMetricExporterBuilder setRetryPolicy(RetryPolicy retryPolicy) {
|
||||
requireNonNull(retryPolicy, "retryPolicy");
|
||||
delegate.setRetryPolicy(retryPolicy);
|
||||
return this;
|
||||
}
|
||||
|
||||
OtlpHttpMetricExporterBuilder exportAsJson() {
|
||||
delegate.exportAsJson();
|
||||
return this;
|
||||
|
|
|
@ -13,6 +13,7 @@ import io.opentelemetry.api.metrics.MeterProvider;
|
|||
import io.opentelemetry.exporter.internal.http.HttpExporterBuilder;
|
||||
import io.opentelemetry.exporter.internal.otlp.traces.TraceRequestMarshaler;
|
||||
import io.opentelemetry.exporter.otlp.internal.OtlpUserAgent;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
@ -114,6 +115,17 @@ public final class OtlpHttpSpanExporterBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ses the retry policy. Retry is disabled by default.
|
||||
*
|
||||
* @since 1.28.0
|
||||
*/
|
||||
public OtlpHttpSpanExporterBuilder setRetryPolicy(RetryPolicy retryPolicy) {
|
||||
requireNonNull(retryPolicy, "retryPolicy");
|
||||
delegate.setRetryPolicy(retryPolicy);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link MeterProvider} to use to collect metrics related to export. If not set, uses
|
||||
* {@link GlobalOpenTelemetry#getMeterProvider()}.
|
||||
|
|
|
@ -7,9 +7,9 @@ package io.opentelemetry.exporter.otlp.internal;
|
|||
|
||||
import static io.opentelemetry.sdk.metrics.Aggregation.explicitBucketHistogram;
|
||||
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
|
||||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import io.opentelemetry.sdk.metrics.Aggregation;
|
||||
import io.opentelemetry.sdk.metrics.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
|
||||
|
|
|
@ -9,7 +9,6 @@ import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.DATA_TYPE_L
|
|||
import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.PROTOCOL_GRPC;
|
||||
import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF;
|
||||
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter;
|
||||
import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder;
|
||||
import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter;
|
||||
|
@ -43,7 +42,7 @@ public class OtlpLogRecordExporterProvider implements ConfigurableLogRecordExpor
|
|||
builder::setTimeout,
|
||||
builder::setTrustedCertificates,
|
||||
builder::setClientTls,
|
||||
retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy));
|
||||
builder::setRetryPolicy);
|
||||
|
||||
return builder.build();
|
||||
} else if (protocol.equals(PROTOCOL_GRPC)) {
|
||||
|
@ -58,7 +57,7 @@ public class OtlpLogRecordExporterProvider implements ConfigurableLogRecordExpor
|
|||
builder::setTimeout,
|
||||
builder::setTrustedCertificates,
|
||||
builder::setClientTls,
|
||||
retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy));
|
||||
builder::setRetryPolicy);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.DATA_TYPE_M
|
|||
import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.PROTOCOL_GRPC;
|
||||
import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF;
|
||||
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter;
|
||||
import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder;
|
||||
import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter;
|
||||
|
@ -43,7 +42,7 @@ public class OtlpMetricExporterProvider implements ConfigurableMetricExporterPro
|
|||
builder::setTimeout,
|
||||
builder::setTrustedCertificates,
|
||||
builder::setClientTls,
|
||||
retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy));
|
||||
builder::setRetryPolicy);
|
||||
OtlpConfigUtil.configureOtlpAggregationTemporality(
|
||||
config, builder::setAggregationTemporalitySelector);
|
||||
OtlpConfigUtil.configureOtlpHistogramDefaultAggregation(
|
||||
|
@ -62,7 +61,7 @@ public class OtlpMetricExporterProvider implements ConfigurableMetricExporterPro
|
|||
builder::setTimeout,
|
||||
builder::setTrustedCertificates,
|
||||
builder::setClientTls,
|
||||
retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy));
|
||||
builder::setRetryPolicy);
|
||||
OtlpConfigUtil.configureOtlpAggregationTemporality(
|
||||
config, builder::setAggregationTemporalitySelector);
|
||||
OtlpConfigUtil.configureOtlpHistogramDefaultAggregation(
|
||||
|
|
|
@ -9,7 +9,6 @@ import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.DATA_TYPE_T
|
|||
import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.PROTOCOL_GRPC;
|
||||
import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF;
|
||||
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter;
|
||||
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder;
|
||||
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
|
||||
|
@ -42,7 +41,7 @@ public class OtlpSpanExporterProvider implements ConfigurableSpanExporterProvide
|
|||
builder::setTimeout,
|
||||
builder::setTrustedCertificates,
|
||||
builder::setClientTls,
|
||||
retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy));
|
||||
builder::setRetryPolicy);
|
||||
|
||||
return builder.build();
|
||||
} else if (protocol.equals(PROTOCOL_GRPC)) {
|
||||
|
@ -57,7 +56,7 @@ public class OtlpSpanExporterProvider implements ConfigurableSpanExporterProvide
|
|||
builder::setTimeout,
|
||||
builder::setTrustedCertificates,
|
||||
builder::setClientTls,
|
||||
retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy));
|
||||
builder::setRetryPolicy);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import io.opentelemetry.exporter.internal.grpc.GrpcExporter;
|
|||
import io.opentelemetry.exporter.internal.grpc.GrpcExporterBuilder;
|
||||
import io.opentelemetry.exporter.internal.otlp.logs.LogsRequestMarshaler;
|
||||
import io.opentelemetry.exporter.otlp.internal.OtlpUserAgent;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -158,6 +159,17 @@ public final class OtlpGrpcLogRecordExporterBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ses the retry policy. Retry is disabled by default.
|
||||
*
|
||||
* @since 1.28.0
|
||||
*/
|
||||
public OtlpGrpcLogRecordExporterBuilder setRetryPolicy(RetryPolicy retryPolicy) {
|
||||
requireNonNull(retryPolicy, "retryPolicy");
|
||||
delegate.setRetryPolicy(retryPolicy);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link MeterProvider} to use to collect metrics related to export. If not set, uses
|
||||
* {@link GlobalOpenTelemetry#getMeterProvider()}.
|
||||
|
|
|
@ -14,6 +14,7 @@ import io.opentelemetry.exporter.internal.grpc.GrpcExporter;
|
|||
import io.opentelemetry.exporter.internal.grpc.GrpcExporterBuilder;
|
||||
import io.opentelemetry.exporter.internal.otlp.metrics.MetricsRequestMarshaler;
|
||||
import io.opentelemetry.exporter.otlp.internal.OtlpUserAgent;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import io.opentelemetry.sdk.metrics.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.export.AggregationTemporalitySelector;
|
||||
import io.opentelemetry.sdk.metrics.export.DefaultAggregationSelector;
|
||||
|
@ -202,6 +203,17 @@ public final class OtlpGrpcMetricExporterBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ses the retry policy. Retry is disabled by default.
|
||||
*
|
||||
* @since 1.28.0
|
||||
*/
|
||||
public OtlpGrpcMetricExporterBuilder setRetryPolicy(RetryPolicy retryPolicy) {
|
||||
requireNonNull(retryPolicy, "retryPolicy");
|
||||
delegate.setRetryPolicy(retryPolicy);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of the exporter based on the builder's values.
|
||||
*
|
||||
|
|
|
@ -15,6 +15,7 @@ import io.opentelemetry.exporter.internal.grpc.GrpcExporter;
|
|||
import io.opentelemetry.exporter.internal.grpc.GrpcExporterBuilder;
|
||||
import io.opentelemetry.exporter.internal.otlp.traces.TraceRequestMarshaler;
|
||||
import io.opentelemetry.exporter.otlp.internal.OtlpUserAgent;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -155,6 +156,17 @@ public final class OtlpGrpcSpanExporterBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ses the retry policy. Retry is disabled by default.
|
||||
*
|
||||
* @since 1.28.0
|
||||
*/
|
||||
public OtlpGrpcSpanExporterBuilder setRetryPolicy(RetryPolicy retryPolicy) {
|
||||
requireNonNull(retryPolicy, "retryPolicy");
|
||||
delegate.setRetryPolicy(retryPolicy);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link MeterProvider} to use to collect metrics related to export. If not set, uses
|
||||
* {@link GlobalOpenTelemetry#getMeterProvider()}.
|
||||
|
|
|
@ -8,13 +8,12 @@ package io.opentelemetry.exporter.otlp.http.logs;
|
|||
import io.opentelemetry.exporter.internal.auth.Authenticator;
|
||||
import io.opentelemetry.exporter.internal.marshal.Marshaler;
|
||||
import io.opentelemetry.exporter.internal.otlp.logs.ResourceLogsMarshaler;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.AbstractHttpTelemetryExporterTest;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.FakeTelemetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporter;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporterBuilder;
|
||||
import io.opentelemetry.proto.logs.v1.ResourceLogs;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import io.opentelemetry.sdk.logs.data.LogRecordData;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
@ -91,7 +90,7 @@ class OtlpHttpLogRecordExporterTest
|
|||
|
||||
@Override
|
||||
public TelemetryExporterBuilder<LogRecordData> setRetryPolicy(RetryPolicy retryPolicy) {
|
||||
RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy);
|
||||
builder.setRetryPolicy(retryPolicy);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,13 +12,12 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|||
import io.opentelemetry.exporter.internal.auth.Authenticator;
|
||||
import io.opentelemetry.exporter.internal.marshal.Marshaler;
|
||||
import io.opentelemetry.exporter.internal.otlp.metrics.ResourceMetricsMarshaler;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.AbstractHttpTelemetryExporterTest;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.FakeTelemetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporter;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporterBuilder;
|
||||
import io.opentelemetry.proto.metrics.v1.ResourceMetrics;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import io.opentelemetry.sdk.metrics.Aggregation;
|
||||
import io.opentelemetry.sdk.metrics.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
|
||||
|
@ -145,7 +144,7 @@ class OtlpHttpMetricExporterTest
|
|||
|
||||
@Override
|
||||
public TelemetryExporterBuilder<MetricData> setRetryPolicy(RetryPolicy retryPolicy) {
|
||||
RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy);
|
||||
builder.setRetryPolicy(retryPolicy);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,13 +8,12 @@ package io.opentelemetry.exporter.otlp.http.trace;
|
|||
import io.opentelemetry.exporter.internal.auth.Authenticator;
|
||||
import io.opentelemetry.exporter.internal.marshal.Marshaler;
|
||||
import io.opentelemetry.exporter.internal.otlp.traces.ResourceSpansMarshaler;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.AbstractHttpTelemetryExporterTest;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.FakeTelemetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporter;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporterBuilder;
|
||||
import io.opentelemetry.proto.trace.v1.ResourceSpans;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
@ -90,7 +89,7 @@ class OtlpHttpSpanExporterTest extends AbstractHttpTelemetryExporterTest<SpanDat
|
|||
|
||||
@Override
|
||||
public TelemetryExporterBuilder<SpanData> setRetryPolicy(RetryPolicy retryPolicy) {
|
||||
RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy);
|
||||
builder.setRetryPolicy(retryPolicy);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,13 +6,10 @@
|
|||
package io.opentelemetry.exporter.otlp.logs;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
|
||||
import io.opentelemetry.exporter.internal.grpc.OkHttpGrpcExporter;
|
||||
import io.opentelemetry.exporter.internal.marshal.Marshaler;
|
||||
import io.opentelemetry.exporter.internal.otlp.logs.ResourceLogsMarshaler;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.AbstractGrpcTelemetryExporterTest;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.FakeTelemetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporterBuilder;
|
||||
|
@ -29,15 +26,6 @@ class OtlpGrpcLogRecordExporterTest
|
|||
super("log", ResourceLogs.getDefaultInstance());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetRetryPolicyOnDelegate() {
|
||||
assertThatCode(
|
||||
() ->
|
||||
RetryUtil.setRetryPolicyOnDelegate(
|
||||
OtlpGrpcLogRecordExporter.builder(), RetryPolicy.getDefault()))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
void usingOkHttp() throws Exception {
|
||||
try (Closeable exporter = OtlpGrpcLogRecordExporter.builder().build()) {
|
||||
|
|
|
@ -12,8 +12,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|||
import io.opentelemetry.exporter.internal.grpc.OkHttpGrpcExporter;
|
||||
import io.opentelemetry.exporter.internal.marshal.Marshaler;
|
||||
import io.opentelemetry.exporter.internal.otlp.metrics.ResourceMetricsMarshaler;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.AbstractGrpcTelemetryExporterTest;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.FakeTelemetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporterBuilder;
|
||||
|
@ -35,15 +33,6 @@ class OtlpGrpcMetricExporterTest
|
|||
super("metric", ResourceMetrics.getDefaultInstance());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetRetryPolicyOnDelegate() {
|
||||
assertThatCode(
|
||||
() ->
|
||||
RetryUtil.setRetryPolicyOnDelegate(
|
||||
OtlpGrpcMetricExporter.builder(), RetryPolicy.getDefault()))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
/** Test configuration specific to metric exporter. */
|
||||
@Test
|
||||
void validMetricConfig() {
|
||||
|
|
|
@ -6,13 +6,10 @@
|
|||
package io.opentelemetry.exporter.otlp.trace;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
|
||||
import io.opentelemetry.exporter.internal.grpc.OkHttpGrpcExporter;
|
||||
import io.opentelemetry.exporter.internal.marshal.Marshaler;
|
||||
import io.opentelemetry.exporter.internal.otlp.traces.ResourceSpansMarshaler;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.AbstractGrpcTelemetryExporterTest;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.FakeTelemetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporterBuilder;
|
||||
|
@ -28,15 +25,6 @@ class OtlpGrpcSpanExporterTest extends AbstractGrpcTelemetryExporterTest<SpanDat
|
|||
super("span", ResourceSpans.getDefaultInstance());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetRetryPolicyOnDelegate() {
|
||||
assertThatCode(
|
||||
() ->
|
||||
RetryUtil.setRetryPolicyOnDelegate(
|
||||
OtlpGrpcSpanExporter.builder(), RetryPolicy.getDefault()))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
void usingOkHttp() throws Exception {
|
||||
try (Closeable exporter = OtlpGrpcSpanExporter.builder().build()) {
|
||||
|
|
|
@ -6,15 +6,12 @@
|
|||
package io.opentelemetry.exporter.otlp.logs;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.inprocess.InProcessChannelBuilder;
|
||||
import io.opentelemetry.exporter.internal.grpc.UpstreamGrpcExporter;
|
||||
import io.opentelemetry.exporter.internal.marshal.Marshaler;
|
||||
import io.opentelemetry.exporter.internal.otlp.logs.ResourceLogsMarshaler;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.AbstractGrpcTelemetryExporterTest;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.FakeTelemetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.ManagedChannelTelemetryExporterBuilder;
|
||||
|
@ -32,15 +29,6 @@ class OtlpGrpcNettyLogRecordExporterTest
|
|||
super("log", ResourceLogs.getDefaultInstance());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetRetryPolicyOnDelegate() {
|
||||
assertThatCode(
|
||||
() ->
|
||||
RetryUtil.setRetryPolicyOnDelegate(
|
||||
OtlpGrpcLogRecordExporter.builder(), RetryPolicy.getDefault()))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // testing deprecated feature
|
||||
void usingGrpc() throws Exception {
|
||||
|
|
|
@ -6,15 +6,12 @@
|
|||
package io.opentelemetry.exporter.otlp.metrics;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.inprocess.InProcessChannelBuilder;
|
||||
import io.opentelemetry.exporter.internal.grpc.UpstreamGrpcExporter;
|
||||
import io.opentelemetry.exporter.internal.marshal.Marshaler;
|
||||
import io.opentelemetry.exporter.internal.otlp.metrics.ResourceMetricsMarshaler;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.AbstractGrpcTelemetryExporterTest;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.FakeTelemetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.ManagedChannelTelemetryExporterBuilder;
|
||||
|
@ -32,15 +29,6 @@ class OtlpGrpcNettyMetricExporterTest
|
|||
super("metric", ResourceMetrics.getDefaultInstance());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetRetryPolicyOnDelegate() {
|
||||
assertThatCode(
|
||||
() ->
|
||||
RetryUtil.setRetryPolicyOnDelegate(
|
||||
OtlpGrpcMetricExporter.builder(), RetryPolicy.getDefault()))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // testing deprecated feature
|
||||
void usingGrpc() throws Exception {
|
||||
|
|
|
@ -6,15 +6,12 @@
|
|||
package io.opentelemetry.exporter.otlp.trace;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.inprocess.InProcessChannelBuilder;
|
||||
import io.opentelemetry.exporter.internal.grpc.UpstreamGrpcExporter;
|
||||
import io.opentelemetry.exporter.internal.marshal.Marshaler;
|
||||
import io.opentelemetry.exporter.internal.otlp.traces.ResourceSpansMarshaler;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.AbstractGrpcTelemetryExporterTest;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.FakeTelemetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.testing.internal.ManagedChannelTelemetryExporterBuilder;
|
||||
|
@ -32,15 +29,6 @@ class OtlpGrpcNettySpanExporterTest
|
|||
super("span", ResourceSpans.getDefaultInstance());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetRetryPolicyOnDelegate() {
|
||||
assertThatCode(
|
||||
() ->
|
||||
RetryUtil.setRetryPolicyOnDelegate(
|
||||
OtlpGrpcSpanExporter.builder(), RetryPolicy.getDefault()))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // testing deprecated feature
|
||||
void usingGrpc() throws Exception {
|
||||
|
|
|
@ -27,7 +27,6 @@ import io.opentelemetry.exporter.internal.TlsUtil;
|
|||
import io.opentelemetry.exporter.internal.grpc.OkHttpGrpcExporter;
|
||||
import io.opentelemetry.exporter.internal.grpc.UpstreamGrpcExporter;
|
||||
import io.opentelemetry.exporter.internal.marshal.Marshaler;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.internal.testing.slf4j.SuppressLogger;
|
||||
import io.opentelemetry.proto.collector.logs.v1.ExportLogsServiceRequest;
|
||||
import io.opentelemetry.proto.collector.logs.v1.ExportLogsServiceResponse;
|
||||
|
@ -36,6 +35,7 @@ import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceResponse;
|
|||
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest;
|
||||
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceResponse;
|
||||
import io.opentelemetry.sdk.common.CompletableResultCode;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
|
|
|
@ -30,7 +30,6 @@ import io.opentelemetry.exporter.internal.TlsUtil;
|
|||
import io.opentelemetry.exporter.internal.grpc.UpstreamGrpcExporter;
|
||||
import io.opentelemetry.exporter.internal.http.HttpExporter;
|
||||
import io.opentelemetry.exporter.internal.marshal.Marshaler;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.internal.testing.slf4j.SuppressLogger;
|
||||
import io.opentelemetry.proto.collector.logs.v1.ExportLogsServiceRequest;
|
||||
import io.opentelemetry.proto.collector.logs.v1.ExportLogsServiceResponse;
|
||||
|
@ -39,6 +38,7 @@ import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceResponse;
|
|||
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest;
|
||||
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceResponse;
|
||||
import io.opentelemetry.sdk.common.CompletableResultCode;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -7,9 +7,8 @@ package io.opentelemetry.exporter.otlp.testing.internal;
|
|||
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.opentelemetry.exporter.internal.auth.Authenticator;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import io.opentelemetry.sdk.logs.data.LogRecordData;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -80,7 +79,7 @@ final class GrpcLogRecordExporterBuilderWrapper implements TelemetryExporterBuil
|
|||
|
||||
@Override
|
||||
public TelemetryExporterBuilder<LogRecordData> setRetryPolicy(RetryPolicy retryPolicy) {
|
||||
RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy);
|
||||
builder.setRetryPolicy(retryPolicy);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,8 @@ package io.opentelemetry.exporter.otlp.testing.internal;
|
|||
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.opentelemetry.exporter.internal.auth.Authenticator;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -80,7 +79,7 @@ final class GrpcMetricExporterBuilderWrapper implements TelemetryExporterBuilder
|
|||
|
||||
@Override
|
||||
public TelemetryExporterBuilder<MetricData> setRetryPolicy(RetryPolicy retryPolicy) {
|
||||
RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy);
|
||||
builder.setRetryPolicy(retryPolicy);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,8 @@ package io.opentelemetry.exporter.otlp.testing.internal;
|
|||
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.opentelemetry.exporter.internal.auth.Authenticator;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -81,7 +80,7 @@ final class GrpcSpanExporterBuilderWrapper implements TelemetryExporterBuilder<S
|
|||
|
||||
@Override
|
||||
public TelemetryExporterBuilder<SpanData> setRetryPolicy(RetryPolicy retryPolicy) {
|
||||
RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy);
|
||||
builder.setRetryPolicy(retryPolicy);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,9 +15,9 @@ import io.netty.handler.ssl.SslContext;
|
|||
import io.opentelemetry.exporter.internal.TlsConfigHelper;
|
||||
import io.opentelemetry.exporter.internal.auth.Authenticator;
|
||||
import io.opentelemetry.exporter.internal.grpc.ManagedChannelUtil;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.exporter.otlp.internal.OtlpUserAgent;
|
||||
import io.opentelemetry.sdk.common.CompletableResultCode;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
|
|
|
@ -7,10 +7,10 @@ package io.opentelemetry.exporter.otlp.testing.internal;
|
|||
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.opentelemetry.exporter.internal.auth.Authenticator;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder;
|
||||
import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder;
|
||||
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import io.opentelemetry.sdk.logs.data.LogRecordData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||
|
|
|
@ -9,9 +9,9 @@ import io.opentelemetry.exporter.internal.auth.Authenticator;
|
|||
import io.opentelemetry.exporter.internal.http.HttpSender;
|
||||
import io.opentelemetry.exporter.internal.okhttp.OkHttpUtil;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryInterceptor;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.sdk.common.CompletableResultCode;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.time.Duration;
|
||||
|
|
|
@ -8,7 +8,7 @@ package io.opentelemetry.exporter.sender.okhttp.internal;
|
|||
import io.opentelemetry.exporter.internal.auth.Authenticator;
|
||||
import io.opentelemetry.exporter.internal.http.HttpSender;
|
||||
import io.opentelemetry.exporter.internal.http.HttpSenderProvider;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.common.export;
|
||||
|
||||
import static io.opentelemetry.api.internal.Utils.checkArgument;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import java.time.Duration;
|
||||
|
||||
/** Configuration for exporter exponential retry policy. */
|
||||
@AutoValue
|
||||
public abstract class RetryPolicy {
|
||||
|
||||
private static final int DEFAULT_MAX_ATTEMPTS = 5;
|
||||
|
||||
@SuppressWarnings("StronglyTypeTime")
|
||||
private static final int DEFAULT_INITIAL_BACKOFF_SECONDS = 1;
|
||||
|
||||
@SuppressWarnings("StronglyTypeTime")
|
||||
private static final int DEFAULT_MAX_BACKOFF_SECONDS = 5;
|
||||
|
||||
private static final double DEFAULT_BACKOFF_MULTIPLIER = 1.5;
|
||||
|
||||
private static final RetryPolicy DEFAULT = RetryPolicy.builder().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 AutoValue_RetryPolicy.Builder()
|
||||
.setMaxAttempts(DEFAULT_MAX_ATTEMPTS)
|
||||
.setInitialBackoff(Duration.ofSeconds(DEFAULT_INITIAL_BACKOFF_SECONDS))
|
||||
.setMaxBackoff(Duration.ofSeconds(DEFAULT_MAX_BACKOFF_SECONDS))
|
||||
.setBackoffMultiplier(DEFAULT_BACKOFF_MULTIPLIER);
|
||||
}
|
||||
|
||||
/** 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();
|
||||
|
||||
/** Builder for {@link RetryPolicy}. */
|
||||
@AutoValue.Builder
|
||||
public abstract static class RetryPolicyBuilder {
|
||||
|
||||
RetryPolicyBuilder() {}
|
||||
|
||||
/**
|
||||
* Set the maximum number of attempts, including the original request. Must be greater than 1
|
||||
* and less than 6. Defaults to {@value DEFAULT_MAX_ATTEMPTS}.
|
||||
*/
|
||||
public abstract RetryPolicyBuilder setMaxAttempts(int maxAttempts);
|
||||
|
||||
/**
|
||||
* Set the initial backoff. Must be greater than 0. Defaults to {@value
|
||||
* DEFAULT_INITIAL_BACKOFF_SECONDS} seconds.
|
||||
*/
|
||||
public abstract RetryPolicyBuilder setInitialBackoff(Duration initialBackoff);
|
||||
|
||||
/**
|
||||
* Set the maximum backoff. Must be greater than 0. Defaults to {@value
|
||||
* DEFAULT_MAX_BACKOFF_SECONDS} seconds.
|
||||
*/
|
||||
public abstract RetryPolicyBuilder setMaxBackoff(Duration maxBackoff);
|
||||
|
||||
/**
|
||||
* Set the backoff multiplier. Must be greater than 0.0. Defaults to {@value
|
||||
* DEFAULT_BACKOFF_MULTIPLIER}.
|
||||
*/
|
||||
public abstract RetryPolicyBuilder setBackoffMultiplier(double backoffMultiplier);
|
||||
|
||||
abstract RetryPolicy autoBuild();
|
||||
|
||||
/** Build and return a {@link RetryPolicy} with the values of this builder. */
|
||||
public RetryPolicy build() {
|
||||
RetryPolicy retryPolicy = autoBuild();
|
||||
checkArgument(
|
||||
retryPolicy.getMaxAttempts() > 1 && retryPolicy.getMaxAttempts() < 6,
|
||||
"maxAttempts must be greater than 1 and less than 6");
|
||||
checkArgument(
|
||||
retryPolicy.getInitialBackoff().toNanos() > 0, "initialBackoff must be greater than 0");
|
||||
checkArgument(retryPolicy.getMaxBackoff().toNanos() > 0, "maxBackoff must be greater than 0");
|
||||
checkArgument(
|
||||
retryPolicy.getBackoffMultiplier() > 0, "backoffMultiplier must be greater than 0");
|
||||
|
||||
return retryPolicy;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,22 +3,27 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.exporter.internal.retry;
|
||||
package io.opentelemetry.sdk.common;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import io.opentelemetry.sdk.common.export.RetryPolicy;
|
||||
import java.time.Duration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class RetryPolicyTest {
|
||||
public class RetryPolicyTest {
|
||||
|
||||
@Test
|
||||
void defaultRetryPolicy() {
|
||||
assertThat(RetryPolicy.getDefault().getMaxAttempts()).isEqualTo(5);
|
||||
assertThat(RetryPolicy.getDefault().getInitialBackoff()).isEqualTo(Duration.ofSeconds(1));
|
||||
assertThat(RetryPolicy.getDefault().getMaxBackoff()).isEqualTo(Duration.ofSeconds(5));
|
||||
assertThat(RetryPolicy.getDefault().getBackoffMultiplier()).isEqualTo(1.5);
|
||||
RetryPolicy retryPolicy = RetryPolicy.builder().build();
|
||||
|
||||
assertThat(retryPolicy.getMaxAttempts()).isEqualTo(5);
|
||||
assertThat(retryPolicy.getInitialBackoff()).isEqualTo(Duration.ofSeconds(1));
|
||||
assertThat(retryPolicy.getMaxBackoff()).isEqualTo(Duration.ofSeconds(5));
|
||||
assertThat(retryPolicy.getBackoffMultiplier()).isEqualTo(1.5);
|
||||
|
||||
assertThat(RetryPolicy.getDefault()).isEqualTo(retryPolicy);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -30,6 +35,7 @@ class RetryPolicyTest {
|
|||
.setMaxBackoff(Duration.ofSeconds(1))
|
||||
.setBackoffMultiplier(1.1)
|
||||
.build();
|
||||
|
||||
assertThat(retryPolicy.getMaxAttempts()).isEqualTo(2);
|
||||
assertThat(retryPolicy.getInitialBackoff()).isEqualTo(Duration.ofMillis(2));
|
||||
assertThat(retryPolicy.getMaxBackoff()).isEqualTo(Duration.ofSeconds(1));
|
||||
|
@ -38,19 +44,19 @@ class RetryPolicyTest {
|
|||
|
||||
@Test
|
||||
void invalidRetryPolicy() {
|
||||
assertThatThrownBy(() -> RetryPolicy.builder().setMaxAttempts(1))
|
||||
assertThatThrownBy(() -> RetryPolicy.builder().setMaxAttempts(1).build())
|
||||
.isInstanceOf(IllegalArgumentException.class);
|
||||
assertThatThrownBy(() -> RetryPolicy.builder().setMaxAttempts(6))
|
||||
assertThatThrownBy(() -> RetryPolicy.builder().setMaxAttempts(6).build())
|
||||
.isInstanceOf(IllegalArgumentException.class);
|
||||
assertThatThrownBy(() -> RetryPolicy.builder().setInitialBackoff(null))
|
||||
assertThatThrownBy(() -> RetryPolicy.builder().setInitialBackoff(null).build())
|
||||
.isInstanceOf(NullPointerException.class);
|
||||
assertThatThrownBy(() -> RetryPolicy.builder().setInitialBackoff(Duration.ofMillis(0)))
|
||||
assertThatThrownBy(() -> RetryPolicy.builder().setInitialBackoff(Duration.ofMillis(0)).build())
|
||||
.isInstanceOf(IllegalArgumentException.class);
|
||||
assertThatThrownBy(() -> RetryPolicy.builder().setMaxBackoff(null))
|
||||
assertThatThrownBy(() -> RetryPolicy.builder().setMaxBackoff(null).build())
|
||||
.isInstanceOf(NullPointerException.class);
|
||||
assertThatThrownBy(() -> RetryPolicy.builder().setMaxBackoff(Duration.ofMillis(0)))
|
||||
assertThatThrownBy(() -> RetryPolicy.builder().setMaxBackoff(Duration.ofMillis(0)).build())
|
||||
.isInstanceOf(IllegalArgumentException.class);
|
||||
assertThatThrownBy(() -> RetryPolicy.builder().setBackoffMultiplier(0))
|
||||
assertThatThrownBy(() -> RetryPolicy.builder().setBackoffMultiplier(0).build())
|
||||
.isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue