Fix latest dep tests (#11925)
This commit is contained in:
parent
4619413cd7
commit
14d87e7323
|
@ -18,14 +18,32 @@ dependencies {
|
|||
testInstrumentation(project(":instrumentation:netty:netty-4.1:javaagent"))
|
||||
}
|
||||
|
||||
otelJava {
|
||||
val latestDepTest = findProperty("testLatestDeps") as Boolean
|
||||
val testJavaVersion =
|
||||
gradle.startParameter.projectProperties["testJavaVersion"]?.let(JavaVersion::toVersion)
|
||||
?: JavaVersion.current()
|
||||
|
||||
if (!latestDepTest) {
|
||||
otelJava {
|
||||
// AHC uses Unsafe and so does not run on later java version
|
||||
maxJavaVersionForTests.set(JavaVersion.VERSION_1_8)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<Test>().configureEach {
|
||||
systemProperty("testLatestDeps", latestDepTest)
|
||||
// async-http-client 3.0 requires java 11
|
||||
// We are not using minJavaVersionSupported for latestDepTest because that way the instrumentation
|
||||
// gets compiled with java 11 when running latestDepTest. This causes play-mvc-2.4 latest dep tests
|
||||
// to fail because they require java 8 and instrumentation compiled with java 11 won't apply.
|
||||
if (latestDepTest && testJavaVersion.isJava8) {
|
||||
enabled = false
|
||||
}
|
||||
}
|
||||
|
||||
// async-http-client 2.0.0 does not work with Netty versions newer than this due to referencing an
|
||||
// internal file.
|
||||
if (!(findProperty("testLatestDeps") as Boolean)) {
|
||||
if (!latestDepTest) {
|
||||
configurations.configureEach {
|
||||
if (!name.contains("muzzle")) {
|
||||
resolutionStrategy {
|
||||
|
|
|
@ -10,11 +10,14 @@ import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTes
|
|||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import org.asynchttpclient.AsyncCompletionHandler;
|
||||
import org.asynchttpclient.AsyncHttpClient;
|
||||
import org.asynchttpclient.DefaultAsyncHttpClientConfig;
|
||||
import org.asynchttpclient.Dsl;
|
||||
import org.asynchttpclient.Request;
|
||||
import org.asynchttpclient.RequestBuilder;
|
||||
|
@ -31,11 +34,26 @@ class AsyncHttpClientTest extends AbstractHttpClientTest<Request> {
|
|||
private static final int CONNECTION_TIMEOUT_MS = (int) CONNECTION_TIMEOUT.toMillis();
|
||||
|
||||
// request timeout is needed in addition to connect timeout on async-http-client versions 2.1.0+
|
||||
private static final AsyncHttpClient client =
|
||||
Dsl.asyncHttpClient(
|
||||
Dsl.config()
|
||||
.setConnectTimeout(CONNECTION_TIMEOUT_MS)
|
||||
.setRequestTimeout(CONNECTION_TIMEOUT_MS));
|
||||
private static final AsyncHttpClient client = Dsl.asyncHttpClient(configureTimeout(Dsl.config()));
|
||||
|
||||
private static DefaultAsyncHttpClientConfig.Builder configureTimeout(
|
||||
DefaultAsyncHttpClientConfig.Builder builder) {
|
||||
setTimeout(builder, "setConnectTimeout", CONNECTION_TIMEOUT_MS);
|
||||
setTimeout(builder, "setRequestTimeout", CONNECTION_TIMEOUT_MS);
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static void setTimeout(
|
||||
DefaultAsyncHttpClientConfig.Builder builder, String methodName, int timeout) {
|
||||
boolean testLatestDeps = Boolean.getBoolean("testLatestDeps");
|
||||
try {
|
||||
Method method =
|
||||
builder.getClass().getMethod(methodName, testLatestDeps ? Duration.class : int.class);
|
||||
method.invoke(builder, testLatestDeps ? Duration.ofMillis(timeout) : timeout);
|
||||
} catch (Exception exception) {
|
||||
throw new IllegalStateException("Failed to set timeout " + methodName, exception);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request buildRequest(String method, URI uri, Map<String, String> headers) {
|
||||
|
|
|
@ -24,4 +24,9 @@ class LettuceAsyncClientTest extends AbstractLettuceAsyncClientTest {
|
|||
protected RedisClient createClient(String uri) {
|
||||
return RedisClient.create(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean connectHasSpans() {
|
||||
return Boolean.getBoolean("testLatestDeps");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,6 +90,10 @@ public abstract class AbstractLettuceAsyncClientTest extends AbstractLettuceClie
|
|||
return true;
|
||||
}
|
||||
|
||||
protected boolean connectHasSpans() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConnectUsingGetOnConnectionFuture() throws Exception {
|
||||
RedisClient testConnectionClient = RedisClient.create(embeddedDbUri);
|
||||
|
@ -103,9 +107,14 @@ public abstract class AbstractLettuceAsyncClientTest extends AbstractLettuceClie
|
|||
cleanup.deferCleanup(testConnectionClient::shutdown);
|
||||
|
||||
assertThat(connection1).isNotNull();
|
||||
if (connectHasSpans()) {
|
||||
// ignore CLIENT SETINFO traces
|
||||
getInstrumentationExtension().waitForTraces(2);
|
||||
} else {
|
||||
// Lettuce tracing does not trace connect
|
||||
assertThat(getInstrumentationExtension().spans()).isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConnectExceptionInsideTheConnectionFuture() {
|
||||
|
|
|
@ -8,7 +8,6 @@ package io.opentelemetry.instrumentation.lettuce.v5_1;
|
|||
import io.lettuce.core.RedisClient;
|
||||
import io.lettuce.core.api.StatefulRedisConnection;
|
||||
import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
|
||||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
@ -22,13 +21,6 @@ import org.testcontainers.containers.wait.strategy.Wait;
|
|||
abstract class AbstractLettuceClientTest {
|
||||
protected static final Logger logger = LoggerFactory.getLogger(AbstractLettuceClientTest.class);
|
||||
|
||||
@RegisterExtension
|
||||
protected static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
|
||||
|
||||
public InstrumentationExtension getInstrumentationExtension() {
|
||||
return testing;
|
||||
}
|
||||
|
||||
@RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create();
|
||||
|
||||
protected static final int DB_INDEX = 0;
|
||||
|
@ -40,18 +32,15 @@ abstract class AbstractLettuceClientTest {
|
|||
.waitingFor(Wait.forLogMessage(".*Ready to accept connections.*", 1));
|
||||
|
||||
protected static RedisClient redisClient;
|
||||
|
||||
protected static StatefulRedisConnection<String, String> connection;
|
||||
protected static String host;
|
||||
protected static String ip;
|
||||
protected static int port;
|
||||
protected static String embeddedDbUri;
|
||||
|
||||
protected abstract RedisClient createClient(String uri);
|
||||
|
||||
protected static String host;
|
||||
|
||||
protected static String ip;
|
||||
|
||||
protected static int port;
|
||||
|
||||
protected static String embeddedDbUri;
|
||||
protected abstract InstrumentationExtension getInstrumentationExtension();
|
||||
|
||||
protected ContainerConnection newContainerConnection() {
|
||||
GenericContainer<?> server =
|
||||
|
|
|
@ -10,6 +10,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
|
||||
import io.lettuce.core.api.sync.RedisCommands;
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions;
|
||||
import io.opentelemetry.semconv.NetworkAttributes;
|
||||
import io.opentelemetry.semconv.ServerAttributes;
|
||||
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
|
||||
|
@ -59,6 +60,58 @@ public abstract class AbstractLettuceSyncClientAuthTest extends AbstractLettuceC
|
|||
|
||||
assertThat(result).isEqualTo("OK");
|
||||
|
||||
if (Boolean.getBoolean("testLatestDeps")) {
|
||||
getInstrumentationExtension()
|
||||
.waitAndAssertTraces(
|
||||
trace ->
|
||||
trace.hasSpansSatisfyingExactly(
|
||||
span ->
|
||||
span.hasName("CLIENT")
|
||||
.hasKind(SpanKind.CLIENT)
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(NetworkAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_PORT, port),
|
||||
equalTo(ServerAttributes.SERVER_ADDRESS, host),
|
||||
equalTo(ServerAttributes.SERVER_PORT, port),
|
||||
equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"),
|
||||
equalTo(
|
||||
DbIncubatingAttributes.DB_STATEMENT,
|
||||
"CLIENT SETINFO lib-name Lettuce"))),
|
||||
trace ->
|
||||
trace.hasSpansSatisfyingExactly(
|
||||
span ->
|
||||
span.hasName("CLIENT")
|
||||
.hasKind(SpanKind.CLIENT)
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(NetworkAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_PORT, port),
|
||||
equalTo(ServerAttributes.SERVER_ADDRESS, host),
|
||||
equalTo(ServerAttributes.SERVER_PORT, port),
|
||||
equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"),
|
||||
OpenTelemetryAssertions.satisfies(
|
||||
DbIncubatingAttributes.DB_STATEMENT,
|
||||
stringAssert ->
|
||||
stringAssert.startsWith("CLIENT SETINFO lib-ver")))),
|
||||
trace ->
|
||||
trace.hasSpansSatisfyingExactly(
|
||||
span ->
|
||||
span.hasName("AUTH")
|
||||
.hasKind(SpanKind.CLIENT)
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(NetworkAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_PORT, port),
|
||||
equalTo(ServerAttributes.SERVER_ADDRESS, host),
|
||||
equalTo(ServerAttributes.SERVER_PORT, port),
|
||||
equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"),
|
||||
equalTo(DbIncubatingAttributes.DB_STATEMENT, "AUTH ?"))
|
||||
.hasEventsSatisfyingExactly(
|
||||
event -> event.hasName("redis.encode.start"),
|
||||
event -> event.hasName("redis.encode.end"))));
|
||||
|
||||
} else {
|
||||
getInstrumentationExtension()
|
||||
.waitAndAssertTraces(
|
||||
trace ->
|
||||
|
@ -78,4 +131,5 @@ public abstract class AbstractLettuceSyncClientAuthTest extends AbstractLettuceC
|
|||
event -> event.hasName("redis.encode.start"),
|
||||
event -> event.hasName("redis.encode.end"))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import io.lettuce.core.api.sync.RedisCommands;
|
|||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.instrumentation.test.utils.PortUtils;
|
||||
import io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions;
|
||||
import io.opentelemetry.semconv.NetworkAttributes;
|
||||
import io.opentelemetry.semconv.ServerAttributes;
|
||||
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
|
||||
|
@ -81,9 +82,14 @@ public abstract class AbstractLettuceSyncClientTest extends AbstractLettuceClien
|
|||
StatefulRedisConnection<String, String> testConnection = redisClient.connect();
|
||||
cleanup.deferCleanup(testConnection);
|
||||
|
||||
if (Boolean.getBoolean("testLatestDeps")) {
|
||||
// ignore CLIENT SETINFO traces
|
||||
getInstrumentationExtension().waitForTraces(2);
|
||||
} else {
|
||||
// Lettuce tracing does not trace connect
|
||||
assertThat(getInstrumentationExtension().spans()).isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConnectException() {
|
||||
|
@ -206,6 +212,12 @@ public abstract class AbstractLettuceSyncClientTest extends AbstractLettuceClien
|
|||
ContainerConnection containerConnection = newContainerConnection();
|
||||
RedisCommands<String, String> commands = containerConnection.connection.sync();
|
||||
|
||||
if (Boolean.getBoolean("testLatestDeps")) {
|
||||
// ignore CLIENT SETINFO traces
|
||||
getInstrumentationExtension().waitForTraces(2);
|
||||
getInstrumentationExtension().clearData();
|
||||
}
|
||||
|
||||
long res = commands.lpush("TESTLIST", "TESTLIST ELEMENT");
|
||||
assertThat(res).isEqualTo(1);
|
||||
|
||||
|
@ -350,24 +362,45 @@ public abstract class AbstractLettuceSyncClientTest extends AbstractLettuceClien
|
|||
|
||||
commands.debugSegfault();
|
||||
|
||||
if (Boolean.getBoolean("testLatestDeps")) {
|
||||
getInstrumentationExtension()
|
||||
.waitAndAssertTraces(
|
||||
trace -> {
|
||||
if (Boolean.getBoolean("testLatestDeps")) {
|
||||
trace ->
|
||||
trace.hasSpansSatisfyingExactly(
|
||||
span ->
|
||||
span.hasName("DEBUG")
|
||||
span.hasName("CLIENT")
|
||||
.hasKind(SpanKind.CLIENT)
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(NetworkAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip),
|
||||
equalTo(
|
||||
NetworkAttributes.NETWORK_PEER_PORT, containerConnection.port),
|
||||
NetworkAttributes.NETWORK_PEER_PORT,
|
||||
containerConnection.port),
|
||||
equalTo(ServerAttributes.SERVER_ADDRESS, host),
|
||||
equalTo(ServerAttributes.SERVER_PORT, containerConnection.port),
|
||||
equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"),
|
||||
equalTo(DbIncubatingAttributes.DB_STATEMENT, "DEBUG SEGFAULT")));
|
||||
} else {
|
||||
equalTo(
|
||||
DbIncubatingAttributes.DB_STATEMENT,
|
||||
"CLIENT SETINFO lib-name Lettuce"))),
|
||||
trace ->
|
||||
trace.hasSpansSatisfyingExactly(
|
||||
span ->
|
||||
span.hasName("CLIENT")
|
||||
.hasKind(SpanKind.CLIENT)
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(NetworkAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip),
|
||||
equalTo(
|
||||
NetworkAttributes.NETWORK_PEER_PORT,
|
||||
containerConnection.port),
|
||||
equalTo(ServerAttributes.SERVER_ADDRESS, host),
|
||||
equalTo(ServerAttributes.SERVER_PORT, containerConnection.port),
|
||||
equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"),
|
||||
OpenTelemetryAssertions.satisfies(
|
||||
DbIncubatingAttributes.DB_STATEMENT,
|
||||
stringAssert ->
|
||||
stringAssert.startsWith("CLIENT SETINFO lib-ver")))),
|
||||
trace ->
|
||||
trace.hasSpansSatisfyingExactly(
|
||||
span ->
|
||||
span.hasName("DEBUG")
|
||||
|
@ -376,7 +409,26 @@ public abstract class AbstractLettuceSyncClientTest extends AbstractLettuceClien
|
|||
equalTo(NetworkAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip),
|
||||
equalTo(
|
||||
NetworkAttributes.NETWORK_PEER_PORT, containerConnection.port),
|
||||
NetworkAttributes.NETWORK_PEER_PORT,
|
||||
containerConnection.port),
|
||||
equalTo(ServerAttributes.SERVER_ADDRESS, host),
|
||||
equalTo(ServerAttributes.SERVER_PORT, containerConnection.port),
|
||||
equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"),
|
||||
equalTo(DbIncubatingAttributes.DB_STATEMENT, "DEBUG SEGFAULT"))));
|
||||
} else {
|
||||
getInstrumentationExtension()
|
||||
.waitAndAssertTraces(
|
||||
trace ->
|
||||
trace.hasSpansSatisfyingExactly(
|
||||
span ->
|
||||
span.hasName("DEBUG")
|
||||
.hasKind(SpanKind.CLIENT)
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(NetworkAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, ip),
|
||||
equalTo(
|
||||
NetworkAttributes.NETWORK_PEER_PORT,
|
||||
containerConnection.port),
|
||||
equalTo(ServerAttributes.SERVER_ADDRESS, host),
|
||||
equalTo(ServerAttributes.SERVER_PORT, containerConnection.port),
|
||||
equalTo(DbIncubatingAttributes.DB_SYSTEM, "redis"),
|
||||
|
@ -384,9 +436,8 @@ public abstract class AbstractLettuceSyncClientTest extends AbstractLettuceClien
|
|||
// these are no longer recorded since Lettuce 6.1.6
|
||||
.hasEventsSatisfyingExactly(
|
||||
event -> event.hasName("redis.encode.start"),
|
||||
event -> event.hasName("redis.encode.end")));
|
||||
event -> event.hasName("redis.encode.end"))));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -395,6 +446,12 @@ public abstract class AbstractLettuceSyncClientTest extends AbstractLettuceClien
|
|||
ContainerConnection containerConnection = newContainerConnection();
|
||||
RedisCommands<String, String> commands = containerConnection.connection.sync();
|
||||
|
||||
if (Boolean.getBoolean("testLatestDeps")) {
|
||||
// ignore CLIENT SETINFO traces
|
||||
getInstrumentationExtension().waitForTraces(2);
|
||||
getInstrumentationExtension().clearData();
|
||||
}
|
||||
|
||||
commands.shutdown(false);
|
||||
|
||||
getInstrumentationExtension()
|
||||
|
|
Loading…
Reference in New Issue