Skip to content

Commit

Permalink
Test OpenTelemetry integration with TLS registry (#1988)
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvavrik committed Sep 7, 2024
1 parent 3294899 commit 51e54bd
Showing 1 changed file with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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.<Certificate> 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;
}
}

0 comments on commit 51e54bd

Please sign in to comment.