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
This commit is contained in:
Mateusz Rzeszutek 2021-12-01 00:25:23 +01:00 committed by GitHub
parent 95f3d37b3f
commit f948ef8051
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 8 deletions

View File

@ -23,6 +23,7 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory
import org.springframework.amqp.rabbit.core.RabbitAdmin import org.springframework.amqp.rabbit.core.RabbitAdmin
import org.springframework.amqp.rabbit.core.RabbitTemplate 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.CLIENT
import static io.opentelemetry.api.trace.SpanKind.CONSUMER import static io.opentelemetry.api.trace.SpanKind.CONSUMER
import static io.opentelemetry.api.trace.SpanKind.PRODUCER import static io.opentelemetry.api.trace.SpanKind.PRODUCER
@ -340,7 +341,7 @@ class RabbitMqTest extends AgentInstrumentationSpecification implements WithRabb
attributes { attributes {
"${SemanticAttributes.NET_PEER_NAME.key}" { it == null || it instanceof String } "${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.NET_PEER_PORT.key}" { it == null || it instanceof Long }
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq" "${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq"

View File

@ -10,6 +10,8 @@ import reactor.rabbitmq.ExchangeSpecification
import reactor.rabbitmq.RabbitFlux import reactor.rabbitmq.RabbitFlux
import reactor.rabbitmq.SenderOptions import reactor.rabbitmq.SenderOptions
import static com.google.common.net.InetAddresses.isInetAddress
class ReactorRabbitMqTest extends AgentInstrumentationSpecification implements WithRabbitMqTrait { class ReactorRabbitMqTest extends AgentInstrumentationSpecification implements WithRabbitMqTrait {
def setupSpec() { def setupSpec() {
@ -38,7 +40,7 @@ class ReactorRabbitMqTest extends AgentInstrumentationSpecification implements W
kind SpanKind.CLIENT kind SpanKind.CLIENT
attributes { attributes {
"${SemanticAttributes.NET_PEER_NAME.key}" { it == null || it instanceof String } "${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.NET_PEER_PORT.key}" { it == null || it instanceof Long }
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq" "${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq"
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue" "${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue"

View File

@ -6,6 +6,7 @@
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes 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.CLIENT
import static io.opentelemetry.api.trace.SpanKind.CONSUMER import static io.opentelemetry.api.trace.SpanKind.CONSUMER
import static io.opentelemetry.api.trace.SpanKind.PRODUCER import static io.opentelemetry.api.trace.SpanKind.PRODUCER
@ -48,7 +49,7 @@ class SpringIntegrationAndRabbitTest extends AgentInstrumentationSpecification i
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_PEER_NAME.key}" { it == null || it == "localhost" } "${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.NET_PEER_PORT.key}" { it == null || it instanceof Long }
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq" "${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq"
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue" "${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue"
@ -62,7 +63,7 @@ class SpringIntegrationAndRabbitTest extends AgentInstrumentationSpecification i
attributes { attributes {
// "localhost" on linux, null on windows // "localhost" on linux, null on windows
"${SemanticAttributes.NET_PEER_NAME.key}" { it == "localhost" || it == null } "${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.NET_PEER_PORT.key}" Long
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq" "${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq"
"${SemanticAttributes.MESSAGING_DESTINATION.key}" "testTopic" "${SemanticAttributes.MESSAGING_DESTINATION.key}" "testTopic"
@ -117,7 +118,7 @@ class SpringIntegrationAndRabbitTest extends AgentInstrumentationSpecification i
attributes { attributes {
// "localhost" on linux, null on windows // "localhost" on linux, null on windows
"${SemanticAttributes.NET_PEER_NAME.key}" { it == "localhost" || it == null } "${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.NET_PEER_PORT.key}" Long
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq" "${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq"
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue" "${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue"

View File

@ -19,6 +19,7 @@ import spock.lang.Shared
import java.time.Duration 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.CLIENT
import static io.opentelemetry.api.trace.SpanKind.CONSUMER import static io.opentelemetry.api.trace.SpanKind.CONSUMER
import static io.opentelemetry.api.trace.SpanKind.PRODUCER import static io.opentelemetry.api.trace.SpanKind.PRODUCER
@ -84,7 +85,7 @@ class ContextPropagationTest extends AgentInstrumentationSpecification {
attributes { attributes {
// "localhost" on linux, null on windows // "localhost" on linux, null on windows
"${SemanticAttributes.NET_PEER_NAME.key}" { it == "localhost" || it == null } "${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.NET_PEER_PORT.key}" Long
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq" "${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq"
"${SemanticAttributes.MESSAGING_DESTINATION.key}" "<default>" "${SemanticAttributes.MESSAGING_DESTINATION.key}" "<default>"
@ -135,7 +136,7 @@ class ContextPropagationTest extends AgentInstrumentationSpecification {
attributes { attributes {
// "localhost" on linux, null on windows // "localhost" on linux, null on windows
"${SemanticAttributes.NET_PEER_NAME.key}" { it == "localhost" || it == null } "${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.NET_PEER_PORT.key}" Long
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq" "${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq"
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue" "${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue"

View File

@ -45,11 +45,12 @@ dependencies {
// Needs to be api dependency due to Spock restriction. // Needs to be api dependency due to Spock restriction.
api("org.awaitility:awaitility") api("org.awaitility:awaitility")
api("com.google.guava:guava")
compileOnly(project(path = ":testing:armeria-shaded-for-testing", configuration = "shadow")) compileOnly(project(path = ":testing:armeria-shaded-for-testing", configuration = "shadow"))
implementation("io.opentelemetry.proto:opentelemetry-proto") implementation("io.opentelemetry.proto:opentelemetry-proto")
implementation("com.google.guava:guava")
implementation("net.bytebuddy:byte-buddy") implementation("net.bytebuddy:byte-buddy")
implementation("org.slf4j:slf4j-api") implementation("org.slf4j:slf4j-api")
implementation("ch.qos.logback:logback-classic") implementation("ch.qos.logback:logback-classic")