From 1b54b61a88c88047154d0d99e61e855b4fcdb3a4 Mon Sep 17 00:00:00 2001 From: hailin0 Date: Sun, 23 Aug 2020 17:13:49 +0800 Subject: [PATCH] Add support for spring @Scheduled (#5339) --- .github/workflows/plugins-test.3.yaml | 1 + .../trace/component/ComponentsDefine.java | 2 + .../apm-sdk-plugin/spring-plugins/pom.xml | 1 + .../scheduled-annotation-plugin/pom.xml | 45 +++++++ ...ethodConstructorWithMethodInterceptor.java | 46 +++++++ ...ethodConstructorWithStringInterceptor.java | 41 ++++++ .../scheduled/ScheduledMethodInterceptor.java | 57 +++++++++ ...duledMethodInterceptorInstrumentation.java | 112 +++++++++++++++++ .../src/main/resources/skywalking-plugin.def | 17 +++ .../service-agent/java-agent/Plugin-list.md | 1 + .../java-agent/Supported-list.md | 1 + .../main/resources/component-libraries.yml | 3 + .../test/resources/component-libraries.yml | 3 + .../config/expectedData.yaml | 69 ++++++++++ .../configuration.yml | 19 +++ .../spring-scheduled-scenario/pom.xml | 118 ++++++++++++++++++ .../scheduled/controller/CaseController.java | 46 +++++++ .../spring/scheduled/job/SchedulingJob.java | 48 +++++++ .../src/main/resources/log4j2.xml | 30 +++++ .../webapp/WEB-INF/spring-mvc-servlet.xml | 38 ++++++ .../src/main/webapp/WEB-INF/web.xml | 34 +++++ .../support-version.list | 27 ++++ 22 files changed, 759 insertions(+) create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/pom.xml create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/scheduled/ScheduledMethodConstructorWithMethodInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/scheduled/ScheduledMethodConstructorWithStringInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/scheduled/ScheduledMethodInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/scheduled/define/ScheduledMethodInterceptorInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/resources/skywalking-plugin.def create mode 100644 test/plugin/scenarios/spring-scheduled-scenario/config/expectedData.yaml create mode 100644 test/plugin/scenarios/spring-scheduled-scenario/configuration.yml create mode 100644 test/plugin/scenarios/spring-scheduled-scenario/pom.xml create mode 100644 test/plugin/scenarios/spring-scheduled-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/scheduled/controller/CaseController.java create mode 100644 test/plugin/scenarios/spring-scheduled-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/scheduled/job/SchedulingJob.java create mode 100644 test/plugin/scenarios/spring-scheduled-scenario/src/main/resources/log4j2.xml create mode 100644 test/plugin/scenarios/spring-scheduled-scenario/src/main/webapp/WEB-INF/spring-mvc-servlet.xml create mode 100644 test/plugin/scenarios/spring-scheduled-scenario/src/main/webapp/WEB-INF/web.xml create mode 100644 test/plugin/scenarios/spring-scheduled-scenario/support-version.list diff --git a/.github/workflows/plugins-test.3.yaml b/.github/workflows/plugins-test.3.yaml index 94b110bec..b038dd8c9 100644 --- a/.github/workflows/plugins-test.3.yaml +++ b/.github/workflows/plugins-test.3.yaml @@ -55,6 +55,7 @@ jobs: - { name: 'hbase-scenario', title: 'hbase-scenario (5)' } - { name: 'spring-kafka-2.2.x-scenario', title: 'Spring-Kafka 2.2.x (7)' } - { name: 'spring-kafka-2.3.x-scenario', title: 'Spring-Kafka 2.3.x (7)' } + - { name: 'spring-scheduled-scenario', title: 'Spring Scheduled 3.1.x-5.2.x (9)' } steps: - uses: actions/checkout@v2 with: diff --git a/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java b/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java index 1ba2bc3ff..809b72b0e 100755 --- a/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java +++ b/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java @@ -172,4 +172,6 @@ public class ComponentsDefine { public static final OfficialComponent HBASE = new OfficialComponent(94, "HBase"); public static final OfficialComponent SPRING_KAFKA_CONSUMER = new OfficialComponent(95, "spring-kafka-consumer"); + + public static final OfficialComponent SPRING_SCHEDULED = new OfficialComponent(96, "SpringScheduled"); } diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml b/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml index c3483080e..863fea7b6 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml @@ -40,6 +40,7 @@ mvc-annotation-5.x-plugin spring-webflux-5.x-plugin spring-kafka-2.x-plugin + scheduled-annotation-plugin pom diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/pom.xml new file mode 100644 index 000000000..c21b135b7 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/pom.xml @@ -0,0 +1,45 @@ + + + + + spring-plugins + org.apache.skywalking + 8.2.0-SNAPSHOT + + 4.0.0 + + apm-spring-scheduled-annotation-plugin + jar + + scheduled-annotation-plugin + http://maven.apache.org + + + 5.1.4.RELEASE + + + + + org.springframework + spring-context + ${spring-context.version} + provided + + + \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/scheduled/ScheduledMethodConstructorWithMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/scheduled/ScheduledMethodConstructorWithMethodInterceptor.java new file mode 100644 index 000000000..ce5874040 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/scheduled/ScheduledMethodConstructorWithMethodInterceptor.java @@ -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.plugin.spring.scheduled; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +import java.lang.reflect.Method; + +/** + * Intercept method of {@code org.springframework.scheduling.support.ScheduledMethodRunnable#ScheduledMethodRunnable(java.lang.Object, java.lang.reflect.Method)}. + * record the execute method full name + */ +public class ScheduledMethodConstructorWithMethodInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable { + Method method = (Method) allArguments[1]; + String fullMethodName = buildFullMethodName(method); + + objInst.setSkyWalkingDynamicField(fullMethodName); + } + + protected String buildFullMethodName(Method method) { + String className = method.getDeclaringClass().getName(); + String methodName = method.getName(); + + return className + "." + methodName; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/scheduled/ScheduledMethodConstructorWithStringInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/scheduled/ScheduledMethodConstructorWithStringInterceptor.java new file mode 100644 index 000000000..191adae0f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/scheduled/ScheduledMethodConstructorWithStringInterceptor.java @@ -0,0 +1,41 @@ +/* + * 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.spring.scheduled; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; + +import java.lang.reflect.Method; + +/** + * Intercept method of {@code org.springframework.scheduling.support.ScheduledMethodRunnable#ScheduledMethodRunnable(java.lang.Object, java.lang.String)}. + * record the execute method full name + */ +public class ScheduledMethodConstructorWithStringInterceptor extends ScheduledMethodConstructorWithMethodInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable { + Object targetObject = allArguments[0]; + String methodName = (String) allArguments[1]; + Method method = targetObject.getClass().getMethod(methodName); + + String fullMethodName = buildFullMethodName(method); + + objInst.setSkyWalkingDynamicField(fullMethodName); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/scheduled/ScheduledMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/scheduled/ScheduledMethodInterceptor.java new file mode 100644 index 000000000..d6def65b4 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/scheduled/ScheduledMethodInterceptor.java @@ -0,0 +1,57 @@ +/* + * 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.spring.scheduled; + +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.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.network.trace.component.ComponentsDefine; + +import java.lang.reflect.Method; + +/** + * Intercept method of {@code org.springframework.scheduling.support.ScheduledMethodRunnable#run()}. + * record the schedule task local span. + */ +public class ScheduledMethodInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + String fullMethodName = (String) objInst.getSkyWalkingDynamicField(); + String operationName = ComponentsDefine.SPRING_SCHEDULED.getName() + "/" + fullMethodName; + + AbstractSpan span = ContextManager.createLocalSpan(operationName); + Tags.LOGIC_ENDPOINT.set(span, Tags.VAL_LOCAL_SPAN_AS_LOGIC_ENDPOINT); + span.setComponent(ComponentsDefine.SPRING_SCHEDULED); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/scheduled/define/ScheduledMethodInterceptorInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/scheduled/define/ScheduledMethodInterceptorInstrumentation.java new file mode 100644 index 000000000..2aacd3720 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/scheduled/define/ScheduledMethodInterceptorInstrumentation.java @@ -0,0 +1,112 @@ +/* + * 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.spring.scheduled.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import java.lang.reflect.Method; + +import static net.bytebuddy.matcher.ElementMatchers.isPublic; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * Enhance {@code org.springframework.scheduling.support.ScheduledMethodRunnable} instance, + * and intercept {@code org.springframework.scheduling.support.ScheduledMethodRunnable#run()} method, + * this method is a unified entrance of execute schedule task. + * + * @see org.apache.skywalking.apm.plugin.spring.scheduled.ScheduledMethodConstructorWithMethodInterceptor + * @see org.apache.skywalking.apm.plugin.spring.scheduled.ScheduledMethodConstructorWithStringInterceptor + * @see org.apache.skywalking.apm.plugin.spring.scheduled.ScheduledMethodInterceptor + */ +public class ScheduledMethodInterceptorInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String CONSTRUCTOR_WITH_METHOD_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.spring.scheduled.ScheduledMethodConstructorWithMethodInterceptor"; + public static final String CONSTRUCTOR_WITH_STRING_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.spring.scheduled.ScheduledMethodConstructorWithStringInterceptor"; + public static final String METHOD_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.spring.scheduled.ScheduledMethodInterceptor"; + public static final String ENHANC_CLASS = "org.springframework.scheduling.support.ScheduledMethodRunnable"; + + @Override + public ClassMatch enhanceClass() { + return byName(ENHANC_CLASS); + } + + @Override + public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArguments(2) + .and(takesArgument(0, Object.class)) + .and(takesArgument(1, Method.class)); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_WITH_METHOD_INTERCEPTOR_CLASS; + } + }, + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArguments(2) + .and(takesArgument(0, Object.class)) + .and(takesArgument(1, String.class)); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_WITH_STRING_INTERCEPTOR_CLASS; + } + } + }; + } + + @Override + public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("run") + .and(isPublic()) + .and(takesArguments(0)); + } + + @Override + public String getMethodsInterceptor() { + return METHOD_INTERCEPTOR_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/resources/skywalking-plugin.def new file mode 100644 index 000000000..e4078db8e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/scheduled-annotation-plugin/src/main/resources/skywalking-plugin.def @@ -0,0 +1,17 @@ +# 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. + +spring-scheduled-annotation=org.apache.skywalking.apm.plugin.spring.scheduled.define.ScheduledMethodInterceptorInstrumentation \ No newline at end of file diff --git a/docs/en/setup/service-agent/java-agent/Plugin-list.md b/docs/en/setup/service-agent/java-agent/Plugin-list.md index 00a4e6b33..578b8090b 100644 --- a/docs/en/setup/service-agent/java-agent/Plugin-list.md +++ b/docs/en/setup/service-agent/java-agent/Plugin-list.md @@ -82,6 +82,7 @@ - spring-mvc-annotation-4.x - spring-mvc-annotation-5.x - spring-resttemplate-4.x +- spring-scheduled-annotation - spring-tx - spring-webflux-5.x - spymemcached-2.x diff --git a/docs/en/setup/service-agent/java-agent/Supported-list.md b/docs/en/setup/service-agent/java-agent/Supported-list.md index 3d48a2ab1..921f08ce6 100644 --- a/docs/en/setup/service-agent/java-agent/Supported-list.md +++ b/docs/en/setup/service-agent/java-agent/Supported-list.md @@ -85,6 +85,7 @@ * Scheduler * [Elastic Job](https://github.com/elasticjob/elastic-job) 2.x * [Apache ShardingSphere-Elasticjob](https://github.com/apache/shardingsphere-elasticjob) 3.0.0-alpha + * [Spring @Scheduled](https://github.com/spring-projects/spring-framework) 3.1+ * OpenTracing community supported * [Canal: Alibaba mysql database binlog incremental subscription & consumer components](https://github.com/alibaba/canal) 1.0.25 -> 1.1.2 * JSON diff --git a/oap-server/server-bootstrap/src/main/resources/component-libraries.yml b/oap-server/server-bootstrap/src/main/resources/component-libraries.yml index 935242d6f..f76f29c51 100755 --- a/oap-server/server-bootstrap/src/main/resources/component-libraries.yml +++ b/oap-server/server-bootstrap/src/main/resources/component-libraries.yml @@ -317,6 +317,9 @@ HBase: spring-kafka-consumer: id: 95 languages: Java +SpringScheduled: + id: 96 + languages: Java # .NET/.NET Core components # [3000, 4000) for C#/.NET only diff --git a/oap-server/server-core/src/test/resources/component-libraries.yml b/oap-server/server-core/src/test/resources/component-libraries.yml index 480577586..a37c9da24 100755 --- a/oap-server/server-core/src/test/resources/component-libraries.yml +++ b/oap-server/server-core/src/test/resources/component-libraries.yml @@ -266,6 +266,9 @@ InfluxDB: influxdb-java: id: 90 languages: Java +SpringScheduled: + id: 96 + languages: Java # .NET/.NET Core components # [3000, 4000) for C#/.NET only diff --git a/test/plugin/scenarios/spring-scheduled-scenario/config/expectedData.yaml b/test/plugin/scenarios/spring-scheduled-scenario/config/expectedData.yaml new file mode 100644 index 000000000..6d6b68fe7 --- /dev/null +++ b/test/plugin/scenarios/spring-scheduled-scenario/config/expectedData.yaml @@ -0,0 +1,69 @@ +# 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-scenario + segmentSize: ge 2 + segments: + - segmentId: not null + spans: + - operationName: /spring-scheduled-scenario/case/call + operationId: 0 + 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-scenario/case/call'} + - {key: http.method, value: GET} + 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 + operationId: 0 + 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-scenario/case/call'} + - operationName: SpringScheduled/org.apache.skywalking.apm.testcase.spring.scheduled.job.SchedulingJob.work + operationId: 0 + 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}'} \ No newline at end of file diff --git a/test/plugin/scenarios/spring-scheduled-scenario/configuration.yml b/test/plugin/scenarios/spring-scheduled-scenario/configuration.yml new file mode 100644 index 000000000..93a92b6b0 --- /dev/null +++ b/test/plugin/scenarios/spring-scheduled-scenario/configuration.yml @@ -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-scenario/case/healthCheck +healthCheck: http://localhost:8080/spring-scheduled-scenario/case/healthCheck \ No newline at end of file diff --git a/test/plugin/scenarios/spring-scheduled-scenario/pom.xml b/test/plugin/scenarios/spring-scheduled-scenario/pom.xml new file mode 100644 index 000000000..cbdeb1af9 --- /dev/null +++ b/test/plugin/scenarios/spring-scheduled-scenario/pom.xml @@ -0,0 +1,118 @@ + + + + + org.apache.skywalking.apm.testcase + spring-scheduled-scenario + 1.0.0 + war + + 4.0.0 + + skywalking-spring-scheduled-scenario + + + UTF-8 + 1.8 + 1.18.10 + + 3.1.0.RELEASE + spring-scheduled + + + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + + + org.apache.logging.log4j + log4j-api + 2.8.1 + + + org.apache.logging.log4j + log4j-core + 2.8.1 + + + org.projectlombok + lombok + ${lombok.version} + provided + + + + org.springframework + spring-context + ${test.framework.version} + + + org.springframework + spring-web + ${test.framework.version} + + + org.springframework + spring-webmvc + ${test.framework.version} + + + cglib + cglib + 2.2 + + + + com.squareup.okhttp3 + okhttp + 3.0.0 + + + + + spring-scheduled-scenario + + + maven-compiler-plugin + + ${compiler.version} + ${compiler.version} + ${project.build.sourceEncoding} + + + + + org.apache.tomcat.maven + tomcat7-maven-plugin + 2.1 + + 8080 + /spring-scheduled-scenario + UTF-8 + tomcat7 + + + + + diff --git a/test/plugin/scenarios/spring-scheduled-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/scheduled/controller/CaseController.java b/test/plugin/scenarios/spring-scheduled-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/scheduled/controller/CaseController.java new file mode 100644 index 000000000..48f90ac18 --- /dev/null +++ b/test/plugin/scenarios/spring-scheduled-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/scheduled/controller/CaseController.java @@ -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; + } +} diff --git a/test/plugin/scenarios/spring-scheduled-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/scheduled/job/SchedulingJob.java b/test/plugin/scenarios/spring-scheduled-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/scheduled/job/SchedulingJob.java new file mode 100644 index 000000000..25b022f2f --- /dev/null +++ b/test/plugin/scenarios/spring-scheduled-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/scheduled/job/SchedulingJob.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.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-scenario/case/call").build(); + Response response = client.newCall(request).execute(); + response.body().close(); + } +} diff --git a/test/plugin/scenarios/spring-scheduled-scenario/src/main/resources/log4j2.xml b/test/plugin/scenarios/spring-scheduled-scenario/src/main/resources/log4j2.xml new file mode 100644 index 000000000..b16354bfa --- /dev/null +++ b/test/plugin/scenarios/spring-scheduled-scenario/src/main/resources/log4j2.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/spring-scheduled-scenario/src/main/webapp/WEB-INF/spring-mvc-servlet.xml b/test/plugin/scenarios/spring-scheduled-scenario/src/main/webapp/WEB-INF/spring-mvc-servlet.xml new file mode 100644 index 000000000..78ce64329 --- /dev/null +++ b/test/plugin/scenarios/spring-scheduled-scenario/src/main/webapp/WEB-INF/spring-mvc-servlet.xml @@ -0,0 +1,38 @@ + + + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/spring-scheduled-scenario/src/main/webapp/WEB-INF/web.xml b/test/plugin/scenarios/spring-scheduled-scenario/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..97967a024 --- /dev/null +++ b/test/plugin/scenarios/spring-scheduled-scenario/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,34 @@ + + + skywalking-spring-scheduled-scenario + + + spring-mvc + org.springframework.web.servlet.DispatcherServlet + 1 + + + spring-mvc + / + + diff --git a/test/plugin/scenarios/spring-scheduled-scenario/support-version.list b/test/plugin/scenarios/spring-scheduled-scenario/support-version.list new file mode 100644 index 000000000..261221bd6 --- /dev/null +++ b/test/plugin/scenarios/spring-scheduled-scenario/support-version.list @@ -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 +# "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. + +# lists your version here + +3.1.4.RELEASE +3.2.18.RELEASE +4.0.9.RELEASE +4.1.9.RELEASE +4.2.9.RELEASE +4.3.28.RELEASE +5.0.18.RELEASE +5.1.17.RELEASE +5.2.8.RELEASE \ No newline at end of file