From f948ef8051c0c8020acbbd25a993bc78592dd026 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Wed, 1 Dec 2021 00:25:23 +0100 Subject: [PATCH] Use containerIpAddress instead of hard-coded 127.0.0.1 in rabbit tests (#4745) * Use containerIpAddress instead of hard-coded 127.0.0.1 in rabbit tests * Fix a situation where testcontainers returns 'localhost' instead of IP * Fix a situation where testcontainers returns 'localhost' instead of IP * Don't use the getContainerIpAddress() method, it'll be deprecated anyways --- .../javaagent/src/test/groovy/RabbitMqTest.groovy | 3 ++- .../javaagent/src/test/groovy/ReactorRabbitMqTest.groovy | 4 +++- .../src/test/groovy/SpringIntegrationAndRabbitTest.groovy | 7 ++++--- .../src/test/groovy/ContextPropagationTest.groovy | 5 +++-- testing-common/build.gradle.kts | 3 ++- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/instrumentation/rabbitmq-2.7/javaagent/src/test/groovy/RabbitMqTest.groovy b/instrumentation/rabbitmq-2.7/javaagent/src/test/groovy/RabbitMqTest.groovy index a2b1b338f2..6dd62c14fd 100644 --- a/instrumentation/rabbitmq-2.7/javaagent/src/test/groovy/RabbitMqTest.groovy +++ b/instrumentation/rabbitmq-2.7/javaagent/src/test/groovy/RabbitMqTest.groovy @@ -23,6 +23,7 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory import org.springframework.amqp.rabbit.core.RabbitAdmin import org.springframework.amqp.rabbit.core.RabbitTemplate +import static com.google.common.net.InetAddresses.isInetAddress import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.CONSUMER import static io.opentelemetry.api.trace.SpanKind.PRODUCER @@ -340,7 +341,7 @@ class RabbitMqTest extends AgentInstrumentationSpecification implements WithRabb attributes { "${SemanticAttributes.NET_PEER_NAME.key}" { it == null || it instanceof String } - "${SemanticAttributes.NET_PEER_IP.key}" { "127.0.0.1" } + "${SemanticAttributes.NET_PEER_IP.key}" { it == null || isInetAddress(it as String) } "${SemanticAttributes.NET_PEER_PORT.key}" { it == null || it instanceof Long } "${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq" diff --git a/instrumentation/rabbitmq-2.7/javaagent/src/test/groovy/ReactorRabbitMqTest.groovy b/instrumentation/rabbitmq-2.7/javaagent/src/test/groovy/ReactorRabbitMqTest.groovy index 9b070587d4..faf47163fb 100644 --- a/instrumentation/rabbitmq-2.7/javaagent/src/test/groovy/ReactorRabbitMqTest.groovy +++ b/instrumentation/rabbitmq-2.7/javaagent/src/test/groovy/ReactorRabbitMqTest.groovy @@ -10,6 +10,8 @@ import reactor.rabbitmq.ExchangeSpecification import reactor.rabbitmq.RabbitFlux import reactor.rabbitmq.SenderOptions +import static com.google.common.net.InetAddresses.isInetAddress + class ReactorRabbitMqTest extends AgentInstrumentationSpecification implements WithRabbitMqTrait { def setupSpec() { @@ -38,7 +40,7 @@ class ReactorRabbitMqTest extends AgentInstrumentationSpecification implements W kind SpanKind.CLIENT attributes { "${SemanticAttributes.NET_PEER_NAME.key}" { it == null || it instanceof String } - "${SemanticAttributes.NET_PEER_IP.key}" String + "${SemanticAttributes.NET_PEER_IP.key}" { isInetAddress(it as String) } "${SemanticAttributes.NET_PEER_PORT.key}" { it == null || it instanceof Long } "${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq" "${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue" diff --git a/instrumentation/spring/spring-integration-4.1/javaagent/src/test/groovy/SpringIntegrationAndRabbitTest.groovy b/instrumentation/spring/spring-integration-4.1/javaagent/src/test/groovy/SpringIntegrationAndRabbitTest.groovy index 162dc7af63..74812fd84d 100644 --- a/instrumentation/spring/spring-integration-4.1/javaagent/src/test/groovy/SpringIntegrationAndRabbitTest.groovy +++ b/instrumentation/spring/spring-integration-4.1/javaagent/src/test/groovy/SpringIntegrationAndRabbitTest.groovy @@ -6,6 +6,7 @@ import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.semconv.trace.attributes.SemanticAttributes +import static com.google.common.net.InetAddresses.isInetAddress import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.CONSUMER import static io.opentelemetry.api.trace.SpanKind.PRODUCER @@ -48,7 +49,7 @@ class SpringIntegrationAndRabbitTest extends AgentInstrumentationSpecification i kind CLIENT attributes { "${SemanticAttributes.NET_PEER_NAME.key}" { it == null || it == "localhost" } - "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" + "${SemanticAttributes.NET_PEER_IP.key}" { isInetAddress(it as String) } "${SemanticAttributes.NET_PEER_PORT.key}" { it == null || it instanceof Long } "${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq" "${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue" @@ -62,7 +63,7 @@ class SpringIntegrationAndRabbitTest extends AgentInstrumentationSpecification i attributes { // "localhost" on linux, null on windows "${SemanticAttributes.NET_PEER_NAME.key}" { it == "localhost" || it == null } - "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" + "${SemanticAttributes.NET_PEER_IP.key}" { isInetAddress(it as String) } "${SemanticAttributes.NET_PEER_PORT.key}" Long "${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq" "${SemanticAttributes.MESSAGING_DESTINATION.key}" "testTopic" @@ -117,7 +118,7 @@ class SpringIntegrationAndRabbitTest extends AgentInstrumentationSpecification i attributes { // "localhost" on linux, null on windows "${SemanticAttributes.NET_PEER_NAME.key}" { it == "localhost" || it == null } - "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" + "${SemanticAttributes.NET_PEER_IP.key}" { isInetAddress(it as String) } "${SemanticAttributes.NET_PEER_PORT.key}" Long "${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq" "${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue" diff --git a/instrumentation/spring/spring-rabbit-1.0/javaagent/src/test/groovy/ContextPropagationTest.groovy b/instrumentation/spring/spring-rabbit-1.0/javaagent/src/test/groovy/ContextPropagationTest.groovy index 8116e4f0f7..46e591c12c 100644 --- a/instrumentation/spring/spring-rabbit-1.0/javaagent/src/test/groovy/ContextPropagationTest.groovy +++ b/instrumentation/spring/spring-rabbit-1.0/javaagent/src/test/groovy/ContextPropagationTest.groovy @@ -19,6 +19,7 @@ import spock.lang.Shared import java.time.Duration +import static com.google.common.net.InetAddresses.isInetAddress import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.CONSUMER import static io.opentelemetry.api.trace.SpanKind.PRODUCER @@ -84,7 +85,7 @@ class ContextPropagationTest extends AgentInstrumentationSpecification { attributes { // "localhost" on linux, null on windows "${SemanticAttributes.NET_PEER_NAME.key}" { it == "localhost" || it == null } - "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" + "${SemanticAttributes.NET_PEER_IP.key}" { isInetAddress(it as String) } "${SemanticAttributes.NET_PEER_PORT.key}" Long "${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq" "${SemanticAttributes.MESSAGING_DESTINATION.key}" "" @@ -135,7 +136,7 @@ class ContextPropagationTest extends AgentInstrumentationSpecification { attributes { // "localhost" on linux, null on windows "${SemanticAttributes.NET_PEER_NAME.key}" { it == "localhost" || it == null } - "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" + "${SemanticAttributes.NET_PEER_IP.key}" { isInetAddress(it as String) } "${SemanticAttributes.NET_PEER_PORT.key}" Long "${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq" "${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue" diff --git a/testing-common/build.gradle.kts b/testing-common/build.gradle.kts index ce0d25e8ce..567ed036c4 100644 --- a/testing-common/build.gradle.kts +++ b/testing-common/build.gradle.kts @@ -45,11 +45,12 @@ dependencies { // Needs to be api dependency due to Spock restriction. api("org.awaitility:awaitility") + api("com.google.guava:guava") + compileOnly(project(path = ":testing:armeria-shaded-for-testing", configuration = "shadow")) implementation("io.opentelemetry.proto:opentelemetry-proto") - implementation("com.google.guava:guava") implementation("net.bytebuddy:byte-buddy") implementation("org.slf4j:slf4j-api") implementation("ch.qos.logback:logback-classic")