From d8397778179304f085c133f4c18d0443ebcb7733 Mon Sep 17 00:00:00 2001 From: litexu Date: Thu, 20 Jan 2022 23:12:48 +0800 Subject: [PATCH 01/10] init --- .../agent/core/theadpool/ThreadPoolName.java | 23 ++++ .../core/theadpool/ThreadPoolRegister.java | 45 ++++++++ .../core/theadpool/ThreadPoolService.java | 102 ++++++++++++++++++ .../core/theadpool/ThreadPoolSourceData.java | 52 +++++++++ ...skywalking.apm.agent.core.boot.BootService | 1 + apm-sniffer/optional-plugins/pom.xml | 1 + .../pom.xml | 17 +++ ...wWorkerThreadPoolConstructorIntercept.java | 34 ++++++ ...dertowWorkerThreadPoolInstrumentation.java | 71 ++++++++++++ .../src/main/resources/skywalking-plugin.def | 17 +++ 10 files changed, 363 insertions(+) create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolName.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolRegister.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolService.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolSourceData.java create mode 100644 apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/pom.xml create mode 100644 apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java create mode 100644 apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/define/UndertowWorkerThreadPoolInstrumentation.java create mode 100644 apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/resources/skywalking-plugin.def diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolName.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolName.java new file mode 100644 index 0000000000..c964cce840 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolName.java @@ -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. + * + */ + +package org.apache.skywalking.apm.agent.core.theadpool; + +public enum ThreadPoolName { + UNDERTOW_WORKER_POOL, TOMCAT_WORKER_POOL +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolRegister.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolRegister.java new file mode 100644 index 0000000000..2ef67409dd --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolRegister.java @@ -0,0 +1,45 @@ +/* + * 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.agent.core.theadpool; + +import static java.util.Collections.synchronizedList; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ThreadPoolExecutor; + +public class ThreadPoolRegister { + + private static final List THREAD_POOL_SOURCE_DATA_LIST = synchronizedList(new ArrayList<>()); + + public static void registerThreadPoolSource(ThreadPoolName threadPoolName, ThreadPoolExecutor threadPoolExecutor) { + if (THREAD_POOL_SOURCE_DATA_LIST.stream().noneMatch(it -> it.getThreadPoolName().equals(threadPoolName))) { + ThreadPoolSourceData threadPoolSourceData = new ThreadPoolSourceData(); + threadPoolSourceData.setThreadPoolName(threadPoolName); + threadPoolSourceData.setHasBuildMetric(false); + threadPoolSourceData.setThreadPoolExecutor(threadPoolExecutor); + THREAD_POOL_SOURCE_DATA_LIST.add(threadPoolSourceData); + } + } + + public static List getThreadPoolSourceDataList() { + return THREAD_POOL_SOURCE_DATA_LIST; + } + +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolService.java new file mode 100644 index 0000000000..3c3385c64b --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolService.java @@ -0,0 +1,102 @@ +/* + * 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.agent.core.theadpool; + +import com.google.common.collect.ImmutableMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.function.Function; +import java.util.function.Supplier; +import org.apache.skywalking.apm.agent.core.boot.BootService; +import org.apache.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.meter.MeterFactory; +import org.apache.skywalking.apm.util.RunnableWithExceptionProtection; + +public class ThreadPoolService implements BootService, Runnable { + + private static final ILog LOGGER = LogManager.getLogger(ThreadPoolService.class); + + private volatile ScheduledFuture buildMeterMetricFuture; + + private static final Map>> METRIC_MAP = ImmutableMap.of( + "core_pool_size", + (ThreadPoolExecutor threadPoolExecutor) -> () -> { + return (double) threadPoolExecutor.getCorePoolSize(); + }, + "max_pool_size", + (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getMaximumPoolSize(), + "pool_size", + (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getPoolSize(), + "queue_size", + (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getQueue().size(), + "active_size", + (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getActiveCount()); + + @Override + public void prepare() throws Throwable { + } + + @Override + public void boot() throws Throwable { + buildMeterMetricFuture = Executors.newSingleThreadScheduledExecutor( + new DefaultNamedThreadFactory("ThreadPoolService-BuildMetric")) + .scheduleAtFixedRate(new RunnableWithExceptionProtection( + this, t -> LOGGER.error("ThreadPoolService-BuildMetric failure.", t) + ), 0, 1, TimeUnit.SECONDS); + + } + + @Override + public void onComplete() throws Throwable { + + } + + @Override + public void shutdown() throws Throwable { + buildMeterMetricFuture.cancel(true); + } + + private void buildThreadPoolMeterMetric() { + String threadPoolMeterName = "thread_pool"; + String poolNameTag = "pool_name"; + String metricTypeTag = "metric_type"; + List threadPoolSourceDataList = ThreadPoolRegister.getThreadPoolSourceDataList(); + threadPoolSourceDataList.forEach(it -> { + if (!it.getHasBuildMetric()) { + String poolName = it.getThreadPoolName().name().toLowerCase(); + ThreadPoolExecutor threadPoolExecutor = it.getThreadPoolExecutor(); + METRIC_MAP.forEach( + (key, value) -> MeterFactory.gauge(threadPoolMeterName, value.apply(threadPoolExecutor)) + .tag(poolNameTag, poolName).tag(metricTypeTag, key).build()); + it.setHasBuildMetric(true); + } + }); + } + + @Override + public void run() { + buildThreadPoolMeterMetric(); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolSourceData.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolSourceData.java new file mode 100644 index 0000000000..c25b27d2a2 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolSourceData.java @@ -0,0 +1,52 @@ +/* + * 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.agent.core.theadpool; + +import java.util.concurrent.ThreadPoolExecutor; + +public class ThreadPoolSourceData { + + private Boolean hasBuildMetric; + private ThreadPoolName threadPoolName; + private ThreadPoolExecutor threadPoolExecutor; + + public ThreadPoolName getThreadPoolName() { + return threadPoolName; + } + + public void setThreadPoolName(ThreadPoolName threadPoolName) { + this.threadPoolName = threadPoolName; + } + + public ThreadPoolExecutor getThreadPoolExecutor() { + return threadPoolExecutor; + } + + public void setThreadPoolExecutor(ThreadPoolExecutor threadPoolExecutor) { + this.threadPoolExecutor = threadPoolExecutor; + } + + public Boolean getHasBuildMetric() { + return hasBuildMetric; + } + + public void setHasBuildMetric(Boolean hasBuildMetric) { + this.hasBuildMetric = hasBuildMetric; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService b/apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService index cfda93521c..13b4a67b04 100644 --- a/apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService +++ b/apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService @@ -36,3 +36,4 @@ org.apache.skywalking.apm.agent.core.remote.LogReportServiceClient org.apache.skywalking.apm.agent.core.conf.dynamic.ConfigurationDiscoveryService org.apache.skywalking.apm.agent.core.remote.EventReportServiceClient org.apache.skywalking.apm.agent.core.ServiceInstanceGenerator +org.apache.skywalking.apm.agent.core.theadpool.ThreadPoolService diff --git a/apm-sniffer/optional-plugins/pom.xml b/apm-sniffer/optional-plugins/pom.xml index 1a07e94e6b..4ce57eef77 100644 --- a/apm-sniffer/optional-plugins/pom.xml +++ b/apm-sniffer/optional-plugins/pom.xml @@ -55,6 +55,7 @@ guava-cache-plugin fastjson-1.2.x-plugin jackson-2.x-plugin + undertow-worker-thread-pool-plugin diff --git a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/pom.xml b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/pom.xml new file mode 100644 index 0000000000..de67c430bf --- /dev/null +++ b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/pom.xml @@ -0,0 +1,17 @@ + + + + optional-plugins + org.apache.skywalking + 8.9.0-SNAPSHOT + + 4.0.0 + + apm-undertow-worker-thread-pool-plugin + undertow-worker-thread-pool-plugin + http://maven.apache.org + + + \ No newline at end of file diff --git a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java new file mode 100644 index 0000000000..b2a7b0a78d --- /dev/null +++ b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java @@ -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. + * + */ + +package org.apache.skywalking.apm.plugin.undertow.worker.thread.pool; + +import java.util.concurrent.ThreadPoolExecutor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.apache.skywalking.apm.agent.core.theadpool.ThreadPoolName; +import org.apache.skywalking.apm.agent.core.theadpool.ThreadPoolRegister; + +public class UndertowWorkerThreadPoolConstructorIntercept implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable { + ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) objInst; + ThreadPoolRegister.registerThreadPoolSource(ThreadPoolName.UNDERTOW_WORKER_POOL, threadPoolExecutor); + } +} diff --git a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/define/UndertowWorkerThreadPoolInstrumentation.java b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/define/UndertowWorkerThreadPoolInstrumentation.java new file mode 100644 index 0000000000..edca92a998 --- /dev/null +++ b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/define/UndertowWorkerThreadPoolInstrumentation.java @@ -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. + * + */ + +package org.apache.skywalking.apm.plugin.undertow.worker.thread.pool.define; + +import static net.bytebuddy.matcher.ElementMatchers.any; +import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch; +import static org.apache.skywalking.apm.agent.core.plugin.match.PrefixMatch.nameStartsWith; + +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.StaticMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.logical.LogicalMatchOperation; + +public class UndertowWorkerThreadPoolInstrumentation extends ClassEnhancePluginDefine { + + private static final String THREAD_POOL_EXECUTOR_CLASS = "java.util.concurrent.ThreadPoolExecutor"; + + private static final String UNDERTOW_WORKER_THREAD_POOL_INTERCEPT = "org.apache.skywalking.apm.plugin.undertow.worker.thread.pool.UndertowWorkerThreadPoolConstructorIntercept"; + + @Override + protected ClassMatch enhanceClass() { + return LogicalMatchOperation.and(nameStartsWith("org.xnio"), byHierarchyMatch(THREAD_POOL_EXECUTOR_CLASS)); + } + + @Override + public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[]{ + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override + public String getConstructorInterceptor() { + return UNDERTOW_WORKER_THREAD_POOL_INTERCEPT; + } + } + }; + } + + @Override + public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[0]; + } + + @Override + public StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { + return new StaticMethodsInterceptPoint[0]; + } +} diff --git a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/resources/skywalking-plugin.def new file mode 100644 index 0000000000..7d5a02e83b --- /dev/null +++ b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-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. + +undertow-worker-thread-pool-plugin=org.apache.skywalking.apm.plugin.undertow.worker.thread.pool.define.UndertowWorkerThreadPoolInstrumentation \ No newline at end of file From e0723fd9427f954bd49626cad7fc611fcc01cfc5 Mon Sep 17 00:00:00 2001 From: litexu Date: Thu, 20 Jan 2022 23:19:26 +0800 Subject: [PATCH 02/10] change log --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 8133a36e63..eab3d918a0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,6 +22,7 @@ Release Notes. * Follow protocol grammar fix `GCPhrase -> GCPhase`. * Support ZGC GC time and count metric collect. (Require 9.0.0 OAP) * Support configuration for collecting redis parameters for jedis-2.x and redisson-3.x plugin. +* Support Java thread pool metric collect. #### Documentation From 1c7b9a760bd83dc8498a5d413655542d5f9120aa Mon Sep 17 00:00:00 2001 From: litexu Date: Thu, 20 Jan 2022 23:26:45 +0800 Subject: [PATCH 03/10] add licence --- .../undertow-worker-thread-pool-plugin/pom.xml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/pom.xml b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/pom.xml index de67c430bf..283f7fc625 100644 --- a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/pom.xml +++ b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/pom.xml @@ -1,4 +1,22 @@ + + From 8f767880c92dae2b349ad351b446ca7030be51c8 Mon Sep 17 00:00:00 2001 From: litexu Date: Mon, 24 Jan 2022 15:03:04 +0800 Subject: [PATCH 04/10] rm --- .../agent/core/theadpool/ThreadPoolName.java | 23 ---- .../core/theadpool/ThreadPoolRegister.java | 45 -------- .../core/theadpool/ThreadPoolService.java | 102 ------------------ .../core/theadpool/ThreadPoolSourceData.java | 52 --------- ...skywalking.apm.agent.core.boot.BootService | 1 - ...wWorkerThreadPoolConstructorIntercept.java | 31 +++++- 6 files changed, 28 insertions(+), 226 deletions(-) delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolName.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolRegister.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolService.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolSourceData.java diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolName.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolName.java deleted file mode 100644 index c964cce840..0000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolName.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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.agent.core.theadpool; - -public enum ThreadPoolName { - UNDERTOW_WORKER_POOL, TOMCAT_WORKER_POOL -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolRegister.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolRegister.java deleted file mode 100644 index 2ef67409dd..0000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolRegister.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.agent.core.theadpool; - -import static java.util.Collections.synchronizedList; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ThreadPoolExecutor; - -public class ThreadPoolRegister { - - private static final List THREAD_POOL_SOURCE_DATA_LIST = synchronizedList(new ArrayList<>()); - - public static void registerThreadPoolSource(ThreadPoolName threadPoolName, ThreadPoolExecutor threadPoolExecutor) { - if (THREAD_POOL_SOURCE_DATA_LIST.stream().noneMatch(it -> it.getThreadPoolName().equals(threadPoolName))) { - ThreadPoolSourceData threadPoolSourceData = new ThreadPoolSourceData(); - threadPoolSourceData.setThreadPoolName(threadPoolName); - threadPoolSourceData.setHasBuildMetric(false); - threadPoolSourceData.setThreadPoolExecutor(threadPoolExecutor); - THREAD_POOL_SOURCE_DATA_LIST.add(threadPoolSourceData); - } - } - - public static List getThreadPoolSourceDataList() { - return THREAD_POOL_SOURCE_DATA_LIST; - } - -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolService.java deleted file mode 100644 index 3c3385c64b..0000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolService.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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.agent.core.theadpool; - -import com.google.common.collect.ImmutableMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.function.Function; -import java.util.function.Supplier; -import org.apache.skywalking.apm.agent.core.boot.BootService; -import org.apache.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory; -import org.apache.skywalking.apm.agent.core.logging.api.ILog; -import org.apache.skywalking.apm.agent.core.logging.api.LogManager; -import org.apache.skywalking.apm.agent.core.meter.MeterFactory; -import org.apache.skywalking.apm.util.RunnableWithExceptionProtection; - -public class ThreadPoolService implements BootService, Runnable { - - private static final ILog LOGGER = LogManager.getLogger(ThreadPoolService.class); - - private volatile ScheduledFuture buildMeterMetricFuture; - - private static final Map>> METRIC_MAP = ImmutableMap.of( - "core_pool_size", - (ThreadPoolExecutor threadPoolExecutor) -> () -> { - return (double) threadPoolExecutor.getCorePoolSize(); - }, - "max_pool_size", - (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getMaximumPoolSize(), - "pool_size", - (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getPoolSize(), - "queue_size", - (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getQueue().size(), - "active_size", - (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getActiveCount()); - - @Override - public void prepare() throws Throwable { - } - - @Override - public void boot() throws Throwable { - buildMeterMetricFuture = Executors.newSingleThreadScheduledExecutor( - new DefaultNamedThreadFactory("ThreadPoolService-BuildMetric")) - .scheduleAtFixedRate(new RunnableWithExceptionProtection( - this, t -> LOGGER.error("ThreadPoolService-BuildMetric failure.", t) - ), 0, 1, TimeUnit.SECONDS); - - } - - @Override - public void onComplete() throws Throwable { - - } - - @Override - public void shutdown() throws Throwable { - buildMeterMetricFuture.cancel(true); - } - - private void buildThreadPoolMeterMetric() { - String threadPoolMeterName = "thread_pool"; - String poolNameTag = "pool_name"; - String metricTypeTag = "metric_type"; - List threadPoolSourceDataList = ThreadPoolRegister.getThreadPoolSourceDataList(); - threadPoolSourceDataList.forEach(it -> { - if (!it.getHasBuildMetric()) { - String poolName = it.getThreadPoolName().name().toLowerCase(); - ThreadPoolExecutor threadPoolExecutor = it.getThreadPoolExecutor(); - METRIC_MAP.forEach( - (key, value) -> MeterFactory.gauge(threadPoolMeterName, value.apply(threadPoolExecutor)) - .tag(poolNameTag, poolName).tag(metricTypeTag, key).build()); - it.setHasBuildMetric(true); - } - }); - } - - @Override - public void run() { - buildThreadPoolMeterMetric(); - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolSourceData.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolSourceData.java deleted file mode 100644 index c25b27d2a2..0000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/theadpool/ThreadPoolSourceData.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.agent.core.theadpool; - -import java.util.concurrent.ThreadPoolExecutor; - -public class ThreadPoolSourceData { - - private Boolean hasBuildMetric; - private ThreadPoolName threadPoolName; - private ThreadPoolExecutor threadPoolExecutor; - - public ThreadPoolName getThreadPoolName() { - return threadPoolName; - } - - public void setThreadPoolName(ThreadPoolName threadPoolName) { - this.threadPoolName = threadPoolName; - } - - public ThreadPoolExecutor getThreadPoolExecutor() { - return threadPoolExecutor; - } - - public void setThreadPoolExecutor(ThreadPoolExecutor threadPoolExecutor) { - this.threadPoolExecutor = threadPoolExecutor; - } - - public Boolean getHasBuildMetric() { - return hasBuildMetric; - } - - public void setHasBuildMetric(Boolean hasBuildMetric) { - this.hasBuildMetric = hasBuildMetric; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService b/apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService index 13b4a67b04..cfda93521c 100644 --- a/apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService +++ b/apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService @@ -36,4 +36,3 @@ org.apache.skywalking.apm.agent.core.remote.LogReportServiceClient org.apache.skywalking.apm.agent.core.conf.dynamic.ConfigurationDiscoveryService org.apache.skywalking.apm.agent.core.remote.EventReportServiceClient org.apache.skywalking.apm.agent.core.ServiceInstanceGenerator -org.apache.skywalking.apm.agent.core.theadpool.ThreadPoolService diff --git a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java index b2a7b0a78d..aee128f998 100644 --- a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java +++ b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java @@ -18,17 +18,42 @@ package org.apache.skywalking.apm.plugin.undertow.worker.thread.pool; +import com.google.common.collect.ImmutableMap; +import java.util.Map; import java.util.concurrent.ThreadPoolExecutor; +import java.util.function.Function; +import java.util.function.Supplier; +import org.apache.skywalking.apm.agent.core.meter.MeterFactory; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import org.apache.skywalking.apm.agent.core.theadpool.ThreadPoolName; -import org.apache.skywalking.apm.agent.core.theadpool.ThreadPoolRegister; public class UndertowWorkerThreadPoolConstructorIntercept implements InstanceConstructorInterceptor { + private static final String THREAD_POOL_NAME = "undertow_worker_pool"; + + private static final Map>> METRIC_MAP = ImmutableMap.of( + "core_pool_size", + (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getCorePoolSize(), + "max_pool_size", + (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getMaximumPoolSize(), + "pool_size", + (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getPoolSize(), + "queue_size", + (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getQueue().size(), + "active_size", + (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getActiveCount()); + @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable { ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) objInst; - ThreadPoolRegister.registerThreadPoolSource(ThreadPoolName.UNDERTOW_WORKER_POOL, threadPoolExecutor); + buildThreadPoolMeterMetric(threadPoolExecutor); + } + + private void buildThreadPoolMeterMetric(ThreadPoolExecutor threadPoolExecutor) { + String threadPoolMeterName = "thread_pool"; + String poolNameTag = "pool_name"; + String metricTypeTag = "metric_type"; + METRIC_MAP.forEach((key, value) -> MeterFactory.gauge(threadPoolMeterName, value.apply(threadPoolExecutor)) + .tag(poolNameTag, THREAD_POOL_NAME).tag(metricTypeTag, key).build()); } } From a50a0dc56e02b20f78ebf61e6da83aad76f02e87 Mon Sep 17 00:00:00 2001 From: litexu Date: Sat, 29 Jan 2022 01:20:23 +0800 Subject: [PATCH 05/10] test support --- ...wWorkerThreadPoolConstructorIntercept.java | 22 ++-- .../bin/startup.sh | 21 ++++ .../config/expectedData.yaml | 50 ++++++++ .../configuration.yml | 22 ++++ .../pom.xml | 119 ++++++++++++++++++ .../src/main/assembly/assembly.xml | 41 ++++++ .../undertowworkerthreadpool/Application.java | 34 +++++ .../controller/CaseController.java | 45 +++++++ .../src/main/resources/application.yaml | 23 ++++ .../src/main/resources/log4j2.xml | 30 +++++ .../support-version.list | 24 ++++ 11 files changed, 418 insertions(+), 13 deletions(-) create mode 100644 test/plugin/scenarios/undertow-worker-thread-pool-scenario/bin/startup.sh create mode 100644 test/plugin/scenarios/undertow-worker-thread-pool-scenario/config/expectedData.yaml create mode 100644 test/plugin/scenarios/undertow-worker-thread-pool-scenario/configuration.yml create mode 100644 test/plugin/scenarios/undertow-worker-thread-pool-scenario/pom.xml create mode 100644 test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/assembly/assembly.xml create mode 100644 test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/java/org/apache/skywalking/apm/testcase/undertowworkerthreadpool/Application.java create mode 100644 test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/java/org/apache/skywalking/apm/testcase/undertowworkerthreadpool/controller/CaseController.java create mode 100644 test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/resources/application.yaml create mode 100644 test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/resources/log4j2.xml create mode 100644 test/plugin/scenarios/undertow-worker-thread-pool-scenario/support-version.list diff --git a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java index aee128f998..e653217f10 100644 --- a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java +++ b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java @@ -18,7 +18,7 @@ package org.apache.skywalking.apm.plugin.undertow.worker.thread.pool; -import com.google.common.collect.ImmutableMap; +import java.util.HashMap; import java.util.Map; import java.util.concurrent.ThreadPoolExecutor; import java.util.function.Function; @@ -31,17 +31,13 @@ public class UndertowWorkerThreadPoolConstructorIntercept implements InstanceCon private static final String THREAD_POOL_NAME = "undertow_worker_pool"; - private static final Map>> METRIC_MAP = ImmutableMap.of( - "core_pool_size", - (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getCorePoolSize(), - "max_pool_size", - (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getMaximumPoolSize(), - "pool_size", - (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getPoolSize(), - "queue_size", - (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getQueue().size(), - "active_size", - (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getActiveCount()); + private static final Map>> METRIC_MAP = new HashMap>>() {{ + put("core_pool_size", (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getCorePoolSize()); + put("max_pool_size", (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getMaximumPoolSize()); + put("pool_size", (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getPoolSize()); + put("queue_size", (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getQueue().size()); + put("active_size", (ThreadPoolExecutor threadPoolExecutor) -> () -> (double) threadPoolExecutor.getActiveCount()); + }}; @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable { @@ -54,6 +50,6 @@ private void buildThreadPoolMeterMetric(ThreadPoolExecutor threadPoolExecutor) { String poolNameTag = "pool_name"; String metricTypeTag = "metric_type"; METRIC_MAP.forEach((key, value) -> MeterFactory.gauge(threadPoolMeterName, value.apply(threadPoolExecutor)) - .tag(poolNameTag, THREAD_POOL_NAME).tag(metricTypeTag, key).build()); + .tag(poolNameTag, THREAD_POOL_NAME).tag(metricTypeTag, key).build()); } } diff --git a/test/plugin/scenarios/undertow-worker-thread-pool-scenario/bin/startup.sh b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/bin/startup.sh new file mode 100644 index 0000000000..72deaadd66 --- /dev/null +++ b/test/plugin/scenarios/undertow-worker-thread-pool-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/undertow-worker-thread-pool-scenario.jar & \ No newline at end of file diff --git a/test/plugin/scenarios/undertow-worker-thread-pool-scenario/config/expectedData.yaml b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/config/expectedData.yaml new file mode 100644 index 0000000000..32d7928752 --- /dev/null +++ b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/config/expectedData.yaml @@ -0,0 +1,50 @@ +# 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. +meterItems: + - serviceName: undertow-worker-thread-pool-scenario + meterSize: 5 + meters: + - meterId: + name: thread_pool + tags: + - {name: metric_type, value: core_pool_size} + - {name: pool_name, value: undertow_worker_pool} + singleValue: ge 1 + - meterId: + name: thread_pool + tags: + - {name: metric_type, value: max_pool_size} + - {name: pool_name, value: undertow_worker_pool} + singleValue: ge 1 + - meterId: + name: thread_pool + tags: + - {name: metric_type, value: pool_size} + - {name: pool_name, value: undertow_worker_pool} + singleValue: ge 0 + - meterId: + name: thread_pool + tags: + - {name: metric_type, value: active_size} + - {name: pool_name, value: undertow_worker_pool} + singleValue: ge 0 + - meterId: + name: thread_pool + tags: + - {name: metric_type, value: queue_size} + - {name: pool_name, value: undertow_worker_pool} + singleValue: ge 0 + diff --git a/test/plugin/scenarios/undertow-worker-thread-pool-scenario/configuration.yml b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/configuration.yml new file mode 100644 index 0000000000..2090b1e187 --- /dev/null +++ b/test/plugin/scenarios/undertow-worker-thread-pool-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/undertow-worker-thread-pool-scenario/case/undertow-worker-thread-pool-scenario +healthCheck: http://localhost:8080/undertow-worker-thread-pool-scenario/case/healthCheck +startScript: ./bin/startup.sh +runningMode: with_optional +withPlugins: apm-undertow-worker-thread-pool-plugin-*.jar diff --git a/test/plugin/scenarios/undertow-worker-thread-pool-scenario/pom.xml b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/pom.xml new file mode 100644 index 0000000000..ba552380f3 --- /dev/null +++ b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/pom.xml @@ -0,0 +1,119 @@ + + + + + org.apache.skywalking.apm.testcase + undertow-worker-thread-pool-scenario + 1.0.0 + + 4.0.0 + + + UTF-8 + 1.8 + 2.1.6.RELEASE + 2.1.6.RELEASE + + + skywalking-undertow-worker-thread-pool-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-tomcat + + + + + org.springframework.boot + spring-boot-starter-undertow + ${test.framework.version} + + + org.springframework.boot + spring-boot-starter-log4j2 + + + + + undertow-worker-thread-pool-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/ + + + + + + + diff --git a/test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/assembly/assembly.xml b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/assembly/assembly.xml new file mode 100644 index 0000000000..eeca39ccd4 --- /dev/null +++ b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/assembly/assembly.xml @@ -0,0 +1,41 @@ + + + + + zip + + + + + ./bin + 0775 + + + + + + ${project.build.directory}/undertow-worker-thread-pool-scenario.jar + ./libs + 0775 + + + diff --git a/test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/java/org/apache/skywalking/apm/testcase/undertowworkerthreadpool/Application.java b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/java/org/apache/skywalking/apm/testcase/undertowworkerthreadpool/Application.java new file mode 100644 index 0000000000..ad4603f9d1 --- /dev/null +++ b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/java/org/apache/skywalking/apm/testcase/undertowworkerthreadpool/Application.java @@ -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. + * + */ + +package org.apache.skywalking.apm.testcase.undertowworkerthreadpool; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + try { + SpringApplication.run(Application.class, args); + } catch (Exception e) { + // Never do this + } + } +} diff --git a/test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/java/org/apache/skywalking/apm/testcase/undertowworkerthreadpool/controller/CaseController.java b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/java/org/apache/skywalking/apm/testcase/undertowworkerthreadpool/controller/CaseController.java new file mode 100644 index 0000000000..1bd39b7686 --- /dev/null +++ b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/java/org/apache/skywalking/apm/testcase/undertowworkerthreadpool/controller/CaseController.java @@ -0,0 +1,45 @@ +/* + * 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.undertowworkerthreadpool.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/case") +public class CaseController { + + private static final String SUCCESS = "Success"; + + @RequestMapping("/undertow-worker-thread-pool-scenario") + @ResponseBody + public String testcase() { + // your codes + return SUCCESS; + } + + @RequestMapping("/healthCheck") + @ResponseBody + public String healthCheck() { + // your codes + return SUCCESS; + } + +} diff --git a/test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/resources/application.yaml b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/resources/application.yaml new file mode 100644 index 0000000000..0029c62c9c --- /dev/null +++ b/test/plugin/scenarios/undertow-worker-thread-pool-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: /undertow-worker-thread-pool-scenario +logging: + config: classpath:log4j2.xml \ No newline at end of file diff --git a/test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/resources/log4j2.xml b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..9849ed5a8a --- /dev/null +++ b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/src/main/resources/log4j2.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/undertow-worker-thread-pool-scenario/support-version.list b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/support-version.list new file mode 100644 index 0000000000..fb748f57e9 --- /dev/null +++ b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/support-version.list @@ -0,0 +1,24 @@ +# 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. + +# lists your version here (Contains only the last version number of each minor version.) + +2.1.9.RELEASE +2.2.13.RELEASE +2.3.12.RELEASE +2.4.13 +2.5.9 +2.6.3 From 92aa411f5ff9628f9354a7f6a87353be0d678f82 Mon Sep 17 00:00:00 2001 From: litexu Date: Sat, 29 Jan 2022 01:35:39 +0800 Subject: [PATCH 06/10] update doc --- docs/en/setup/service-agent/java-agent/Plugin-list.md | 1 + docs/en/setup/service-agent/java-agent/Supported-list.md | 2 ++ 2 files changed, 3 insertions(+) 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 9ebd2d4ab6..91e7d5d5b5 100644 --- a/docs/en/setup/service-agent/java-agent/Plugin-list.md +++ b/docs/en/setup/service-agent/java-agent/Plugin-list.md @@ -130,3 +130,4 @@ - kylin-jdbc-2.6.x-3.x-4.x - okhttp-2.x - pulsar-2.8.x +- undertow-worker-thread-pool 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 6e1f93963f..85bf023544 100644 --- a/docs/en/setup/service-agent/java-agent/Supported-list.md +++ b/docs/en/setup/service-agent/java-agent/Supported-list.md @@ -135,6 +135,8 @@ metrics based on the tracing data. * [logback](https://github.com/qos-ch/logback) 1.2.x * ORM * [MyBatis](https://github.com/mybatis/mybatis-3) 3.4.x -> 3.5.x +* Thread Pool + * [Undertow](https://github.com/undertow-io/undertow) 2.1.x -> 2.6.x # Meter Plugins The meter plugin provides the advanced metrics collections, which are not a part of tracing. From 77b21ae526e640a7aa76ac99c71d08b7658d8ad3 Mon Sep 17 00:00:00 2001 From: litexu Date: Sat, 29 Jan 2022 02:25:05 +0800 Subject: [PATCH 07/10] update to 8.10.0 --- .../optional-plugins/undertow-worker-thread-pool-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/pom.xml b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/pom.xml index 283f7fc625..7f365d32f7 100644 --- a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/pom.xml +++ b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/pom.xml @@ -23,7 +23,7 @@ optional-plugins org.apache.skywalking - 8.9.0-SNAPSHOT + 8.10.0-SNAPSHOT 4.0.0 From e2c992012f689f38056957f4b8702468a007edf3 Mon Sep 17 00:00:00 2001 From: litexu Date: Sat, 29 Jan 2022 02:39:38 +0800 Subject: [PATCH 08/10] add test --- .github/workflows/plugins-test.3.yaml | 1 + .../src/main/resources/skywalking-plugin.def | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/plugins-test.3.yaml b/.github/workflows/plugins-test.3.yaml index dae3a51315..3e3070c33e 100644 --- a/.github/workflows/plugins-test.3.yaml +++ b/.github/workflows/plugins-test.3.yaml @@ -92,6 +92,7 @@ jobs: - hikaricp-scenario - clickhouse-0.3.x-scenario - kylin-jdbc-2.6.x-3.x-4.x-scenario + - undertow-worker-thread-pool-scenario steps: - uses: actions/checkout@v2 with: diff --git a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/resources/skywalking-plugin.def index 7d5a02e83b..22837a7aad 100644 --- a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/resources/skywalking-plugin.def @@ -14,4 +14,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -undertow-worker-thread-pool-plugin=org.apache.skywalking.apm.plugin.undertow.worker.thread.pool.define.UndertowWorkerThreadPoolInstrumentation \ No newline at end of file +undertow-worker-thread-pool=org.apache.skywalking.apm.plugin.undertow.worker.thread.pool.define.UndertowWorkerThreadPoolInstrumentation \ No newline at end of file From c8942298012270609870691477fc233225af4b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=99=9F=20Wu=20Sheng?= Date: Sat, 29 Jan 2022 08:00:29 +0800 Subject: [PATCH 09/10] Update Supported-list.md --- docs/en/setup/service-agent/java-agent/Supported-list.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 cbd7b81f37..aafa5bb737 100644 --- a/docs/en/setup/service-agent/java-agent/Supported-list.md +++ b/docs/en/setup/service-agent/java-agent/Supported-list.md @@ -135,12 +135,13 @@ metrics based on the tracing data. * [logback](https://github.com/qos-ch/logback) 1.2.x * ORM * [MyBatis](https://github.com/mybatis/mybatis-3) 3.4.x -> 3.5.x -* Thread Pool - * [Undertow](https://github.com/undertow-io/undertow) 2.1.x -> 2.6.x # Meter Plugins The meter plugin provides the advanced metrics collections, which are not a part of tracing. +* Thread Pool + * [Undertow](https://github.com/undertow-io/undertow) 2.1.x -> 2.6.x + ___ ¹Due to license incompatibilities/restrictions these plugins are hosted and released in 3rd part repository, go to [SkyAPM java plugin extension repository](https://github.com/SkyAPM/java-plugin-extensions) to get these. From 725b47c54d46f0505b1e0b214ddff2790cdfb23a Mon Sep 17 00:00:00 2001 From: litexu Date: Sat, 29 Jan 2022 13:59:11 +0800 Subject: [PATCH 10/10] mv to default --- apm-sniffer/apm-sdk-plugin/pom.xml | 1 + .../undertow-worker-thread-pool-plugin/pom.xml | 2 +- .../pool/UndertowWorkerThreadPoolConstructorIntercept.java | 0 .../pool/define/UndertowWorkerThreadPoolInstrumentation.java | 0 .../src/main/resources/skywalking-plugin.def | 0 apm-sniffer/optional-plugins/pom.xml | 1 - .../undertow-worker-thread-pool-scenario/configuration.yml | 2 -- 7 files changed, 2 insertions(+), 4 deletions(-) rename apm-sniffer/{optional-plugins => apm-sdk-plugin}/undertow-worker-thread-pool-plugin/pom.xml (96%) rename apm-sniffer/{optional-plugins => apm-sdk-plugin}/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java (100%) rename apm-sniffer/{optional-plugins => apm-sdk-plugin}/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/define/UndertowWorkerThreadPoolInstrumentation.java (100%) rename apm-sniffer/{optional-plugins => apm-sdk-plugin}/undertow-worker-thread-pool-plugin/src/main/resources/skywalking-plugin.def (100%) diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index a8f08eb16d..f0ba0080e9 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -117,6 +117,7 @@ okhttp-2.x-plugin pulsar-common pulsar-2.8.x-plugin + undertow-worker-thread-pool-plugin pom diff --git a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/undertow-worker-thread-pool-plugin/pom.xml similarity index 96% rename from apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/pom.xml rename to apm-sniffer/apm-sdk-plugin/undertow-worker-thread-pool-plugin/pom.xml index 7f365d32f7..ce004db7de 100644 --- a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/undertow-worker-thread-pool-plugin/pom.xml @@ -21,7 +21,7 @@ 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"> - optional-plugins + apm-sdk-plugin org.apache.skywalking 8.10.0-SNAPSHOT diff --git a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java b/apm-sniffer/apm-sdk-plugin/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java similarity index 100% rename from apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java rename to apm-sniffer/apm-sdk-plugin/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java diff --git a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/define/UndertowWorkerThreadPoolInstrumentation.java b/apm-sniffer/apm-sdk-plugin/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/define/UndertowWorkerThreadPoolInstrumentation.java similarity index 100% rename from apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/define/UndertowWorkerThreadPoolInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/undertow-worker-thread-pool-plugin/src/main/java/org/apache/skywalking/apm/plugin/undertow/worker/thread/pool/define/UndertowWorkerThreadPoolInstrumentation.java diff --git a/apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/undertow-worker-thread-pool-plugin/src/main/resources/skywalking-plugin.def similarity index 100% rename from apm-sniffer/optional-plugins/undertow-worker-thread-pool-plugin/src/main/resources/skywalking-plugin.def rename to apm-sniffer/apm-sdk-plugin/undertow-worker-thread-pool-plugin/src/main/resources/skywalking-plugin.def diff --git a/apm-sniffer/optional-plugins/pom.xml b/apm-sniffer/optional-plugins/pom.xml index ae77d22751..308d1d9a90 100644 --- a/apm-sniffer/optional-plugins/pom.xml +++ b/apm-sniffer/optional-plugins/pom.xml @@ -55,7 +55,6 @@ guava-cache-plugin fastjson-1.2.x-plugin jackson-2.x-plugin - undertow-worker-thread-pool-plugin diff --git a/test/plugin/scenarios/undertow-worker-thread-pool-scenario/configuration.yml b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/configuration.yml index 2090b1e187..d88246c81a 100644 --- a/test/plugin/scenarios/undertow-worker-thread-pool-scenario/configuration.yml +++ b/test/plugin/scenarios/undertow-worker-thread-pool-scenario/configuration.yml @@ -18,5 +18,3 @@ type: jvm entryService: http://localhost:8080/undertow-worker-thread-pool-scenario/case/undertow-worker-thread-pool-scenario healthCheck: http://localhost:8080/undertow-worker-thread-pool-scenario/case/healthCheck startScript: ./bin/startup.sh -runningMode: with_optional -withPlugins: apm-undertow-worker-thread-pool-plugin-*.jar