|
5 | 5 |
|
6 | 6 | package io.opentelemetry.exporter.otlp.testing.internal; |
7 | 7 |
|
| 8 | +import static java.util.Collections.singletonList; |
| 9 | +import static java.util.Collections.singletonMap; |
8 | 10 | import static java.util.Objects.requireNonNull; |
| 11 | +import static java.util.stream.Collectors.toList; |
9 | 12 |
|
10 | 13 | import io.grpc.ManagedChannel; |
11 | 14 | import io.grpc.ManagedChannelBuilder; |
|
15 | 18 | import io.netty.handler.ssl.SslContext; |
16 | 19 | import io.opentelemetry.api.metrics.MeterProvider; |
17 | 20 | import io.opentelemetry.common.ComponentLoader; |
| 21 | +import io.opentelemetry.exporter.internal.RetryUtil; |
18 | 22 | import io.opentelemetry.exporter.internal.TlsConfigHelper; |
19 | | -import io.opentelemetry.exporter.internal.grpc.ManagedChannelUtil; |
20 | 23 | import io.opentelemetry.exporter.otlp.internal.OtlpUserAgent; |
21 | 24 | import io.opentelemetry.sdk.common.CompletableResultCode; |
22 | 25 | import io.opentelemetry.sdk.common.InternalTelemetryVersion; |
|
25 | 28 | import java.net.URI; |
26 | 29 | import java.time.Duration; |
27 | 30 | import java.util.Collection; |
| 31 | +import java.util.HashMap; |
| 32 | +import java.util.List; |
28 | 33 | import java.util.Map; |
29 | 34 | import java.util.concurrent.ExecutorService; |
30 | 35 | import java.util.concurrent.TimeUnit; |
@@ -148,11 +153,32 @@ public TelemetryExporterBuilder<T> setRetryPolicy(@Nullable RetryPolicy retryPol |
148 | 153 | throw new IllegalStateException("Can't happen"); |
149 | 154 | } |
150 | 155 | requireNonNull(channelBuilder, "channel"); |
151 | | - channelBuilder.defaultServiceConfig( |
152 | | - ManagedChannelUtil.toServiceConfig(grpcServiceName, retryPolicy)); |
| 156 | + channelBuilder.defaultServiceConfig(toServiceConfig(grpcServiceName, retryPolicy)); |
153 | 157 | return this; |
154 | 158 | } |
155 | 159 |
|
| 160 | + /** |
| 161 | + * Convert the {@link RetryPolicy} into a gRPC service config for the {@code serviceName}. The |
| 162 | + * resulting map can be passed to {@link ManagedChannelBuilder#defaultServiceConfig(Map)}. |
| 163 | + */ |
| 164 | + private static Map<String, ?> toServiceConfig(String serviceName, RetryPolicy retryPolicy) { |
| 165 | + List<Double> retryableStatusCodes = |
| 166 | + RetryUtil.retryableGrpcStatusCodes().stream().map(Double::parseDouble).collect(toList()); |
| 167 | + |
| 168 | + Map<String, Object> retryConfig = new HashMap<>(); |
| 169 | + retryConfig.put("retryableStatusCodes", retryableStatusCodes); |
| 170 | + retryConfig.put("maxAttempts", (double) retryPolicy.getMaxAttempts()); |
| 171 | + retryConfig.put("initialBackoff", retryPolicy.getInitialBackoff().toMillis() / 1000.0 + "s"); |
| 172 | + retryConfig.put("maxBackoff", retryPolicy.getMaxBackoff().toMillis() / 1000.0 + "s"); |
| 173 | + retryConfig.put("backoffMultiplier", retryPolicy.getBackoffMultiplier()); |
| 174 | + |
| 175 | + Map<String, Object> methodConfig = new HashMap<>(); |
| 176 | + methodConfig.put("name", singletonList(singletonMap("service", serviceName))); |
| 177 | + methodConfig.put("retryPolicy", retryConfig); |
| 178 | + |
| 179 | + return singletonMap("methodConfig", singletonList(methodConfig)); |
| 180 | + } |
| 181 | + |
156 | 182 | @Override |
157 | 183 | public TelemetryExporterBuilder<T> setProxyOptions(ProxyOptions proxyOptions) { |
158 | 184 | delegate.setProxyOptions(proxyOptions); |
|
0 commit comments