Skip to content

Commit f6e4791

Browse files
committed
Fixed test case errors and reviewed comments.
1 parent e7c145b commit f6e4791

File tree

6 files changed

+17
-45
lines changed

6 files changed

+17
-45
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ jobs:
6565
- c3p0-0.9.2.x-0.10.x-scenario
6666
- spring-scheduled-6.x-scenario
6767
- caffeine-3.x-scenario
68+
- spring-kafka-3.3.x-scenario
6869
steps:
6970
- uses: actions/checkout@v2
7071
with:

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ jobs:
8181
- spring-kafka-1.3.x-scenario
8282
- spring-kafka-2.2.x-scenario
8383
- spring-kafka-2.3.x-scenario
84-
- spring-kafka-3.3.x-scenario
8584
- spring-scheduled-3.x-5.x-scenario
8685
- elasticjob-2.x-scenario
8786
- quartz-scheduler-2.x-scenario

apm-sniffer/apm-sdk-plugin/spring-plugins/spring-kafka-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/kafka/ExtendedConstructorInterceptPoint.java renamed to apm-sniffer/apm-sdk-plugin/spring-plugins/spring-kafka-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/kafka/ExtendedConstructorInterceptor.java

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,45 +23,25 @@
2323
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
2424
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
2525

26-
public class ExtendedConstructorInterceptPoint implements InstanceConstructorInterceptor {
26+
public class ExtendedConstructorInterceptor implements InstanceConstructorInterceptor {
2727

2828
@Override
2929
public void onConstruct(final EnhancedInstance objInst, final Object[] allArguments) throws Throwable {
3030
ExtendedConsumerEnhanceRequiredInfo requiredInfo = new ExtendedConsumerEnhanceRequiredInfo();
31-
extractConsumerConfig(allArguments, requiredInfo);
32-
objInst.setSkyWalkingDynamicField(requiredInfo);
33-
}
3431

35-
private void extractConsumerConfig(Object[] allArguments, ExtendedConsumerEnhanceRequiredInfo requiredInfo) {
36-
if (allArguments == null || allArguments.length == 0) {
37-
return;
32+
Map<String, Object> configMap = (Map<String, Object>) allArguments[0];
33+
Object bootstrapServers = configMap.get("bootstrap.servers");
34+
if (bootstrapServers instanceof List) {
35+
requiredInfo.setBrokerServers(String.join(";", (List<String>) bootstrapServers));
36+
} else if (bootstrapServers != null) {
37+
requiredInfo.setBrokerServers(String.valueOf(bootstrapServers).trim().replaceAll("\\s*,\\s*", ";"));
3838
}
3939

40-
for (Object arg : allArguments) {
41-
if (arg instanceof Map) {
42-
extractConfigFromMap(arg, requiredInfo);
43-
break;
44-
}
40+
Object groupId = configMap.get("group.id");
41+
if (groupId != null) {
42+
requiredInfo.setGroupId(groupId.toString());
4543
}
46-
}
47-
48-
private void extractConfigFromMap(Object arg, ExtendedConsumerEnhanceRequiredInfo requiredInfo) {
49-
try {
50-
Map<String, Object> configMap = (Map<String, Object>) arg;
51-
Object bootstrapServers = configMap.get("bootstrap.servers");
52-
if (bootstrapServers instanceof List) {
53-
requiredInfo.setBrokerServers(String.join(";", (List<String>) bootstrapServers));
54-
} else if (bootstrapServers != null) {
55-
requiredInfo.setBrokerServers(String.valueOf(bootstrapServers).trim().replaceAll("\\s*,\\s*", ";"));
56-
}
5744

58-
Object groupId = configMap.get("group.id");
59-
if (groupId != null) {
60-
requiredInfo.setGroupId(groupId.toString());
61-
}
62-
} catch (Exception e) {
63-
// Ignore exception and continue
64-
}
45+
objInst.setSkyWalkingDynamicField(requiredInfo);
6546
}
66-
6747
}

apm-sniffer/apm-sdk-plugin/spring-plugins/spring-kafka-2.x-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/kafka/define/ExtendedKafkaConsumerInstrumentation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
2626
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
2727

28-
import static net.bytebuddy.matcher.ElementMatchers.any;
2928
import static net.bytebuddy.matcher.ElementMatchers.named;
29+
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
3030
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
3131

3232
/**
3333
* Enhanced the ExtendedKafkaConsumer class to intercept poll method
3434
*/
3535
public class ExtendedKafkaConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
36-
36+
public static final String CONSTRUCTOR_INTERCEPT_MAP_TYPE = "java.util.Map";
3737
private static final String ENHANCE_CLASS = "org.springframework.kafka.core.DefaultKafkaConsumerFactory$ExtendedKafkaConsumer";
3838
private static final String CONSTRUCTOR_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.spring.kafka.ExtendedConstructorInterceptPoint";
3939
private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.spring.kafka.ExtendedKafkaConsumerInterceptor";
@@ -44,7 +44,7 @@ public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
4444
new ConstructorInterceptPoint() {
4545
@Override
4646
public ElementMatcher<MethodDescription> getConstructorMatcher() {
47-
return any();
47+
return takesArgumentWithType(0, CONSTRUCTOR_INTERCEPT_MAP_TYPE);
4848
}
4949

5050
@Override

apm-sniffer/apm-sdk-plugin/spring-plugins/spring-kafka-2.x-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/kafka/ExtendedKafkaConsumerInterceptorTest.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,9 @@ public void testAfterMethodWithRecords() throws Throwable {
155155
assertThat(span.getOperationName(), is("Kafka/test/Consumer/testGroup"));
156156
}
157157

158-
@Test
159-
public void testOnConstructWithEmptyArguments() throws Throwable {
160-
ExtendedConstructorInterceptPoint constructorInterceptPoint = new ExtendedConstructorInterceptPoint();
161-
constructorInterceptPoint.onConstruct(enhancedInstance, new Object[] {});
162-
assertThat(requiredInfo.getGroupId(), is("Unknown"));
163-
assertThat(requiredInfo.getBrokerServers(), is("Unknown"));
164-
}
165-
166158
@Test
167159
public void testOnConstructWithMapConfig() throws Throwable {
168-
ExtendedConstructorInterceptPoint constructorInterceptPoint = new ExtendedConstructorInterceptPoint();
160+
ExtendedConstructorInterceptor constructorInterceptPoint = new ExtendedConstructorInterceptor();
169161
Map<String, Object> config = new HashMap<>();
170162
config.put("bootstrap.servers", "localhost:9092");
171163
config.put("group.id", "testGroup");

test/plugin/scenarios/spring-kafka-3.3.x-scenario/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
<properties>
2929
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
30-
<compiler.version>1.8</compiler.version>
30+
<compiler.version>17</compiler.version>
3131
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
3232
<test.framework.version>3.3.10</test.framework.version>
3333
<log4j.version>2.6.2</log4j.version>

0 commit comments

Comments
 (0)