From 2e0d93c916d3171704d6628f0e2182204d66fab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Fri, 25 Jun 2021 10:42:05 +0200 Subject: [PATCH] Creates an OpenTracing integration test --- .../smallrye-opentracing/pom.xml | 100 +++++- .../it/opentracing/ExporterResource.java | 31 ++ .../quarkus/it/opentracing/JdbcResource.java | 30 ++ .../it/opentracing/MockTracerProvider.java | 22 ++ .../it/opentracing/PingPongResource.java | 52 +++ .../it/opentracing/SimpleResource.java | 52 +++ .../io/quarkus/it/opentracing/TraceData.java | 7 + .../quarkus/it/opentracing/TracedService.java | 10 + .../json/MockSpanModuleSerializer.java | 19 ++ .../opentracing/json/MockSpanSerializer.java | 46 +++ .../it/rest/client/server/EchoService.java | 16 - .../src/main/resources/application.properties | 12 +- .../it/opentracing}/OpenTracingITCase.java | 2 +- .../it/opentracing/OpenTracingTestCase.java | 296 ++++++++++++++++++ .../it/rest/client/WireMockZipkin.java | 39 --- .../it/rest/client/ZipkinIntegrationTest.java | 46 --- .../rest/client/ZipkinIntegrationTestIT.java | 7 - 17 files changed, 664 insertions(+), 123 deletions(-) create mode 100644 integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/ExporterResource.java create mode 100644 integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/JdbcResource.java create mode 100644 integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/MockTracerProvider.java create mode 100644 integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/PingPongResource.java create mode 100644 integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/SimpleResource.java create mode 100644 integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/TraceData.java create mode 100644 integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/TracedService.java create mode 100644 integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/json/MockSpanModuleSerializer.java create mode 100644 integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/json/MockSpanSerializer.java delete mode 100644 integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/rest/client/server/EchoService.java rename integration-tests/{main/src/test/java/io/quarkus/it/main => smallrye-opentracing/src/test/java/io/quarkus/it/opentracing}/OpenTracingITCase.java (78%) create mode 100644 integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/opentracing/OpenTracingTestCase.java delete mode 100644 integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/rest/client/WireMockZipkin.java delete mode 100644 integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/rest/client/ZipkinIntegrationTest.java delete mode 100644 integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/rest/client/ZipkinIntegrationTestIT.java diff --git a/integration-tests/smallrye-opentracing/pom.xml b/integration-tests/smallrye-opentracing/pom.xml index d7d6aec813b56..9f305c8d7334a 100644 --- a/integration-tests/smallrye-opentracing/pom.xml +++ b/integration-tests/smallrye-opentracing/pom.xml @@ -11,22 +11,55 @@ quarkus-integration-test-smallrye-opentracing Quarkus - Integration Tests - Smallrye Opentracing + + + + org.hamcrest + hamcrest-core + 2.1 + + + + io.quarkus - quarkus-resteasy + quarkus-resteasy-jackson io.quarkus quarkus-smallrye-opentracing + + io.opentracing.contrib + opentracing-jdbc + + + io.quarkus + quarkus-jdbc-postgresql + + + io.quarkus + quarkus-agroal + + + io.quarkus + quarkus-resteasy-mutiny + io.quarkus quarkus-rest-client + + + + io.opentracing + opentracing-mock + + io.quarkus @@ -39,15 +72,30 @@ test - com.github.tomakehurst - wiremock-jre8 + org.awaitility + awaitility + test + + + org.jboss.logging + commons-logging-jboss-logging + test + + + org.testcontainers + postgresql + test + + + org.testcontainers + junit-jupiter test io.quarkus - quarkus-rest-client-deployment + quarkus-agroal-deployment ${project.version} pom test @@ -60,7 +108,7 @@ io.quarkus - quarkus-resteasy-deployment + quarkus-jdbc-postgresql-deployment ${project.version} pom test @@ -73,7 +121,33 @@ io.quarkus - quarkus-smallrye-opentracing-deployment + quarkus-resteasy-jackson-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-resteasy-mutiny-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-rest-client-deployment ${project.version} pom test @@ -85,10 +159,18 @@ - io.jaegertracing - jaeger-zipkin + io.quarkus + quarkus-smallrye-opentracing-deployment + ${project.version} + pom + test + + + * + * + + - diff --git a/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/ExporterResource.java b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/ExporterResource.java new file mode 100644 index 0000000000000..8c211aa9b3b38 --- /dev/null +++ b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/ExporterResource.java @@ -0,0 +1,31 @@ +package io.quarkus.it.opentracing; + +import java.util.List; +import java.util.stream.Collectors; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import io.opentracing.mock.MockSpan; +import io.opentracing.mock.MockTracer; + +@Path("/export") +public class ExporterResource { + @Inject + MockTracer mockTracer; + + @GET + @Path("/clear") + public void clearExporter() { + mockTracer.reset(); + } + + @GET + public List retrieve() { + return mockTracer.finishedSpans().stream() + .filter(span -> !span.operationName().equals("GET:io.quarkus.it.opentracing.ExporterResource.clearExporter") && + !span.operationName().equals("GET:io.quarkus.it.opentracing.ExporterResource.retrieve")) + .collect(Collectors.toList()); + } +} diff --git a/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/JdbcResource.java b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/JdbcResource.java new file mode 100644 index 0000000000000..fff39dd376ada --- /dev/null +++ b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/JdbcResource.java @@ -0,0 +1,30 @@ +package io.quarkus.it.opentracing; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import javax.inject.Inject; +import javax.sql.DataSource; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +@Path("/jdbc") +public class JdbcResource { + @Inject + DataSource defaultDataSource; + + @GET + public TraceData jdbc() throws SQLException { + Connection con = defaultDataSource.getConnection(); + try (Statement stmt = con.createStatement()) { + ResultSet resultSet = stmt.executeQuery("select 1"); + resultSet.next(); + String result = resultSet.getString(1); + TraceData data = new TraceData(); + data.message = result; + return data; + } + } +} diff --git a/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/MockTracerProvider.java b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/MockTracerProvider.java new file mode 100644 index 0000000000000..1a45fff41f029 --- /dev/null +++ b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/MockTracerProvider.java @@ -0,0 +1,22 @@ +package io.quarkus.it.opentracing; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.inject.Singleton; + +import io.opentracing.mock.MockTracer; +import io.opentracing.util.GlobalTracer; +import io.quarkus.arc.AlternativePriority; + +@ApplicationScoped +public class MockTracerProvider { + + @Produces + @Singleton + @AlternativePriority(1) + public MockTracer createInMemoryExporter() { + MockTracer tracer = new MockTracer(); + GlobalTracer.registerIfAbsent(tracer); + return tracer; + } +} diff --git a/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/PingPongResource.java b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/PingPongResource.java new file mode 100644 index 0000000000000..9ea16b4ca27b8 --- /dev/null +++ b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/PingPongResource.java @@ -0,0 +1,52 @@ +package io.quarkus.it.opentracing; + +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; +import org.eclipse.microprofile.rest.client.inject.RestClient; + +import io.smallrye.common.annotation.Blocking; +import io.smallrye.mutiny.Uni; + +@Singleton +@Path("/client") +public class PingPongResource { + @RegisterRestClient(configKey = "pingpong") + public interface PingPongRestClient { + + @Path("/client/pong/{message}") + @GET + String pingpong(@PathParam("message") String message); + + @GET + @Path("/client/pong/{message}") + Uni asyncPingpong(@PathParam("message") String message); + } + + @Inject + @RestClient + PingPongRestClient pingRestClient; + + @GET + @Path("pong/{message}") + public String pong(@PathParam("message") String message) { + return message; + } + + @GET + @Blocking + @Path("ping/{message}") + public String ping(@PathParam("message") String message) { + return pingRestClient.pingpong(message); + } + + @GET + @Path("async-ping/{message}") + public Uni asyncPing(@PathParam("message") String message) { + return pingRestClient.asyncPingpong(message); + } +} diff --git a/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/SimpleResource.java b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/SimpleResource.java new file mode 100644 index 0000000000000..1af7a8c968563 --- /dev/null +++ b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/SimpleResource.java @@ -0,0 +1,52 @@ +package io.quarkus.it.opentracing; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/") +@Produces(MediaType.APPLICATION_JSON) +public class SimpleResource { + + @Inject + TracedService tracedService; + + @GET + @Path("/direct") + public TraceData directTrace() { + TraceData data = new TraceData(); + data.message = "Direct trace"; + + return data; + } + + @GET + @Path("/chained") + public TraceData chainedTrace() { + TraceData data = new TraceData(); + data.message = tracedService.call(); + + return data; + } + + @GET + @Path("/deep/path") + public TraceData deepUrlPathTrace() { + TraceData data = new TraceData(); + data.message = "Deep url path"; + + return data; + } + + @GET + @Path("/param/{paramId}") + public TraceData pathParameters(@PathParam("paramId") String paramId) { + TraceData data = new TraceData(); + data.message = "ParameterId: " + paramId; + + return data; + } +} diff --git a/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/TraceData.java b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/TraceData.java new file mode 100644 index 0000000000000..bfdc70488c310 --- /dev/null +++ b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/TraceData.java @@ -0,0 +1,7 @@ +package io.quarkus.it.opentracing; + +public class TraceData { + public String message; + public String tracer; + public String span; +} diff --git a/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/TracedService.java b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/TracedService.java new file mode 100644 index 0000000000000..e9834a06c3391 --- /dev/null +++ b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/TracedService.java @@ -0,0 +1,10 @@ +package io.quarkus.it.opentracing; + +import javax.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class TracedService { + public String call() { + return "Chained trace"; + } +} diff --git a/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/json/MockSpanModuleSerializer.java b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/json/MockSpanModuleSerializer.java new file mode 100644 index 0000000000000..f8d30fe5088c1 --- /dev/null +++ b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/json/MockSpanModuleSerializer.java @@ -0,0 +1,19 @@ +package io.quarkus.it.opentracing.json; + +import javax.inject.Singleton; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; + +import io.opentracing.mock.MockSpan; +import io.quarkus.jackson.ObjectMapperCustomizer; + +@Singleton +public class MockSpanModuleSerializer implements ObjectMapperCustomizer { + @Override + public void customize(ObjectMapper objectMapper) { + SimpleModule simpleModule = new SimpleModule(); + simpleModule.addSerializer(MockSpan.class, new MockSpanSerializer()); + objectMapper.registerModule(simpleModule); + } +} diff --git a/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/json/MockSpanSerializer.java b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/json/MockSpanSerializer.java new file mode 100644 index 0000000000000..0ddcec9edfc82 --- /dev/null +++ b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/json/MockSpanSerializer.java @@ -0,0 +1,46 @@ +package io.quarkus.it.opentracing.json; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; + +import io.opentracing.mock.MockSpan; + +public class MockSpanSerializer extends StdSerializer { + + public MockSpanSerializer() { + super(MockSpan.class); + } + + @Override + public void serialize(MockSpan mockSpan, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) + throws IOException { + jsonGenerator.writeStartObject(); + + jsonGenerator.writeStringField("spanId", mockSpan.context().toSpanId()); + jsonGenerator.writeStringField("traceId", mockSpan.context().toTraceId()); + jsonGenerator.writeStringField("operation_name", mockSpan.operationName()); + + jsonGenerator.writeNumberField("parent_spanId", mockSpan.parentId()); + + mockSpan.tags().forEach((k, v) -> { + try { + jsonGenerator.writeStringField("tag_" + k, v.toString()); + } catch (IOException e) { + e.printStackTrace(); + } + }); + + mockSpan.context().baggageItems().forEach(entry -> { + try { + jsonGenerator.writeStringField("baggage_" + entry.getKey(), entry.getValue()); + } catch (IOException e) { + e.printStackTrace(); + } + }); + + jsonGenerator.writeEndObject(); + } +} diff --git a/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/rest/client/server/EchoService.java b/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/rest/client/server/EchoService.java deleted file mode 100644 index 3818ccc09b75a..0000000000000 --- a/integration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/rest/client/server/EchoService.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.quarkus.it.rest.client.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -@Path("/echo") -public class EchoService { - - @GET - @Produces(MediaType.TEXT_PLAIN) - public String echo() { - return "result"; - } -} \ No newline at end of file diff --git a/integration-tests/smallrye-opentracing/src/main/resources/application.properties b/integration-tests/smallrye-opentracing/src/main/resources/application.properties index cdb302678cee7..9bc3dbe080a7e 100644 --- a/integration-tests/smallrye-opentracing/src/main/resources/application.properties +++ b/integration-tests/smallrye-opentracing/src/main/resources/application.properties @@ -1,5 +1,7 @@ -quarkus.jaeger.service-name=encryptions -quarkus.jaeger.sampler-type=const -quarkus.jaeger.sampler-param=1 -quarkus.jaeger.propagation=b3 -quarkus.jaeger.zipkin.compatibility-mode=true \ No newline at end of file +quarkus.datasource.db-kind=postgresql +quarkus.datasource.jdbc.url=jdbc:tracing:postgresql://localhost:5432/mydatabase +quarkus.datasource.jdbc.driver=io.opentracing.contrib.jdbc.TracingDriver +quarkus.datasource.username=sa +quarkus.datasource.password=sa + +pingpong/mp-rest/url=${test.url} diff --git a/integration-tests/main/src/test/java/io/quarkus/it/main/OpenTracingITCase.java b/integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/opentracing/OpenTracingITCase.java similarity index 78% rename from integration-tests/main/src/test/java/io/quarkus/it/main/OpenTracingITCase.java rename to integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/opentracing/OpenTracingITCase.java index 96ea1b34ddd7b..c8f90d96d69b1 100644 --- a/integration-tests/main/src/test/java/io/quarkus/it/main/OpenTracingITCase.java +++ b/integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/opentracing/OpenTracingITCase.java @@ -1,4 +1,4 @@ -package io.quarkus.it.main; +package io.quarkus.it.opentracing; import io.quarkus.test.junit.NativeImageTest; diff --git a/integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/opentracing/OpenTracingTestCase.java b/integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/opentracing/OpenTracingTestCase.java new file mode 100644 index 0000000000000..11033ca5ce0e0 --- /dev/null +++ b/integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/opentracing/OpenTracingTestCase.java @@ -0,0 +1,296 @@ +package io.quarkus.it.opentracing; + +import static io.restassured.RestAssured.get; +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.equalTo; + +import java.time.Duration; +import java.util.List; +import java.util.Map; + +import org.awaitility.Awaitility; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.PostgreSQLContainer; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.common.mapper.TypeRef; + +@QuarkusTest +@DisabledOnOs(OS.WINDOWS) +public class OpenTracingTestCase { + + static GenericContainer postgreSQLContainer; + + @BeforeAll + static void initPostgres() { + postgreSQLContainer = new PostgreSQLContainer(PostgreSQLContainer.IMAGE) + .withDatabaseName("mydatabase").withUsername("sa").withPassword("sa"); + postgreSQLContainer.setPortBindings(List.of("5432:5432")); + postgreSQLContainer.start(); + } + + private void resetExporter() { + given() + .when().get("/export/clear") + .then() + .statusCode(204); + } + + private List> getSpans() { + return get("/export").body().as(new TypeRef>>() { + }); + } + + @Test + void testResourceTracing() { + resetExporter(); + + given() + .contentType("application/json") + .when().get("/direct") + .then() + .statusCode(200) + .body("message", equalTo("Direct trace")); + + Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> getSpans().size() == 1); + Map spanData = getSpans().get(0); + Assertions.assertNotNull(spanData); + Assertions.assertNotNull(spanData.get("spanId")); + Assertions.assertNotNull(spanData.get("traceId")); + Assertions.assertEquals("GET:io.quarkus.it.opentracing.SimpleResource.directTrace", spanData.get("operation_name")); + Assertions.assertEquals(0, spanData.get("parent_spanId")); + + Assertions.assertEquals("server", spanData.get("tag_span.kind")); + Assertions.assertEquals("jaxrs", spanData.get("tag_component")); + Assertions.assertEquals("GET", spanData.get("tag_http.method")); + Assertions.assertEquals("200", spanData.get("tag_http.status_code")); + } + + @Test + void testChainedResourceTracing() { + resetExporter(); + + given() + .contentType("application/json") + .when().get("/chained") + .then() + .statusCode(200) + .body("message", equalTo("Chained trace")); + + Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> getSpans().size() == 1); + Map spanData = getSpans().get(0); + Assertions.assertNotNull(spanData); + Assertions.assertNotNull(spanData.get("spanId")); + Assertions.assertNotNull(spanData.get("traceId")); + Assertions.assertEquals("GET:io.quarkus.it.opentracing.SimpleResource.chainedTrace", spanData.get("operation_name")); + Assertions.assertEquals(0, spanData.get("parent_spanId")); + + Assertions.assertEquals("server", spanData.get("tag_span.kind")); + Assertions.assertEquals("jaxrs", spanData.get("tag_component")); + Assertions.assertEquals("GET", spanData.get("tag_http.method")); + Assertions.assertEquals("200", spanData.get("tag_http.status_code")); + } + + @Test + void testDeepPathNaming() { + resetExporter(); + + given() + .contentType("application/json") + .when().get("/deep/path") + .then() + .statusCode(200) + .body("message", equalTo("Deep url path")); + + Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> getSpans().size() == 1); + Map spanData = getSpans().get(0); + Assertions.assertNotNull(spanData); + Assertions.assertNotNull(spanData.get("spanId")); + Assertions.assertNotNull(spanData.get("traceId")); + Assertions.assertEquals("GET:io.quarkus.it.opentracing.SimpleResource.deepUrlPathTrace", + spanData.get("operation_name")); + Assertions.assertEquals(0, spanData.get("parent_spanId")); + + Assertions.assertEquals("server", spanData.get("tag_span.kind")); + Assertions.assertEquals("jaxrs", spanData.get("tag_component")); + Assertions.assertEquals("GET", spanData.get("tag_http.method")); + Assertions.assertEquals("200", spanData.get("tag_http.status_code")); + } + + @Test + void testPathParameter() { + resetExporter(); + + given() + .contentType("application/json") + .when().get("/param/12345") + .then() + .statusCode(200) + .body("message", equalTo("ParameterId: 12345")); + + Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> getSpans().size() == 1); + Map spanData = getSpans().get(0); + Assertions.assertNotNull(spanData); + Assertions.assertNotNull(spanData.get("spanId")); + Assertions.assertNotNull(spanData.get("traceId")); + Assertions.assertEquals("GET:io.quarkus.it.opentracing.SimpleResource.pathParameters", spanData.get("operation_name")); + Assertions.assertEquals(0, spanData.get("parent_spanId")); + + Assertions.assertEquals("server", spanData.get("tag_span.kind")); + Assertions.assertEquals("jaxrs", spanData.get("tag_component")); + Assertions.assertEquals("GET", spanData.get("tag_http.method")); + Assertions.assertEquals("200", spanData.get("tag_http.status_code")); + } + + @Test + void testClientTracing() { + resetExporter(); + + given() + .when().get("/client/ping/one") + .then() + .statusCode(200) + .body(containsString("one")); + + Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> getSpans().size() == 3); + + boolean outsideServerFound = false; + boolean clientFound = false; + + for (Map spanData : getSpans()) { + Assertions.assertNotNull(spanData); + Assertions.assertNotNull(spanData.get("spanId")); + + if (spanData.get("tag_span.kind").equals("server") + && spanData.get("operation_name").equals("GET:io.quarkus.it.opentracing.PingPongResource.ping")) { + outsideServerFound = true; + // Server Span + Assertions.assertNotNull(spanData); + Assertions.assertNotNull(spanData.get("spanId")); + Assertions.assertNotNull(spanData.get("traceId")); + Assertions.assertEquals("GET:io.quarkus.it.opentracing.PingPongResource.ping", + spanData.get("operation_name")); + Assertions.assertEquals(0, spanData.get("parent_spanId")); + + Assertions.assertEquals("server", spanData.get("tag_span.kind")); + Assertions.assertEquals("jaxrs", spanData.get("tag_component")); + Assertions.assertEquals("GET", spanData.get("tag_http.method")); + Assertions.assertEquals("200", spanData.get("tag_http.status_code")); + } else if (spanData.get("tag_span.kind").equals("server") + && spanData.get("operation_name").equals("GET:io.quarkus.it.opentracing.PingPongResource.pong")) { + clientFound = true; + // Client span + Assertions.assertNotNull(spanData); + Assertions.assertNotNull(spanData.get("spanId")); + Assertions.assertNotNull(spanData.get("traceId")); + Assertions.assertEquals("GET:io.quarkus.it.opentracing.PingPongResource.pong", + spanData.get("operation_name")); + Assertions.assertEquals("server", spanData.get("tag_span.kind")); + Assertions.assertEquals("jaxrs", spanData.get("tag_component")); + Assertions.assertEquals("GET", spanData.get("tag_http.method")); + Assertions.assertEquals("200", spanData.get("tag_http.status_code")); + } + } + + Assertions.assertTrue(outsideServerFound); + Assertions.assertTrue(clientFound); + } + + @Test + void testAsyncClientTracing() { + resetExporter(); + + given() + .when().get("/client/async-ping/one") + .then() + .statusCode(200) + .body(containsString("one")); + + Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> getSpans().size() == 3); + + boolean outsideServerFound = false; + boolean clientFound = false; + + for (Map spanData : getSpans()) { + Assertions.assertNotNull(spanData); + Assertions.assertNotNull(spanData.get("spanId")); + + if (spanData.get("tag_span.kind").equals("server") + && spanData.get("operation_name").equals("GET:io.quarkus.it.opentracing.PingPongResource.asyncPing")) { + outsideServerFound = true; + // Server Span + Assertions.assertNotNull(spanData); + Assertions.assertNotNull(spanData.get("spanId")); + Assertions.assertNotNull(spanData.get("traceId")); + Assertions.assertEquals("GET:io.quarkus.it.opentracing.PingPongResource.asyncPing", + spanData.get("operation_name")); + Assertions.assertEquals(0, spanData.get("parent_spanId")); + + Assertions.assertEquals("server", spanData.get("tag_span.kind")); + Assertions.assertEquals("jaxrs", spanData.get("tag_component")); + Assertions.assertEquals("GET", spanData.get("tag_http.method")); + Assertions.assertEquals("200", spanData.get("tag_http.status_code")); + } else if (spanData.get("tag_span.kind").equals("server") + && spanData.get("operation_name").equals("GET:io.quarkus.it.opentracing.PingPongResource.pong")) { + clientFound = true; + // Client span + Assertions.assertNotNull(spanData); + Assertions.assertNotNull(spanData.get("spanId")); + Assertions.assertNotNull(spanData.get("traceId")); + Assertions.assertEquals("GET:io.quarkus.it.opentracing.PingPongResource.pong", + spanData.get("operation_name")); + Assertions.assertEquals("server", spanData.get("tag_span.kind")); + Assertions.assertEquals("jaxrs", spanData.get("tag_component")); + Assertions.assertEquals("GET", spanData.get("tag_http.method")); + Assertions.assertEquals("200", spanData.get("tag_http.status_code")); + } + } + + Assertions.assertTrue(outsideServerFound); + Assertions.assertTrue(clientFound); + } + + @Test + void testJdbcTracing() { + resetExporter(); + + given() + .contentType("application/json") + .when().get("/jdbc") + .then() + .statusCode(200) + .body("message", equalTo("1")); + + Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> getSpans().size() == 3); + + boolean resourceSpanFound = false; + boolean jdbcSpanFound = false; + for (Map spanData : getSpans()) { + Assertions.assertNotNull(spanData); + Assertions.assertNotNull(spanData.get("spanId")); + Assertions.assertNotNull(spanData.get("traceId")); + + if (spanData.get("operation_name").equals("GET:io.quarkus.it.opentracing.JdbcResource.jdbc")) { + Assertions.assertEquals(0, spanData.get("parent_spanId")); + Assertions.assertEquals("server", spanData.get("tag_span.kind")); + Assertions.assertEquals("jaxrs", spanData.get("tag_component")); + Assertions.assertEquals("GET", spanData.get("tag_http.method")); + Assertions.assertEquals("200", spanData.get("tag_http.status_code")); + resourceSpanFound = true; + } else if (spanData.get("operation_name").equals("Query")) { + Assertions.assertEquals("client", spanData.get("tag_span.kind")); + Assertions.assertEquals("java-jdbc", spanData.get("tag_component")); + Assertions.assertEquals("select 1", spanData.get("tag_db.statement")); + jdbcSpanFound = true; + } + } + Assertions.assertTrue(resourceSpanFound); + Assertions.assertTrue(jdbcSpanFound); + } +} diff --git a/integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/rest/client/WireMockZipkin.java b/integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/rest/client/WireMockZipkin.java deleted file mode 100644 index 02b977c380a21..0000000000000 --- a/integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/rest/client/WireMockZipkin.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.quarkus.it.rest.client; - -import static com.github.tomakehurst.wiremock.client.WireMock.*; - -import java.util.Collections; -import java.util.Map; - -import com.github.tomakehurst.wiremock.WireMockServer; - -import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; - -public class WireMockZipkin implements QuarkusTestResourceLifecycleManager { - - private static WireMockServer wireMockServer; - - @Override - public Map start() { - wireMockServer = new WireMockServer(); - wireMockServer.start(); - - stubFor(post(anyUrl()).withRequestBody(equalToJson( - "[{\"name\": \"get:io.quarkus.it.rest.client.server.echoservice.echo\",\"tags\": {\"component\": \"jaxrs\",\"http.method\": \"GET\",\"http.status_code\": \"200\",\"sampler.param\": \"true\",\"sampler.type\": \"const\"}}]", - true, true)).willReturn(aResponse().withStatus(200))); - - return Collections.singletonMap("quarkus.jaeger.endpoint", wireMockServer.baseUrl() + "/zipkin"); - } - - @Override - public void stop() { - if (null != wireMockServer) { - wireMockServer.stop(); - } - } - - public static WireMockServer getWireMockServer() { - return wireMockServer; - } - -} diff --git a/integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/rest/client/ZipkinIntegrationTest.java b/integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/rest/client/ZipkinIntegrationTest.java deleted file mode 100644 index 5e9381baeeeb5..0000000000000 --- a/integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/rest/client/ZipkinIntegrationTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package io.quarkus.it.rest.client; - -import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static com.github.tomakehurst.wiremock.client.WireMock.verify; -import static io.restassured.RestAssured.given; -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.Date; - -import org.junit.jupiter.api.Test; - -import com.github.tomakehurst.wiremock.client.VerificationException; - -import io.quarkus.test.common.QuarkusTestResource; -import io.quarkus.test.junit.QuarkusTest; - -@QuarkusTest -@QuarkusTestResource(WireMockZipkin.class) -public class ZipkinIntegrationTest { - - @Test - public void testZipkinIntegration() { - - given().when().get("/echo").then().statusCode(200).body(containsString("result")); - - boolean continues = true; - long current = new Date().getTime(); - while (continues) { - try { - verify(postRequestedFor(urlEqualTo("/zipkin"))); - continues = false; - } catch (VerificationException e) { - // Because the request to zipkin is asynchronous we should wait maximum 10 - // seconds. - if (new Date().getTime() - current > 10000) { - throw e; - } - } - } - - assertEquals(0, WireMockZipkin.getWireMockServer().findAllUnmatchedRequests().size()); - } - -} diff --git a/integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/rest/client/ZipkinIntegrationTestIT.java b/integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/rest/client/ZipkinIntegrationTestIT.java deleted file mode 100644 index cd89e385e6350..0000000000000 --- a/integration-tests/smallrye-opentracing/src/test/java/io/quarkus/it/rest/client/ZipkinIntegrationTestIT.java +++ /dev/null @@ -1,7 +0,0 @@ -package io.quarkus.it.rest.client; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class ZipkinIntegrationTestIT extends ZipkinIntegrationTest { -}