Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class NoSharedInternalCodeTest {
"opentelemetry-exporter-common",
"opentelemetry-exporter-logging-otlp",
"opentelemetry-exporter-prometheus",
"opentelemetry-extension-trace-propagators",
"opentelemetry-opencensus-shim",
"opentelemetry-sdk",
"opentelemetry-sdk-logs",
Expand All @@ -52,9 +51,7 @@ class NoSharedInternalCodeTest {
"opentelemetry-exporter-otlp",
"opentelemetry-exporter-otlp-common",
"opentelemetry-exporter-otlp-profiles",
"opentelemetry-exporter-sender-grpc-managed-channel",
"opentelemetry-exporter-sender-jdk",
"opentelemetry-exporter-sender-okhttp");
"opentelemetry-exporter-sender-grpc-managed-channel");

private static final String OTEL_BASE_PACKAGE = "io.opentelemetry";
private static final Logger logger = Logger.getLogger(NoSharedInternalCodeTest.class.getName());
Expand Down
18 changes: 17 additions & 1 deletion docs/apidiffs/current_vs_latest/opentelemetry-sdk-common.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
Comparing source compatibility of opentelemetry-sdk-common-1.69.0-SNAPSHOT.jar against opentelemetry-sdk-common-1.68.0.jar
No changes.
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.common.export.GrpcSenderConfig (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) java.util.Set<io.opentelemetry.sdk.common.export.GrpcStatusCode> getRetryableGrpcStatusCodes()
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.common.export.HttpSenderConfig (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) java.util.Set<java.lang.Integer> getRetryableHttpResponseCodes()
+++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.common.export.impl.HttpExportUtil (not serializable)
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
+++ NEW SUPERCLASS: java.lang.Object
+++ NEW METHOD: PUBLIC(+) STATIC(+) java.util.OptionalLong retryAfterNanos(java.lang.String)
+++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.common.impl.DaemonThreadFactory (not serializable)
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
+++ NEW INTERFACE: java.util.concurrent.ThreadFactory
+++ NEW SUPERCLASS: java.lang.Object
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.common.impl.DaemonThreadFactory create(java.lang.String)
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.common.impl.DaemonThreadFactory createWithDelegate(java.lang.String, java.util.concurrent.ThreadFactory)
+++ NEW METHOD: PUBLIC(+) java.lang.Thread newThread(java.lang.Runnable)
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ public X509KeyManager getKeyManager() {
/** Get the {@link X509TrustManager}. */
@Nullable
public X509TrustManager getTrustManager() {
if (trustManager == null) {
try {
trustManager = TlsUtil.defaultTrustManager();
} catch (SSLException e) {
throw new IllegalStateException("Could not build default TrustManager.", e);
}
}
return trustManager;
}

Expand All @@ -129,10 +136,12 @@ public SSLContext getSslContext() {

try {
SSLContext sslContext = SSLContext.getInstance("TLS");
X509TrustManager trustManager = getTrustManager();
sslContext.init(
keyManager == null ? null : new KeyManager[] {keyManager},
trustManager == null ? null : new TrustManager[] {trustManager},
null);
this.sslContext = sslContext;
return sslContext;
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new IllegalArgumentException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,12 @@ void setSslContext_AlreadyExists_Throws() throws Exception {
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("keyManager has been previously configured");
}

@Test
void getTrustManager_keyManagerConfigured_resolvesDefaultTrustManager() throws Exception {
helper.setKeyManagerFromCerts(
serverTls.privateKey().getEncoded(), serverTls.certificate().getEncoded());
assertThat(helper.getTrustManager()).isNotNull();
assertThat(helper.getSslContext()).isNotNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.sun.net.httpserver.HttpHandler;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.common.export.MemoryMode;
import io.opentelemetry.sdk.common.internal.DaemonThreadFactory;
import io.opentelemetry.sdk.common.impl.DaemonThreadFactory;
import io.opentelemetry.sdk.metrics.Aggregation;
import io.opentelemetry.sdk.metrics.InstrumentType;
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
Expand Down Expand Up @@ -95,7 +95,7 @@ public static PrometheusHttpServerBuilder builder() {
0L,
TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(),
new DaemonThreadFactory("prometheus-http-server"));
DaemonThreadFactory.create("prometheus-http-server"));
}
HTTPServer.Builder httpServerBuilder = HTTPServer.builder();
if (translationStrategy != TranslationStrategy.UNDERSCORE_ESCAPING_WITH_SUFFIXES) {
Expand Down
1 change: 0 additions & 1 deletion exporters/sender/jdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ otelJava.osgiServiceLoaderProvides.set(listOf("io.opentelemetry.sdk.common.expor
dependencies {
annotationProcessor("com.google.auto.value:auto-value")

implementation(project(":exporters:common"))
implementation(project(":sdk:common"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
package io.opentelemetry.exporter.sender.jdk.internal;

import io.opentelemetry.api.impl.InstrumentationUtil;
import io.opentelemetry.exporter.internal.RetryUtil;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.common.export.Compressor;
import io.opentelemetry.sdk.common.export.HttpResponse;
import io.opentelemetry.sdk.common.export.HttpSender;
import io.opentelemetry.sdk.common.export.MessageWriter;
import io.opentelemetry.sdk.common.export.ProxyOptions;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import io.opentelemetry.sdk.common.internal.DaemonThreadFactory;
import io.opentelemetry.sdk.common.export.impl.HttpExportUtil;
import io.opentelemetry.sdk.common.impl.DaemonThreadFactory;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -26,6 +26,9 @@
import java.net.http.HttpResponse.BodyHandlers;
import java.nio.ByteBuffer;
import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -59,7 +62,8 @@
*/
public final class JdkHttpSender implements HttpSender {

private static final Set<Integer> retryableStatusCodes = RetryUtil.retryableHttpResponseCodes();
private static final Set<Integer> DEFAULT_RETRYABLE_HTTP_STATUS_CODES =
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(429, 502, 503, 504)));

private static final ThreadLocal<NoCopyByteArrayOutputStream> threadLocalBaos =
ThreadLocal.withInitial(NoCopyByteArrayOutputStream::new);
Expand All @@ -79,6 +83,7 @@ public final class JdkHttpSender implements HttpSender {
@Nullable private final RetryPolicy retryPolicy;
private final Predicate<IOException> retryExceptionPredicate;
private final long maxResponseBodySize;
private final Set<Integer> retryableStatusCodes;

// Visible for testing
JdkHttpSender(
Expand All @@ -91,6 +96,31 @@ public final class JdkHttpSender implements HttpSender {
@Nullable RetryPolicy retryPolicy,
@Nullable ExecutorService executorService,
long maxResponseBodySize) {
this(
client,
endpoint,
contentType,
compressor,
timeout,
headerSupplier,
retryPolicy,
executorService,
maxResponseBodySize,
DEFAULT_RETRYABLE_HTTP_STATUS_CODES);
}

// Visible for testing
JdkHttpSender(
HttpClient client,
URI endpoint,
String contentType,
@Nullable Compressor compressor,
Duration timeout,
Supplier<Map<String, List<String>>> headerSupplier,
@Nullable RetryPolicy retryPolicy,
@Nullable ExecutorService executorService,
long maxResponseBodySize,
Set<Integer> retryableStatusCodes) {
this.client = client;
this.endpoint = endpoint;
this.contentType = contentType;
Expand All @@ -110,6 +140,7 @@ public final class JdkHttpSender implements HttpSender {
this.managedExecutor = false;
}
this.maxResponseBodySize = maxResponseBodySize;
this.retryableStatusCodes = retryableStatusCodes;
}

JdkHttpSender(
Expand All @@ -124,7 +155,8 @@ public final class JdkHttpSender implements HttpSender {
@Nullable SSLContext sslContext,
@Nullable ExecutorService executorService,
long maxResponseBodySize,
@Nullable List<String> enabledProtocols) {
@Nullable List<String> enabledProtocols,
Set<Integer> retryableStatusCodes) {
this(
configureClient(sslContext, connectTimeout, proxyOptions, enabledProtocols),
endpoint,
Expand All @@ -134,7 +166,8 @@ public final class JdkHttpSender implements HttpSender {
headerSupplier,
retryPolicy,
executorService,
maxResponseBodySize);
maxResponseBodySize,
retryableStatusCodes);
}

private static ExecutorService newExecutor() {
Expand All @@ -144,7 +177,7 @@ private static ExecutorService newExecutor() {
60,
TimeUnit.SECONDS,
new SynchronousQueue<>(),
new DaemonThreadFactory("jdkhttp-executor"));
DaemonThreadFactory.create("jdkhttp-executor"));
}

private static HttpClient configureClient(
Expand Down Expand Up @@ -373,7 +406,7 @@ private static final class UnsupportedContentEncodingException extends IOExcepti

private static class NoCopyByteArrayOutputStream extends ByteArrayOutputStream {
NoCopyByteArrayOutputStream() {
super(retryableStatusCodes.size());
super();
}

private byte[] buf() {
Expand Down Expand Up @@ -456,7 +489,8 @@ private void resetPool() {
}

private static OptionalLong retryDelayNanos(java.net.http.HttpResponse<?> response) {
return RetryUtil.retryAfterNanos(response.headers().firstValue("Retry-After").orElse(null));
return HttpExportUtil.retryAfterNanos(
response.headers().firstValue("Retry-After").orElse(null));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public HttpSender createSender(HttpSenderConfig httpSenderConfig) {
httpSenderConfig.getSslContext(),
httpSenderConfig.getExecutorService(),
httpSenderConfig.getMaxResponseBodySize(),
httpSenderConfig.getEnabledProtocols());
httpSenderConfig.getEnabledProtocols(),
httpSenderConfig.getRetryableHttpResponseCodes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ void defaultExecutor_isBounded() {
null,
null,
Long.MAX_VALUE,
null);
null,
Collections.emptySet());

try {
int expectedMax = Math.max(Runtime.getRuntime().availableProcessors(), 5);
Expand Down Expand Up @@ -326,7 +327,8 @@ void connectTimeout() {
null,
null,
Long.MAX_VALUE,
null);
null,
Collections.emptySet());

assertThat(sender)
.extracting("client", as(InstanceOfAssertFactories.type(HttpClient.class)))
Expand Down
2 changes: 1 addition & 1 deletion exporters/sender/okhttp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tasks.withType<Test>().configureEach {
}

dependencies {
implementation(project(":exporters:common"))
testImplementation(project(":exporters:common"))
implementation(project(":sdk:common"))

annotationProcessor("com.google.auto.value:auto-value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package io.opentelemetry.exporter.sender.okhttp.internal;

import io.opentelemetry.exporter.internal.marshal.Marshaler;
import io.opentelemetry.sdk.common.export.Compressor;
import io.opentelemetry.sdk.common.export.MessageWriter;
import java.io.IOException;
Expand All @@ -17,7 +16,7 @@
import okio.Okio;

/**
* A {@link RequestBody} for reading from a {@link Marshaler} and writing in gRPC wire format.
* A {@link RequestBody} for reading from a {@link MessageWriter} and writing in gRPC wire format.
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
Expand Down
Loading
Loading