From f7714fe85436cefaf4e4ff7a0873890a80eb29d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9C=84=E9=B8=BF?= Date: Thu, 29 Feb 2024 14:10:23 +0800 Subject: [PATCH] refactor: add md5 in alarmRule --- .../common/service/MetricInfoService.java | 2 ++ .../common/service/MetricInfoServiceImpl.java | 16 +++++++++ .../server/home/facade/AlertRuleExtra.java | 1 + .../home/biz/service/AlertRuleService.java | 4 +++ .../service/impl/AlertRuleServiceImpl.java | 36 +++++++++++++++++++ .../controller/CustomPluginFacadeImpl.java | 27 +++++++++++++- 6 files changed, 85 insertions(+), 1 deletion(-) 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 d0d29e130..b8a5ece31 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 @@ -28,6 +28,8 @@ public interface MetricInfoService extends IService { List queryListByTenantProduct(String tenant, String workspace, String product); + List queryListByRef(String tenant, String workspace, String product, String ref); + MetricInfoDTO queryByMetric(String tenant, String workspace, String metric); Map querySpmList(); 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 b83119238..118aa98b0 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 @@ -96,6 +96,22 @@ public List queryListByTenantProduct(String tenant, String worksp return metricInfoConverter.dosToDTOs(metricInfos); } + @Override + public List queryListByRef(String tenant, String workspace, String product, + String ref) { + Map columnMap = new HashMap<>(); + columnMap.put("tenant", tenant); + columnMap.put("workspace", workspace); + columnMap.put("product", product); + columnMap.put("ref", ref); + columnMap.put("deleted", 0); + List metricInfos = listByMap(columnMap); + if (CollectionUtils.isEmpty(metricInfos)) { + return null; + } + return metricInfoConverter.dosToDTOs(metricInfos); + } + @Override public MetricInfoDTO queryByMetric(String tenant, String workspace, String metric) { Map columnMap = new HashMap<>(); diff --git a/server/home/home-facade/src/main/java/io/holoinsight/server/home/facade/AlertRuleExtra.java b/server/home/home-facade/src/main/java/io/holoinsight/server/home/facade/AlertRuleExtra.java index a82b851f0..95e703f20 100644 --- a/server/home/home-facade/src/main/java/io/holoinsight/server/home/facade/AlertRuleExtra.java +++ b/server/home/home-facade/src/main/java/io/holoinsight/server/home/facade/AlertRuleExtra.java @@ -18,6 +18,7 @@ public class AlertRuleExtra { public List alertTags; public Map tagAlias; public boolean isRecord; + public String md5; public AlertSilenceConfig alertSilenceConfig; public NotificationTemplate getDingTalkTemplate() { diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/AlertRuleService.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/AlertRuleService.java index a73a86a64..312c55676 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/AlertRuleService.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/AlertRuleService.java @@ -25,6 +25,10 @@ public interface AlertRuleService extends IService { AlarmRuleDTO queryById(Long id, String tenant, String workspace); + List queryBySourceType(String sourceType, String tenant, String workspace); + + List queryBySourceId(Long sourceId); + MonitorPageResult getListByPage(MonitorPageRequest pageRequest); List getListByKeyword(String keyword, String tenant, String workspace); diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/AlertRuleServiceImpl.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/AlertRuleServiceImpl.java index 5a4a0def4..7f58006a8 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/AlertRuleServiceImpl.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/AlertRuleServiceImpl.java @@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import io.holoinsight.server.common.J; +import io.holoinsight.server.common.MD5Hash; import io.holoinsight.server.home.biz.service.AlertBlockService; import io.holoinsight.server.home.biz.service.AlertRuleService; import io.holoinsight.server.home.common.service.RequestContextAdapter; @@ -15,9 +17,11 @@ import io.holoinsight.server.home.dal.model.AlarmBlock; import io.holoinsight.server.home.dal.model.AlarmRule; import io.holoinsight.server.home.facade.AlarmRuleDTO; +import io.holoinsight.server.home.facade.AlertRuleExtra; import io.holoinsight.server.home.facade.page.MonitorPageRequest; import io.holoinsight.server.home.facade.page.MonitorPageResult; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import javax.annotation.Resource; @@ -45,6 +49,10 @@ public class AlertRuleServiceImpl extends ServiceImpl queryBySourceType(String sourceType, String tenant, String workspace) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("tenant", tenant); + wrapper.eq("workspace", workspace); + wrapper.eq("source_type", sourceType); + return alarmRuleConverter.dosToDTOs(this.baseMapper.selectList(wrapper)); + } + + @Override + public List queryBySourceId(Long sourceId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("source_id", sourceId); + return alarmRuleConverter.dosToDTOs(this.baseMapper.selectList(wrapper)); + } @Override public MonitorPageResult getListByPage( diff --git a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/CustomPluginFacadeImpl.java b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/CustomPluginFacadeImpl.java index 39acbfe53..48f374525 100644 --- a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/CustomPluginFacadeImpl.java +++ b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/CustomPluginFacadeImpl.java @@ -4,6 +4,8 @@ package io.holoinsight.server.home.web.controller; import io.holoinsight.server.common.UtilMisc; +import io.holoinsight.server.common.dao.entity.dto.MetricInfoDTO; +import io.holoinsight.server.common.service.MetricInfoService; import io.holoinsight.server.home.biz.plugin.core.LogPluginUtil; import io.holoinsight.server.home.biz.service.AlarmMetricService; import io.holoinsight.server.home.biz.service.CustomPluginService; @@ -75,6 +77,9 @@ public class CustomPluginFacadeImpl extends BaseFacade { @Autowired private AlarmMetricService alarmMetricService; + @Autowired + private MetricInfoService metricInfoService; + @Autowired private TenantInitService tenantInitService; @@ -294,12 +299,32 @@ public void doManage() { if (null == byId) { throw new MonitorException(ResultCodeEnum.CANNOT_FIND_RECORD, "can not find record"); } + + List metricInfoDTOS = metricInfoService.queryListByRef(ms.getTenant(), + ms.getWorkspace(), "logmonitor", String.valueOf(byId.getId())); + if (!CollectionUtils.isEmpty(metricInfoDTOS)) { + boolean checkHasAlarmMetric = false; + + for (MetricInfoDTO metricInfoDTO : metricInfoDTOS) { + List alarmMetrics = alarmMetricService + .queryByMetric(metricInfoDTO.getMetricTable(), ms.getTenant(), ms.getWorkspace()); + if (!CollectionUtils.isEmpty(alarmMetrics)) { + checkHasAlarmMetric = true; + break; + } + } + + if (checkHasAlarmMetric) { + throw new MonitorException(ResultCodeEnum.CANNOT_FIND_RECORD, + "This log configuration is associated with the alarm rule configuration. Delete the alarm rule first"); + } + } + customPluginService.deleteById(id); JsonResult.createSuccessResult(result, null); userOpLogService.append("custom_plugin", byId.getId(), OpType.DELETE, RequestContext.getContext().mu.getLoginName(), ms.getTenant(), ms.getWorkspace(), J.toJson(byId), null, null, "custom_plugin_delete"); - } }); return result;