From 21d327c3571b76bc6f4ce8c453b6968830cb52c1 Mon Sep 17 00:00:00 2001 From: masaimu Date: Thu, 7 Mar 2024 20:23:14 +0800 Subject: [PATCH] feat: batch query (#814) --- .../server/home/common/util/CommonThreadPool.java | 8 ++++++++ .../server/home/biz/service/TenantInitService.java | 4 +++- .../service/impl/DefaultTenantInitServiceImpl.java | 4 +++- .../server/home/web/controller/QueryFacadeImpl.java | 12 +++++++++--- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/server/home/home-common/src/main/java/io/holoinsight/server/home/common/util/CommonThreadPool.java b/server/home/home-common/src/main/java/io/holoinsight/server/home/common/util/CommonThreadPool.java index 83a4c8b7b..dc7029dc8 100644 --- a/server/home/home-common/src/main/java/io/holoinsight/server/home/common/util/CommonThreadPool.java +++ b/server/home/home-common/src/main/java/io/holoinsight/server/home/common/util/CommonThreadPool.java @@ -7,6 +7,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ThreadPoolExecutor; /** @@ -17,12 +18,19 @@ public class CommonThreadPool { public static ThreadPoolTaskExecutor createThreadPool(int coreSize, int maxSize, int queueCapacity, String tpname) { + return createThreadPool(coreSize, maxSize, queueCapacity, tpname, + new ThreadPoolExecutor.AbortPolicy()); + } + + public static ThreadPoolTaskExecutor createThreadPool(int coreSize, int maxSize, + int queueCapacity, String tpname, RejectedExecutionHandler rejectedExecutionHandler) { ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor(); threadPool.setThreadNamePrefix(tpname); threadPool.setMaxPoolSize(maxSize); threadPool.setCorePoolSize(coreSize); threadPool.setQueueCapacity(queueCapacity); threadPool.afterPropertiesSet(); + threadPool.setRejectedExecutionHandler(rejectedExecutionHandler); return threadPool; } diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/TenantInitService.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/TenantInitService.java index 7baf77644..c38ae6e08 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/TenantInitService.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/TenantInitService.java @@ -7,6 +7,8 @@ import io.holoinsight.server.common.dao.entity.MetricInfo; import io.holoinsight.server.common.dao.entity.dto.TenantOpsStorage; import io.holoinsight.server.home.biz.plugin.config.MetaLabel; +import io.holoinsight.server.home.common.util.scope.MonitorScope; +import io.holoinsight.server.home.common.util.scope.MonitorUser; import io.holoinsight.server.home.dal.model.dto.CloudMonitorRange; import io.holoinsight.server.home.dal.model.dto.CustomPluginDTO; import io.holoinsight.server.home.dal.model.dto.IntegrationGeneratedDTO; @@ -65,7 +67,7 @@ public interface TenantInitService { String getTsdbTenant(String tenant, MetricInfo metricInfo); Boolean checkConditions(String tenant, String workspace, String environment, String metric, - List filters); + List filters, MonitorScope ms, MonitorUser mu); /** diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/DefaultTenantInitServiceImpl.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/DefaultTenantInitServiceImpl.java index 723b85a3c..3536e62d5 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/DefaultTenantInitServiceImpl.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/DefaultTenantInitServiceImpl.java @@ -9,6 +9,8 @@ import io.holoinsight.server.home.biz.common.GaeaConvertUtil; import io.holoinsight.server.home.biz.plugin.config.MetaLabel; import io.holoinsight.server.home.biz.service.TenantInitService; +import io.holoinsight.server.home.common.util.scope.MonitorScope; +import io.holoinsight.server.home.common.util.scope.MonitorUser; import io.holoinsight.server.home.dal.model.dto.CloudMonitorRange; import io.holoinsight.server.home.dal.model.dto.CustomPluginDTO; import io.holoinsight.server.home.dal.model.dto.IntegrationGeneratedDTO; @@ -62,7 +64,7 @@ public String getTsdbTenant(String tenant, MetricInfo metricInfo) { @Override public Boolean checkConditions(String tenant, String workspace, String environment, String metric, - List filters) { + List filters, MonitorScope ms, MonitorUser mu) { return true; } diff --git a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/QueryFacadeImpl.java b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/QueryFacadeImpl.java index 3cfd89b3b..b70d11259 100644 --- a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/QueryFacadeImpl.java +++ b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/QueryFacadeImpl.java @@ -26,6 +26,7 @@ import io.holoinsight.server.home.common.util.StringUtil; import io.holoinsight.server.home.common.util.scope.AuthTargetType; import io.holoinsight.server.home.common.util.scope.MonitorScope; +import io.holoinsight.server.home.common.util.scope.MonitorUser; import io.holoinsight.server.home.common.util.scope.PowerConstants; import io.holoinsight.server.home.common.util.scope.RequestContext; import io.holoinsight.server.home.web.common.ManageCallback; @@ -547,7 +548,11 @@ public List convertQueryRequest(DelTagReq req) { } public QueryProto.QueryRequest convertRequest(DataQueryRequest request) { - MonitorScope ms = RequestContext.getContext().ms; + return convertRequest(request, RequestContext.getContext().ms, RequestContext.getContext().mu); + } + + public QueryProto.QueryRequest convertRequest(DataQueryRequest request, MonitorScope ms, + MonitorUser mu) { QueryProto.QueryRequest.Builder builder = QueryProto.QueryRequest.newBuilder(); builder.setTenant(tenantInitService.getTsdbTenant(ms.getTenant())); if (StringUtil.isNotBlank(request.getQuery())) { @@ -587,8 +592,9 @@ public QueryProto.QueryRequest convertRequest(DataQueryRequest request) { objMap.remove("select"); } toProtoBean(datasourceBuilder, objMap); - Boolean aBoolean = tenantInitService.checkConditions(ms.getTenant(), ms.getWorkspace(), - ms.getEnvironment(), datasourceBuilder.getMetric(), datasourceBuilder.getFiltersList()); + Boolean aBoolean = + tenantInitService.checkConditions(ms.getTenant(), ms.getWorkspace(), ms.getEnvironment(), + datasourceBuilder.getMetric(), datasourceBuilder.getFiltersList(), ms, mu); if (!aBoolean) { throw new MonitorException("workspace is illegal"); }