This commit is contained in:
Albumen Kevin 2024-06-23 19:52:35 +08:00
parent 07adb92daf
commit 31eb8fd2f6
4 changed files with 16 additions and 7 deletions

View File

@ -36,5 +36,4 @@ public interface DataStore {
void remove(String componentName, String key);
default void addListener(DataStoreUpdateListener dataStoreUpdateListener) {}
;
}

View File

@ -82,7 +82,12 @@ public class SimpleDataStore implements DataStore {
listener.onUpdate(componentName, key, value);
} catch (Throwable t) {
logger.warn(
LoggerCodeConstants.INTERNAL_ERROR, "", "", "Failed to notify data store update listener", t);
LoggerCodeConstants.INTERNAL_ERROR,
"",
"",
"Failed to notify data store update listener. " + "ComponentName: " + componentName + " Key: "
+ key,
t);
}
}
}

View File

@ -149,7 +149,11 @@ public interface Constants {
String SERVER_THREAD_POOL_NAME = "DubboServerHandler";
String SERVER_THREAD_POOL_PREFIX = SERVER_THREAD_POOL_NAME + "-";
String CLIENT_THREAD_POOL_NAME = "DubboClientHandler";
String CLIENT_THREAD_POOL_PREFIX = CLIENT_THREAD_POOL_NAME + "-";
String REST_PROTOCOL = "rest";
}

View File

@ -43,8 +43,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
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.CLIENT_THREAD_POOL_PREFIX;
import static org.apache.dubbo.config.Constants.SERVER_THREAD_POOL_NAME;
import static org.apache.dubbo.config.Constants.SERVER_THREAD_POOL_PREFIX;
import static org.apache.dubbo.metrics.model.MetricsCategory.THREAD_POOL;
public class ThreadPoolMetricsSampler implements MetricsSampler, DataStoreUpdateListener {
@ -66,11 +67,11 @@ public class ThreadPoolMetricsSampler implements MetricsSampler, DataStoreUpdate
public void onUpdate(String componentName, String key, Object value) {
if (EXECUTOR_SERVICE_COMPONENT_KEY.equals(componentName)) {
if (value instanceof ThreadPoolExecutor) {
addExecutors(SERVER_THREAD_POOL_NAME + "-" + key, (ThreadPoolExecutor) value);
addExecutors(SERVER_THREAD_POOL_PREFIX + key, (ThreadPoolExecutor) value);
}
} else if (CONSUMER_SHARED_EXECUTOR_SERVICE_COMPONENT_KEY.equals(componentName)) {
if (value instanceof ThreadPoolExecutor) {
addExecutors(CLIENT_THREAD_POOL_NAME + "-" + key, (ThreadPoolExecutor) value);
addExecutors(CLIENT_THREAD_POOL_PREFIX + key, (ThreadPoolExecutor) value);
}
}
}
@ -173,14 +174,14 @@ public class ThreadPoolMetricsSampler implements MetricsSampler, DataStoreUpdate
for (Map.Entry<String, Object> entry : executors.entrySet()) {
ExecutorService executor = (ExecutorService) entry.getValue();
if (executor instanceof ThreadPoolExecutor) {
this.addExecutors(SERVER_THREAD_POOL_NAME + "-" + entry.getKey(), executor);
this.addExecutors(SERVER_THREAD_POOL_PREFIX + 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);
this.addExecutors(CLIENT_THREAD_POOL_PREFIX + entry.getKey(), executor);
}
}