diff --git a/.github/workflows/plugins-test.1.yaml b/.github/workflows/plugins-test.1.yaml index df63d4d80..63b50fcb6 100644 --- a/.github/workflows/plugins-test.1.yaml +++ b/.github/workflows/plugins-test.1.yaml @@ -66,6 +66,7 @@ jobs: - jedis-2.x-scenario - jedis-3.1.x-plus-scenario - jedis-4.x-scenario + - jedis-3.3.x-plus-scenario - jetty-scenario - kafka-scenario - kotlin-coroutine-scenario diff --git a/CHANGES.md b/CHANGES.md index d861e3a11..a044ed561 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ Release Notes. * Fix ClassCastException when SQLServer inserts data * [Chore] Exclude org.checkerframework:checker-qual and com.google.j2objc:j2objc-annotations * [Chore] Exclude proto files in the generated jar +* Fix Jedis-2.x plugin can not get host info in jedis 3.3.x+ #### Documentation diff --git a/apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/JedisClusterConstructorWithHostAndPortArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/JedisConstructorInterceptor.java similarity index 77% rename from apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/JedisClusterConstructorWithHostAndPortArgInterceptor.java rename to apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/JedisConstructorInterceptor.java index 6a1124112..5f1573b29 100644 --- a/apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/JedisClusterConstructorWithHostAndPortArgInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/JedisConstructorInterceptor.java @@ -19,13 +19,14 @@ package org.apache.skywalking.apm.plugin.jedis.v3; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import redis.clients.jedis.HostAndPort; - -public class JedisClusterConstructorWithHostAndPortArgInterceptor implements InstanceConstructorInterceptor { +import redis.clients.jedis.Client; +import redis.clients.jedis.Jedis; +public class JedisConstructorInterceptor implements InstanceConstructorInterceptor { @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - HostAndPort hostAndPort = (HostAndPort) allArguments[0]; - objInst.setSkyWalkingDynamicField(hostAndPort.getHost() + ":" + hostAndPort.getPort()); + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable { + Client client = ((Jedis) objInst).getClient(); + objInst.setSkyWalkingDynamicField(client.getHost() + ":" + client.getPort()); } + } diff --git a/apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/JedisConstructorWithShardInfoArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/JedisConstructorWithShardInfoArgInterceptor.java deleted file mode 100644 index ea99a24ff..000000000 --- a/apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/JedisConstructorWithShardInfoArgInterceptor.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.jedis.v3; - -import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import redis.clients.jedis.JedisShardInfo; - -public class JedisConstructorWithShardInfoArgInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - String redisConnInfo; - JedisShardInfo shardInfo = (JedisShardInfo) allArguments[0]; - redisConnInfo = shardInfo.getHost() + ":" + shardInfo.getPort(); - objInst.setSkyWalkingDynamicField(redisConnInfo); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/JedisConstructorWithStringArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/JedisConstructorWithStringArgInterceptor.java deleted file mode 100644 index 3b731d213..000000000 --- a/apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/JedisConstructorWithStringArgInterceptor.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.jedis.v3; - -import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; - -public class JedisConstructorWithStringArgInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - String host = (String) allArguments[0]; - String port = "6379"; - if (allArguments.length > 1) { - port = String.valueOf(allArguments[1]); - } - - objInst.setSkyWalkingDynamicField(host + ":" + port); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/JedisConstructorWithUriArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/JedisConstructorWithUriArgInterceptor.java deleted file mode 100644 index 3db84b517..000000000 --- a/apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/JedisConstructorWithUriArgInterceptor.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.jedis.v3; - -import java.net.URI; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; - -public class JedisConstructorWithUriArgInterceptor implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - URI uri = (URI) allArguments[0]; - objInst.setSkyWalkingDynamicField(uri.getHost() + ":" + uri.getPort()); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/define/JedisInstrumentation.java b/apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/define/JedisInstrumentation.java index cfc6d50c8..3191bcd42 100644 --- a/apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/define/JedisInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/jedis-plugins/jedis-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jedis/v3/define/JedisInstrumentation.java @@ -24,22 +24,14 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsIn import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.plugin.jedis.v3.RedisMethodMatch; -import java.net.URI; - -import static net.bytebuddy.matcher.ElementMatchers.takesArgument; -import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static net.bytebuddy.matcher.ElementMatchers.any; import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; public class JedisInstrumentation extends AbstractWitnessInstrumentation { - private static final String HOST_AND_PORT_ARG_TYPE_NAME = "redis.clients.jedis.HostAndPort"; - private static final String JEDIS_SHARD_INFO_ARG_TYPE_NAME = "redis.clients.jedis.JedisShardInfo"; private static final String ENHANCE_CLASS = "redis.clients.jedis.Jedis"; - private static final String CONSTRUCTOR_WITH_STRING_ARG_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisConstructorWithStringArgInterceptor"; - private static final String CONSTRUCTOR_WITH_SHARD_INFO_ARG_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisConstructorWithShardInfoArgInterceptor"; - private static final String CONSTRUCTOR_WITH_HOST_AND_PORT_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisClusterConstructorWithHostAndPortArgInterceptor"; - private static final String CONSTRUCTOR_WITH_URI_ARG_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisConstructorWithUriArgInterceptor"; - private static final String JEDIS_METHOD_INTERCET_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisMethodInterceptor"; + private static final String JEDIS_METHOD_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisMethodInterceptor"; + private static final String JEDIS_CONSTRUCTOR_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisConstructorInterceptor"; @Override public ClassMatch enhanceClass() { @@ -52,45 +44,12 @@ public class JedisInstrumentation extends AbstractWitnessInstrumentation { new ConstructorInterceptPoint() { @Override public ElementMatcher getConstructorMatcher() { - return takesArgument(0, String.class); + return any(); } @Override public String getConstructorInterceptor() { - return CONSTRUCTOR_WITH_STRING_ARG_INTERCEPT_CLASS; - } - }, - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return takesArgumentWithType(0, HOST_AND_PORT_ARG_TYPE_NAME); - } - - @Override - public String getConstructorInterceptor() { - return CONSTRUCTOR_WITH_HOST_AND_PORT_INTERCEPT_CLASS; - } - }, - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return takesArgumentWithType(0, JEDIS_SHARD_INFO_ARG_TYPE_NAME); - } - - @Override - public String getConstructorInterceptor() { - return CONSTRUCTOR_WITH_SHARD_INFO_ARG_INTERCEPT_CLASS; - } - }, - new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return takesArgument(0, URI.class); - } - - @Override - public String getConstructorInterceptor() { - return CONSTRUCTOR_WITH_URI_ARG_INTERCEPT_CLASS; + return JEDIS_CONSTRUCTOR_INTERCEPT_CLASS; } } }; @@ -107,7 +66,7 @@ public class JedisInstrumentation extends AbstractWitnessInstrumentation { @Override public String getMethodsInterceptor() { - return JEDIS_METHOD_INTERCET_CLASS; + return JEDIS_METHOD_INTERCEPT_CLASS; } @Override diff --git a/test/plugin/scenarios/jedis-3.3.x-plus-scenario/bin/startup.sh b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/bin/startup.sh new file mode 100644 index 000000000..314543630 --- /dev/null +++ b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/bin/startup.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# +# 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. + +home="$(cd "$(dirname $0)"; pwd)" + +java -jar ${agent_opts} -Dredis.host=${REDIS_HOST} -Dredis.port=${REDIS_PORT} -Dskywalking.plugin.jedis.trace_redis_parameters=true ${home}/../libs/jedis-3.3.x-plus-scenario.jar & \ No newline at end of file diff --git a/test/plugin/scenarios/jedis-3.3.x-plus-scenario/config/expectedData.yaml b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/config/expectedData.yaml new file mode 100644 index 000000000..a42060957 --- /dev/null +++ b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/config/expectedData.yaml @@ -0,0 +1,214 @@ +# 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. +segmentItems: + - serviceName: jedis-3.3.x-plus-scenario + segmentSize: ge 1 + segments: + - segmentId: not null + spans: + - operationName: Jedis/echo + operationId: 0 + parentSpanId: 0 + spanId: 1 + spanLayer: Cache + startTime: gt 0 + endTime: gt 0 + componentId: 30 + isError: false + spanType: Exit + peer: redis-server:6379 + skipAnalysis: false + tags: + - {key: cache.type, value: Redis} + - {key: cache.cmd, value: echo} + - {key: cache.key, value: Test} + - operationName: Jedis/set + operationId: 0 + parentSpanId: 0 + spanId: 2 + spanLayer: Cache + startTime: gt 0 + endTime: gt 0 + componentId: 30 + isError: false + spanType: Exit + peer: redis-server:6379 + skipAnalysis: false + tags: + - {key: cache.type, value: Redis} + - {key: cache.cmd, value: set} + - {key: cache.key, value: a} + - {key: cache.op, value: write} + - operationName: Jedis/get + operationId: 0 + parentSpanId: 0 + spanId: 3 + spanLayer: Cache + startTime: gt 0 + endTime: gt 0 + componentId: 30 + isError: false + spanType: Exit + peer: redis-server:6379 + skipAnalysis: false + tags: + - {key: cache.type, value: Redis} + - {key: cache.cmd, value: get} + - {key: cache.key, value: a} + - {key: cache.op, value: read} + - operationName: Jedis/del + operationId: 0 + parentSpanId: 0 + spanId: 4 + spanLayer: Cache + startTime: gt 0 + endTime: gt 0 + componentId: 30 + isError: false + spanType: Exit + peer: redis-server:6379 + skipAnalysis: false + tags: + - {key: cache.type, value: Redis} + - {key: cache.cmd, value: del} + - {key: cache.key, value: a} + - {key: cache.op, value: write} + - operationName: Jedis/syncAndReturnAll + operationId: 0 + parentSpanId: 0 + spanId: 5 + spanLayer: Cache + startTime: gt 0 + endTime: gt 0 + componentId: 30 + isError: false + spanType: Exit + peer: redis-server:6379 + skipAnalysis: false + tags: + - {key: cache.type, value: Redis} + - {key: cache.cmd, value: BATCH_EXECUTE} + - operationName: Jedis/discard + operationId: 0 + parentSpanId: 0 + spanId: 6 + spanLayer: Cache + startTime: gt 0 + endTime: gt 0 + componentId: 30 + isError: false + spanType: Exit + peer: redis-server:6379 + skipAnalysis: false + tags: + - { key: cache.type, value: Redis } + - { key: cache.cmd, value: BATCH_EXECUTE } + - operationName: Jedis/exec + operationId: 0 + parentSpanId: 0 + spanId: 7 + spanLayer: Cache + startTime: gt 0 + endTime: gt 0 + componentId: 30 + isError: false + spanType: Exit + peer: redis-server:6379 + skipAnalysis: false + tags: + - {key: cache.type, value: Redis} + - {key: cache.cmd, value: BATCH_EXECUTE} + - operationName: Jedis/discard + operationId: 0 + parentSpanId: 0 + spanId: 8 + spanLayer: Cache + startTime: gt 0 + endTime: gt 0 + componentId: 30 + isError: false + spanType: Exit + peer: redis-server:6379 + skipAnalysis: false + tags: + - { key: cache.type, value: Redis } + - { key: cache.cmd, value: BATCH_EXECUTE } + - operationName: Jedis/xadd + operationId: 0 + parentSpanId: 0 + spanId: 9 + spanLayer: Cache + startTime: gt 0 + endTime: gt 0 + componentId: 30 + isError: false + spanType: Exit + peer: redis-server:6379 + skipAnalysis: false + tags: + - {key: cache.type, value: Redis} + - {key: cache.cmd, value: xadd} + - {key: cache.key, value: abc} + - {key: cache.op, value: write} + - operationName: Jedis/xread + operationId: 0 + parentSpanId: 0 + spanId: 10 + spanLayer: Cache + startTime: gt 0 + endTime: gt 0 + componentId: 30 + isError: false + spanType: Exit + peer: redis-server:6379 + skipAnalysis: false + tags: + - {key: cache.type, value: Redis} + - {key: cache.cmd, value: xread} + - {key: cache.op, value: read} + - operationName: Jedis/xdel + operationId: 0 + parentSpanId: 0 + spanId: 11 + spanLayer: Cache + startTime: gt 0 + endTime: gt 0 + componentId: 30 + isError: false + spanType: Exit + peer: redis-server:6379 + skipAnalysis: false + tags: + - {key: cache.type, value: Redis} + - {key: cache.cmd, value: xdel} + - {key: cache.key, value: abc} + - {key: cache.op, value: write} + - operationName: GET:/jedis-3.3.x-plus-scenario/case/jedis-3.3.x-plus-scenario + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: gt 0 + endTime: gt 0 + componentId: 1 + isError: false + spanType: Entry + peer: '' + skipAnalysis: false + tags: + - {key: url, value: 'http://localhost:8080/jedis-3.3.x-plus-scenario/case/jedis-3.3.x-plus-scenario'} + - {key: http.method, value: GET} + - {key: http.status_code, value: '200'} diff --git a/test/plugin/scenarios/jedis-3.3.x-plus-scenario/configuration.yml b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/configuration.yml new file mode 100644 index 000000000..f6e7db431 --- /dev/null +++ b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/configuration.yml @@ -0,0 +1,27 @@ +# 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. + +type: jvm +entryService: http://localhost:8080/jedis-3.3.x-plus-scenario/case/jedis-3.3.x-plus-scenario +healthCheck: http://localhost:8080/jedis-3.3.x-plus-scenario/case/healthCheck +startScript: ./bin/startup.sh +environment: + - REDIS_HOST=redis-server + - REDIS_PORT=6379 +dependencies: + redis-server: + image: redis:6.2.7 + hostname: redis-server diff --git a/test/plugin/scenarios/jedis-3.3.x-plus-scenario/pom.xml b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/pom.xml new file mode 100644 index 000000000..781c57e74 --- /dev/null +++ b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/pom.xml @@ -0,0 +1,109 @@ + + + + + org.apache.skywalking.apm.testcase + jedis-3.3.x-plus-scenario + 1.0.0 + jar + + 4.0.0 + + + UTF-8 + 1.8 + 3.8.1 + 3.8.0 + 2.1.6.RELEASE + 1.18.20 + + + skywalking-jedis-3.3.x-plus-scenario + + + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot.version} + pom + import + + + + + + + redis.clients + jedis + ${test.framework.version} + + + org.springframework.boot + spring-boot-starter-web + + + + + jedis-3.3.x-plus-scenario + + + org.springframework.boot + spring-boot-maven-plugin + 1.5.9.RELEASE + + + + repackage + + + + + + maven-compiler-plugin + + ${compiler.version} + ${compiler.version} + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-assembly-plugin + + + assemble + package + + single + + + + src/main/assembly/assembly.xml + + ./target/ + + + + + + + diff --git a/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/assembly/assembly.xml b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/assembly/assembly.xml new file mode 100644 index 000000000..c6046db71 --- /dev/null +++ b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/assembly/assembly.xml @@ -0,0 +1,41 @@ + + + + + zip + + + + + ./bin + 0775 + + + + + + ${project.build.directory}/jedis-3.3.x-plus-scenario.jar + ./libs + 0775 + + + diff --git a/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/Application.java b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/Application.java new file mode 100644 index 000000000..6cfc49b3a --- /dev/null +++ b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/Application.java @@ -0,0 +1,34 @@ +/* + * 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.testcase.jedis; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + try { + SpringApplication.run(Application.class, args); + } catch (Exception e) { + // Never do this + } + } +} diff --git a/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/CaseController.java b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/CaseController.java new file mode 100644 index 000000000..39dc164ff --- /dev/null +++ b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/CaseController.java @@ -0,0 +1,68 @@ +/* + * 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.testcase.jedis.controller; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/case") +public class CaseController { + + private static final String SUCCESS = "Success"; + + @Value("${redis.host:127.0.0.1}") + private String redisHost; + + @Value("${redis.port:6379}") + private Integer redisPort; + + @RequestMapping("/jedis-3.3.x-plus-scenario") + @ResponseBody + public String testcase() throws Exception { + try (RedisCommandExecutor command = new RedisCommandExecutor(redisHost, redisPort)) { + command.set("a", "a"); + command.get("a"); + command.del("a"); + } + + try (RedisPipelineCommandExecutor command = new RedisPipelineCommandExecutor(redisHost, redisPort)) { + command.pipelineExecute(); + command.pipelineDiscard(); + } + + try (RedisTransactionCommandExecutor command = new RedisTransactionCommandExecutor(redisHost, redisPort)) { + command.multiExecute(); + command.multiDiscard(); + } + try (RedisStreamCommandExecutor c = new RedisStreamCommandExecutor(redisHost, redisPort)) { + c.exec(); + } + + return SUCCESS; + } + + @RequestMapping("/healthCheck") + @ResponseBody + public String healthCheck() throws Exception { + return SUCCESS; + } +} diff --git a/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/JedisXreadparamAdaptor.java b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/JedisXreadparamAdaptor.java new file mode 100644 index 000000000..b4e608cd8 --- /dev/null +++ b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/JedisXreadparamAdaptor.java @@ -0,0 +1,48 @@ +/* + * 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.testcase.jedis.controller; + +import redis.clients.jedis.StreamEntryID; +import java.lang.reflect.Method; +import java.util.Map; + +public class JedisXreadparamAdaptor { + + // The stream apis have changed from 3.6.0 + public static Object callXReadMethod(Object target, int count, Map map) { + try { + Class xReadParamsCls = Class.forName("redis.clients.jedis.params.XReadParams"); + Object xReadParams = xReadParamsCls.getConstructor().newInstance(); + xReadParamsCls.getDeclaredMethod("count", Integer.TYPE).invoke(xReadParams, count); + Method xread = target.getClass().getDeclaredMethod("xread", xReadParamsCls, Map.class); + return xread.invoke(target, xReadParams, map); + } catch (Exception e) { + Map.Entry[] entries = new Map.Entry[map.size()]; + int i = 0; + for (Map.Entry stringStreamEntryIDEntry : map.entrySet()) { + entries[i++] = stringStreamEntryIDEntry; + } + try { + return target.getClass().getDeclaredMethod("xread", Integer.TYPE, Long.TYPE, Map.Entry[].class).invoke(target, count, 0, entries); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + } + +} diff --git a/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/RedisCommandExecutor.java b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/RedisCommandExecutor.java new file mode 100644 index 000000000..85f7cdb80 --- /dev/null +++ b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/RedisCommandExecutor.java @@ -0,0 +1,49 @@ +/* + * 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.testcase.jedis.controller; + +import redis.clients.jedis.DefaultJedisSocketFactory; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisSocketFactory; + +public class RedisCommandExecutor implements AutoCloseable { + private Jedis jedis; + + public RedisCommandExecutor(String host, Integer port) { + JedisSocketFactory jedisSocketFactory = new DefaultJedisSocketFactory(host, port, 1000, 1000, false, null, null, null); + jedis = new Jedis(jedisSocketFactory); + jedis.echo("Test"); + } + + public void set(String key, String value) { + jedis.set(key, value); + } + + public void get(String key) { + jedis.get(key); + } + + public void del(String key) { + jedis.del(key); + } + + public void close() throws Exception { + jedis.close(); + } +} diff --git a/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/RedisPipelineCommandExecutor.java b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/RedisPipelineCommandExecutor.java new file mode 100644 index 000000000..2a04c414a --- /dev/null +++ b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/RedisPipelineCommandExecutor.java @@ -0,0 +1,54 @@ +/* + * 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.testcase.jedis.controller; + +import redis.clients.jedis.DefaultJedisSocketFactory; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisSocketFactory; +import redis.clients.jedis.Pipeline; + +public class RedisPipelineCommandExecutor implements AutoCloseable { + private Jedis jedis; + + public RedisPipelineCommandExecutor(String host, Integer port) { + JedisSocketFactory jedisSocketFactory = new DefaultJedisSocketFactory(host, port, 1000, 1000, false, null, null, null); + jedis = new Jedis(jedisSocketFactory); + } + + public void pipelineExecute() { + Pipeline pipeline = jedis.pipelined(); + pipeline.hset("a", "a", "a"); + pipeline.hget("a", "a"); + pipeline.hdel("a", "a"); + pipeline.syncAndReturnAll(); + } + + public void pipelineDiscard() { + Pipeline pipeline = jedis.pipelined(); + pipeline.multi(); + pipeline.hset("a", "a", "a"); + pipeline.hget("a", "a"); + pipeline.hdel("a", "a"); + pipeline.discard(); + } + + public void close() throws Exception { + jedis.close(); + } +} diff --git a/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/RedisStreamCommandExecutor.java b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/RedisStreamCommandExecutor.java new file mode 100644 index 000000000..fc33a4801 --- /dev/null +++ b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/RedisStreamCommandExecutor.java @@ -0,0 +1,55 @@ +/* + * 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.testcase.jedis.controller; + +import redis.clients.jedis.DefaultJedisSocketFactory; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisSocketFactory; +import redis.clients.jedis.StreamEntryID; + +import java.util.HashMap; +import java.util.Map; + +public class RedisStreamCommandExecutor implements AutoCloseable { + + private final Jedis jedis; + + public RedisStreamCommandExecutor(String host, Integer port) { + JedisSocketFactory jedisSocketFactory = new DefaultJedisSocketFactory(host, port, 1000, 1000, false, null, null, null); + jedis = new Jedis(jedisSocketFactory); + } + + public void exec() { + + HashMap hash = new HashMap<>(); + hash.put("a", "1"); + StreamEntryID streamEntryID = new StreamEntryID("0-1"); + jedis.xadd("abc", streamEntryID, hash); + Map hashMap = new HashMap<>(); + hashMap.put("abc", new StreamEntryID("0-1")); + // adapt jedis 3.6.0 jedis.xread(XReadParams param,Map<> stream); + // and jedis.3.5.2 xread(final int count, final long block, final Entry... streams) + JedisXreadparamAdaptor.callXReadMethod(jedis, 1, hashMap); + jedis.xdel("abc", streamEntryID); + } + + public void close() throws Exception { + jedis.close(); + } +} diff --git a/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/RedisTransactionCommandExecutor.java b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/RedisTransactionCommandExecutor.java new file mode 100644 index 000000000..c5f750bee --- /dev/null +++ b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/java/org/apache/skywalking/apm/testcase/jedis/controller/RedisTransactionCommandExecutor.java @@ -0,0 +1,51 @@ +/* + * 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.testcase.jedis.controller; + +import redis.clients.jedis.DefaultJedisSocketFactory; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisSocketFactory; +import redis.clients.jedis.Transaction; + +public class RedisTransactionCommandExecutor implements AutoCloseable { + private Jedis jedis; + + public RedisTransactionCommandExecutor(String host, Integer port) { + JedisSocketFactory jedisSocketFactory = new DefaultJedisSocketFactory(host, port, 1000, 1000, false, null, null, null); + jedis = new Jedis(jedisSocketFactory); + } + + public void multiExecute() { + Transaction pipeline = jedis.multi(); + pipeline.set("key", "a"); + pipeline.expire("key", 5); + pipeline.exec(); + } + + public void multiDiscard() { + Transaction pipeline = jedis.multi(); + pipeline.set("key", "a"); + pipeline.expire("key", 5); + pipeline.discard(); + } + + public void close() throws Exception { + jedis.close(); + } +} diff --git a/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/resources/application.yaml b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/resources/application.yaml new file mode 100644 index 000000000..4cb880f57 --- /dev/null +++ b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/src/main/resources/application.yaml @@ -0,0 +1,21 @@ +# +# 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. +# +# +server: + port: 8080 + servlet: + context-path: /jedis-3.3.x-plus-scenario \ No newline at end of file diff --git a/test/plugin/scenarios/jedis-3.3.x-plus-scenario/support-version.list b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/support-version.list new file mode 100644 index 000000000..10f29d1f1 --- /dev/null +++ b/test/plugin/scenarios/jedis-3.3.x-plus-scenario/support-version.list @@ -0,0 +1,24 @@ +# 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. + +3.9.0 +3.8.0 +3.7.1 +3.6.3 +3.5.2 +3.4.1 +3.3.0 +# jedis socket factory from 3.3.0