From 4c88d71fa6c83d8ac28079710e1296daeeeaee29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9C=84=E9=B8=BF?= Date: Thu, 20 Jul 2023 12:46:49 +0800 Subject: [PATCH] refactor(home): add conditons when query tagvalues --- .../common/service/MetricInfoService.java | 2 ++ .../common/service/MetricInfoServiceImpl.java | 16 ++++++++++++++ .../impl/DefaultTenantInitServiceImpl.java | 3 ++- .../home/web/controller/QueryFacadeImpl.java | 8 +++++++ .../home/web/controller/SearchFacadeImpl.java | 22 ++++++++++++++++--- .../web/controller/model/TagQueryRequest.java | 4 ++++ 6 files changed, 51 insertions(+), 4 deletions(-) diff --git a/server/common/common-service/src/main/java/io/holoinsight/server/common/service/MetricInfoService.java b/server/common/common-service/src/main/java/io/holoinsight/server/common/service/MetricInfoService.java index a9114e03a..85818b039 100644 --- a/server/common/common-service/src/main/java/io/holoinsight/server/common/service/MetricInfoService.java +++ b/server/common/common-service/src/main/java/io/holoinsight/server/common/service/MetricInfoService.java @@ -30,4 +30,6 @@ public interface MetricInfoService extends IService { Map querySpmList(); + List getListByKeyword(String keyword, String tenant, String workspace); + } diff --git a/server/common/common-service/src/main/java/io/holoinsight/server/common/service/MetricInfoServiceImpl.java b/server/common/common-service/src/main/java/io/holoinsight/server/common/service/MetricInfoServiceImpl.java index 0db997f22..a657e8d3d 100644 --- a/server/common/common-service/src/main/java/io/holoinsight/server/common/service/MetricInfoServiceImpl.java +++ b/server/common/common-service/src/main/java/io/holoinsight/server/common/service/MetricInfoServiceImpl.java @@ -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; @@ -148,4 +149,19 @@ public Map querySpmList() { }); return map; } + + @Override + public List getListByKeyword(String keyword, String tenant, String workspace) { + QueryWrapper 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)); + } } 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 7fb062f2f..25870da2f 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 @@ -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; @@ -62,7 +63,7 @@ public Map getTenantWorkspaceMetaConditions(String workspace) { @Override public List getTenantFilters(String workspace) { - return null; + return new ArrayList<>(); } @Override 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 2cf9fe303..a3050f564 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 @@ -298,6 +298,14 @@ public void doManage() { List 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); } diff --git a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/SearchFacadeImpl.java b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/SearchFacadeImpl.java index 1d6788374..0cc20a230 100644 --- a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/SearchFacadeImpl.java +++ b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/SearchFacadeImpl.java @@ -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; @@ -35,6 +37,7 @@ import java.util.Map; import java.util.concurrent.Future; import java.util.regex.Pattern; +import java.util.stream.Collectors; /** * @@ -60,6 +63,9 @@ public class SearchFacadeImpl extends BaseFacade { @Autowired private AlertRuleService alarmRuleService; + @Autowired + private MetricInfoService metricInfoService; + @Autowired private DataClientService dataClientService; @@ -89,7 +95,6 @@ public void doManage() { List ret = new ArrayList<>(); List> futures = new ArrayList<>(); futures.add(queryThreadPool.submit(() -> { - log.info(">>>>>, " + tenant + ", ..... , " + workspace); return searchLogEntity(req.keyword, tenant, workspace); })); @@ -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 future : futures) { try { @@ -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)) { @@ -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 listByKeyword = + metricInfoService.getListByKeyword(keyword, tenant, workspace); + List 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(); diff --git a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/model/TagQueryRequest.java b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/model/TagQueryRequest.java index 4a573fff1..a405f361d 100644 --- a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/model/TagQueryRequest.java +++ b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/model/TagQueryRequest.java @@ -5,6 +5,8 @@ import lombok.Data; +import java.util.Map; + /** * @author wangsiyuan * @date 2022/8/16 7:00 下午 @@ -15,4 +17,6 @@ public class TagQueryRequest { private String metric; private String key; + + private Map conditions; }