forked from wildfly/wildfly
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request wildfly#17632 from jasondlee/WFLY-18913
[WFLY-18913] Restore the ignored service-name attribute in the opentelemetry subsystem
- Loading branch information
Showing
33 changed files
with
1,043 additions
and
504 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
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
70 changes: 70 additions & 0 deletions
70
...ile/src/test/java/org/wildfly/test/integration/observability/container/BaseContainer.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,70 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.wildfly.test.integration.observability.container; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
|
||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.WaitAllStrategy; | ||
import org.testcontainers.containers.wait.strategy.WaitStrategy; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
public abstract class BaseContainer<SELF extends GenericContainer<SELF>> extends GenericContainer<SELF> { | ||
private final String containerName; | ||
private final List<Integer> exposedPorts; | ||
|
||
private static final int STARTUP_ATTEMPTS = Integer.parseInt( | ||
System.getProperty("testsuite.integration.container.startup.attempts", "1")); | ||
private static final Duration ATTEMPT_DURATION = Duration.parse( | ||
System.getProperty("testsuite.integration.container.attempt.duration", "PT5S")); | ||
protected final Boolean loggingEnabled; // Default: null/false | ||
|
||
public BaseContainer(String containerName, | ||
String imageName, | ||
String imageVersion, | ||
List<Integer> exposedPorts, | ||
List<WaitStrategy> waitStrategies) { | ||
super(DockerImageName.parse(imageName + ":" + imageVersion)); | ||
|
||
this.containerName = containerName; | ||
this.exposedPorts = exposedPorts; | ||
|
||
setWaitStrategy(buildWaitStrategy(waitStrategies)); | ||
setExposedPorts(exposedPorts); | ||
setStartupAttempts(STARTUP_ATTEMPTS); | ||
|
||
loggingEnabled = | ||
Boolean.parseBoolean(System.getProperty("testsuite.integration.container.logging")) || | ||
Boolean.parseBoolean(System.getProperty("testsuite.integration.container." + containerName.toLowerCase() + ".logging")); | ||
|
||
if (loggingEnabled) { | ||
setLogConsumers(List.of(outputFrame -> { | ||
byte[] bytes = outputFrame.getBytes(); | ||
if (bytes != null) { | ||
debugLog(new String(bytes)); | ||
} | ||
})); | ||
} | ||
} | ||
|
||
protected void debugLog(String message) { | ||
debugLog(containerName.toUpperCase(), message); | ||
} | ||
|
||
protected void debugLog(String prefix, String message) { | ||
if (loggingEnabled) { | ||
System.err.println("[" + prefix + "] " + message); | ||
} | ||
} | ||
|
||
private WaitStrategy buildWaitStrategy(List<WaitStrategy> waitStrategies) { | ||
WaitAllStrategy strategy = new WaitAllStrategy() | ||
.withStartupTimeout(ATTEMPT_DURATION); | ||
waitStrategies.forEach(strategy::withStrategy); | ||
|
||
return strategy; | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...e/src/test/java/org/wildfly/test/integration/observability/container/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,94 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.wildfly.test.integration.observability.container; | ||
|
||
import java.util.List; | ||
import jakarta.ws.rs.client.Client; | ||
import jakarta.ws.rs.client.ClientBuilder; | ||
import jakarta.ws.rs.client.WebTarget; | ||
|
||
import org.junit.Assert; | ||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.wildfly.common.annotation.NotNull; | ||
import org.wildfly.test.integration.observability.opentelemetry.jaeger.JaegerResponse; | ||
import org.wildfly.test.integration.observability.opentelemetry.jaeger.JaegerTrace; | ||
|
||
/* | ||
* This class is really intended to be called ONLY from OpenTelemetryCollectorContainer. Any test working with | ||
* tracing data should be passing through the otel collector and any methods on its Container. | ||
*/ | ||
class JaegerContainer extends BaseContainer<JaegerContainer> { | ||
private static JaegerContainer INSTANCE = null; | ||
|
||
public static final int PORT_JAEGER_QUERY = 16686; | ||
public static final int PORT_JAEGER_OTLP = 4317; | ||
|
||
private String jaegerEndpoint; | ||
|
||
private JaegerContainer() { | ||
super("Jaeger", "jaegertracing/all-in-one", "latest", | ||
List.of(PORT_JAEGER_QUERY, PORT_JAEGER_OTLP), | ||
List.of(Wait.forHttp("/").forPort(PORT_JAEGER_QUERY))); | ||
} | ||
|
||
@NotNull | ||
public static synchronized JaegerContainer getInstance() { | ||
if (INSTANCE == null) { | ||
INSTANCE = new JaegerContainer() | ||
.withNetwork(Network.SHARED) | ||
.withNetworkAliases("jaeger") | ||
.withEnv("JAEGER_DISABLED", "true"); | ||
INSTANCE.start(); | ||
} | ||
|
||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public void start() { | ||
super.start(); | ||
jaegerEndpoint = "http://localhost:" + getMappedPort(PORT_JAEGER_QUERY); | ||
} | ||
|
||
@Override | ||
public synchronized void stop() { | ||
INSTANCE = null; | ||
super.stop(); | ||
} | ||
|
||
List<JaegerTrace> getTraces(String serviceName) throws InterruptedException { | ||
try (Client client = ClientBuilder.newClient()) { | ||
waitForDataToAppear(serviceName); | ||
String jaegerUrl = jaegerEndpoint + "/api/traces?service=" + serviceName; | ||
JaegerResponse jaegerResponse = client.target(jaegerUrl).request().get().readEntity(JaegerResponse.class); | ||
return jaegerResponse.getData(); | ||
} | ||
} | ||
|
||
private void waitForDataToAppear(String serviceName) { | ||
try (Client client = ClientBuilder.newClient()) { | ||
String uri = jaegerEndpoint + "/api/services"; | ||
WebTarget target = client.target(uri); | ||
boolean found = false; | ||
int count = 0; | ||
while (count < 10) { | ||
String response = target.request().get().readEntity(String.class); | ||
if (response.contains(serviceName)) { | ||
found = true; | ||
break; | ||
} | ||
count++; | ||
try { | ||
Thread.sleep(500); | ||
} catch (InterruptedException e) { | ||
// | ||
} | ||
} | ||
|
||
Assert.assertTrue("Expected service name not found", found); | ||
} | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...org/wildfly/test/integration/observability/container/OpenTelemetryCollectorContainer.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,89 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.wildfly.test.integration.observability.container; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.testcontainers.utility.MountableFile; | ||
import org.wildfly.common.annotation.NotNull; | ||
import org.wildfly.test.integration.observability.opentelemetry.jaeger.JaegerTrace; | ||
|
||
public class OpenTelemetryCollectorContainer extends BaseContainer<OpenTelemetryCollectorContainer> { | ||
private static OpenTelemetryCollectorContainer INSTANCE = null; | ||
private static JaegerContainer jaegerContainer; | ||
|
||
public static final int OTLP_GRPC_PORT = 4317; | ||
public static final int OTLP_HTTP_PORT = 4318; | ||
public static final int PROMETHEUS_PORT = 49152; | ||
public static final int HEALTH_CHECK_PORT = 13133; | ||
|
||
public static final String OTEL_COLLECTOR_CONFIG_YAML = "/etc/otel-collector-config.yaml"; | ||
|
||
private String otlpGrpcEndpoint; | ||
private String otlpHttpEndpoint; | ||
private String prometheusUrl; | ||
|
||
|
||
private OpenTelemetryCollectorContainer() { | ||
super("OpenTelemetryCollector", | ||
"otel/opentelemetry-collector", | ||
"0.93.0", | ||
List.of(OTLP_GRPC_PORT, OTLP_HTTP_PORT, HEALTH_CHECK_PORT, PROMETHEUS_PORT), | ||
List.of(Wait.forHttp("/").forPort(HEALTH_CHECK_PORT))); | ||
} | ||
|
||
@NotNull | ||
public static synchronized OpenTelemetryCollectorContainer getInstance() { | ||
if (INSTANCE == null) { | ||
jaegerContainer = JaegerContainer.getInstance(); | ||
|
||
INSTANCE = new OpenTelemetryCollectorContainer() | ||
.withNetwork(Network.SHARED) | ||
.withCopyToContainer(MountableFile.forClasspathResource( | ||
"org/wildfly/test/integration/observability/container/otel-collector-config.yaml"), | ||
OpenTelemetryCollectorContainer.OTEL_COLLECTOR_CONFIG_YAML) | ||
.withCommand("--config " + OpenTelemetryCollectorContainer.OTEL_COLLECTOR_CONFIG_YAML); | ||
INSTANCE.start(); | ||
} | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public void start() { | ||
super.start(); | ||
otlpGrpcEndpoint = "http://localhost:" + getMappedPort(OTLP_GRPC_PORT); | ||
otlpHttpEndpoint = "http://localhost:" + getMappedPort(OTLP_HTTP_PORT); | ||
prometheusUrl = "http://localhost:" + getMappedPort(PROMETHEUS_PORT) + "/metrics"; | ||
} | ||
|
||
@Override | ||
public synchronized void stop() { | ||
if (jaegerContainer != null) { | ||
jaegerContainer.stop(); | ||
jaegerContainer = null; | ||
} | ||
INSTANCE = null; | ||
super.stop(); | ||
} | ||
|
||
public String getOtlpGrpcEndpoint() { | ||
return otlpGrpcEndpoint; | ||
} | ||
|
||
public String getOtlpHttpEndpoint() { | ||
return otlpHttpEndpoint; | ||
} | ||
|
||
public String getPrometheusUrl() { | ||
return prometheusUrl; | ||
} | ||
|
||
public List<JaegerTrace> getTraces(String serviceName) throws InterruptedException { | ||
return (jaegerContainer != null ? jaegerContainer.getTraces(serviceName) : Collections.emptyList()); | ||
} | ||
} |
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
Oops, something went wrong.