-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
730 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>system-x-services</artifactId> | ||
<groupId>software.tnb</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>system-x-jaeger</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>TNB :: System-X :: Services :: Jaeger</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>testcontainers</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
22 changes: 22 additions & 0 deletions
22
system-x/services/jaeger/src/main/java/software/tnb/jaeger/client/BaseJaegerClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package software.tnb.jaeger.client; | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
class BaseJaegerClient { | ||
|
||
private static final String API_TRACES = "/api/traces"; | ||
protected final String queryUrl; | ||
|
||
protected final ObjectMapper objectMapper; | ||
|
||
BaseJaegerClient(final String queryUrl) { | ||
this.queryUrl = queryUrl; | ||
objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
} | ||
|
||
protected String apiTraceId(String traceId) { | ||
return String.format("%s%s/%s", queryUrl, API_TRACES, traceId); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
system-x/services/jaeger/src/main/java/software/tnb/jaeger/client/JaegerClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package software.tnb.jaeger.client; | ||
|
||
import software.tnb.jaeger.validation.model.Span; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public interface JaegerClient { | ||
|
||
Map<String, Object> getTrace(String traceId); | ||
|
||
List<Span> getSpans(String traceId); | ||
} |
49 changes: 49 additions & 0 deletions
49
...services/jaeger/src/main/java/software/tnb/jaeger/client/UnauthenticatedJaegerClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package software.tnb.jaeger.client; | ||
|
||
import software.tnb.common.utils.HTTPUtils; | ||
import software.tnb.common.utils.WaitUtils; | ||
import software.tnb.jaeger.validation.model.Span; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
public class UnauthenticatedJaegerClient extends BaseJaegerClient implements JaegerClient { | ||
|
||
private static final int MAX_RETRIES_IN_SECONDS = 15; | ||
private final HTTPUtils apiClient; | ||
|
||
public UnauthenticatedJaegerClient(String queryUrl) { | ||
super(queryUrl); | ||
apiClient = HTTPUtils.getInstance(HTTPUtils.trustAllSslClient()); | ||
} | ||
|
||
private String getRawJsonTrace(String traceId) { | ||
final String url = apiTraceId(traceId); | ||
WaitUtils.waitFor(() -> apiClient.get(url).isSuccessful(), MAX_RETRIES_IN_SECONDS, 1000L, "Wait for the trace to be elaborated"); | ||
return apiClient.get(url).getBody(); | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getTrace(String traceId) { | ||
try { | ||
return objectMapper.readValue(getRawJsonTrace(traceId), Map.class); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException("unable to read json from response", e); | ||
} | ||
} | ||
|
||
@Override | ||
public List<Span> getSpans(String traceId) { | ||
final Map data = ((List<Map>) getTrace(traceId).get("data")).get(0); | ||
String serviceName = (String) ((Map) Optional.ofNullable(((Map) data.get("processes")).get("p1")) | ||
.orElseGet(() -> Map.of("serviceName", ""))).get("serviceName"); | ||
final List<Span> spans = objectMapper.convertValue(data.get("spans"), new TypeReference<List<Span>>() { | ||
}); | ||
return spans.stream().map(span -> span.withServiceName(serviceName)).collect(Collectors.toList()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...m-x/services/jaeger/src/main/java/software/tnb/jaeger/resource/local/JaegerContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package software.tnb.jaeger.resource.local; | ||
|
||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
|
||
import java.util.Map; | ||
|
||
public class JaegerContainer extends GenericContainer<JaegerContainer> { | ||
|
||
public JaegerContainer(String image, Map<String, String> env) { | ||
super(image); | ||
withEnv(env); | ||
withNetworkMode("host"); | ||
waitingFor(Wait.forLogMessage(".*Channel Connectivity change to IDLE\",\"system\":\"grpc\".*", 1)); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
system-x/services/jaeger/src/main/java/software/tnb/jaeger/resource/local/LocalJaeger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package software.tnb.jaeger.resource.local; | ||
|
||
import software.tnb.common.deployment.Deployable; | ||
import software.tnb.common.deployment.WithDockerImage; | ||
import software.tnb.jaeger.client.UnauthenticatedJaegerClient; | ||
import software.tnb.jaeger.service.Jaeger; | ||
import software.tnb.jaeger.service.configuration.JaegerConfiguration; | ||
import software.tnb.jaeger.validation.JaegerValidation; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.auto.service.AutoService; | ||
|
||
@AutoService(Jaeger.class) | ||
public class LocalJaeger extends Jaeger implements Deployable, WithDockerImage { | ||
private static final Logger LOG = LoggerFactory.getLogger(LocalJaeger.class); | ||
private JaegerContainer container; | ||
|
||
@Override | ||
public void deploy() { | ||
LOG.info("Starting Jaeger container"); | ||
container = new JaegerContainer(image(), env()); | ||
container.start(); | ||
LOG.info("Jaeger container started"); | ||
} | ||
|
||
@Override | ||
public void undeploy() { | ||
if (container != null) { | ||
LOG.info("Stopping Jaeger container"); | ||
container.stop(); | ||
} | ||
} | ||
|
||
@Override | ||
public void openResources() { | ||
|
||
} | ||
|
||
@Override | ||
public void closeResources() { | ||
|
||
} | ||
|
||
@Override | ||
public String getLog() { | ||
return container.getLogs(); | ||
} | ||
|
||
@Override | ||
public String getCollectorUrl(JaegerConfiguration.CollectorPort port) { | ||
return getUrl(port); | ||
} | ||
|
||
@Override | ||
public String getQueryUrl(JaegerConfiguration.QueryPort port) { | ||
return getUrl(port); | ||
} | ||
|
||
@Override | ||
public String getExternalUrl() { | ||
return getQueryUrl(JaegerConfiguration.QueryPort.HTTP); | ||
} | ||
|
||
@Override | ||
protected JaegerValidation getClientBasedValidation() { | ||
return new JaegerValidation(new UnauthenticatedJaegerClient(getQueryUrl(JaegerConfiguration.QueryPort.HTTP))); | ||
} | ||
|
||
@NotNull | ||
private String getUrl(JaegerConfiguration.WithPort port) { | ||
return "http://localhost:" + port.portNumber(); | ||
} | ||
|
||
@Override | ||
public String defaultImage() { | ||
return "registry.redhat.io/rhosdt/jaeger-all-in-one-rhel8:latest"; | ||
} | ||
} |
Oops, something went wrong.