Fix method name missing in spring-plugins:scheduled-annotation-plugin with spring 6.1.x (#691)

This commit is contained in:
Chen Ziyan 2024-05-14 20:21:27 +08:00 committed by GitHub
parent 0bf535e861
commit 4dfc1e85b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 475 additions and 29 deletions

View File

@ -62,6 +62,7 @@ jobs:
- activemq-artemis-2.x-scenario
- c3p0-0.9.0.x-0.9.1.x-scenario
- c3p0-0.9.2.x-0.10.x-scenario
- spring-scheduled-6.x-scenario
steps:
- uses: actions/checkout@v2
with:

View File

@ -81,7 +81,7 @@ jobs:
- spring-kafka-1.3.x-scenario
- spring-kafka-2.2.x-scenario
- spring-kafka-2.3.x-scenario
- spring-scheduled-scenario
- spring-scheduled-3.x-5.x-scenario
- elasticjob-2.x-scenario
- quartz-scheduler-2.x-scenario
- xxl-job-2.2.0-scenario

View File

@ -11,6 +11,7 @@ Release Notes.
* Use a daemon thread to flush logs.
* Fix typos in `URLParser`.
* Add support for `Derby`/`Sybase`/`SQLite`/`DB2`/`OceanBase` jdbc url format in `URLParser`.
* Optimize spring-plugins:scheduled-annotation-plugin compatibility about Spring 6.1.x support.
All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/213?closed=1)

View File

@ -82,6 +82,19 @@ public class ScheduledMethodInterceptorInstrumentation extends ClassInstanceMeth
public String getConstructorInterceptor() {
return CONSTRUCTOR_WITH_STRING_INTERCEPTOR_CLASS;
}
},
new ConstructorInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getConstructorMatcher() {
return takesArguments(4)
.and(takesArgument(0, Object.class))
.and(takesArgument(1, Method.class));
}
@Override
public String getConstructorInterceptor() {
return CONSTRUCTOR_WITH_METHOD_INTERCEPTOR_CLASS;
}
}
};
}

View File

@ -120,7 +120,7 @@ metrics based on the tracing data.
* Scheduler
* [Elastic Job](https://github.com/elasticjob/elastic-job) 2.x
* [Apache ShardingSphere-Elasticjob](https://github.com/apache/shardingsphere-elasticjob) 3.x
* [Spring @Scheduled](https://github.com/spring-projects/spring-framework) 3.1+
* [Spring @Scheduled](https://github.com/spring-projects/spring-framework) 3.1.x -> 6.1.x
* [Quartz Scheduler](https://github.com/quartz-scheduler/quartz) 2.x (Optional²)
* [XXL Job](https://github.com/xuxueli/xxl-job) 2.x
* OpenTracing community supported

View File

@ -87,8 +87,8 @@ public class MessageService {
.build();
try {
CompletableFuture<SendReceipt> future = producer.sendAsync(message);
future.join();
log.info("Send async message successfully");
SendReceipt sendReceipt = future.join();
log.info("Send async message successfully, messageId={}", sendReceipt.getMessageId());
} catch (Throwable t) {
log.error("Failed to send message", t);
}
@ -142,17 +142,34 @@ public class MessageService {
.build();
Duration invisibleDuration = Duration.ofSeconds(duration);
final List<MessageView> messages = consumer.receive(maxMessageNum, invisibleDuration);
messages.forEach(messageView -> {
log.info("Received message: {}", messageView);
});
for (MessageView msg : messages) {
final MessageId messageId = msg.getMessageId();
try {
consumer.ack(msg);
log.info("Message is acknowledged successfully, messageId={}", messageId);
} catch (Throwable t) {
log.error("Message is failed to be acknowledged, messageId={}", messageId, t);
int counter = 0;
int checkCounter = 0;
while (true) {
final List<MessageView> messages = consumer.receive(maxMessageNum, invisibleDuration);
messages.forEach(messageView -> {
log.info("Received message: {}", messageView);
});
boolean finishFlag = false;
for (MessageView msg : messages) {
final MessageId messageId = msg.getMessageId();
try {
consumer.ack(msg);
log.info("Message is acknowledged successfully, messageId={}", messageId);
counter++;
if (counter >= 2) {
finishFlag = true;
}
} catch (Throwable t) {
log.error("Message is failed to be acknowledged, messageId={}", messageId, t);
}
}
checkCounter++;
if (finishFlag) {
break;
}
if (checkCounter >= 3) {
log.error("Message is failed to receive after 3 attempts");
break;
}
}
} catch (Exception e) {

View File

@ -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.
segmentItems:
- serviceName: spring-scheduled-3.x-5.x-scenario
segmentSize: ge 2
segments:
- segmentId: not null
spans:
- operationName: GET:/spring-scheduled-3.x-5.x-scenario/case/call
parentSpanId: -1
spanId: 0
spanLayer: Http
startTime: nq 0
endTime: nq 0
componentId: 1
isError: false
spanType: Entry
peer: ''
skipAnalysis: false
tags:
- {key: url, value: 'http://localhost:8080/spring-scheduled-3.x-5.x-scenario/case/call'}
- {key: http.method, value: GET}
- {key: http.status_code, value: '200'}
refs:
- {parentEndpoint: SpringScheduled/org.apache.skywalking.apm.testcase.spring.scheduled.job.SchedulingJob.work, networkAddress: 'localhost:8080', refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null, parentServiceInstance: not null, parentService: not null, traceId: not null}
- segmentId: not null
spans:
- operationName: /spring-scheduled-3.x-5.x-scenario/case/call
parentSpanId: 0
spanId: 1
spanLayer: Http
startTime: not null
endTime: not null
componentId: 12
isError: false
spanType: Exit
peer: localhost:8080
skipAnalysis: false
tags:
- {key: http.method, value: GET}
- {key: url, value: 'http://localhost:8080/spring-scheduled-3.x-5.x-scenario/case/call'}
- {key: http.status_code, value: '200'}
- operationName: SpringScheduled/org.apache.skywalking.apm.testcase.spring.scheduled.job.SchedulingJob.work
parentSpanId: -1
spanId: 0
spanLayer: Unknown
startTime: not null
endTime: not null
componentId: 96
isError: false
spanType: Local
peer: ''
skipAnalysis: false
tags:
- {key: x-le, value: '{"logic-span":true}'}

View File

@ -0,0 +1,19 @@
# 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: tomcat
entryService: http://localhost:8080/spring-scheduled-3.x-5.x-scenario/case/healthCheck
healthCheck: http://localhost:8080/spring-scheduled-3.x-5.x-scenario/case/healthCheck

View File

@ -21,13 +21,13 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>org.apache.skywalking.apm.testcase</groupId>
<artifactId>spring-scheduled-scenario</artifactId>
<artifactId>spring-scheduled-3.x-5.x-scenario</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<modelVersion>4.0.0</modelVersion>
<name>skywalking-spring-scheduled-scenario</name>
<name>skywalking-spring-scheduled-3.x-5.x-scenario</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -92,7 +92,7 @@
</dependencies>
<build>
<finalName>spring-scheduled-scenario</finalName>
<finalName>spring-scheduled-3.x-5.x-scenario</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
@ -109,7 +109,7 @@
<version>2.1</version>
<configuration>
<port>8080</port>
<path>/spring-scheduled-scenario</path>
<path>/spring-scheduled-3.x-5.x-scenario</path>
<uriEncoding>UTF-8</uriEncoding>
<server>tomcat7</server>
</configuration>

View File

@ -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.spring.scheduled.job;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import java.io.IOException;
@Configuration
@EnableScheduling
public class SchedulingJob {
private static final Logger LOGGER = LogManager.getLogger(SchedulingJob.class);
private static final OkHttpClient CLIENT = new OkHttpClient.Builder().build();
@Scheduled(fixedDelay = 5000)
public void work() throws IOException {
LOGGER.info("work job running!");
Request request = new Request.Builder().url("http://localhost:8080/spring-scheduled-3.x-5.x-scenario/case/call").build();
Response response = CLIENT.newCall(request).execute();
response.body().close();
}
}

View File

@ -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.
~
-->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>skywalking-spring-scheduled-3.x-5.x-scenario</display-name>
<servlet>
<servlet-name>spring-mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

View File

@ -22,4 +22,5 @@
4.3.28.RELEASE
5.0.18.RELEASE
5.1.17.RELEASE
5.2.8.RELEASE
5.2.25.RELEASE
5.3.34

View File

@ -14,12 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
segmentItems:
- serviceName: spring-scheduled-scenario
- serviceName: spring-scheduled-6.x-scenario
segmentSize: ge 2
segments:
- segmentId: not null
spans:
- operationName: GET:/spring-scheduled-scenario/case/call
- operationName: GET:/spring-scheduled-6.x-scenario/case/call
parentSpanId: -1
spanId: 0
spanLayer: Http
@ -31,14 +31,14 @@ segmentItems:
peer: ''
skipAnalysis: false
tags:
- {key: url, value: 'http://localhost:8080/spring-scheduled-scenario/case/call'}
- {key: url, value: 'http://localhost:8080/spring-scheduled-6.x-scenario/case/call'}
- {key: http.method, value: GET}
- {key: http.status_code, value: '200'}
refs:
- {parentEndpoint: SpringScheduled/org.apache.skywalking.apm.testcase.spring.scheduled.job.SchedulingJob.work, networkAddress: 'localhost:8080', refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null, parentServiceInstance: not null, parentService: not null, traceId: not null}
- segmentId: not null
spans:
- operationName: /spring-scheduled-scenario/case/call
- operationName: /spring-scheduled-6.x-scenario/case/call
parentSpanId: 0
spanId: 1
spanLayer: Http
@ -51,7 +51,7 @@ segmentItems:
skipAnalysis: false
tags:
- {key: http.method, value: GET}
- {key: url, value: 'http://localhost:8080/spring-scheduled-scenario/case/call'}
- {key: url, value: 'http://localhost:8080/spring-scheduled-6.x-scenario/case/call'}
- {key: http.status_code, value: '200'}
- operationName: SpringScheduled/org.apache.skywalking.apm.testcase.spring.scheduled.job.SchedulingJob.work
parentSpanId: -1

View File

@ -15,5 +15,5 @@
# limitations under the License.
type: tomcat
entryService: http://localhost:8080/spring-scheduled-scenario/case/healthCheck
healthCheck: http://localhost:8080/spring-scheduled-scenario/case/healthCheck
entryService: http://localhost:8080/spring-scheduled-6.x-scenario/case/healthCheck
healthCheck: http://localhost:8080/spring-scheduled-6.x-scenario/case/healthCheck

View File

@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>org.apache.skywalking.apm.testcase</groupId>
<artifactId>spring-scheduled-6.x-scenario</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<modelVersion>4.0.0</modelVersion>
<name>skywalking-spring-scheduled-6.x-scenario</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler.version>17</compiler.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<lombok.version>1.18.20</lombok.version>
<test.framework.version>6.1.6</test.framework.version>
<test.framework>spring-scheduled</test.framework>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${test.framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${test.framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${test.framework.version}</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
<build>
<finalName>spring-scheduled-6.x-scenario</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${compiler.version}</source>
<target>${compiler.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,46 @@
/*
* 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.spring.scheduled.controller;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/case")
public class CaseController {
private static final Logger LOGGER = LogManager.getLogger(CaseController.class);
private static final String SUCCESS = "Success";
@RequestMapping("/healthCheck")
@ResponseBody
public String healthCheck() {
return SUCCESS;
}
@RequestMapping("/call")
@ResponseBody
public String call() {
return SUCCESS;
}
}

View File

@ -41,7 +41,7 @@ public class SchedulingJob {
public void work() throws IOException {
LOGGER.info("work job running!");
Request request = new Request.Builder().url("http://localhost:8080/spring-scheduled-scenario/case/call").build();
Request request = new Request.Builder().url("http://localhost:8080/spring-scheduled-6.x-scenario/case/call").build();
Response response = CLIENT.newCall(request).execute();
response.body().close();
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_ERR">
<PatternLayout charset="UTF-8" pattern="[%d{yyyy-MM-dd HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<context:component-scan base-package="org.apache.skywalking.apm.testcase.*"/>
<context:annotation-config/>
<mvc:annotation-driven/>
<task:annotation-driven/>
</beans>

View File

@ -20,7 +20,7 @@
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>skywalking-spring-scheduled-scenario</display-name>
<display-name>skywalking-spring-scheduled-6.x-scenario</display-name>
<servlet>
<servlet-name>spring-mvc</servlet-name>

View File

@ -0,0 +1,18 @@
# 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.
6.0.19
6.1.6