diff --git a/Jenkinsfile-Agent-Test-2 b/Jenkinsfile-Agent-Test-2 index 8b43e9487..ece91a999 100755 --- a/Jenkinsfile-Agent-Test-2 +++ b/Jenkinsfile-Agent-Test-2 @@ -67,7 +67,7 @@ pipeline { sh './mvnw -f test/plugin/pom.xml clean package -DskipTests docker:build' } } - stage('Test Cases Report (198)') { + stage('Test Cases Report (212)') { steps { echo "Test Cases Report" } @@ -82,7 +82,7 @@ pipeline { parallel { stage('Group1') { stages { - stage('redisson-scenario 3.x (23)') { + stage('redisson-scenario 3.x (37)') { steps { sh 'bash test/plugin/run.sh redisson-scenario' } diff --git a/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/ConnectionManagerInterceptor.java b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/ConnectionManagerInterceptor.java index 07c99179f..8df009d0f 100644 --- a/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/ConnectionManagerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/ConnectionManagerInterceptor.java @@ -15,19 +15,18 @@ * limitations under the License. * */ - package org.apache.skywalking.apm.plugin.redisson.v3; +import org.apache.skywalking.apm.agent.core.context.util.PeerFormat; import org.apache.skywalking.apm.agent.core.logging.api.ILog; import org.apache.skywalking.apm.agent.core.logging.api.LogManager; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.apache.skywalking.apm.agent.core.context.util.PeerFormat; +import org.apache.skywalking.apm.plugin.redisson.v3.util.ClassUtil; import org.redisson.config.*; import org.redisson.connection.ConnectionManager; -import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.URI; import java.util.Collection; @@ -51,33 +50,33 @@ public class ConnectionManagerInterceptor implements InstanceMethodsAroundInterc ConnectionManager connectionManager = (ConnectionManager) objInst; Config config = connectionManager.getCfg(); - SentinelServersConfig sentinelServersConfig = (SentinelServersConfig) getServersConfig(config, "sentinelServersConfig"); - MasterSlaveServersConfig masterSlaveServersConfig = (MasterSlaveServersConfig) getServersConfig(config, "masterSlaveServersConfig"); - ClusterServersConfig clusterServersConfig = (ClusterServersConfig) getServersConfig(config, "clusterServersConfig"); - ReplicatedServersConfig replicatedServersConfig = (ReplicatedServersConfig) getServersConfig(config, "replicatedServersConfig"); + Object sentinelServersConfig = ClassUtil.getObjectField(config, "sentinelServersConfig"); + Object masterSlaveServersConfig = ClassUtil.getObjectField(config, "masterSlaveServersConfig"); + Object clusterServersConfig = ClassUtil.getObjectField(config, "clusterServersConfig"); + Object replicatedServersConfig = ClassUtil.getObjectField(config, "replicatedServersConfig"); StringBuilder peer = new StringBuilder(); EnhancedInstance retInst = (EnhancedInstance) ret; if (sentinelServersConfig != null) { - appendAddresses(peer, sentinelServersConfig.getSentinelAddresses()); + appendAddresses(peer, (Collection) ClassUtil.getObjectField(sentinelServersConfig, "sentinelAddresses")); retInst.setSkyWalkingDynamicField(PeerFormat.shorten(peer.toString())); return ret; } if (masterSlaveServersConfig != null) { - URI masterAddress = masterSlaveServersConfig.getMasterAddress(); - peer.append(masterAddress.getHost()).append(":").append(masterAddress.getPort()); - appendAddresses(peer, masterSlaveServersConfig.getSlaveAddresses()); + Object masterAddress = ClassUtil.getObjectField(masterSlaveServersConfig, "masterAddress"); + peer.append(getPeer(masterAddress)); + appendAddresses(peer, (Collection) ClassUtil.getObjectField(masterSlaveServersConfig, "slaveAddresses")); retInst.setSkyWalkingDynamicField(PeerFormat.shorten(peer.toString())); return ret; } if (clusterServersConfig != null) { - appendAddresses(peer, clusterServersConfig.getNodeAddresses()); + appendAddresses(peer, (Collection) ClassUtil.getObjectField(clusterServersConfig, "nodeAddresses")); retInst.setSkyWalkingDynamicField(PeerFormat.shorten(peer.toString())); return ret; } if (replicatedServersConfig != null) { - appendAddresses(peer, replicatedServersConfig.getNodeAddresses()); + appendAddresses(peer, (Collection) ClassUtil.getObjectField(replicatedServersConfig, "nodeAddresses")); retInst.setSkyWalkingDynamicField(PeerFormat.shorten(peer.toString())); return ret; } @@ -87,17 +86,30 @@ public class ConnectionManagerInterceptor implements InstanceMethodsAroundInterc return ret; } - private Object getServersConfig(Config config, String fieldName) throws NoSuchFieldException, IllegalAccessException { - Field field = config.getClass().getDeclaredField(fieldName); - field.setAccessible(true); - return field.get(config); + private void appendAddresses(StringBuilder peer, Collection nodeAddresses) { + if (nodeAddresses != null && !nodeAddresses.isEmpty()) { + for (Object uri : nodeAddresses) { + peer.append(getPeer(uri)).append(";"); + } + } } - private void appendAddresses(StringBuilder peer, Collection nodeAddresses) { - if (nodeAddresses != null && !nodeAddresses.isEmpty()) { - for (URI uri : nodeAddresses) { - peer.append(uri.getHost()).append(":").append(uri.getPort()).append(";"); - } + /** + * In some high versions of redisson, such as 3.11.1. + * The attribute address in the RedisClientConfig class is changed from the lower version of the URI to the String. + * So use the following code for compatibility. + * @param obj Address object + * @return the sw peer + */ + private String getPeer(Object obj) { + if (obj instanceof String) { + return ((String) obj).replace("redis://", ""); + } else if (obj instanceof URI) { + URI uri = (URI) obj; + return uri.getHost() + ":" + uri.getPort(); + } else { + logger.warn("redisson not support this version"); + return null; } } diff --git a/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/RedisClientConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/RedisClientConstructorInterceptor.java index 233334b1d..8cc407626 100644 --- a/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/RedisClientConstructorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/RedisClientConstructorInterceptor.java @@ -15,8 +15,6 @@ * limitations under the License. * */ - - package org.apache.skywalking.apm.plugin.redisson.v3; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; diff --git a/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/RedisConnectionMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/RedisConnectionMethodInterceptor.java index 398713d2f..80029470d 100644 --- a/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/RedisConnectionMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/RedisConnectionMethodInterceptor.java @@ -15,8 +15,6 @@ * limitations under the License. * */ - - package org.apache.skywalking.apm.plugin.redisson.v3; import io.netty.buffer.ByteBuf; @@ -25,11 +23,14 @@ import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.redisson.v3.util.ClassUtil; import org.redisson.client.RedisClient; import org.redisson.client.RedisConnection; import org.redisson.client.protocol.CommandData; @@ -43,6 +44,8 @@ import java.net.InetSocketAddress; */ public class RedisConnectionMethodInterceptor implements InstanceMethodsAroundInterceptor, InstanceConstructorInterceptor { + private static final ILog logger = LogManager.getLogger(RedisConnectionMethodInterceptor.class); + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { @@ -106,7 +109,19 @@ public class RedisConnectionMethodInterceptor implements InstanceMethodsAroundIn public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { String peer = (String) ((EnhancedInstance) allArguments[0]).getSkyWalkingDynamicField(); if (peer == null) { - peer = ((RedisClient) allArguments[0]).getConfig().getAddress().getAuthority(); + try { + /* + In some high versions of redisson, such as 3.11.1. + The attribute address in the RedisClientConfig class changed from a lower version of the URI to a RedisURI. + But they all have the host and port attributes, so use the following code for compatibility. + */ + Object address = ClassUtil.getObjectField(((RedisClient) allArguments[0]).getConfig(), "address"); + String host = (String) ClassUtil.getObjectField(address, "host"); + String port = String.valueOf(ClassUtil.getObjectField(address, "port")); + peer = host + ":" + port; + } catch (Exception e) { + logger.warn("RedisConnection create peer error: ", e); + } } objInst.setSkyWalkingDynamicField(peer); } diff --git a/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/define/ConnectionManagerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/define/ConnectionManagerInstrumentation.java index cc29f33cc..2711acab7 100644 --- a/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/define/ConnectionManagerInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/define/ConnectionManagerInstrumentation.java @@ -15,8 +15,6 @@ * limitations under the License. * */ - - package org.apache.skywalking.apm.plugin.redisson.v3.define; import net.bytebuddy.description.method.MethodDescription; diff --git a/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/define/RedisClientInstrumentation.java b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/define/RedisClientInstrumentation.java index b976baf95..b1fbd5ab8 100644 --- a/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/define/RedisClientInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/define/RedisClientInstrumentation.java @@ -15,8 +15,6 @@ * limitations under the License. * */ - - package org.apache.skywalking.apm.plugin.redisson.v3.define; import net.bytebuddy.description.method.MethodDescription; diff --git a/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/define/RedisConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/define/RedisConnectionInstrumentation.java index 779d48334..681070dbe 100644 --- a/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/define/RedisConnectionInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/define/RedisConnectionInstrumentation.java @@ -15,8 +15,6 @@ * limitations under the License. * */ - - package org.apache.skywalking.apm.plugin.redisson.v3.define; import net.bytebuddy.description.method.MethodDescription; diff --git a/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/util/ClassUtil.java b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/util/ClassUtil.java new file mode 100644 index 000000000..23df3c4fd --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/redisson-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/util/ClassUtil.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.skywalking.apm.plugin.redisson.v3.util; + +import java.lang.reflect.Field; + +/** + * @author zhaoyuguang + */ +public class ClassUtil { + + /** + * This method should only be used in low frequency. + * It should not use in trace context, but just in the metadata preparation stage. + */ + public static Object getObjectField(Object obj, String name) throws NoSuchFieldException, IllegalAccessException { + Field field = obj.getClass().getDeclaredField(name); + field.setAccessible(true); + return field.get(obj); + } +} diff --git a/test/plugin/scenarios/redisson-scenario/pom.xml b/test/plugin/scenarios/redisson-scenario/pom.xml index 288129b55..de15f8f2d 100644 --- a/test/plugin/scenarios/redisson-scenario/pom.xml +++ b/test/plugin/scenarios/redisson-scenario/pom.xml @@ -29,7 +29,7 @@ UTF-8 1.8 1.5.2.RELEASE - 3.6.0 + 3.11.5 ${test.framework.version} diff --git a/test/plugin/scenarios/redisson-scenario/support-version.list b/test/plugin/scenarios/redisson-scenario/support-version.list index ace97afaa..72333aeb8 100644 --- a/test/plugin/scenarios/redisson-scenario/support-version.list +++ b/test/plugin/scenarios/redisson-scenario/support-version.list @@ -14,6 +14,20 @@ # See the License for the specific language governing permissions and # limitations under the License. +3.11.5 +3.11.4 +3.11.3 +3.11.2 +3.11.1 +3.11.0 +3.10.7 +3.10.6 +3.10.5 +3.10.4 +3.10.3 +3.10.2 +3.10.1 +3.10.0 3.9.1 3.9.0 3.8.2