Add new TLS related APIs on Jaeger buiders. (#5422)
This commit is contained in:
parent
a91995e5af
commit
db8ade397f
|
|
@ -1,2 +1,4 @@
|
|||
Comparing source compatibility of against
|
||||
No changes.
|
||||
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder (not serializable)
|
||||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
|
||||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder setSslContext(javax.net.ssl.SSLContext, javax.net.ssl.X509TrustManager)
|
||||
|
|
|
|||
|
|
@ -1,2 +1,4 @@
|
|||
Comparing source compatibility of against
|
||||
No changes.
|
||||
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.extension.trace.jaeger.sampler.JaegerRemoteSamplerBuilder (not serializable)
|
||||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
|
||||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.extension.trace.jaeger.sampler.JaegerRemoteSamplerBuilder setSslContext(javax.net.ssl.SSLContext, javax.net.ssl.X509TrustManager)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ import io.opentelemetry.exporter.internal.grpc.GrpcExporterBuilder;
|
|||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
/** Builder utility for this exporter. */
|
||||
public final class JaegerGrpcSpanExporterBuilder {
|
||||
|
|
@ -119,6 +121,16 @@ public final class JaegerGrpcSpanExporterBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the "bring-your-own" SSLContext for use with TLS. Users should call this _or_ set raw
|
||||
* certificate bytes, but not both.
|
||||
*/
|
||||
public JaegerGrpcSpanExporterBuilder setSslContext(
|
||||
SSLContext sslContext, X509TrustManager trustManager) {
|
||||
delegate.setSslContext(sslContext, trustManager);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link MeterProvider} to use to collect metrics related to export. If not set, uses
|
||||
* {@link GlobalOpenTelemetry#getMeterProvider()}.
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import io.opentelemetry.api.trace.SpanKind;
|
|||
import io.opentelemetry.api.trace.TraceFlags;
|
||||
import io.opentelemetry.api.trace.TraceId;
|
||||
import io.opentelemetry.api.trace.TraceState;
|
||||
import io.opentelemetry.exporter.internal.TlsUtil;
|
||||
import io.opentelemetry.exporter.internal.grpc.OkHttpGrpcExporter;
|
||||
import io.opentelemetry.exporter.jaeger.proto.api_v2.Collector;
|
||||
import io.opentelemetry.exporter.jaeger.proto.api_v2.Model;
|
||||
|
|
@ -50,6 +51,11 @@ import java.util.concurrent.CompletableFuture;
|
|||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.net.ssl.KeyManager;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509KeyManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
|
@ -309,6 +315,21 @@ class JaegerGrpcSpanExporterTest {
|
|||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
void validSslContextConfig() throws Exception {
|
||||
X509TrustManager trustManager = TlsUtil.trustManager(serverTls.certificate().getEncoded());
|
||||
|
||||
X509KeyManager keyManager =
|
||||
TlsUtil.keyManager(
|
||||
clientTls.privateKey().getEncoded(), clientTls.certificate().getEncoded());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(new KeyManager[] {keyManager}, new TrustManager[] {trustManager}, null);
|
||||
|
||||
assertThatCode(() -> JaegerGrpcSpanExporter.builder().setSslContext(sslContext, trustManager))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("PreferJavaTimeOverload")
|
||||
void invalidConfig() {
|
||||
|
|
|
|||
|
|
@ -92,6 +92,16 @@ public final class JaegerRemoteSamplerBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the "bring-your-own" SSLContext for use with TLS. Users should call this _or_ set raw
|
||||
* certificate bytes, but not both.
|
||||
*/
|
||||
public JaegerRemoteSamplerBuilder setSslContext(
|
||||
SSLContext sslContext, X509TrustManager trustManager) {
|
||||
tlsConfigHelper.setSslContext(sslContext, trustManager);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the polling interval for configuration updates. If unset, defaults to {@value
|
||||
* DEFAULT_POLLING_INTERVAL_MILLIS}ms. Must be positive.
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import com.linecorp.armeria.testing.junit5.server.SelfSignedCertificateExtension
|
|||
import com.linecorp.armeria.testing.junit5.server.ServerExtension;
|
||||
import io.github.netmikey.logunit.api.LogCapturer;
|
||||
import io.netty.handler.ssl.ClientAuth;
|
||||
import io.opentelemetry.exporter.internal.TlsUtil;
|
||||
import io.opentelemetry.internal.testing.slf4j.SuppressLogger;
|
||||
import io.opentelemetry.sdk.extension.trace.jaeger.proto.api_v2.Sampling;
|
||||
import io.opentelemetry.sdk.extension.trace.jaeger.proto.api_v2.Sampling.RateLimitingSamplingStrategy;
|
||||
|
|
@ -34,6 +35,11 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.net.ssl.KeyManager;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509KeyManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import org.awaitility.core.ThrowingRunnable;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Order;
|
||||
|
|
@ -192,6 +198,34 @@ class JaegerRemoteSamplerTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void tlsViaSslContext() throws Exception {
|
||||
X509TrustManager trustManager = TlsUtil.trustManager(certificate.certificate().getEncoded());
|
||||
|
||||
X509KeyManager keyManager =
|
||||
TlsUtil.keyManager(
|
||||
clientCertificate.privateKey().getEncoded(),
|
||||
clientCertificate.certificate().getEncoded());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(new KeyManager[] {keyManager}, new TrustManager[] {trustManager}, null);
|
||||
|
||||
try (JaegerRemoteSampler sampler =
|
||||
JaegerRemoteSampler.builder()
|
||||
.setEndpoint(server.httpsUri().toString())
|
||||
.setPollingInterval(1, TimeUnit.SECONDS)
|
||||
.setSslContext(sslContext, trustManager)
|
||||
.setServiceName(SERVICE_NAME)
|
||||
.build()) {
|
||||
assertThat(sampler).extracting("delegate").isInstanceOf(OkHttpGrpcService.class);
|
||||
|
||||
await().untilAsserted(samplerIsType(sampler, RateLimitingSampler.class));
|
||||
|
||||
// verify
|
||||
assertThat(sampler.getDescription()).contains("RateLimitingSampler{999.00}");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void description() {
|
||||
try (JaegerRemoteSampler sampler =
|
||||
|
|
|
|||
Loading…
Reference in New Issue