Skip to content

Commit

Permalink
Creates an OpenTracing integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Aug 20, 2021
1 parent c80e65e commit ff4f072
Show file tree
Hide file tree
Showing 17 changed files with 688 additions and 121 deletions.
101 changes: 94 additions & 7 deletions integration-tests/smallrye-opentracing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,55 @@
<artifactId>quarkus-integration-test-smallrye-opentracing</artifactId>
<name>Quarkus - Integration Tests - Smallrye Opentracing</name>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- Server dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-opentracing</artifactId>
</dependency>
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-jdbc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-mutiny</artifactId>
</dependency>

<!-- Client dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
</dependency>

<!-- In-memory tracer -->
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-mock</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
Expand All @@ -43,11 +76,31 @@
<artifactId>wiremock-jre8</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>commons-logging-jboss-logging</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-deployment</artifactId>
<artifactId>quarkus-agroal-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand All @@ -60,7 +113,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-deployment</artifactId>
<artifactId>quarkus-jdbc-postgresql-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand All @@ -73,7 +126,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-opentracing-deployment</artifactId>
<artifactId>quarkus-resteasy-jackson-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand All @@ -85,10 +138,44 @@
</exclusions>
</dependency>
<dependency>
<groupId>io.jaegertracing</groupId>
<artifactId>jaeger-zipkin</artifactId>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-mutiny-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-opentracing-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<MockSpan> 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());
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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.quarkus.arc.AlternativePriority;

@ApplicationScoped
public class MockTracerProvider {

@Produces
@Singleton
@AlternativePriority(1)
public MockTracer createInMemoryExporter() {
return new MockTracer();
}
}
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> asyncPing(@PathParam("message") String message) {
return pingRestClient.asyncPingpong(message);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.quarkus.it.opentracing;

public class TraceData {
public String message;
public String tracer;
public String span;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.quarkus.it.opentracing;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class TracedService {
public String call() {
return "Chained trace";
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading

0 comments on commit ff4f072

Please sign in to comment.