Remove usage of FixedHostPortGenericContainer (#4651)

* Remove usage of FixedHostPortGenericContainer
This commit is contained in:
Nikita Salnikov-Tarnovski 2021-11-17 18:23:56 +02:00 committed by GitHub
parent 3458afb8a4
commit 69336dac3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 151 additions and 131 deletions

View File

@ -16,7 +16,7 @@ import com.lambdaworks.redis.protocol.AsyncCommand
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.instrumentation.test.utils.PortUtils
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import org.testcontainers.containers.FixedHostPortGenericContainer import org.testcontainers.containers.GenericContainer
import spock.lang.Shared import spock.lang.Shared
import spock.util.concurrent.AsyncConditions import spock.util.concurrent.AsyncConditions
@ -32,13 +32,14 @@ import static io.opentelemetry.api.trace.SpanKind.INTERNAL
import static io.opentelemetry.api.trace.StatusCode.ERROR import static io.opentelemetry.api.trace.StatusCode.ERROR
class LettuceAsyncClientTest extends AgentInstrumentationSpecification { class LettuceAsyncClientTest extends AgentInstrumentationSpecification {
public static final String HOST = "localhost"
public static final int DB_INDEX = 0 public static final int DB_INDEX = 0
// Disable autoreconnect so we do not get stray traces popping up on server shutdown // Disable autoreconnect so we do not get stray traces popping up on server shutdown
public static final ClientOptions CLIENT_OPTIONS = new ClientOptions.Builder().autoReconnect(false).build() public static final ClientOptions CLIENT_OPTIONS = new ClientOptions.Builder().autoReconnect(false).build()
private static FixedHostPortGenericContainer redisServer = new FixedHostPortGenericContainer<>("redis:6.2.3-alpine") private static GenericContainer redisServer = new GenericContainer<>("redis:6.2.3-alpine").withExposedPorts(6379)
@Shared
String host
@Shared @Shared
int port int port
@Shared @Shared
@ -64,21 +65,18 @@ class LettuceAsyncClientTest extends AgentInstrumentationSpecification {
RedisAsyncCommands<String, ?> asyncCommands RedisAsyncCommands<String, ?> asyncCommands
RedisCommands<String, ?> syncCommands RedisCommands<String, ?> syncCommands
def setupSpec() { def setup() {
port = PortUtils.findOpenPort() redisServer.start()
incorrectPort = PortUtils.findOpenPort() host = redisServer.getHost()
dbAddr = HOST + ":" + port + "/" + DB_INDEX port = redisServer.getMappedPort(6379)
dbAddrNonExistent = HOST + ":" + incorrectPort + "/" + DB_INDEX dbAddr = host + ":" + port + "/" + DB_INDEX
dbUriNonExistent = "redis://" + dbAddrNonExistent
embeddedDbUri = "redis://" + dbAddr embeddedDbUri = "redis://" + dbAddr
redisServer = redisServer.withFixedExposedPort(port, 6379) incorrectPort = PortUtils.findOpenPort()
} dbAddrNonExistent = host + incorrectPort + "/" + DB_INDEX
dbUriNonExistent = "redis://" + dbAddrNonExistent
def setup() {
redisClient = RedisClient.create(embeddedDbUri) redisClient = RedisClient.create(embeddedDbUri)
redisServer.start()
redisClient.setOptions(CLIENT_OPTIONS) redisClient.setOptions(CLIENT_OPTIONS)
connection = redisClient.connect() connection = redisClient.connect()
@ -103,7 +101,7 @@ class LettuceAsyncClientTest extends AgentInstrumentationSpecification {
when: when:
StatefulConnection connection = testConnectionClient.connect(new Utf8StringCodec(), StatefulConnection connection = testConnectionClient.connect(new Utf8StringCodec(),
new RedisURI(HOST, port, 3, TimeUnit.SECONDS)) new RedisURI(host, port, 3, TimeUnit.SECONDS))
then: then:
connection != null connection != null
@ -113,7 +111,7 @@ class LettuceAsyncClientTest extends AgentInstrumentationSpecification {
name "CONNECT" name "CONNECT"
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_PEER_NAME.key}" HOST "${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
} }
@ -132,7 +130,7 @@ class LettuceAsyncClientTest extends AgentInstrumentationSpecification {
when: when:
StatefulConnection connection = testConnectionClient.connect(new Utf8StringCodec(), StatefulConnection connection = testConnectionClient.connect(new Utf8StringCodec(),
new RedisURI(HOST, incorrectPort, 3, TimeUnit.SECONDS)) new RedisURI(host, incorrectPort, 3, TimeUnit.SECONDS))
then: then:
connection == null connection == null
@ -145,7 +143,7 @@ class LettuceAsyncClientTest extends AgentInstrumentationSpecification {
status ERROR status ERROR
errorEvent RedisConnectionException, String errorEvent RedisConnectionException, String
attributes { attributes {
"${SemanticAttributes.NET_PEER_NAME.key}" HOST "${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_PORT.key}" incorrectPort "${SemanticAttributes.NET_PEER_PORT.key}" incorrectPort
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
} }

View File

@ -11,20 +11,21 @@ import com.lambdaworks.redis.api.sync.RedisCommands
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.instrumentation.test.utils.PortUtils
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import org.testcontainers.containers.FixedHostPortGenericContainer import org.testcontainers.containers.GenericContainer
import spock.lang.Shared import spock.lang.Shared
import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.CLIENT
import static io.opentelemetry.api.trace.StatusCode.ERROR import static io.opentelemetry.api.trace.StatusCode.ERROR
class LettuceSyncClientTest extends AgentInstrumentationSpecification { class LettuceSyncClientTest extends AgentInstrumentationSpecification {
public static final String HOST = "localhost"
public static final int DB_INDEX = 0 public static final int DB_INDEX = 0
// Disable autoreconnect so we do not get stray traces popping up on server shutdown // Disable autoreconnect so we do not get stray traces popping up on server shutdown
public static final ClientOptions CLIENT_OPTIONS = new ClientOptions.Builder().autoReconnect(false).build() public static final ClientOptions CLIENT_OPTIONS = new ClientOptions.Builder().autoReconnect(false).build()
private static FixedHostPortGenericContainer redis = new FixedHostPortGenericContainer<>("redis:6.2.3-alpine") private static GenericContainer redisServer = new GenericContainer<>("redis:6.2.3-alpine").withExposedPorts(6379)
@Shared
String host
@Shared @Shared
int port int port
@Shared @Shared
@ -49,20 +50,18 @@ class LettuceSyncClientTest extends AgentInstrumentationSpecification {
StatefulConnection connection StatefulConnection connection
RedisCommands<String, ?> syncCommands RedisCommands<String, ?> syncCommands
def setupSpec() {
port = PortUtils.findOpenPort()
incorrectPort = PortUtils.findOpenPort()
dbAddr = HOST + ":" + port + "/" + DB_INDEX
dbAddrNonExistent = HOST + ":" + incorrectPort + "/" + DB_INDEX
dbUriNonExistent = "redis://" + dbAddrNonExistent
embeddedDbUri = "redis://" + dbAddr
redis = redis.withFixedExposedPort(port, 6379)
}
def setup() { def setup() {
//TODO do not restart server for every test //TODO do not restart server for every test
redis.start() redisServer.start()
host = redisServer.getHost()
port = redisServer.getMappedPort(6379)
dbAddr = host + ":" + port + "/" + DB_INDEX
embeddedDbUri = "redis://" + dbAddr
incorrectPort = PortUtils.findOpenPort()
dbAddrNonExistent = host + ":" + incorrectPort + "/" + DB_INDEX
dbUriNonExistent = "redis://" + dbAddrNonExistent
redisClient = RedisClient.create(embeddedDbUri) redisClient = RedisClient.create(embeddedDbUri)
@ -78,7 +77,7 @@ class LettuceSyncClientTest extends AgentInstrumentationSpecification {
def cleanup() { def cleanup() {
connection.close() connection.close()
redis.stop() redisServer.stop()
} }
def "connect"() { def "connect"() {
@ -96,7 +95,7 @@ class LettuceSyncClientTest extends AgentInstrumentationSpecification {
name "CONNECT" name "CONNECT"
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_PEER_NAME.key}" HOST "${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
} }
@ -126,7 +125,7 @@ class LettuceSyncClientTest extends AgentInstrumentationSpecification {
status ERROR status ERROR
errorEvent RedisConnectionException, String errorEvent RedisConnectionException, String
attributes { attributes {
"${SemanticAttributes.NET_PEER_NAME.key}" HOST "${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_PORT.key}" incorrectPort "${SemanticAttributes.NET_PEER_PORT.key}" incorrectPort
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
} }

View File

@ -17,7 +17,7 @@ import io.netty.channel.AbstractChannel
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.instrumentation.test.utils.PortUtils
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import org.testcontainers.containers.FixedHostPortGenericContainer import org.testcontainers.containers.GenericContainer
import spock.lang.Shared import spock.lang.Shared
import spock.util.concurrent.AsyncConditions import spock.util.concurrent.AsyncConditions
@ -34,14 +34,14 @@ import static io.opentelemetry.api.trace.SpanKind.INTERNAL
import static io.opentelemetry.api.trace.StatusCode.ERROR import static io.opentelemetry.api.trace.StatusCode.ERROR
class LettuceAsyncClientTest extends AgentInstrumentationSpecification { class LettuceAsyncClientTest extends AgentInstrumentationSpecification {
public static final String PEER_NAME = "localhost"
public static final String PEER_IP = "127.0.0.1"
public static final int DB_INDEX = 0 public static final int DB_INDEX = 0
// Disable autoreconnect so we do not get stray traces popping up on server shutdown // Disable autoreconnect so we do not get stray traces popping up on server shutdown
public static final ClientOptions CLIENT_OPTIONS = ClientOptions.builder().autoReconnect(false).build() public static final ClientOptions CLIENT_OPTIONS = ClientOptions.builder().autoReconnect(false).build()
private static FixedHostPortGenericContainer redisServer = new FixedHostPortGenericContainer<>("redis:6.2.3-alpine") private static GenericContainer redisServer = new GenericContainer<>("redis:6.2.3-alpine").withExposedPorts(6379)
@Shared
String host
@Shared @Shared
int port int port
@Shared @Shared
@ -67,21 +67,20 @@ class LettuceAsyncClientTest extends AgentInstrumentationSpecification {
RedisAsyncCommands<String, ?> asyncCommands RedisAsyncCommands<String, ?> asyncCommands
RedisCommands<String, ?> syncCommands RedisCommands<String, ?> syncCommands
def setupSpec() { def setup() {
port = PortUtils.findOpenPort() redisServer.start()
incorrectPort = PortUtils.findOpenPort()
dbAddr = PEER_NAME + ":" + port + "/" + DB_INDEX host = redisServer.getHost()
dbAddrNonExistent = PEER_NAME + ":" + incorrectPort + "/" + DB_INDEX port = redisServer.getMappedPort(6379)
dbUriNonExistent = "redis://" + dbAddrNonExistent dbAddr = host + ":" + port + "/" + DB_INDEX
embeddedDbUri = "redis://" + dbAddr embeddedDbUri = "redis://" + dbAddr
redisServer = redisServer.withFixedExposedPort(port, 6379) incorrectPort = PortUtils.findOpenPort()
} dbAddrNonExistent = host + ":" + incorrectPort + "/" + DB_INDEX
dbUriNonExistent = "redis://" + dbAddrNonExistent
def setup() {
redisClient = RedisClient.create(embeddedDbUri) redisClient = RedisClient.create(embeddedDbUri)
redisServer.start()
redisClient.setOptions(CLIENT_OPTIONS) redisClient.setOptions(CLIENT_OPTIONS)
connection = redisClient.connect() connection = redisClient.connect()
@ -106,7 +105,7 @@ class LettuceAsyncClientTest extends AgentInstrumentationSpecification {
when: when:
ConnectionFuture connectionFuture = testConnectionClient.connectAsync(StringCodec.UTF8, ConnectionFuture connectionFuture = testConnectionClient.connectAsync(StringCodec.UTF8,
new RedisURI(PEER_NAME, port, 3, TimeUnit.SECONDS)) new RedisURI(host, port, 3, TimeUnit.SECONDS))
StatefulConnection connection = connectionFuture.get() StatefulConnection connection = connectionFuture.get()
then: then:
@ -117,7 +116,7 @@ class LettuceAsyncClientTest extends AgentInstrumentationSpecification {
name "CONNECT" name "CONNECT"
kind CLIENT kind CLIENT
attributes { attributes {
"$SemanticAttributes.NET_PEER_NAME.key" PEER_NAME "$SemanticAttributes.NET_PEER_NAME.key" host
"$SemanticAttributes.NET_PEER_PORT.key" port "$SemanticAttributes.NET_PEER_PORT.key" port
"$SemanticAttributes.DB_SYSTEM.key" "redis" "$SemanticAttributes.DB_SYSTEM.key" "redis"
} }
@ -136,7 +135,7 @@ class LettuceAsyncClientTest extends AgentInstrumentationSpecification {
when: when:
ConnectionFuture connectionFuture = testConnectionClient.connectAsync(StringCodec.UTF8, ConnectionFuture connectionFuture = testConnectionClient.connectAsync(StringCodec.UTF8,
new RedisURI(PEER_NAME, incorrectPort, 3, TimeUnit.SECONDS)) new RedisURI(host, incorrectPort, 3, TimeUnit.SECONDS))
StatefulConnection connection = connectionFuture.get() StatefulConnection connection = connectionFuture.get()
then: then:
@ -150,7 +149,7 @@ class LettuceAsyncClientTest extends AgentInstrumentationSpecification {
status ERROR status ERROR
errorEvent AbstractChannel.AnnotatedConnectException, String errorEvent AbstractChannel.AnnotatedConnectException, String
attributes { attributes {
"$SemanticAttributes.NET_PEER_NAME.key" PEER_NAME "$SemanticAttributes.NET_PEER_NAME.key" host
"$SemanticAttributes.NET_PEER_PORT.key" incorrectPort "$SemanticAttributes.NET_PEER_PORT.key" incorrectPort
"$SemanticAttributes.DB_SYSTEM.key" "redis" "$SemanticAttributes.DB_SYSTEM.key" "redis"
} }

View File

@ -9,9 +9,8 @@ import io.lettuce.core.api.StatefulConnection
import io.lettuce.core.api.reactive.RedisReactiveCommands import io.lettuce.core.api.reactive.RedisReactiveCommands
import io.lettuce.core.api.sync.RedisCommands import io.lettuce.core.api.sync.RedisCommands
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.instrumentation.test.utils.PortUtils
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import org.testcontainers.containers.FixedHostPortGenericContainer import org.testcontainers.containers.GenericContainer
import reactor.core.scheduler.Schedulers import reactor.core.scheduler.Schedulers
import spock.lang.Shared import spock.lang.Shared
import spock.util.concurrent.AsyncConditions import spock.util.concurrent.AsyncConditions
@ -22,13 +21,11 @@ import static io.opentelemetry.api.trace.SpanKind.CLIENT
import static io.opentelemetry.api.trace.SpanKind.INTERNAL import static io.opentelemetry.api.trace.SpanKind.INTERNAL
class LettuceReactiveClientTest extends AgentInstrumentationSpecification { class LettuceReactiveClientTest extends AgentInstrumentationSpecification {
public static final String PEER_HOST = "localhost"
public static final String PEER_IP = "127.0.0.1"
public static final int DB_INDEX = 0 public static final int DB_INDEX = 0
// Disable autoreconnect so we do not get stray traces popping up on server shutdown // Disable autoreconnect so we do not get stray traces popping up on server shutdown
public static final ClientOptions CLIENT_OPTIONS = ClientOptions.builder().autoReconnect(false).build() public static final ClientOptions CLIENT_OPTIONS = ClientOptions.builder().autoReconnect(false).build()
private static FixedHostPortGenericContainer redisServer = new FixedHostPortGenericContainer<>("redis:6.2.3-alpine") private static GenericContainer redisServer = new GenericContainer<>("redis:6.2.3-alpine").withExposedPorts(6379)
@Shared @Shared
String embeddedDbUri String embeddedDbUri
@ -40,17 +37,18 @@ class LettuceReactiveClientTest extends AgentInstrumentationSpecification {
RedisCommands<String, ?> syncCommands RedisCommands<String, ?> syncCommands
def setupSpec() { def setupSpec() {
int port = PortUtils.findOpenPort()
String dbAddr = PEER_HOST + ":" + port + "/" + DB_INDEX
embeddedDbUri = "redis://" + dbAddr
redisServer = redisServer.withFixedExposedPort(port, 6379)
} }
def setup() { def setup() {
redisServer.start()
String host = redisServer.getHost()
int port = redisServer.getMappedPort(6379)
String dbAddr = host + ":" + port + "/" + DB_INDEX
embeddedDbUri = "redis://" + dbAddr
redisClient = RedisClient.create(embeddedDbUri) redisClient = RedisClient.create(embeddedDbUri)
redisServer.start()
redisClient.setOptions(CLIENT_OPTIONS) redisClient.setOptions(CLIENT_OPTIONS)
connection = redisClient.connect() connection = redisClient.connect()

View File

@ -12,21 +12,21 @@ import io.netty.channel.AbstractChannel
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.instrumentation.test.utils.PortUtils
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import org.testcontainers.containers.FixedHostPortGenericContainer import org.testcontainers.containers.GenericContainer
import spock.lang.Shared import spock.lang.Shared
import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.CLIENT
import static io.opentelemetry.api.trace.StatusCode.ERROR import static io.opentelemetry.api.trace.StatusCode.ERROR
class LettuceSyncClientTest extends AgentInstrumentationSpecification { class LettuceSyncClientTest extends AgentInstrumentationSpecification {
public static final String PEER_NAME = "localhost"
public static final String PEER_IP = "127.0.0.1"
public static final int DB_INDEX = 0 public static final int DB_INDEX = 0
// Disable autoreconnect so we do not get stray traces popping up on server shutdown // Disable autoreconnect so we do not get stray traces popping up on server shutdown
public static final ClientOptions CLIENT_OPTIONS = ClientOptions.builder().autoReconnect(false).build() public static final ClientOptions CLIENT_OPTIONS = ClientOptions.builder().autoReconnect(false).build()
private static FixedHostPortGenericContainer redisServer = new FixedHostPortGenericContainer<>("redis:6.2.3-alpine") private static GenericContainer redisServer = new GenericContainer<>("redis:6.2.3-alpine").withExposedPorts(6379)
@Shared
String host
@Shared @Shared
int port int port
@Shared @Shared
@ -51,21 +51,20 @@ class LettuceSyncClientTest extends AgentInstrumentationSpecification {
StatefulConnection connection StatefulConnection connection
RedisCommands<String, ?> syncCommands RedisCommands<String, ?> syncCommands
def setupSpec() { def setup() {
port = PortUtils.findOpenPort() redisServer.start()
incorrectPort = PortUtils.findOpenPort()
dbAddr = PEER_NAME + ":" + port + "/" + DB_INDEX host = redisServer.getHost()
dbAddrNonExistent = PEER_NAME + ":" + incorrectPort + "/" + DB_INDEX port = redisServer.getMappedPort(6379)
dbUriNonExistent = "redis://" + dbAddrNonExistent dbAddr = host + ":" + port + "/" + DB_INDEX
embeddedDbUri = "redis://" + dbAddr embeddedDbUri = "redis://" + dbAddr
redisServer = redisServer.withFixedExposedPort(port, 6379) incorrectPort = PortUtils.findOpenPort()
} dbAddrNonExistent = host + ":" + incorrectPort + "/" + DB_INDEX
dbUriNonExistent = "redis://" + dbAddrNonExistent
def setup() {
redisClient = RedisClient.create(embeddedDbUri) redisClient = RedisClient.create(embeddedDbUri)
redisServer.start()
connection = redisClient.connect() connection = redisClient.connect()
syncCommands = connection.sync() syncCommands = connection.sync()
@ -96,7 +95,7 @@ class LettuceSyncClientTest extends AgentInstrumentationSpecification {
name "CONNECT" name "CONNECT"
kind CLIENT kind CLIENT
attributes { attributes {
"$SemanticAttributes.NET_PEER_NAME.key" PEER_NAME "$SemanticAttributes.NET_PEER_NAME.key" host
"$SemanticAttributes.NET_PEER_PORT.key" port "$SemanticAttributes.NET_PEER_PORT.key" port
"$SemanticAttributes.DB_SYSTEM.key" "redis" "$SemanticAttributes.DB_SYSTEM.key" "redis"
} }
@ -126,7 +125,7 @@ class LettuceSyncClientTest extends AgentInstrumentationSpecification {
status ERROR status ERROR
errorEvent AbstractChannel.AnnotatedConnectException, String errorEvent AbstractChannel.AnnotatedConnectException, String
attributes { attributes {
"$SemanticAttributes.NET_PEER_NAME.key" PEER_NAME "$SemanticAttributes.NET_PEER_NAME.key" host
"$SemanticAttributes.NET_PEER_PORT.key" incorrectPort "$SemanticAttributes.NET_PEER_PORT.key" incorrectPort
"$SemanticAttributes.DB_SYSTEM.key" "redis" "$SemanticAttributes.DB_SYSTEM.key" "redis"
} }

View File

@ -45,6 +45,7 @@ class LettuceReactiveClientTest extends AbstractLettuceReactiveClientTest implem
childOf span(0) childOf span(0)
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -63,6 +64,7 @@ class LettuceReactiveClientTest extends AbstractLettuceReactiveClientTest implem
childOf span(0) childOf span(0)
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"

View File

@ -16,7 +16,7 @@ import io.lettuce.core.codec.StringCodec
import io.opentelemetry.instrumentation.test.InstrumentationSpecification import io.opentelemetry.instrumentation.test.InstrumentationSpecification
import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.instrumentation.test.utils.PortUtils
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import org.testcontainers.containers.FixedHostPortGenericContainer import org.testcontainers.containers.GenericContainer
import spock.lang.Shared import spock.lang.Shared
import spock.util.concurrent.AsyncConditions import spock.util.concurrent.AsyncConditions
@ -32,13 +32,14 @@ import static io.opentelemetry.api.trace.SpanKind.INTERNAL
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP
abstract class AbstractLettuceAsyncClientTest extends InstrumentationSpecification { abstract class AbstractLettuceAsyncClientTest extends InstrumentationSpecification {
public static final String HOST = "127.0.0.1"
public static final int DB_INDEX = 0 public static final int DB_INDEX = 0
private static FixedHostPortGenericContainer redisServer = new FixedHostPortGenericContainer<>("redis:6.2.3-alpine") private static GenericContainer redisServer = new GenericContainer<>("redis:6.2.3-alpine").withExposedPorts(6379)
abstract RedisClient createClient(String uri) abstract RedisClient createClient(String uri)
@Shared
String host
@Shared @Shared
int port int port
@Shared @Shared
@ -64,21 +65,20 @@ abstract class AbstractLettuceAsyncClientTest extends InstrumentationSpecificati
RedisAsyncCommands<String, ?> asyncCommands RedisAsyncCommands<String, ?> asyncCommands
RedisCommands<String, ?> syncCommands RedisCommands<String, ?> syncCommands
def setupSpec() { def setup() {
port = PortUtils.findOpenPort() redisServer.start()
incorrectPort = PortUtils.findOpenPort()
dbAddr = HOST + ":" + port + "/" + DB_INDEX host = redisServer.getHost()
dbAddrNonExistent = HOST + ":" + incorrectPort + "/" + DB_INDEX port = redisServer.getMappedPort(6379)
dbUriNonExistent = "redis://" + dbAddrNonExistent dbAddr = host + ":" + port + "/" + DB_INDEX
embeddedDbUri = "redis://" + dbAddr embeddedDbUri = "redis://" + dbAddr
redisServer = redisServer.withFixedExposedPort(port, 6379) incorrectPort = PortUtils.findOpenPort()
} dbAddrNonExistent = host + ":" + incorrectPort + "/" + DB_INDEX
dbUriNonExistent = "redis://" + dbAddrNonExistent
def setup() {
redisClient = createClient(embeddedDbUri) redisClient = createClient(embeddedDbUri)
redisServer.start()
redisClient.setOptions(LettuceTestUtil.CLIENT_OPTIONS) redisClient.setOptions(LettuceTestUtil.CLIENT_OPTIONS)
connection = redisClient.connect() connection = redisClient.connect()
@ -115,7 +115,7 @@ abstract class AbstractLettuceAsyncClientTest extends InstrumentationSpecificati
when: when:
ConnectionFuture connectionFuture = testConnectionClient.connectAsync(StringCodec.UTF8, ConnectionFuture connectionFuture = testConnectionClient.connectAsync(StringCodec.UTF8,
RedisURI.create("redis://${HOST}:${port}?timeout=3s")) RedisURI.create("redis://${host}:${port}?timeout=3s"))
StatefulConnection connection = connectionFuture.get() StatefulConnection connection = connectionFuture.get()
then: then:
@ -135,7 +135,7 @@ abstract class AbstractLettuceAsyncClientTest extends InstrumentationSpecificati
when: when:
ConnectionFuture connectionFuture = testConnectionClient.connectAsync(StringCodec.UTF8, ConnectionFuture connectionFuture = testConnectionClient.connectAsync(StringCodec.UTF8,
RedisURI.create("redis://${HOST}:${incorrectPort}?timeout=3s")) RedisURI.create("redis://${host}:${incorrectPort}?timeout=3s"))
StatefulConnection connection = connectionFuture.get() StatefulConnection connection = connectionFuture.get()
then: then:
@ -162,6 +162,7 @@ abstract class AbstractLettuceAsyncClientTest extends InstrumentationSpecificati
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -212,6 +213,7 @@ abstract class AbstractLettuceAsyncClientTest extends InstrumentationSpecificati
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -286,6 +288,7 @@ abstract class AbstractLettuceAsyncClientTest extends InstrumentationSpecificati
childOf(span(0)) childOf(span(0))
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -349,6 +352,7 @@ abstract class AbstractLettuceAsyncClientTest extends InstrumentationSpecificati
childOf(span(0)) childOf(span(0))
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_STATEMENT.key}" "RANDOMKEY" "${SemanticAttributes.DB_STATEMENT.key}" "RANDOMKEY"
@ -415,6 +419,7 @@ abstract class AbstractLettuceAsyncClientTest extends InstrumentationSpecificati
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -434,6 +439,7 @@ abstract class AbstractLettuceAsyncClientTest extends InstrumentationSpecificati
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"

View File

@ -10,9 +10,8 @@ import io.lettuce.core.api.StatefulConnection
import io.lettuce.core.api.reactive.RedisReactiveCommands import io.lettuce.core.api.reactive.RedisReactiveCommands
import io.lettuce.core.api.sync.RedisCommands import io.lettuce.core.api.sync.RedisCommands
import io.opentelemetry.instrumentation.test.InstrumentationSpecification import io.opentelemetry.instrumentation.test.InstrumentationSpecification
import io.opentelemetry.instrumentation.test.utils.PortUtils
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import org.testcontainers.containers.FixedHostPortGenericContainer import org.testcontainers.containers.GenericContainer
import spock.lang.Shared import spock.lang.Shared
import spock.util.concurrent.AsyncConditions import spock.util.concurrent.AsyncConditions
@ -23,13 +22,14 @@ import static io.opentelemetry.api.trace.SpanKind.INTERNAL
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP
abstract class AbstractLettuceReactiveClientTest extends InstrumentationSpecification { abstract class AbstractLettuceReactiveClientTest extends InstrumentationSpecification {
public static final String HOST = "127.0.0.1"
public static final int DB_INDEX = 0 public static final int DB_INDEX = 0
private static FixedHostPortGenericContainer redisServer = new FixedHostPortGenericContainer<>("redis:6.2.3-alpine") private static GenericContainer redisServer = new GenericContainer<>("redis:6.2.3-alpine").withExposedPorts(6379)
abstract RedisClient createClient(String uri) abstract RedisClient createClient(String uri)
@Shared
String host
@Shared @Shared
int port int port
@Shared @Shared
@ -40,18 +40,15 @@ abstract class AbstractLettuceReactiveClientTest extends InstrumentationSpecific
RedisReactiveCommands<String, ?> reactiveCommands RedisReactiveCommands<String, ?> reactiveCommands
RedisCommands<String, ?> syncCommands RedisCommands<String, ?> syncCommands
def setupSpec() {
port = PortUtils.findOpenPort()
String dbAddr = HOST + ":" + port + "/" + DB_INDEX
embeddedDbUri = "redis://" + dbAddr
redisServer = redisServer.withFixedExposedPort(port, 6379)
}
def setup() { def setup() {
redisServer.start()
host = redisServer.getHost()
port = redisServer.getMappedPort(6379)
String dbAddr = host + ":" + port + "/" + DB_INDEX
embeddedDbUri = "redis://" + dbAddr
redisClient = createClient(embeddedDbUri) redisClient = createClient(embeddedDbUri)
redisServer.start()
redisClient.setOptions(LettuceTestUtil.CLIENT_OPTIONS) redisClient.setOptions(LettuceTestUtil.CLIENT_OPTIONS)
connection = redisClient.connect() connection = redisClient.connect()
@ -104,6 +101,7 @@ abstract class AbstractLettuceReactiveClientTest extends InstrumentationSpecific
childOf(span(0)) childOf(span(0))
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -141,6 +139,7 @@ abstract class AbstractLettuceReactiveClientTest extends InstrumentationSpecific
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -191,6 +190,7 @@ abstract class AbstractLettuceReactiveClientTest extends InstrumentationSpecific
childOf(span(0)) childOf(span(0))
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -234,6 +234,7 @@ abstract class AbstractLettuceReactiveClientTest extends InstrumentationSpecific
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_STATEMENT.key}" "RANDOMKEY" "${SemanticAttributes.DB_STATEMENT.key}" "RANDOMKEY"
@ -262,6 +263,7 @@ abstract class AbstractLettuceReactiveClientTest extends InstrumentationSpecific
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_STATEMENT.key}" "COMMAND" "${SemanticAttributes.DB_STATEMENT.key}" "COMMAND"
@ -309,6 +311,7 @@ abstract class AbstractLettuceReactiveClientTest extends InstrumentationSpecific
childOf span(0) childOf span(0)
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -327,6 +330,7 @@ abstract class AbstractLettuceReactiveClientTest extends InstrumentationSpecific
childOf span(0) childOf span(0)
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -365,6 +369,7 @@ abstract class AbstractLettuceReactiveClientTest extends InstrumentationSpecific
childOf span(0) childOf span(0)
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -383,6 +388,7 @@ abstract class AbstractLettuceReactiveClientTest extends InstrumentationSpecific
childOf span(0) childOf span(0)
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"

View File

@ -7,22 +7,22 @@ package io.opentelemetry.instrumentation.lettuce.v5_1
import io.lettuce.core.RedisClient import io.lettuce.core.RedisClient
import io.opentelemetry.instrumentation.test.InstrumentationSpecification import io.opentelemetry.instrumentation.test.InstrumentationSpecification
import io.opentelemetry.instrumentation.test.utils.PortUtils
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import org.testcontainers.containers.FixedHostPortGenericContainer import org.testcontainers.containers.GenericContainer
import spock.lang.Shared import spock.lang.Shared
import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.CLIENT
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP
abstract class AbstractLettuceSyncClientAuthTest extends InstrumentationSpecification { abstract class AbstractLettuceSyncClientAuthTest extends InstrumentationSpecification {
public static final String HOST = "127.0.0.1"
public static final int DB_INDEX = 0 public static final int DB_INDEX = 0
private static FixedHostPortGenericContainer redisServer = new FixedHostPortGenericContainer<>("redis:6.2.3-alpine") private static GenericContainer redisServer = new GenericContainer<>("redis:6.2.3-alpine").withExposedPorts(6379)
abstract RedisClient createClient(String uri) abstract RedisClient createClient(String uri)
@Shared
String host
@Shared @Shared
int port int port
@Shared @Shared
@ -35,20 +35,21 @@ abstract class AbstractLettuceSyncClientAuthTest extends InstrumentationSpecific
RedisClient redisClient RedisClient redisClient
def setupSpec() { def setupSpec() {
port = PortUtils.findOpenPort()
dbAddr = HOST + ":" + port + "/" + DB_INDEX
embeddedDbUri = "redis://" + dbAddr
password = "password" password = "password"
redisServer = redisServer redisServer = redisServer
.withFixedExposedPort(port, 6379)
.withCommand("redis-server", "--requirepass $password") .withCommand("redis-server", "--requirepass $password")
} }
def setup() { def setup() {
redisServer.start()
host = redisServer.getHost()
port = redisServer.getMappedPort(6379)
dbAddr = host + ":" + port + "/" + DB_INDEX
embeddedDbUri = "redis://" + dbAddr
redisClient = createClient(embeddedDbUri) redisClient = createClient(embeddedDbUri)
redisClient.setOptions(LettuceTestUtil.CLIENT_OPTIONS) redisClient.setOptions(LettuceTestUtil.CLIENT_OPTIONS)
redisServer.start()
} }
def cleanup() { def cleanup() {
@ -69,6 +70,7 @@ abstract class AbstractLettuceSyncClientAuthTest extends InstrumentationSpecific
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"

View File

@ -14,7 +14,7 @@ import io.lettuce.core.api.sync.RedisCommands
import io.opentelemetry.instrumentation.test.InstrumentationSpecification import io.opentelemetry.instrumentation.test.InstrumentationSpecification
import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.instrumentation.test.utils.PortUtils
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import org.testcontainers.containers.FixedHostPortGenericContainer import org.testcontainers.containers.GenericContainer
import spock.lang.Shared import spock.lang.Shared
import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.CLIENT
@ -23,13 +23,14 @@ import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTr
import static java.nio.charset.StandardCharsets.UTF_8 import static java.nio.charset.StandardCharsets.UTF_8
abstract class AbstractLettuceSyncClientTest extends InstrumentationSpecification { abstract class AbstractLettuceSyncClientTest extends InstrumentationSpecification {
public static final String HOST = "127.0.0.1"
public static final int DB_INDEX = 0 public static final int DB_INDEX = 0
private static FixedHostPortGenericContainer redisServer = new FixedHostPortGenericContainer<>("redis:6.2.3-alpine") private static GenericContainer redisServer = new GenericContainer<>("redis:6.2.3-alpine").withExposedPorts(6379)
abstract RedisClient createClient(String uri) abstract RedisClient createClient(String uri)
@Shared
String host
@Shared @Shared
int port int port
@Shared @Shared
@ -56,23 +57,22 @@ abstract class AbstractLettuceSyncClientTest extends InstrumentationSpecificatio
StatefulConnection connection StatefulConnection connection
RedisCommands<String, ?> syncCommands RedisCommands<String, ?> syncCommands
def setupSpec() { def setup() {
port = PortUtils.findOpenPort() redisServer.start()
incorrectPort = PortUtils.findOpenPort()
dbAddr = HOST + ":" + port + "/" + DB_INDEX host = redisServer.getHost()
dbAddrNonExistent = HOST + ":" + incorrectPort + "/" + DB_INDEX port = redisServer.getMappedPort(6379)
dbUriNonExistent = "redis://" + dbAddrNonExistent dbAddr = host + ":" + port + "/" + DB_INDEX
embeddedDbUri = "redis://" + dbAddr embeddedDbUri = "redis://" + dbAddr
embeddedDbLocalhostUri = "redis://localhost:" + port + "/" + DB_INDEX embeddedDbLocalhostUri = "redis://localhost:" + port + "/" + DB_INDEX
redisServer = redisServer.withFixedExposedPort(port, 6379) incorrectPort = PortUtils.findOpenPort()
} dbAddrNonExistent = host + ":" + incorrectPort + "/" + DB_INDEX
dbUriNonExistent = "redis://" + dbAddrNonExistent
def setup() {
redisClient = createClient(embeddedDbUri) redisClient = createClient(embeddedDbUri)
redisClient.setOptions(LettuceTestUtil.CLIENT_OPTIONS) redisClient.setOptions(LettuceTestUtil.CLIENT_OPTIONS)
redisServer.start()
connection = redisClient.connect() connection = redisClient.connect()
syncCommands = connection.sync() syncCommands = connection.sync()
@ -136,6 +136,7 @@ abstract class AbstractLettuceSyncClientTest extends InstrumentationSpecificatio
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -202,6 +203,7 @@ abstract class AbstractLettuceSyncClientTest extends InstrumentationSpecificatio
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -231,6 +233,7 @@ abstract class AbstractLettuceSyncClientTest extends InstrumentationSpecificatio
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -260,6 +263,7 @@ abstract class AbstractLettuceSyncClientTest extends InstrumentationSpecificatio
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_STATEMENT.key}" "RANDOMKEY" "${SemanticAttributes.DB_STATEMENT.key}" "RANDOMKEY"
@ -289,6 +293,7 @@ abstract class AbstractLettuceSyncClientTest extends InstrumentationSpecificatio
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -318,6 +323,7 @@ abstract class AbstractLettuceSyncClientTest extends InstrumentationSpecificatio
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -347,6 +353,7 @@ abstract class AbstractLettuceSyncClientTest extends InstrumentationSpecificatio
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -381,6 +388,7 @@ abstract class AbstractLettuceSyncClientTest extends InstrumentationSpecificatio
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -414,6 +422,7 @@ abstract class AbstractLettuceSyncClientTest extends InstrumentationSpecificatio
kind CLIENT kind CLIENT
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -443,6 +452,7 @@ abstract class AbstractLettuceSyncClientTest extends InstrumentationSpecificatio
// Disconnect not an actual error even though an exception is recorded. // Disconnect not an actual error even though an exception is recorded.
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"
@ -479,6 +489,7 @@ abstract class AbstractLettuceSyncClientTest extends InstrumentationSpecificatio
} }
attributes { attributes {
"${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP "${SemanticAttributes.NET_TRANSPORT.key}" IP_TCP
"${SemanticAttributes.NET_PEER_NAME.key}" host
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1" "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key}" port "${SemanticAttributes.NET_PEER_PORT.key}" port
"${SemanticAttributes.DB_SYSTEM.key}" "redis" "${SemanticAttributes.DB_SYSTEM.key}" "redis"