From a7ce11fdbed7253d2532f90f8658c5a2db422a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Vav=C5=99=C3=ADk?= Date: Fri, 6 Sep 2024 18:24:51 +0200 Subject: [PATCH] Test OpenTelemetry integration with TLS registry --- .../OpenTelemetryManagementIT.java | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/monitoring/opentelemetry/src/test/java/io/quarkus/ts/opentelemetry/OpenTelemetryManagementIT.java b/monitoring/opentelemetry/src/test/java/io/quarkus/ts/opentelemetry/OpenTelemetryManagementIT.java index 81846b115..9b768ed06 100644 --- a/monitoring/opentelemetry/src/test/java/io/quarkus/ts/opentelemetry/OpenTelemetryManagementIT.java +++ b/monitoring/opentelemetry/src/test/java/io/quarkus/ts/opentelemetry/OpenTelemetryManagementIT.java @@ -1,5 +1,7 @@ package io.quarkus.ts.opentelemetry; +import static io.quarkus.test.services.containers.JaegerGenericDockerContainerManagedResource.CERTIFICATE_CONTEXT_KEY; +import static io.quarkus.test.services.containers.JaegerGenericDockerContainerManagedResource.JAEGER_CLIENT_CERT_CN; import static io.restassured.RestAssured.given; import static org.awaitility.Awaitility.await; import static org.hamcrest.Matchers.containsString; @@ -10,23 +12,32 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.OS; import io.quarkus.test.bootstrap.JaegerService; +import io.quarkus.test.bootstrap.Protocol; import io.quarkus.test.bootstrap.RestService; import io.quarkus.test.scenarios.QuarkusScenario; +import io.quarkus.test.security.certificate.Certificate; +import io.quarkus.test.security.certificate.PemClientCertificate; import io.quarkus.test.services.JaegerContainer; import io.quarkus.test.services.QuarkusApplication; +@Tag("QUARKUS-4592") @QuarkusScenario public class OpenTelemetryManagementIT { - @JaegerContainer + @JaegerContainer(tls = true) static final JaegerService jaeger = new JaegerService(); @QuarkusApplication static RestService pong = new RestService() .withProperty("quarkus.application.name", "pong") .withProperty("quarkus.management.enabled", "true") - .withProperty("quarkus.otel.exporter.otlp.traces.endpoint", jaeger::getCollectorUrl); + .withProperty("quarkus.otel.exporter.otlp.traces.endpoint", () -> jaeger.getCollectorUrl(Protocol.HTTPS)) + .withProperty("quarkus.otel.exporter.otlp.traces.tls-configuration-name", "jaeger") + .withProperty("quarkus.tls.jaeger.key-store.pem.0.cert", OpenTelemetryManagementIT::getTlsCertPath) + .withProperty("quarkus.tls.jaeger.key-store.pem.0.key", OpenTelemetryManagementIT::getTlsKeyPath) + .withProperty("quarkus.tls.jaeger.trust-store.pem.certs", OpenTelemetryManagementIT::getTlsCaCertPath); private static final String PONG_ENDPOINT = "/hello"; private static final String MANAGEMENT_ENDPOINT = "/q/health/ready"; @@ -66,4 +77,30 @@ public void managementEndpointExcludedFromTracesTest() { Assertions.assertTrue(traces.contains(PONG_ENDPOINT), "Pong endpoint should be logged in traces"); Assertions.assertFalse(traces.contains(MANAGEMENT_ENDPOINT), "Management endpoint should not be logged in traces"); } + + private static String getTlsKeyPath() { + return addEscapes(getClientCertificate().keyPath()); + } + + private static String getTlsCertPath() { + return addEscapes(getClientCertificate().certPath()); + } + + private static String getTlsCaCertPath() { + return addEscapes(getClientCertificate().truststorePath()); + } + + private static PemClientCertificate getClientCertificate() { + return (PemClientCertificate) jaeger. getPropertyFromContext(CERTIFICATE_CONTEXT_KEY) + .getClientCertificateByCn(JAEGER_CLIENT_CERT_CN); + } + + static String addEscapes(String path) { + if (OS.WINDOWS.isCurrentOs()) { + // TODO: move this to the FW + // back-slashes have special meaning in Cygwin etc. + return path.replace("\\", "\\\\"); + } + return path; + } }