Skip to content

Commit

Permalink
fix: query schema (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
masaimu authored Mar 11, 2024
1 parent 21d327c commit 7fb3439
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ public class MetaDictKey {
public static final String METERING_HOLOINSIGHT_SUBMIT_OPEN = "metering_holoinsight_submit_open";
public static final String INTEGRATION_LOCAL_PRODUCT = "integration_local_product";
public static final String NETWORK_MODE = "networkMode";
public static final String SCHEMA_METRIC_TABLE_PREFIX = "schema_metric_table_prefix";
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package io.holoinsight.server.home.web.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.holoinsight.server.common.J;
import io.holoinsight.server.common.JsonResult;
import com.google.protobuf.InvalidProtocolBufferException;
Expand All @@ -11,6 +12,7 @@
import io.holoinsight.server.common.LatchWork;
import io.holoinsight.server.common.UtilMisc;
import io.holoinsight.server.common.dao.entity.MetricInfo;
import io.holoinsight.server.common.dao.mapper.MetricInfoMapper;
import io.holoinsight.server.common.service.SuperCacheService;
import io.holoinsight.server.common.threadpool.CommonThreadPools;
import io.holoinsight.server.home.biz.common.MetaDictUtil;
Expand Down Expand Up @@ -62,6 +64,7 @@
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -73,6 +76,11 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import static io.holoinsight.server.home.biz.common.MetaDictKey.SCHEMA_METRIC_TABLE_PREFIX;
import static io.holoinsight.server.home.biz.common.MetaDictType.GLOBAL_CONFIG;
import static io.holoinsight.server.home.task.MetricCrawlerConstant.GLOBAL_TENANT;
import static io.holoinsight.server.home.task.MetricCrawlerConstant.GLOBAL_WORKSPACE;

@RestController
@RequestMapping("/webapi/v1/query")
@TokenUrls("/webapi/v1/query")
Expand All @@ -96,6 +104,8 @@ public class QueryFacadeImpl extends BaseFacade {

@Autowired
private ParameterSecurityService parameterSecurityService;
@Resource
private MetricInfoMapper metricInfoMapper;

@PostMapping
@MonitorScopeAuth(targetType = AuthTargetType.TENANT, needPower = PowerConstants.VIEW)
Expand Down Expand Up @@ -272,6 +282,17 @@ public void checkParameter() {}

@Override
public void doManage() {
if (useGlobalMetricInfo(metric)) {
MetricInfo metricInfo = getGlobalMetricInfo(metric);
if (metricInfo != null) {
List<String> tags = getTagsFromMetricInfo(metricInfo);
KeyResult keyResult = new KeyResult();
keyResult.setMetric(metric);
keyResult.setTags(tags);
result.setData(keyResult);
return;
}
}
MonitorScope ms = RequestContext.getContext().ms;
Builder builder = Datasource.newBuilder().setMetric(metric)
.setStart(System.currentTimeMillis() - 60000 * 60 * 5)
Expand Down Expand Up @@ -305,6 +326,40 @@ public void doManage() {
return result;
}

private List<String> getTagsFromMetricInfo(MetricInfo metricInfo) {
String tags = metricInfo.getTags();
if (StringUtils.isBlank(tags)) {
return Collections.emptyList();
}
return J.toList(tags);
}

private MetricInfo getGlobalMetricInfo(String metric) {
QueryWrapper<MetricInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("tenant", GLOBAL_TENANT);
queryWrapper.eq("workspace", GLOBAL_WORKSPACE);
queryWrapper.eq("metric_table", metric);
List<MetricInfo> metricInfos = metricInfoMapper.selectList(queryWrapper);
if (CollectionUtils.isEmpty(metricInfos)) {
return null;
}
return metricInfos.get(0);
}

private boolean useGlobalMetricInfo(String metric) {
List<String> schemaMetricTablePrefix =
MetaDictUtil.getList(GLOBAL_CONFIG, SCHEMA_METRIC_TABLE_PREFIX);
if (CollectionUtils.isEmpty(schemaMetricTablePrefix)) {
return false;
}
for (String prefix : schemaMetricTablePrefix) {
if (metric.startsWith(prefix)) {
return true;
}
}
return false;
}

/**
* 模糊匹配查询
*
Expand Down

0 comments on commit 7fb3439

Please sign in to comment.