-
Notifications
You must be signed in to change notification settings - Fork 679
Support thread pool metric collect #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wu-sheng
merged 12 commits into
apache:main
from
xu1009:feature/support-java-thread-pool
Jan 29, 2022
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d839777
init
e0723fd
change log
1c7b9a7
add licence
8f76788
rm
a50a0dc
test support
92aa411
update doc
f98cdcc
Merge remote-tracking branch 'origin/main' into feature/support-java-…
77b21ae
update to 8.10.0
e2c9920
add test
c894229
Update Supported-list.md
wu-sheng 725b47c
mv to default
056f2b7
Merge remote-tracking branch 'origin/feature/support-java-thread-pool…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
apm-sniffer/apm-sdk-plugin/undertow-worker-thread-pool-plugin/pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| ~ Licensed to the Apache Software Foundation (ASF) under one or more | ||
| ~ contributor license agreements. See the NOTICE file distributed with | ||
| ~ this work for additional information regarding copyright ownership. | ||
| ~ The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| ~ (the "License"); you may not use this file except in compliance with | ||
| ~ the License. You may obtain a copy of the License at | ||
| ~ | ||
| ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| ~ | ||
| ~ Unless required by applicable law or agreed to in writing, software | ||
| ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| ~ See the License for the specific language governing permissions and | ||
| ~ limitations under the License. | ||
| ~ | ||
| --> | ||
|
|
||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <parent> | ||
| <artifactId>apm-sdk-plugin</artifactId> | ||
| <groupId>org.apache.skywalking</groupId> | ||
| <version>8.10.0-SNAPSHOT</version> | ||
| </parent> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <artifactId>apm-undertow-worker-thread-pool-plugin</artifactId> | ||
| <name>undertow-worker-thread-pool-plugin</name> | ||
| <url>http://maven.apache.org</url> | ||
|
|
||
|
|
||
| </project> |
55 changes: 55 additions & 0 deletions
55
.../apm/plugin/undertow/worker/thread/pool/UndertowWorkerThreadPoolConstructorIntercept.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * 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.HashMap; | ||
| 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; | ||
|
|
||
| public class UndertowWorkerThreadPoolConstructorIntercept implements InstanceConstructorInterceptor { | ||
|
|
||
| private static final String THREAD_POOL_NAME = "undertow_worker_pool"; | ||
|
|
||
| private static final Map<String, Function<ThreadPoolExecutor, Supplier<Double>>> METRIC_MAP = new HashMap<String, Function<ThreadPoolExecutor, Supplier<Double>>>() {{ | ||
| 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 { | ||
| ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) objInst; | ||
| 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()); | ||
| } | ||
| } |
71 changes: 71 additions & 0 deletions
71
...pm/plugin/undertow/worker/thread/pool/define/UndertowWorkerThreadPoolInstrumentation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<MethodDescription> 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]; | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
...pm-sdk-plugin/undertow-worker-thread-pool-plugin/src/main/resources/skywalking-plugin.def
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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=org.apache.skywalking.apm.plugin.undertow.worker.thread.pool.define.UndertowWorkerThreadPoolInstrumentation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,3 +130,4 @@ | |
| - kylin-jdbc-2.6.x-3.x-4.x | ||
| - okhttp-2.x | ||
| - pulsar-2.8.x | ||
| - undertow-worker-thread-pool | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
test/plugin/scenarios/undertow-worker-thread-pool-scenario/bin/startup.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 & |
50 changes: 50 additions & 0 deletions
50
test/plugin/scenarios/undertow-worker-thread-pool-scenario/config/expectedData.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
|
20 changes: 20 additions & 0 deletions
20
test/plugin/scenarios/undertow-worker-thread-pool-scenario/configuration.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR only provides thread pool metrics of Undertow, but the change log makes me (and probably other users) feel that we support JDK's thread pool. WDYT @wu-sheng ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, check the latest codes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noted that the V9.0.0 just display tomcat thread pool metric. Now I have many customized thread pool which created by "org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor". How can I collect the metric of my thread pool and display it in UI?Is need to write another customized plugins or just need write some config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check #146 you may be interested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had checked #146 before i asked and i had read the code. The code does not contains any METRIC about "CorePoolSize","MaximumPoolSize".

I find a plugin more closer I wanted but hard coded[org.apache.skywalking.apm.plugin.undertow.worker.thread.pool.UndertowWorkerThreadPoolConstructorIntercept]. So I want to konw if i have to write some customized plugin which the count is same to the ThreadPool count?Or have some config more convenient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why only including two methods, there was a long discussion on that PR, you could check.
You definitely could write a new plugin to do whatever you want, but you should know, that the discussion context is recommended for you before you take action. There are risks to instrument all, which is why we don't do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, i will check later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wu-sheng There are many thread pools in my project, such as ThreadPoolA and ThreadPoolB. If I want to monitor the metrics of these two thread pools separately, do I need to add a new plugin to the agent and two rules to the threadpool.ymal of OAP like:
- name: ThreadPoolA
exp: ThreadPoolA.avg(['metric_type', 'pool_name', 'instance', 'service'])
- name: ThreadPoolB
exp: ThreadPoolB.avg(['metric_type', 'pool_name', 'instance', 'service'])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Learn MAL, your questions are irrelevant