Skip to content

Commit

Permalink
refactor(home): add conditons when query tagvalues
Browse files Browse the repository at this point in the history
  • Loading branch information
霄鸿 committed Jul 20, 2023
1 parent 228ebd6 commit 4c88d71
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ public interface MetricInfoService extends IService<MetricInfo> {

Map<String, QueryRequest> querySpmList();

List<MetricInfoDTO> getListByKeyword(String keyword, String tenant, String workspace);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package io.holoinsight.server.common.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.holoinsight.server.common.dao.converter.MetricInfoConverter;
import io.holoinsight.server.common.dao.entity.MetricInfo;
Expand Down Expand Up @@ -148,4 +149,19 @@ public Map<String, QueryRequest> querySpmList() {
});
return map;
}

@Override
public List<MetricInfoDTO> getListByKeyword(String keyword, String tenant, String workspace) {
QueryWrapper<MetricInfo> wrapper = new QueryWrapper<>();
if (StringUtils.isNotBlank(tenant) || "-".equalsIgnoreCase(tenant)) {
wrapper.eq("tenant", tenant);
}
if (StringUtils.isNotBlank(workspace) || "-".equalsIgnoreCase(workspace)) {
wrapper.eq("workspace", workspace);
}

wrapper.like("metric_table", keyword);
wrapper.last("LIMIT 10");
return metricInfoConverter.dosToDTOs(baseMapper.selectList(wrapper));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.holoinsight.server.home.dal.model.dto.CloudMonitorRange;
import io.holoinsight.server.query.grpc.QueryProto.QueryFilter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -62,7 +63,7 @@ public Map<String, String> getTenantWorkspaceMetaConditions(String workspace) {

@Override
public List<QueryFilter> getTenantFilters(String workspace) {
return null;
return new ArrayList<>();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@ public void doManage() {

List<QueryProto.QueryFilter> tenantFilters =
tenantInitService.getTenantFilters(ms.getWorkspace());

if (!CollectionUtils.isEmpty(tagQueryRequest.getConditions())) {
tagQueryRequest.getConditions().forEach((k, v) -> {
tenantFilters.add(QueryProto.QueryFilter.newBuilder().setName(k).setType("literal_or")
.setValue(v).build());
});
}

if (!CollectionUtils.isEmpty(tenantFilters)) {
builder.addAllFilters(tenantFilters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/
package io.holoinsight.server.home.web.controller;

import io.holoinsight.server.common.dao.entity.dto.MetricInfoDTO;
import io.holoinsight.server.common.service.MetricInfoService;
import io.holoinsight.server.home.biz.service.AlertRuleService;
import io.holoinsight.server.home.biz.service.CustomPluginService;
import io.holoinsight.server.home.biz.service.DashboardService;
Expand Down Expand Up @@ -35,6 +37,7 @@
import java.util.Map;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
*
Expand All @@ -60,6 +63,9 @@ public class SearchFacadeImpl extends BaseFacade {
@Autowired
private AlertRuleService alarmRuleService;

@Autowired
private MetricInfoService metricInfoService;

@Autowired
private DataClientService dataClientService;

Expand Down Expand Up @@ -89,7 +95,6 @@ public void doManage() {
List<SearchKeywordRet> ret = new ArrayList<>();
List<Future<SearchKeywordRet>> futures = new ArrayList<>();
futures.add(queryThreadPool.submit(() -> {
log.info(">>>>>, " + tenant + ", ..... , " + workspace);
return searchLogEntity(req.keyword, tenant, workspace);
}));

Expand All @@ -113,6 +118,10 @@ public void doManage() {
return searchAlarmEntity(req.keyword, tenant, workspace);
}));

futures.add(queryThreadPool.submit(() -> {
return searchLogMetricEntity(req.keyword, tenant, workspace);
}));

// 多线程
for (Future<SearchKeywordRet> future : futures) {
try {
Expand Down Expand Up @@ -208,8 +217,6 @@ public SearchKeywordRet searchDashboardEntity(String keyword, String tenant, Str
public SearchKeywordRet searchInfraEntity(String keyword, String tenant, String workspace) {

QueryExample queryExample = new QueryExample();
// queryExample.getParams().put("ip",
// Pattern.compile(String.format("^.*%s.*$", keyword), Pattern.CASE_INSENSITIVE));
queryExample.getParams().put("hostname",
Pattern.compile(String.format("^.*%s.*$", keyword), Pattern.CASE_INSENSITIVE));
if (StringUtils.isNotBlank(workspace)) {
Expand Down Expand Up @@ -245,6 +252,15 @@ public SearchKeywordRet searchAlarmEntity(String keyword, String tenant, String
return genSearchResult("alarm", alarmRuleService.getListByKeyword(keyword, tenant, workspace));
}

public SearchKeywordRet searchLogMetricEntity(String keyword, String tenant, String workspace) {
List<MetricInfoDTO> listByKeyword =
metricInfoService.getListByKeyword(keyword, tenant, workspace);
List<MetricInfoDTO> logList =
listByKeyword.stream().filter(item -> item.getProduct().equalsIgnoreCase("logmonitor"))
.collect(Collectors.toList());
return genSearchResult("logMetric", logList);
}

public SearchKeywordRet genSearchResult(String type, List<?> datas) {
SearchKeywordRet skr = new SearchKeywordRet();
skr.count = datas.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import lombok.Data;

import java.util.Map;

/**
* @author wangsiyuan
* @date 2022/8/16 7:00 下午
Expand All @@ -15,4 +17,6 @@ public class TagQueryRequest {
private String metric;

private String key;

private Map<String, String> conditions;
}

0 comments on commit 4c88d71

Please sign in to comment.