Skip to content

Commit

Permalink
feat: batch query (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
masaimu authored Mar 7, 2024
1 parent e370363 commit 21d327c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,7 +67,7 @@ public interface TenantInitService {
String getTsdbTenant(String tenant, MetricInfo metricInfo);

Boolean checkConditions(String tenant, String workspace, String environment, String metric,
List<QueryFilter> filters);
List<QueryFilter> filters, MonitorScope ms, MonitorUser mu);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,7 +64,7 @@ public String getTsdbTenant(String tenant, MetricInfo metricInfo) {

@Override
public Boolean checkConditions(String tenant, String workspace, String environment, String metric,
List<QueryFilter> filters) {
List<QueryFilter> filters, MonitorScope ms, MonitorUser mu) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -547,7 +548,11 @@ public List<DataQueryRequest> 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())) {
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit 21d327c

Please sign in to comment.