From ca957699dcaaa33d104ee574e0e66c5ee1fef589 Mon Sep 17 00:00:00 2001 From: hailin0 Date: Sun, 30 Aug 2020 23:48:26 +0800 Subject: [PATCH] Add support for quartz-scheduler (#5413) --- .github/workflows/plugins-test.3.yaml | 1 + .../trace/component/ComponentsDefine.java | 2 + apm-sniffer/optional-plugins/pom.xml | 1 + .../quartz-scheduler-2.x-plugin/pom.xml | 47 +++++++ .../JobRunShellConstructorInterceptor.java | 36 +++++ .../quartz/JobRunShellMethodInterceptor.java | 83 +++++++++++ ...JobRunShellInterceptorInstrumentation.java | 94 +++++++++++++ .../src/main/resources/skywalking-plugin.def | 17 +++ .../service-agent/java-agent/Plugin-list.md | 1 + .../setup/service-agent/java-agent/README.md | 1 + .../java-agent/Supported-list.md | 1 + .../main/resources/component-libraries.yml | 3 + .../test/resources/component-libraries.yml | 3 + .../bin/startup.sh | 21 +++ .../config/expectedData.yaml | 71 ++++++++++ .../configuration.yml | 22 +++ .../quartz-scheduler-2.x-scenario/pom.xml | 130 ++++++++++++++++++ .../src/main/assembly/assembly.xml | 41 ++++++ .../testcase/quartzscheduler/Application.java | 30 ++++ .../controller/CaseController.java | 44 ++++++ .../testcase/quartzscheduler/job/DemoJob.java | 48 +++++++ .../quartzscheduler/job/QuartzConfig.java | 59 ++++++++ .../src/main/resources/application.yaml | 23 ++++ .../src/main/resources/log4j2.xml | 30 ++++ .../support-version.list | 22 +++ 25 files changed, 831 insertions(+) create mode 100644 apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/pom.xml create mode 100644 apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/quartz/JobRunShellConstructorInterceptor.java create mode 100644 apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/quartz/JobRunShellMethodInterceptor.java create mode 100644 apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/quartz/define/JobRunShellInterceptorInstrumentation.java create mode 100644 apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/src/main/resources/skywalking-plugin.def create mode 100644 test/plugin/scenarios/quartz-scheduler-2.x-scenario/bin/startup.sh create mode 100644 test/plugin/scenarios/quartz-scheduler-2.x-scenario/config/expectedData.yaml create mode 100644 test/plugin/scenarios/quartz-scheduler-2.x-scenario/configuration.yml create mode 100644 test/plugin/scenarios/quartz-scheduler-2.x-scenario/pom.xml create mode 100644 test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/assembly/assembly.xml create mode 100644 test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/quartzscheduler/Application.java create mode 100644 test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/quartzscheduler/controller/CaseController.java create mode 100644 test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/quartzscheduler/job/DemoJob.java create mode 100644 test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/quartzscheduler/job/QuartzConfig.java create mode 100644 test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/resources/application.yaml create mode 100644 test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/resources/log4j2.xml create mode 100644 test/plugin/scenarios/quartz-scheduler-2.x-scenario/support-version.list diff --git a/.github/workflows/plugins-test.3.yaml b/.github/workflows/plugins-test.3.yaml index c1d4605a3f..845272dea8 100644 --- a/.github/workflows/plugins-test.3.yaml +++ b/.github/workflows/plugins-test.3.yaml @@ -57,6 +57,7 @@ jobs: - { 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)' } - { name: 'elasticjob-2.x-scenario', title: 'elasticjob-2.x-scenario (2)' } + - { name: 'quartz-scheduler-2.x-scenario', title: 'quartz-scheduler-2.x-scenario (5)' } 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 809b72b0e6..8c36bd5d4f 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 @@ -174,4 +174,6 @@ public class ComponentsDefine { public static final OfficialComponent SPRING_KAFKA_CONSUMER = new OfficialComponent(95, "spring-kafka-consumer"); public static final OfficialComponent SPRING_SCHEDULED = new OfficialComponent(96, "SpringScheduled"); + + public static final OfficialComponent QUARTZ_SCHEDULER = new OfficialComponent(97, "quartz-scheduler"); } diff --git a/apm-sniffer/optional-plugins/pom.xml b/apm-sniffer/optional-plugins/pom.xml index 7b29269f47..78ccd0eba9 100644 --- a/apm-sniffer/optional-plugins/pom.xml +++ b/apm-sniffer/optional-plugins/pom.xml @@ -48,6 +48,7 @@ zookeeper-3.4.x-plugin customize-enhance-plugin kotlin-coroutine-plugin + quartz-scheduler-2.x-plugin diff --git a/apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/pom.xml b/apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/pom.xml new file mode 100644 index 0000000000..a755c22530 --- /dev/null +++ b/apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/pom.xml @@ -0,0 +1,47 @@ + + + + + 4.0.0 + + + org.apache.skywalking + optional-plugins + 8.2.0-SNAPSHOT + + + apm-quartz-scheduler-2.x-plugin + jar + quartz-scheduler-2.x-plugin + + + 2.0.0 + + + + + org.quartz-scheduler + quartz + ${quartz-scheduler.version} + provided + + + \ No newline at end of file diff --git a/apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/quartz/JobRunShellConstructorInterceptor.java b/apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/quartz/JobRunShellConstructorInterceptor.java new file mode 100644 index 0000000000..a79b425ca9 --- /dev/null +++ b/apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/quartz/JobRunShellConstructorInterceptor.java @@ -0,0 +1,36 @@ +/* + * 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.quartz; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.quartz.spi.TriggerFiredBundle; + +/** + * Intercept method of {@link org.quartz.core.JobRunShell#JobRunShell(org.quartz.Scheduler, org.quartz.spi.TriggerFiredBundle)}. + * cache the execute job details + */ +public class JobRunShellConstructorInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable { + TriggerFiredBundle triggerFiredBundle = (TriggerFiredBundle) allArguments[1]; + objInst.setSkyWalkingDynamicField(triggerFiredBundle.getJobDetail()); + } +} diff --git a/apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/quartz/JobRunShellMethodInterceptor.java b/apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/quartz/JobRunShellMethodInterceptor.java new file mode 100644 index 0000000000..dba50706b8 --- /dev/null +++ b/apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/quartz/JobRunShellMethodInterceptor.java @@ -0,0 +1,83 @@ +/* + * 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.quartz; + +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.AbstractTag; +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 org.quartz.JobDataMap; +import org.quartz.JobDetail; + +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.Map; + +/** + * Intercept method of {@link org.quartz.core.JobRunShell#run()}. + * record the quartz job local span. + */ +public class JobRunShellMethodInterceptor implements InstanceMethodsAroundInterceptor { + + private static final AbstractTag JOB_GROUP = Tags.ofKey("jobGroup"); + private static final AbstractTag JOB_DATA_MAP = Tags.ofKey("jobDataMap"); + + private static final String EMPTY_JOB_DATA_MAP_STRING = Collections.emptyMap().toString(); + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + JobDetail jobDetail = (JobDetail) objInst.getSkyWalkingDynamicField(); + + String jobName = jobDetail.getKey().getName(); + String jobGroup = jobDetail.getKey().getGroup(); + String operationName = ComponentsDefine.QUARTZ_SCHEDULER.getName() + "/" + jobName; + + AbstractSpan span = ContextManager.createLocalSpan(operationName); + span.setComponent(ComponentsDefine.QUARTZ_SCHEDULER); + Tags.LOGIC_ENDPOINT.set(span, Tags.VAL_LOCAL_SPAN_AS_LOGIC_ENDPOINT); + span.tag(JOB_GROUP, jobGroup == null ? "" : jobGroup); + span.tag(JOB_DATA_MAP, getJobDataMapString(jobDetail)); + } + + @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); + } + + private static String getJobDataMapString(JobDetail jobDetail) { + JobDataMap jobDataMap = jobDetail.getJobDataMap(); + if (jobDataMap != null) { + Map wrappedMap = jobDataMap.getWrappedMap(); + if (wrappedMap != null) { + return wrappedMap.toString(); + } + } + return EMPTY_JOB_DATA_MAP_STRING; + } +} diff --git a/apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/quartz/define/JobRunShellInterceptorInstrumentation.java b/apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/quartz/define/JobRunShellInterceptorInstrumentation.java new file mode 100644 index 0000000000..6cfad9264a --- /dev/null +++ b/apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/quartz/define/JobRunShellInterceptorInstrumentation.java @@ -0,0 +1,94 @@ +/* + * 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.quartz.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 static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.isPublic; +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 {@link org.quartz.core.JobRunShell} instance and intercept {@link org.quartz.core.JobRunShell#run()} method, + * this method is a unified entrance of execute schedule job. + * + * @see org.apache.skywalking.apm.plugin.quartz.JobRunShellConstructorInterceptor + * @see org.apache.skywalking.apm.plugin.quartz.JobRunShellMethodInterceptor + */ +public class JobRunShellInterceptorInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String CONSTRUCTOR_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.quartz.JobRunShellConstructorInterceptor"; + public static final String METHOD_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.quartz.JobRunShellMethodInterceptor"; + public static final String ENHANC_CLASS = "org.quartz.core.JobRunShell"; + + @Override + protected 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, named("org.quartz.Scheduler"))) + .and(takesArgument(1, named("org.quartz.spi.TriggerFiredBundle"))); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_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/optional-plugins/quartz-scheduler-2.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/optional-plugins/quartz-scheduler-2.x-plugin/src/main/resources/skywalking-plugin.def new file mode 100644 index 0000000000..e8dbbb8606 --- /dev/null +++ b/apm-sniffer/optional-plugins/quartz-scheduler-2.x-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. + +quartz-scheduler-2.x=org.apache.skywalking.apm.plugin.quartz.define.JobRunShellInterceptorInstrumentation \ 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 578b8090b9..d20ef384f4 100644 --- a/docs/en/setup/service-agent/java-agent/Plugin-list.md +++ b/docs/en/setup/service-agent/java-agent/Plugin-list.md @@ -53,6 +53,7 @@ - postgresql-8.x - pulsar - quasar +- quartz-scheduler-2.x - rabbitmq-5.x - redisson-3.x - resteasy-server-3.x diff --git a/docs/en/setup/service-agent/java-agent/README.md b/docs/en/setup/service-agent/java-agent/README.md index 44cb374acc..cd0b5ec89f 100755 --- a/docs/en/setup/service-agent/java-agent/README.md +++ b/docs/en/setup/service-agent/java-agent/README.md @@ -170,6 +170,7 @@ Now, we have the following known optional plugins. * Plugin of Spring Cloud Gateway 2.1.x in optional plugin folder. Please only active this plugin when you install agent in Spring Gateway. spring-cloud-gateway-2.x-plugin and spring-webflux-5.x-plugin are both required. * Plugin of Spring Transaction in optional plugin folder. The reason of being optional plugin is, many local span are generated, which also spend more CPU, memory and network. * [Plugin of Kotlin coroutine](agent-optional-plugins/Kotlin-Coroutine-plugin.md) provides the tracing across coroutines automatically. As it will add local spans to all across routines scenarios, Please assess the performance impact. +* Plugin of quartz-scheduler-2.x in the optional plugin folder. The reason for being an optional plugin is, many task scheduling systems are based on quartz-scheduler, this will cause duplicate tracing and link different sub-tasks as they share the same quartz level trigger, such as ElasticJob. ## Bootstrap class plugins All bootstrap plugins are optional, due to unexpected risk. Bootstrap plugins are provided in `bootstrap-plugins` folder. 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 921f08ce66..961bf74896 100644 --- a/docs/en/setup/service-agent/java-agent/Supported-list.md +++ b/docs/en/setup/service-agent/java-agent/Supported-list.md @@ -86,6 +86,7 @@ * [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+ + * [Quartz Scheduler](https://github.com/quartz-scheduler/quartz) 2.x (Optional²) * 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 f76f29c519..75150fcc4d 100755 --- a/oap-server/server-bootstrap/src/main/resources/component-libraries.yml +++ b/oap-server/server-bootstrap/src/main/resources/component-libraries.yml @@ -320,6 +320,9 @@ spring-kafka-consumer: SpringScheduled: id: 96 languages: Java +quartz-scheduler: + id: 97 + 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 a37c9da243..5bc888db44 100755 --- a/oap-server/server-core/src/test/resources/component-libraries.yml +++ b/oap-server/server-core/src/test/resources/component-libraries.yml @@ -269,6 +269,9 @@ influxdb-java: SpringScheduled: id: 96 languages: Java +quartz-scheduler: + id: 97 + languages: Java # .NET/.NET Core components # [3000, 4000) for C#/.NET only diff --git a/test/plugin/scenarios/quartz-scheduler-2.x-scenario/bin/startup.sh b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/bin/startup.sh new file mode 100644 index 0000000000..85766ef67e --- /dev/null +++ b/test/plugin/scenarios/quartz-scheduler-2.x-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} ${home}/../libs/quartz-scheduler-2.x-scenario.jar & \ No newline at end of file diff --git a/test/plugin/scenarios/quartz-scheduler-2.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/config/expectedData.yaml new file mode 100644 index 0000000000..ae649d7d93 --- /dev/null +++ b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/config/expectedData.yaml @@ -0,0 +1,71 @@ +# 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: quartz-scheduler-2.x-scenario + segmentSize: ge 2 + segments: + - segmentId: not null + spans: + - operationName: /quartz-scheduler-2.x-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/quartz-scheduler-2.x-scenario/case/call'} + - {key: http.method, value: GET} + refs: + - {parentEndpoint: quartz-scheduler/DemoJob, networkAddress: 'localhost:8080', refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null, parentServiceInstance: not null, parentService: not null, traceId: not null} + - segmentId: not null + spans: + - operationName: /quartz-scheduler-2.x-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/quartz-scheduler-2.x-scenario/case/call'} + - operationName: quartz-scheduler/DemoJob + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Unknown + startTime: not null + endTime: not null + componentId: 97 + isError: false + spanType: Local + peer: '' + skipAnalysis: false + tags: + - {key: x-le, value: '{"logic-span":true}'} + - {key: jobGroup, value: 'DemoJobGroup'} + - {key: jobDataMap, value: '{param1=test}'} \ No newline at end of file diff --git a/test/plugin/scenarios/quartz-scheduler-2.x-scenario/configuration.yml b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/configuration.yml new file mode 100644 index 0000000000..45d3470e79 --- /dev/null +++ b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/configuration.yml @@ -0,0 +1,22 @@ +# 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/quartz-scheduler-2.x-scenario/case/healthCheck +healthCheck: http://localhost:8080/quartz-scheduler-2.x-scenario/case/healthCheck +startScript: ./bin/startup.sh +runningMode: with_optional +withPlugins: apm-quartz-scheduler-2.x-plugin-*.jar \ No newline at end of file diff --git a/test/plugin/scenarios/quartz-scheduler-2.x-scenario/pom.xml b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/pom.xml new file mode 100644 index 0000000000..3b04494f5f --- /dev/null +++ b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/pom.xml @@ -0,0 +1,130 @@ + + + + + org.apache.skywalking.apm.testcase + quartz-scheduler-2.x-scenario + 1.0.0 + jar + + 4.0.0 + + + UTF-8 + 1.8 + 2.0.0 + 2.1.6.RELEASE + 1.18.10 + 3.0.0 + + + skywalking-quartz-scheduler-2.x-scenario + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot-version} + pom + import + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-logging + + + + + org.springframework.boot + spring-boot-starter-log4j2 + + + org.projectlombok + lombok + ${lombok.version} + provided + + + + org.quartz-scheduler + quartz + ${test.framework.version} + + + com.squareup.okhttp3 + okhttp + ${okhttp.version} + + + + + quartz-scheduler-2.x-scenario + + + org.springframework.boot + spring-boot-maven-plugin + + + + 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/ + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/assembly/assembly.xml b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/assembly/assembly.xml new file mode 100644 index 0000000000..3c67f781e9 --- /dev/null +++ b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/assembly/assembly.xml @@ -0,0 +1,41 @@ + + + + + zip + + + + + ./bin + 0775 + + + + + + ${project.build.directory}/quartz-scheduler-2.x-scenario.jar + ./libs + 0775 + + + diff --git a/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/quartzscheduler/Application.java b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/quartzscheduler/Application.java new file mode 100644 index 0000000000..65b890a1fc --- /dev/null +++ b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/quartzscheduler/Application.java @@ -0,0 +1,30 @@ +/* + * 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.quartzscheduler; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/quartzscheduler/controller/CaseController.java b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/quartzscheduler/controller/CaseController.java new file mode 100644 index 0000000000..68568d4a40 --- /dev/null +++ b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/quartzscheduler/controller/CaseController.java @@ -0,0 +1,44 @@ +/* + * 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.quartzscheduler.controller; + +import lombok.extern.log4j.Log4j2; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/case") +@Log4j2 +public class CaseController { + + private static final String SUCCESS = "Success"; + + @RequestMapping("/call") + @ResponseBody + public String call() { + return SUCCESS; + } + + @RequestMapping("/healthCheck") + @ResponseBody + public String healthCheck() { + return SUCCESS; + } +} diff --git a/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/quartzscheduler/job/DemoJob.java b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/quartzscheduler/job/DemoJob.java new file mode 100644 index 0000000000..699be8caea --- /dev/null +++ b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/quartzscheduler/job/DemoJob.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.quartzscheduler.job; + +import lombok.extern.slf4j.Slf4j; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.quartz.Job; +import org.quartz.JobExecutionContext; + +import java.io.IOException; + +@Slf4j +public class DemoJob implements Job { + + private static final OkHttpClient client = new OkHttpClient.Builder().build(); + + @Override + public void execute(JobExecutionContext jobExecutionContext) { + log.info("quartz job execute: {}", jobExecutionContext.getJobDetail().getKey()); + + Request request = new Request.Builder().url("http://localhost:8080/quartz-scheduler-2.x-scenario/case/call").build(); + Response response = null; + try { + response = client.newCall(request).execute(); + } catch (IOException e) { + throw new RuntimeException(e); + } + response.body().close(); + } +} diff --git a/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/quartzscheduler/job/QuartzConfig.java b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/quartzscheduler/job/QuartzConfig.java new file mode 100644 index 0000000000..e4d2e48a28 --- /dev/null +++ b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/quartzscheduler/job/QuartzConfig.java @@ -0,0 +1,59 @@ +/* + * 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.quartzscheduler.job; + +import org.quartz.*; +import org.quartz.impl.StdSchedulerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.text.ParseException; +import java.util.AbstractMap; +import java.util.Map; + +@Configuration +public class QuartzConfig { + + @Bean(initMethod = "start", destroyMethod = "shutdown") + public Scheduler scheduler() throws SchedulerException, ParseException { + SchedulerFactory schedulerFactory = new StdSchedulerFactory(); + Scheduler scheduler = schedulerFactory.getScheduler(); + + Map.Entry demoJobConfig = demoJobConfig(); + scheduler.scheduleJob(demoJobConfig.getKey(), demoJobConfig.getValue()); + + return scheduler; + } + + private Map.Entry demoJobConfig() throws ParseException { + JobDetail demoJobDetail = JobBuilder.newJob(DemoJob.class) + .withIdentity("DemoJob","DemoJobGroup") + .usingJobData("param1", "test") + .storeDurably() + .build(); + + Trigger demoJobTrigger = TriggerBuilder.newTrigger() + .forJob(demoJobDetail) + .startNow() + .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?")) + .build(); + + return new AbstractMap.SimpleEntry(demoJobDetail, demoJobTrigger); + } +} \ No newline at end of file diff --git a/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/resources/application.yaml b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/resources/application.yaml new file mode 100644 index 0000000000..0988b797b9 --- /dev/null +++ b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/resources/application.yaml @@ -0,0 +1,23 @@ +# +# 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: /quartz-scheduler-2.x-scenario +logging: + config: classpath:log4j2.xml \ No newline at end of file diff --git a/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/resources/log4j2.xml b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..b16354bfa3 --- /dev/null +++ b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/src/main/resources/log4j2.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/quartz-scheduler-2.x-scenario/support-version.list b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/support-version.list new file mode 100644 index 0000000000..41fe60ad21 --- /dev/null +++ b/test/plugin/scenarios/quartz-scheduler-2.x-scenario/support-version.list @@ -0,0 +1,22 @@ +# 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 +2.0.0 +2.0.2 +2.1.7 +2.2.3 +2.3.2 \ No newline at end of file -- GitLab