Fixed the issue where core thread metrics were in effect(#11704) (#11752)

* Fixed the issue where core thread metrics were in effect

* Fixed the issue where core thread metrics were in effect(#11704)

* fix: add core thread metrics name (#11704)

* fix: remove useless dependencies (#11704)

---------

Co-authored-by: robin <pengrobin607@gmail.com>
This commit is contained in:
robin977 2023-03-10 15:21:25 +08:00 committed by GitHub
parent 8d1152d86d
commit 14f2d79693
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 8 deletions

View File

@ -108,7 +108,6 @@ public class DefaultExecutorRepository implements ExecutorRepository, ExtensionA
executor = createExecutor(url);
executors.put(executorCacheKey, executor);
}
dataStore.put(executorKey, executorCacheKey, executor);
return executor;
}

View File

@ -149,5 +149,5 @@ public interface Constants {
String SERVER_THREAD_POOL_NAME = "DubboServerHandler";
String CLIENT_THREAD_POOL_NAME = "DubboClientHandler";
}

View File

@ -1088,6 +1088,7 @@ public class DefaultApplicationDeployer extends AbstractDeployer<ApplicationMode
return;
}
setStarted();
startMetricsCollector();
if (logger.isInfoEnabled()) {
logger.info(getIdentifier() + " is ready.");
}
@ -1105,6 +1106,11 @@ public class DefaultApplicationDeployer extends AbstractDeployer<ApplicationMode
}
}
private void startMetricsCollector(){
DefaultMetricsCollector collector = applicationModel.getBeanFactory().getBean(DefaultMetricsCollector.class);
collector.registryDefaultSample();
}
private void completeStartFuture(boolean success) {
if (startFuture != null) {
startFuture.complete(success);

View File

@ -95,6 +95,10 @@ public class DefaultMetricsCollector implements MetricsCollector {
applicationSampler.inc(applicationName, MetricsEvent.Type.APPLICATION_INFO);
}
public void registryDefaultSample(){
this.threadPoolSampler.registryDefaultSampleThreadPoolExecutor();
}
@Override
public List<MetricSample> collect() {
List<MetricSample> list = new ArrayList<>();

View File

@ -37,9 +37,12 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SHARED_EXECUTOR_SERVICE_COMPONENT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.EXECUTOR_SERVICE_COMPONENT_KEY;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_METRICS_COLLECTOR_EXCEPTION;
import static org.apache.dubbo.config.Constants.CLIENT_THREAD_POOL_NAME;
import static org.apache.dubbo.config.Constants.SERVER_THREAD_POOL_NAME;
import static org.apache.dubbo.metrics.model.MetricsCategory.THREAD_POOL;
public class ThreadPoolMetricsSampler implements MetricsSampler {
@ -53,7 +56,6 @@ public class ThreadPoolMetricsSampler implements MetricsSampler {
public ThreadPoolMetricsSampler(DefaultMetricsCollector collector) {
this.collector = collector;
this.registryDefaultSampleThreadPoolExecutor();
}
public void addExecutors(String name, ExecutorService executorService) {
@ -87,7 +89,7 @@ public class ThreadPoolMetricsSampler implements MetricsSampler {
return list;
}
private void registryDefaultSampleThreadPoolExecutor() {
public void registryDefaultSampleThreadPoolExecutor() {
ApplicationModel applicationModel = collector.getApplicationModel();
if (applicationModel == null) {
return;
@ -103,20 +105,26 @@ public class ThreadPoolMetricsSampler implements MetricsSampler {
if (this.dataStore == null) {
this.dataStore = collector.getApplicationModel().getExtensionLoader(DataStore.class).getDefaultExtension();
}
if (dataStore != null) {
Map<String, Object> executors = dataStore.get(EXECUTOR_SERVICE_COMPONENT_KEY);
for (Map.Entry<String, Object> entry : executors.entrySet()) {
ExecutorService executor = (ExecutorService) entry.getValue();
if (executor instanceof ThreadPoolExecutor) {
this.addExecutors(entry.getKey(), executor);
this.addExecutors( SERVER_THREAD_POOL_NAME + "-" + entry.getKey(), executor);
}
}
executors = dataStore.get(CONSUMER_SHARED_EXECUTOR_SERVICE_COMPONENT_KEY);
for (Map.Entry<String, Object> entry : executors.entrySet()) {
ExecutorService executor = (ExecutorService) entry.getValue();
if (executor instanceof ThreadPoolExecutor) {
this.addExecutors(CLIENT_THREAD_POOL_NAME + "-" + entry.getKey(), executor);
}
}
}
if (this.frameworkExecutorRepository != null) {
this.addExecutors("sharedExecutor", frameworkExecutorRepository.getSharedExecutor());
this.addExecutors("mappingRefreshingExecutor", frameworkExecutorRepository.getMappingRefreshingExecutor());
this.addExecutors("poolRouterExecutor", frameworkExecutorRepository.getPoolRouterExecutor());
}
}
}
}