Skip to content

Commit 6e6aafe

Browse files
authored
fix jedis can not get host info when use jedis 3.3.x+ (#526)
1 parent 04603b2 commit 6e6aafe

21 files changed

Lines changed: 831 additions & 152 deletions

File tree

.github/workflows/plugins-test.1.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ jobs:
6666
- jedis-2.x-scenario
6767
- jedis-3.1.x-plus-scenario
6868
- jedis-4.x-scenario
69+
- jedis-3.3.x-plus-scenario
6970
- jetty-scenario
7071
- kafka-scenario
7172
- kotlin-coroutine-scenario

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Release Notes.
1313
* Fix ClassCastException when SQLServer inserts data
1414
* [Chore] Exclude org.checkerframework:checker-qual and com.google.j2objc:j2objc-annotations
1515
* [Chore] Exclude proto files in the generated jar
16+
* Fix Jedis-2.x plugin can not get host info in jedis 3.3.x+
1617

1718
#### Documentation
1819

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 renamed 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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919

2020
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
2121
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
22-
import redis.clients.jedis.HostAndPort;
23-
24-
public class JedisClusterConstructorWithHostAndPortArgInterceptor implements InstanceConstructorInterceptor {
22+
import redis.clients.jedis.Client;
23+
import redis.clients.jedis.Jedis;
2524

25+
public class JedisConstructorInterceptor implements InstanceConstructorInterceptor {
2626
@Override
27-
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
28-
HostAndPort hostAndPort = (HostAndPort) allArguments[0];
29-
objInst.setSkyWalkingDynamicField(hostAndPort.getHost() + ":" + hostAndPort.getPort());
27+
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable {
28+
Client client = ((Jedis) objInst).getClient();
29+
objInst.setSkyWalkingDynamicField(client.getHost() + ":" + client.getPort());
3030
}
31+
3132
}

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

Lines changed: 0 additions & 33 deletions
This file was deleted.

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

Lines changed: 0 additions & 35 deletions
This file was deleted.

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

Lines changed: 0 additions & 31 deletions
This file was deleted.

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

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,14 @@
2424
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
2525
import org.apache.skywalking.apm.plugin.jedis.v3.RedisMethodMatch;
2626

27-
import java.net.URI;
28-
29-
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
30-
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
27+
import static net.bytebuddy.matcher.ElementMatchers.any;
3128
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
3229

3330
public class JedisInstrumentation extends AbstractWitnessInstrumentation {
3431

35-
private static final String HOST_AND_PORT_ARG_TYPE_NAME = "redis.clients.jedis.HostAndPort";
36-
private static final String JEDIS_SHARD_INFO_ARG_TYPE_NAME = "redis.clients.jedis.JedisShardInfo";
3732
private static final String ENHANCE_CLASS = "redis.clients.jedis.Jedis";
38-
private static final String CONSTRUCTOR_WITH_STRING_ARG_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisConstructorWithStringArgInterceptor";
39-
private static final String CONSTRUCTOR_WITH_SHARD_INFO_ARG_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisConstructorWithShardInfoArgInterceptor";
40-
private static final String CONSTRUCTOR_WITH_HOST_AND_PORT_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisClusterConstructorWithHostAndPortArgInterceptor";
41-
private static final String CONSTRUCTOR_WITH_URI_ARG_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisConstructorWithUriArgInterceptor";
42-
private static final String JEDIS_METHOD_INTERCET_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisMethodInterceptor";
33+
private static final String JEDIS_METHOD_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisMethodInterceptor";
34+
private static final String JEDIS_CONSTRUCTOR_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisConstructorInterceptor";
4335

4436
@Override
4537
public ClassMatch enhanceClass() {
@@ -52,45 +44,12 @@ public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
5244
new ConstructorInterceptPoint() {
5345
@Override
5446
public ElementMatcher<MethodDescription> getConstructorMatcher() {
55-
return takesArgument(0, String.class);
56-
}
57-
58-
@Override
59-
public String getConstructorInterceptor() {
60-
return CONSTRUCTOR_WITH_STRING_ARG_INTERCEPT_CLASS;
61-
}
62-
},
63-
new ConstructorInterceptPoint() {
64-
@Override
65-
public ElementMatcher<MethodDescription> getConstructorMatcher() {
66-
return takesArgumentWithType(0, HOST_AND_PORT_ARG_TYPE_NAME);
67-
}
68-
69-
@Override
70-
public String getConstructorInterceptor() {
71-
return CONSTRUCTOR_WITH_HOST_AND_PORT_INTERCEPT_CLASS;
72-
}
73-
},
74-
new ConstructorInterceptPoint() {
75-
@Override
76-
public ElementMatcher<MethodDescription> getConstructorMatcher() {
77-
return takesArgumentWithType(0, JEDIS_SHARD_INFO_ARG_TYPE_NAME);
78-
}
79-
80-
@Override
81-
public String getConstructorInterceptor() {
82-
return CONSTRUCTOR_WITH_SHARD_INFO_ARG_INTERCEPT_CLASS;
83-
}
84-
},
85-
new ConstructorInterceptPoint() {
86-
@Override
87-
public ElementMatcher<MethodDescription> getConstructorMatcher() {
88-
return takesArgument(0, URI.class);
47+
return any();
8948
}
9049

9150
@Override
9251
public String getConstructorInterceptor() {
93-
return CONSTRUCTOR_WITH_URI_ARG_INTERCEPT_CLASS;
52+
return JEDIS_CONSTRUCTOR_INTERCEPT_CLASS;
9453
}
9554
}
9655
};
@@ -107,7 +66,7 @@ public ElementMatcher<MethodDescription> getMethodsMatcher() {
10766

10867
@Override
10968
public String getMethodsInterceptor() {
110-
return JEDIS_METHOD_INTERCET_CLASS;
69+
return JEDIS_METHOD_INTERCEPT_CLASS;
11170
}
11271

11372
@Override
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
home="$(cd "$(dirname $0)"; pwd)"
20+
21+
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 &

0 commit comments

Comments
 (0)