Fix Redisson latestDep tests (#1507)
* Fix Redisson latestDep tests * spotless * Add comment
This commit is contained in:
parent
58c78ec7d0
commit
9bb13bd8f0
|
@ -5,13 +5,13 @@
|
||||||
|
|
||||||
package io.opentelemetry.javaagent.instrumentation.redisson;
|
package io.opentelemetry.javaagent.instrumentation.redisson;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
|
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
|
||||||
import io.opentelemetry.javaagent.instrumentation.api.db.DbSystem;
|
import io.opentelemetry.javaagent.instrumentation.api.db.DbSystem;
|
||||||
import io.opentelemetry.javaagent.instrumentation.api.db.RedisCommandNormalizer;
|
import io.opentelemetry.javaagent.instrumentation.api.db.RedisCommandNormalizer;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.redisson.client.RedisConnection;
|
import org.redisson.client.RedisConnection;
|
||||||
import org.redisson.client.protocol.CommandData;
|
import org.redisson.client.protocol.CommandData;
|
||||||
|
@ -71,7 +71,21 @@ public class RedissonClientTracer extends DatabaseClientTracer<RedisConnection,
|
||||||
if (command.getCommand().getSubName() != null) {
|
if (command.getCommand().getSubName() != null) {
|
||||||
args.add(command.getCommand().getSubName());
|
args.add(command.getCommand().getSubName());
|
||||||
}
|
}
|
||||||
args.addAll(Arrays.asList(commandParams));
|
for (Object param : commandParams) {
|
||||||
|
if (param instanceof ByteBuf) {
|
||||||
|
try {
|
||||||
|
// slice() does not copy the actual byte buffer, it only returns a readable/writable
|
||||||
|
// "view" of the original buffer (i.e. read and write marks are not shared)
|
||||||
|
ByteBuf buf = ((ByteBuf) param).slice();
|
||||||
|
// state can be null here: no Decoders used by Codecs use it
|
||||||
|
args.add(command.getCodec().getValueDecoder().decode(buf, null));
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
args.add("?");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
args.add(param);
|
||||||
|
}
|
||||||
|
}
|
||||||
return RedisCommandNormalizer.normalize(command.getCommand().getName(), args);
|
return RedisCommandNormalizer.normalize(command.getCommand().getName(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import static io.opentelemetry.trace.Span.Kind.CLIENT
|
import static io.opentelemetry.trace.Span.Kind.CLIENT
|
||||||
|
import static java.util.regex.Pattern.compile
|
||||||
|
import static java.util.regex.Pattern.quote
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.test.AgentTestRunner
|
import io.opentelemetry.instrumentation.test.AgentTestRunner
|
||||||
import io.opentelemetry.instrumentation.test.utils.PortUtils
|
import io.opentelemetry.instrumentation.test.utils.PortUtils
|
||||||
|
@ -276,10 +278,9 @@ class RedissonClientTest extends AgentTestRunner {
|
||||||
assertTraces(2) {
|
assertTraces(2) {
|
||||||
trace(0, 1) {
|
trace(0, 1) {
|
||||||
span(0) {
|
span(0) {
|
||||||
def lockScript = "if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1);" +
|
// Use .* to match the actual script, since it changes between redisson versions
|
||||||
" redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end;" +
|
// everything that does not change is quoted so that it's matched literally
|
||||||
" if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1);" +
|
def lockScriptPattern = compile("^" + quote("EVAL ") + ".*" + quote(" 1 lock ? ?") + "\$")
|
||||||
" redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);"
|
|
||||||
|
|
||||||
name "EVAL"
|
name "EVAL"
|
||||||
kind CLIENT
|
kind CLIENT
|
||||||
|
@ -289,16 +290,13 @@ class RedissonClientTest extends AgentTestRunner {
|
||||||
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
|
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
|
||||||
"$SemanticAttributes.DB_CONNECTION_STRING.key" "localhost:$port"
|
"$SemanticAttributes.DB_CONNECTION_STRING.key" "localhost:$port"
|
||||||
"$SemanticAttributes.NET_PEER_PORT.key" port
|
"$SemanticAttributes.NET_PEER_PORT.key" port
|
||||||
"$SemanticAttributes.DB_STATEMENT.key" "EVAL $lockScript 1 lock ? ?"
|
"$SemanticAttributes.DB_STATEMENT.key" { lockScriptPattern.matcher(it).matches() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
trace(1, 1) {
|
trace(1, 1) {
|
||||||
span(0) {
|
span(0) {
|
||||||
def unlockScript = "if (redis.call('exists', KEYS[1]) == 0) then redis.call('publish', KEYS[2], ARGV[1]);" +
|
def lockScriptPattern = compile("^" + quote("EVAL ") + ".*" + quote(" 2 lock ") + "\\S+" + quote(" ? ? ?") + "\$")
|
||||||
" return 1; end;if (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then return nil;end;" +
|
|
||||||
" local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); if (counter > 0) then redis.call('pexpire', KEYS[1], ARGV[2]);" +
|
|
||||||
" return 0; else redis.call('del', KEYS[1]); redis.call('publish', KEYS[2], ARGV[1]); return 1; end; return nil;"
|
|
||||||
|
|
||||||
name "EVAL"
|
name "EVAL"
|
||||||
kind CLIENT
|
kind CLIENT
|
||||||
|
@ -308,7 +306,7 @@ class RedissonClientTest extends AgentTestRunner {
|
||||||
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
|
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
|
||||||
"$SemanticAttributes.DB_CONNECTION_STRING.key" "localhost:$port"
|
"$SemanticAttributes.DB_CONNECTION_STRING.key" "localhost:$port"
|
||||||
"$SemanticAttributes.NET_PEER_PORT.key" port
|
"$SemanticAttributes.NET_PEER_PORT.key" port
|
||||||
"$SemanticAttributes.DB_STATEMENT.key" "EVAL $unlockScript 2 lock redisson_lock__channel__{lock} ? ? ?"
|
"$SemanticAttributes.DB_STATEMENT.key" { lockScriptPattern.matcher(it).matches() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue