diff --git a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/model/compute/ComputeTaskPackage.java b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/model/compute/ComputeTaskPackage.java index 933a2e958..1f6ec47c1 100644 --- a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/model/compute/ComputeTaskPackage.java +++ b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/model/compute/ComputeTaskPackage.java @@ -3,7 +3,6 @@ */ package io.holoinsight.server.home.alert.model.compute; -import io.holoinsight.server.home.dal.model.AlertNotifyRecord; import io.holoinsight.server.home.facade.AlertNotifyRecordDTO; import io.holoinsight.server.home.facade.InspectConfig; import lombok.Data; diff --git a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/model/event/AlertNotify.java b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/model/event/AlertNotify.java index 39120d356..26265e78e 100644 --- a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/model/event/AlertNotify.java +++ b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/model/event/AlertNotify.java @@ -145,7 +145,7 @@ public static AlertNotify eventInfoConvert(EventInfo eventInfo, InspectConfig in alertNotify.setAlertIp(AddressUtil.getHostAddress()); } } catch (Exception e) { - RecordSucOrFailNotify.alertNotifyProcess("event convert alert notify exception" + e, + RecordSucOrFailNotify.alertNotifyProcessFail("event convert alert notify exception" + e, "alert task compute", "event convert alert notify", alertNotify.getAlertNotifyRecord()); throw e; } diff --git a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/AlertNotifyHandler.java b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/AlertNotifyHandler.java index 19a00bf8b..ba61124b9 100644 --- a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/AlertNotifyHandler.java +++ b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/AlertNotifyHandler.java @@ -68,8 +68,8 @@ public void handle(List alertNotifies) { LOGGER.error( "[HoloinsightAlertInternalException][AlertNotifyHandler][1] {} fail to alert_notify_handle for {}", alertNotify.getTraceId(), e.getMessage(), e); - RecordSucOrFailNotify.alertNotifyProcess( - "fail to alert_notify_handle for " + e.getMessage(), NOTIFY_HANDLER, + RecordSucOrFailNotify.alertNotifyProcessFail( + "fail to alert notify handle for " + e.getMessage(), NOTIFY_HANDLER, "alert notify handle", alertNotify.getAlertNotifyRecord()); } finally { if (latch != null && alertNotify.isAlertRecord()) { @@ -90,7 +90,7 @@ public void handle(List alertNotifies) { } if (status) { LOGGER.info("alert notify record data size {} .", recordLatch.size()); - RecordSucOrFailNotify.batchInsert(recordLatch.getAlertNotifyRecordDTOList()); + // RecordSucOrFailNotify.batchInsert(recordLatch.getAlertNotifyRecordDTOList()); } LOGGER.info("alert_notification_notify_step size [{}]", count); diff --git a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/AlertSaveHistoryHandler.java b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/AlertSaveHistoryHandler.java index 697a7a174..64d72fd4d 100644 --- a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/AlertSaveHistoryHandler.java +++ b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/AlertSaveHistoryHandler.java @@ -390,8 +390,8 @@ private void makeAlertHistory(Map alertHistoryMap, RecordSucOrFailNotify.alertNotifyProcessSuc(SAVE_HISTORY, "save history", alertNotify.getAlertNotifyRecord()); } catch (Exception e) { - RecordSucOrFailNotify.alertNotifyProcess( - alertNotify.getTraceId() + "fail to alert_history_save for" + e.getMessage(), + RecordSucOrFailNotify.alertNotifyProcessFail( + alertNotify.getTraceId() + "fail to alert history save for" + e.getMessage(), SAVE_HISTORY, "save history", alertNotify.getAlertNotifyRecord()); LOGGER.error( "[HoloinsightAlertInternalException][AlertSaveHistoryHandler][1] {} fail to alert_history_save for {}", @@ -569,12 +569,12 @@ private void makeAlertRecover(Map alertHistoryDOMap, AlarmHistory alertHistory = alertHistoryDOMap.get(alertNotify.getUniqueId()); alertHistory.setRecoverTime(new Date(alertNotify.getAlarmTime())); alarmHistoryDOMapper.updateById(alertHistory); - RecordSucOrFailNotify.alertNotifyProcessSuc(SAVE_HISTORY, "save history is recover", + RecordSucOrFailNotify.alertNotifyProcessSuc(SAVE_HISTORY, "alert recover", alertNotify.getAlertNotifyRecord()); } catch (Exception e) { - RecordSucOrFailNotify.alertNotifyProcess( - alertNotify.getTraceId() + "fail to alert_recover_update for" + e.getMessage(), - SAVE_HISTORY, "save history is recover", alertNotify.getAlertNotifyRecord()); + RecordSucOrFailNotify.alertNotifyProcessFail( + alertNotify.getTraceId() + "fail to alert recover for" + e.getMessage(), SAVE_HISTORY, + "alert recover", alertNotify.getAlertNotifyRecord()); LOGGER.error( "[HoloinsightAlertInternalException][AlertSaveHistoryHandler][1] {} fail to alert_recover_update for {}", alertNotify.getTraceId(), e.getMessage(), e); diff --git a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/GatewayService.java b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/GatewayService.java index 4b1dcefd1..48dd7c474 100644 --- a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/GatewayService.java +++ b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/GatewayService.java @@ -73,16 +73,17 @@ public boolean sendAlertNotifyV3(AlertNotifyRequest notify, AlertNotifyRecordLat String type = defaultNotifyChain.name; if (CollectionUtils.isEmpty(notify.getNotifyDataInfos())) { LOGGER.info("{} notify data info is empty.", traceId); - RecordSucOrFailNotify.alertNotifyProcess(traceId + ": notify data info is empty ", GATEWAY, - "check notify data info", notify.getAlertNotifyRecord()); + RecordSucOrFailNotify.alertNotifyProcessFail(traceId + ": notify data info is empty ", + GATEWAY, "check notify data info", notify.getAlertNotifyRecord()); return true; } String ruleId = notify.getRuleId(); if (!StringUtils.isNumeric(ruleId)) { LOGGER.warn("{} invalid rule {}", traceId, ruleId); - RecordSucOrFailNotify.alertNotifyProcess(traceId + ": invalid rule fail; ruleId is " + ruleId, - GATEWAY, "invalid rule", notify.getAlertNotifyRecord()); + RecordSucOrFailNotify.alertNotifyProcessFail( + traceId + ": invalid rule fail; ruleId is " + ruleId, GATEWAY, "invalid rule", + notify.getAlertNotifyRecord()); return true; } @@ -99,7 +100,7 @@ public boolean sendAlertNotifyV3(AlertNotifyRequest notify, AlertNotifyRecordLat if (CollectionUtils.isEmpty(notifyChainList)) { LOGGER.info("{} {} notifyChainList is empty, skip.", traceId, ruleId); - RecordSucOrFailNotify.alertNotifyProcess(traceId + ": notifyChainList is empty, skip ", + RecordSucOrFailNotify.alertNotifyProcessFail(traceId + ": notifyChainList is empty, skip ", GATEWAY, " get notify chainList", notify.getAlertNotifyRecord()); return true; } @@ -108,8 +109,9 @@ public boolean sendAlertNotifyV3(AlertNotifyRequest notify, AlertNotifyRecordLat AlarmRuleDTO alertRule = this.alarmRuleConverter.doToDTO(rawRule); if (alertRule == null) { LOGGER.warn("{} can not find alarmRule by {}", traceId, ruleId); - RecordSucOrFailNotify.alertNotifyProcess(traceId + ": can not find alarmRule by " + ruleId, - GATEWAY, "find alarmRule", notify.getAlertNotifyRecord()); + RecordSucOrFailNotify.alertNotifyProcessFail( + traceId + ": can not find alarmRule by " + ruleId, GATEWAY, "find alarmRule", + notify.getAlertNotifyRecord()); return true; } diff --git a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/GetSubscriptionHandler.java b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/GetSubscriptionHandler.java index c2976261c..9d1356ac0 100644 --- a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/GetSubscriptionHandler.java +++ b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/GetSubscriptionHandler.java @@ -89,6 +89,8 @@ public void handle(List alertNotifies) { // 查询消息通知订阅关系 alertNotifies.parallelStream().forEach(alertNotify -> { + RecordSucOrFailNotify.alertNotifyProcessSuc(GET_SUBSCRIPTION, "query subscriber", + alertNotify.getAlertNotifyRecord()); try { QueryWrapper alertSubscribeQueryWrapper = new QueryWrapper<>(); alertSubscribeQueryWrapper.eq("unique_id", alertNotify.getUniqueId()); @@ -109,7 +111,6 @@ public void handle(List alertNotifies) { } if (!CollectionUtils.isEmpty(alertSubscribeList)) { - Set userIdList = new HashSet<>(); Set dingDingGroupIdList = new HashSet<>(); List webhookInfos = new ArrayList<>(); Map> userNotifyMap = new HashMap<>(); @@ -205,14 +206,20 @@ public void handle(List alertNotifies) { alertNotify.setDingdingUrl(dingdingUrls); } } - RecordSucOrFailNotify.alertNotifyProcessSuc(GET_SUBSCRIPTION, "query subscription", - alertNotify.getAlertNotifyRecord()); + + if (CollectionUtils.isEmpty(alertNotify.getUserNotifyMap()) + && CollectionUtils.isEmpty(alertNotify.getWebhookInfos()) + && CollectionUtils.isEmpty(alertNotify.getDingdingUrl())) { + RecordSucOrFailNotify.alertNotifyProcessFail("query subscriber is empty", + GET_SUBSCRIPTION, "query subscriber error", alertNotify.getAlertNotifyRecord()); + } } catch (Throwable e) { LOGGER.error( "[HoloinsightAlertInternalException][GetSubscriptionHandler][1] {} fail to get_subscription for {}", alertNotify.getTraceId(), e.getMessage(), e); - RecordSucOrFailNotify.alertNotifyProcess("fail to get_subscription for " + e.getMessage(), - GET_SUBSCRIPTION, "query subscription", alertNotify.getAlertNotifyRecord()); + RecordSucOrFailNotify.alertNotifyProcessFail( + "query subscriber is error, " + e.getMessage(), GET_SUBSCRIPTION, + "query subscriber error", alertNotify.getAlertNotifyRecord()); } }); LOGGER.info("[GetSubscriptionHandler][{}] finish to get_subscription.", alertNotifies.size()); @@ -239,8 +246,6 @@ private void handleBlock(List alertNotifies) { AlertNotify alertNotify = iterator.next(); if (alertNotify.getIsRecover()) { - RecordSucOrFailNotify.alertNotifyProcess("alertNotify is recover", GET_SUBSCRIPTION, - "remove block subscription", alertNotify.getAlertNotifyRecord()); iterator.remove(); LOGGER.info("{} alert rule {} has recovered.", alertNotify.getTraceId(), alertNotify.getUniqueId()); @@ -253,8 +258,6 @@ private void handleBlock(List alertNotifies) { } if (StringUtils.isEmpty(alertBlock.getTags()) || alertBlock.getTags().equals("{}")) { - RecordSucOrFailNotify.alertNotifyProcess("alertNotify is blocked", GET_SUBSCRIPTION, - "remove block subscription", alertNotify.getAlertNotifyRecord()); iterator.remove(); LOGGER.info("{} alert rule {} has been blocked.", alertNotify.getTraceId(), alertNotify.getUniqueId()); @@ -278,6 +281,8 @@ private void handleBlock(List alertNotifies) { if (matcher.find()) { LOGGER.info("{} pql alert rule {} tag {} {} has been blocked.", alertNotify.getTraceId(), alertNotify.getUniqueId(), key, value); + RecordSucOrFailNotify.alertNotifyProcessSuc(GET_SUBSCRIPTION, "alarm block", + alertNotify.getAlertNotifyRecord()); it.remove(); } } @@ -286,6 +291,8 @@ private void handleBlock(List alertNotifies) { if (CollectionUtils.isEmpty(pqlRule.getDataResult())) { LOGGER.info("{} pql alert rule {} has been blocked because all tags have been blocked.", alertNotify.getTraceId(), alertNotify.getUniqueId()); + RecordSucOrFailNotify.alertNotifyProcessSuc(GET_SUBSCRIPTION, "alarm block", + alertNotify.getAlertNotifyRecord()); iterator.remove(); } } else { @@ -304,6 +311,8 @@ private void handleBlock(List alertNotifies) { LOGGER.info("{} alert rule {} tag {} {} has been blocked.", alertNotify.getTraceId(), alertNotify.getUniqueId(), key, value); it.remove(); + RecordSucOrFailNotify.alertNotifyProcessSuc(GET_SUBSCRIPTION, "alarm block", + alertNotify.getAlertNotifyRecord()); } } }); @@ -315,15 +324,14 @@ private void handleBlock(List alertNotifies) { if (CollectionUtils.isEmpty(notifyDataInfos)) { LOGGER.info("{} alert rule {} has been blocked because all tags have been blocked.", alertNotify.getTraceId(), alertNotify.getUniqueId()); + RecordSucOrFailNotify.alertNotifyProcessSuc(GET_SUBSCRIPTION, "alarm block", + alertNotify.getAlertNotifyRecord()); iterator.remove(); } else { alertNotify.setNotifyDataInfos(notifyDataInfos); } } } - - RecordSucOrFailNotify.alertNotifyProcessSuc(GET_SUBSCRIPTION, "remove block subscription", - alertNotify.getAlertNotifyRecord()); } } diff --git a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/calculate/AbstractUniformInspectRunningRule.java b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/calculate/AbstractUniformInspectRunningRule.java index 16b29b10b..a4dd2a554 100644 --- a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/calculate/AbstractUniformInspectRunningRule.java +++ b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/calculate/AbstractUniformInspectRunningRule.java @@ -3,7 +3,6 @@ */ package io.holoinsight.server.home.alert.service.calculate; -import io.holoinsight.server.home.alert.common.G; import io.holoinsight.server.home.alert.model.compute.ComputeContext; import io.holoinsight.server.home.alert.model.compute.ComputeInfo; import io.holoinsight.server.home.alert.model.event.EventInfo; @@ -72,7 +71,7 @@ public EventInfo eval(ComputeContext context, events = runRule(inspectConfig, period, alertNotifyRecordDTOList); } } catch (Throwable ex) { - RecordSucOrFailNotify.alertNotifyProcess("AlertTaskCompute Exception: " + ex, + RecordSucOrFailNotify.alertNotifyProcessFail("AlertTaskCompute Exception: " + ex, ALERT_TASK_COMPUTE, "alert task compute", inspectConfig.getAlertNotifyRecord()); logger.error("ALERT_EXCEPTION_MONITOR inspectConfig {}, traceId: {} ", inspectConfig.getUniqueId(), traceId, ex); @@ -82,6 +81,19 @@ public EventInfo eval(ComputeContext context, public EventInfo runPqlRule(InspectConfig inspectConfig, long period, List alertNotifyRecordDTOList) { + + if (!inspectConfig.getIsPql() + || CollectionUtils.isEmpty(inspectConfig.getPqlRule().getDataResult())) { + // record pql rule alert + AlertNotifyRecordDTO alertNotifyRecordDTO = inspectConfig.getAlertNotifyRecord(); + if (Objects.nonNull(alertNotifyRecordDTO)) { + RecordSucOrFailNotify.alertNotifyNoEventGenerated("pql rule is empty", ALERT_TASK_COMPUTE, + "run pql rule", alertNotifyRecordDTO, null); + alertNotifyRecordDTOList.add(alertNotifyRecordDTO); + } + return null; + } + if (inspectConfig.getIsPql() && !CollectionUtils.isEmpty(inspectConfig.getPqlRule().getDataResult())) { EventInfo eventInfo = new EventInfo(); @@ -94,15 +106,13 @@ public EventInfo runPqlRule(InspectConfig inspectConfig, long period, Map> triggerMap = convertFromPql(inspectConfig.getPqlRule(), period, inspectConfig); eventInfo.setAlarmTriggerResults(triggerMap); + + RecordSucOrFailNotify.alertNotifyProcessSuc(ALERT_TASK_COMPUTE, "run pql rule", + inspectConfig.getAlertNotifyRecord()); + return eventInfo; } - // record pql rule alert - AlertNotifyRecordDTO alertNotifyRecordDTO = inspectConfig.getAlertNotifyRecord(); - if (Objects.nonNull(alertNotifyRecordDTO)) { - RecordSucOrFailNotify.alertNotifyNoEventGenerated("pql rule is empty", ALERT_TASK_COMPUTE, - "run pql rule", alertNotifyRecordDTO, null); - alertNotifyRecordDTOList.add(alertNotifyRecordDTO); - } + // 恢复时这里返回null return null; } @@ -190,6 +200,9 @@ public EventInfo runRule(InspectConfig inspectConfig, long period, eventInfo.setAlarmTime(period); eventInfo.setIsRecover(false); eventInfo.setEnvType(inspectConfig.getEnvType()); + + RecordSucOrFailNotify.alertNotifyProcessSuc(ALERT_TASK_COMPUTE, "run rule", + inspectConfig.getAlertNotifyRecord()); return eventInfo; } // record no alarm event generated data diff --git a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/calculate/AlertTaskCompute.java b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/calculate/AlertTaskCompute.java index 3779e4b95..56a97b401 100644 --- a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/calculate/AlertTaskCompute.java +++ b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/calculate/AlertTaskCompute.java @@ -198,9 +198,9 @@ protected List calculate(ComputeTaskPackage computeTaskPackage) { inspectConfig.getAlertNotifyRecord()); } latch.await(30, TimeUnit.SECONDS); - if (!CollectionUtils.isEmpty(alertNotifyRecordDTOList)) { - RecordSucOrFailNotify.batchInsert(alertNotifyRecordDTOList); - } + // if (!CollectionUtils.isEmpty(alertNotifyRecordDTOList)) { + // RecordSucOrFailNotify.batchInsert(alertNotifyRecordDTOList); + // } } catch (Exception e) { LOGGER.error("AlertTaskCompute Exception", e); } diff --git a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/data/AlarmDataSet.java b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/data/AlarmDataSet.java index b476d8971..1c7e33ad3 100644 --- a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/data/AlarmDataSet.java +++ b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/data/AlarmDataSet.java @@ -10,6 +10,7 @@ import io.holoinsight.server.home.facade.PqlRule; import io.holoinsight.server.home.facade.Rule; import io.holoinsight.server.home.facade.trigger.Trigger; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,6 +25,7 @@ * @date 2022/2/22 4:51 下午 */ @Service +@Slf4j public class AlarmDataSet { private static Logger LOGGER = LoggerFactory.getLogger(AlarmDataSet.class); @@ -46,6 +48,7 @@ public void loadData(ComputeTaskPackage computeTaskPackage) { } computeTaskPackage.getInspectConfigs().parallelStream().forEach(inspectConfig -> { + // 处理pql告警逻辑 if (inspectConfig.getIsPql()) { try { @@ -56,21 +59,24 @@ public void loadData(ComputeTaskPackage computeTaskPackage) { pqlRule.setDataResult(result); inspectConfig.setPqlRule(pqlRule); } - RecordSucOrFailNotify.alertNotifyProcessSuc(ALERT_TASK_COMPUTE, "Pql query", + + RecordSucOrFailNotify.alertNotifyProcessSuc(ALERT_TASK_COMPUTE, "pql query", inspectConfig.getAlertNotifyRecord()); } catch (Exception exception) { - RecordSucOrFailNotify.alertNotifyProcess("Pql query Exception: " + exception, - ALERT_TASK_COMPUTE, "Pql query", inspectConfig.getAlertNotifyRecord()); + RecordSucOrFailNotify.alertNotifyProcessFail("pql query Exception: " + exception, + ALERT_TASK_COMPUTE, "pql query", inspectConfig.getAlertNotifyRecord()); LOGGER.error("Pql query Exception", exception); } - } - // 处理current&ai告警逻辑 - else { + } else { + // 处理rule&ai告警逻辑 Rule rule = inspectConfig.getRule(); if (rule == null || CollectionUtils.isEmpty(rule.getTriggers())) { return; } + boolean notifySuccess = true; for (Trigger trigger : rule.getTriggers()) { + if (null == trigger || null == trigger.getType()) + continue; try { // 接入统一数据源,查询数据信息 alarmLoadData = loadDataFactory.getLoadDataService(trigger.getType().getType()); @@ -79,12 +85,15 @@ public void loadData(ComputeTaskPackage computeTaskPackage) { trigger.setDataResult(dataResults); } catch (Exception exception) { LOGGER.error("AlarmLoadData Exception", exception); - RecordSucOrFailNotify.alertNotifyProcess("alarm load data Exception: " + exception, + RecordSucOrFailNotify.alertNotifyProcessFail("alarm load data Exception: " + exception, ALERT_TASK_COMPUTE, "alarm load data", inspectConfig.getAlertNotifyRecord()); + notifySuccess = false; } } - RecordSucOrFailNotify.alertNotifyProcessSuc(ALERT_TASK_COMPUTE, "alarm load data", - inspectConfig.getAlertNotifyRecord()); + if (notifySuccess) { + RecordSucOrFailNotify.alertNotifyProcessSuc(ALERT_TASK_COMPUTE, "alarm load data", + inspectConfig.getAlertNotifyRecord()); + } } }); diff --git a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/event/RecordSucOrFailNotify.java b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/event/RecordSucOrFailNotify.java index 010e914cc..463bd0fc5 100644 --- a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/event/RecordSucOrFailNotify.java +++ b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/event/RecordSucOrFailNotify.java @@ -9,8 +9,6 @@ import io.holoinsight.server.home.biz.common.MetaDictUtil; import io.holoinsight.server.home.biz.service.AlertNotifyRecordService; import io.holoinsight.server.home.common.service.SpringContext; -import io.holoinsight.server.home.dal.mapper.AlertNotifyRecordMapper; -import io.holoinsight.server.home.dal.model.AlertNotifyRecord; import io.holoinsight.server.home.facade.AlertNotifyRecordDTO; import io.holoinsight.server.home.facade.InspectConfig; import io.holoinsight.server.home.facade.NotifyErrorMsg; @@ -21,7 +19,6 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; -import org.springframework.beans.BeanUtils; import org.springframework.util.CollectionUtils; import java.util.ArrayList; @@ -40,8 +37,6 @@ */ @Slf4j public class RecordSucOrFailNotify { - private static AlertNotifyRecordMapper alertNotifyRecordMapper = - SpringContext.getBean(AlertNotifyRecordMapper.class); private static AlertNotifyRecordService alertNotifyRecordService = SpringContext.getBean(AlertNotifyRecordService.class); @@ -55,6 +50,42 @@ private static boolean recordEnable() { return StringUtils.isNotEmpty(enable) && StringUtils.equals(enable, "true"); } + + public static void alertNotifyMigrate(ComputeTaskPackage computeTaskPackage) { + if (Objects.isNull(computeTaskPackage) + || Objects.isNull(computeTaskPackage.getAlertNotifyRecord())) { + log.warn("alertNotifyMigrate record fail. computeTaskPackage or alertNotifyRecord is null"); + return; + } + try { + AlertNotifyRecordDTO alertNotifyRecord = computeTaskPackage.getAlertNotifyRecord(); + List inspectConfigs = computeTaskPackage.getInspectConfigs(); + List inspectConfigList = new ArrayList<>(); + + for (int i = 0; i < inspectConfigs.size(); i++) { + + InspectConfig inspectConfig = inspectConfigs.get(i); + List notifyStage = new ArrayList<>(alertNotifyRecord.getNotifyStage()); + AlertNotifyRecordDTO alertNotifyRecordDTO = new AlertNotifyRecordDTO(); + alertNotifyRecordDTO.setGmtCreate(alertNotifyRecord.getGmtCreate()); + alertNotifyRecordDTO.setIsSuccess(alertNotifyRecord.getIsSuccess()); + alertNotifyRecordDTO.setTraceId(alertNotifyRecord.getTraceId()); + alertNotifyRecordDTO.setNotifyStage(notifyStage); + alertNotifyRecordDTO.setIsRecord(inspectConfig.isAlertRecord()); + alertNotifyRecordDTO.setTenant(inspectConfig.getTenant()); + alertNotifyRecordDTO.setUniqueId(inspectConfig.getUniqueId()); + alertNotifyRecordDTO.setRuleName(inspectConfig.getRuleName()); + alertNotifyRecordDTO.setEnvType(inspectConfig.getEnvType()); + + inspectConfig.setAlertNotifyRecord(alertNotifyRecordDTO); + inspectConfigList.add(inspectConfig); + } + computeTaskPackage.setInspectConfigs(inspectConfigList); + } catch (Exception e) { + log.error("{} alertNotifyMigrate record fail.", computeTaskPackage.getTraceId(), e); + } + } + public static void alertNotifyChannelFail(String errorNode, String notifyChannel, AlertNotifyRecordDTO alertNotifyRecord, String notifyUser) { if (!recordEnable()) { @@ -74,14 +105,9 @@ public static void alertNotifyChannelFail(String errorNode, String notifyChannel alertNotifyRecord.setNotifyErrorTime(new Date()); alertNotifyRecord.setIsSuccess((byte) 0); - alertNotifyRecord.setExtra(J.toJson(notifyStageList)); - alertNotifyRecord.setNotifyErrorNode(J.toJson(notifyErrorMsgList)); - alertNotifyRecord.setNotifyChannel(J.toJson(alertNotifyRecord.getNotifyChannelList())); - alertNotifyRecord.setNotifyUser(J.toJson(alertNotifyRecord.getNotifyUserList())); - - AlertNotifyRecord alertNotifyRecord1 = new AlertNotifyRecord(); - BeanUtils.copyProperties(alertNotifyRecord, alertNotifyRecord1); - alertNotifyRecordMapper.insert(alertNotifyRecord1); + alertNotifyRecord.setNotifyErrorNode(notifyErrorMsgList); + + alertNotifyRecordService.insert(alertNotifyRecord); } } catch (Exception e) { log.error("{} {} {} {} {} record fail. ", alertNotifyRecord.getTraceId(), @@ -99,10 +125,9 @@ private static List buildErrorMsg(String errorNode, String notif NotifyErrorMsg notifyErrorMsg = new NotifyErrorMsg(); notifyErrorMsg.setNotifyType(notifyChannel); notifyErrorMsg.setErrMsg(errorNode); - notifyErrorMsg.setIsSuccess(false); notifyErrorMsg.setAddress(address); notifyErrorMsg.setNotifyUser(notifyUser); - List notifyErrorMsgList = alertNotifyRecord.getNotifyErrorMsgList(); + List notifyErrorMsgList = alertNotifyRecord.getNotifyErrorNode(); if (CollectionUtils.isEmpty(notifyErrorMsgList)) { notifyErrorMsgList = new ArrayList<>(); } @@ -110,8 +135,11 @@ private static List buildErrorMsg(String errorNode, String notif return notifyErrorMsgList; } - public static void alertNotifySuccess(String notifyChannel, + public static void alertNotifyChannelSuccess(String notifyChannel, AlertNotifyRecordDTO alertNotifyRecord, String user) { + if (!recordEnable()) { + return; + } if (Objects.isNull(alertNotifyRecord)) { log.warn("{} {} record fail. alertNotifyRecord is null", NOTIFY_CHAIN, notifyChannel); return; @@ -121,7 +149,10 @@ public static void alertNotifySuccess(String notifyChannel, List notifyStageList = alertNotifyRecord.getNotifyStage(); buildNotifyStage(notifyStageList, NOTIFY_CHAIN, notifyChannel, true); alertNotifyRecord.setNotifyStage(notifyStageList); + buildChannelAndUser(notifyChannel, alertNotifyRecord, user); + alertNotifyRecord.setNotifyErrorNode(new ArrayList<>()); + alertNotifyRecordService.insert(alertNotifyRecord); } } catch (Exception e) { log.error("{} {} {} {} record fail. ", alertNotifyRecord.getTraceId(), @@ -142,11 +173,12 @@ public static void alertNotifyNoEventGenerated(String errorNode, String stage, S List notifyErrorMsgList = buildErrorMsg(errorNode, "", alertNotifyRecord, ""); alertNotifyRecord.setNotifyStage(notifyStageList); - alertNotifyRecord.setNotifyErrorMsgList(notifyErrorMsgList); + alertNotifyRecord.setNotifyErrorNode(notifyErrorMsgList); alertNotifyRecord.setIsSuccess((byte) 1); - alertNotifyRecord.setNotifyErrorTime(new Date()); alertNotifyRecord.setTriggerResult(J.toJson(noEventGeneratedList)); } + log.info("{} {} {} {} no alarm event generated, {}", alertNotifyRecord.getTraceId(), + alertNotifyRecord.getUniqueId(), stage, step, errorNode); } catch (Exception e) { log.error("{} {} {} {} record fail. ", alertNotifyRecord.getTraceId(), alertNotifyRecord.getUniqueId(), stage, step, e); @@ -155,29 +187,18 @@ public static void alertNotifyNoEventGenerated(String errorNode, String stage, S private static void buildChannelAndUser(String notifyChannel, AlertNotifyRecordDTO alertNotifyRecord, String user) { - List notifyUserList = alertNotifyRecord.getNotifyUserList(); - if (CollectionUtils.isEmpty(notifyUserList)) { - notifyUserList = new ArrayList<>(); - } NotifyUser notifyUser = new NotifyUser(); notifyUser.setNotifyChannel(notifyChannel); notifyUser.setUser(user); - if (!notifyUserList.contains(notifyUser)) { - notifyUserList.add(notifyUser); - alertNotifyRecord.setNotifyUserList(notifyUserList); - } - List notifyChannelList = alertNotifyRecord.getNotifyChannelList(); - if (CollectionUtils.isEmpty(notifyChannelList)) { - notifyChannelList = new ArrayList<>(); - } - if (!notifyChannelList.contains(notifyChannel)) { - notifyChannelList.add(notifyChannel); - alertNotifyRecord.setNotifyChannelList(notifyChannelList); - } + List notifyUserList = new ArrayList<>(); + notifyUserList.add(notifyUser); + + alertNotifyRecord.setNotifyUser(notifyUserList); + alertNotifyRecord.setNotifyChannel(notifyChannel); } - public static void alertNotifyProcess(String errorNode, String stage, String step, + public static void alertNotifyProcessFail(String errorNode, String stage, String step, AlertNotifyRecordDTO alertNotifyRecord) { if (!recordEnable()) { return; @@ -193,19 +214,16 @@ public static void alertNotifyProcess(String errorNode, String stage, String ste buildNotifyStage(notifyStageList, stage, step, false); NotifyErrorMsg notifyErrorMsg = new NotifyErrorMsg(); - notifyErrorMsg.setNotifyType("default"); + notifyErrorMsg.setNotifyType("-"); notifyErrorMsg.setErrMsg(errorNode); - notifyErrorMsg.setIsSuccess(false); notifyErrorMsg.setAddress(address); List notifyErrorMsgList = new ArrayList<>(); notifyErrorMsgList.add(notifyErrorMsg); + alertNotifyRecord.setNotifyStage(notifyStageList); - alertNotifyRecord.setExtra(J.toJson(notifyStageList)); - alertNotifyRecord.setNotifyErrorNode(J.toJson(notifyErrorMsgList)); + alertNotifyRecord.setNotifyErrorNode(notifyErrorMsgList); alertNotifyRecord.setIsSuccess((byte) 0); - AlertNotifyRecord alertNotifyRecord1 = new AlertNotifyRecord(); - BeanUtils.copyProperties(alertNotifyRecord, alertNotifyRecord1); - alertNotifyRecordMapper.insert(alertNotifyRecord1); + alertNotifyRecordService.insert(alertNotifyRecord); } } catch (Exception e) { log.error("{} {} {} {} record fail. ", alertNotifyRecord.getTraceId(), @@ -269,35 +287,12 @@ public static void alertNotifyProcessSuc(String stage, String step, } } + public static void alertNotifyFailAppendMsg(String errorNode, String notifyChannel, + AlertNotifyRecordDTO alertNotifyRecord, String notifyUser) { - public static void alertNotifyMigrate(ComputeTaskPackage computeTaskPackage) { - if (Objects.isNull(computeTaskPackage) - || Objects.isNull(computeTaskPackage.getAlertNotifyRecord())) { - log.warn("alertNotifyMigrate record fail. computeTaskPackage or alertNotifyRecord is null"); + if (!recordEnable()) { return; } - try { - AlertNotifyRecordDTO alertNotifyRecord = computeTaskPackage.getAlertNotifyRecord(); - List inspectConfigs = computeTaskPackage.getInspectConfigs(); - List inspectConfigList = new ArrayList<>(); - for (int i = 0; i < inspectConfigs.size(); i++) { - AlertNotifyRecordDTO alertNotifyRecordDTO = new AlertNotifyRecordDTO(); - BeanUtils.copyProperties(alertNotifyRecord, alertNotifyRecordDTO); - InspectConfig inspectConfig = inspectConfigs.get(i); - BeanUtils.copyProperties(inspectConfig, alertNotifyRecordDTO); - alertNotifyRecordDTO.setIsRecord(inspectConfig.isAlertRecord()); - inspectConfig.setAlertNotifyRecord(alertNotifyRecordDTO); - log.info("alertNotifyRecord switch :{}", alertNotifyRecordDTO.getIsRecord()); - inspectConfigList.add(inspectConfig); - } - computeTaskPackage.setInspectConfigs(inspectConfigList); - } catch (Exception e) { - log.error("{} alertNotifyMigrate record fail.", computeTaskPackage.getTraceId(), e); - } - } - - public static void alertNotifyFailAppendMsg(String errorNode, String notifyChannel, - AlertNotifyRecordDTO alertNotifyRecord, String notifyUser) { if (Objects.isNull(alertNotifyRecord)) { log.warn("{} {} {} record fail. alertNotifyRecord is null", NOTIFY_CHAIN, notifyChannel, errorNode); @@ -313,8 +308,10 @@ public static void alertNotifyFailAppendMsg(String errorNode, String notifyChann List notifyErrorMsgList = buildErrorMsg(errorNode, notifyChannel, alertNotifyRecord, notifyUser); - alertNotifyRecord.setNotifyErrorNode(J.toJson(notifyErrorMsgList)); + alertNotifyRecord.setNotifyErrorNode(notifyErrorMsgList); alertNotifyRecord.setIsSuccess((byte) 0); + + alertNotifyRecordService.insert(alertNotifyRecord); } } catch (Exception e) { log.error("{} {} {} {} {} record fail. ", alertNotifyRecord.getTraceId(), @@ -322,36 +319,23 @@ public static void alertNotifyFailAppendMsg(String errorNode, String notifyChann } } - public static void batchInsert(List alertNotifyRecordDTOList) { - if (!recordEnable()) { - return; - } - try { - List alertNotifyRecords = new ArrayList<>(); - if (!CollectionUtils.isEmpty(alertNotifyRecordDTOList)) { - alertNotifyRecordDTOList.forEach(alertNotifyRecord -> { - if (Objects.nonNull(alertNotifyRecord) && alertNotifyRecord.getIsRecord()) { - alertNotifyRecord.setExtra(J.toJson(alertNotifyRecord.getNotifyStage())); - alertNotifyRecord.setNotifyUser(J.toJson(alertNotifyRecord.getNotifyUserList())); - alertNotifyRecord - .setNotifyErrorNode(J.toJson(alertNotifyRecord.getNotifyErrorMsgList())); - alertNotifyRecord.setNotifyChannel(J.toJson(alertNotifyRecord.getNotifyChannelList())); - alertNotifyRecord.setNotifyUser(J.toJson(alertNotifyRecord.getNotifyUserList())); - - AlertNotifyRecord alertNotifyRecord1 = new AlertNotifyRecord(); - BeanUtils.copyProperties(alertNotifyRecord, alertNotifyRecord1); - alertNotifyRecords.add(alertNotifyRecord1); - } - }); - } else { - log.warn("batch insert record fail. alertNotifyRecordDTOList is null"); - return; - } - log.info("batch insert data size {}", alertNotifyRecords.size()); - alertNotifyRecordService.saveBatch(alertNotifyRecords); - } catch (Exception e) { - log.error("batch insert record fail. {}", e.getMessage(), e); - } - - } + // public static void batchInsert(List alertNotifyRecordDTOList) { + // if (!recordEnable()) { + // return; + // } + // try { + // if (!CollectionUtils.isEmpty(alertNotifyRecordDTOList)) { + // alertNotifyRecordDTOList.forEach(alertNotifyRecord -> { + // if (Objects.nonNull(alertNotifyRecord) && alertNotifyRecord.getIsRecord()) { + // alertNotifyRecordService.insert(alertNotifyRecord); + // } + // }); + // } else { + // log.warn("batch insert record fail. alertNotifyRecordDTOList is null"); + // } + // } catch (Exception e) { + // log.error("batch insert record fail. {}", e.getMessage(), e); + // } + // + // } } diff --git a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/task/AlertTaskScheduler.java b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/task/AlertTaskScheduler.java index e8a445aaf..f03859224 100644 --- a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/task/AlertTaskScheduler.java +++ b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/task/AlertTaskScheduler.java @@ -135,7 +135,7 @@ public void execute(JobExecutionContext context) throws JobExecutionException { break; } } catch (Throwable e) { - RecordSucOrFailNotify.alertNotifyProcess( + RecordSucOrFailNotify.alertNotifyProcessFail( "fail to consume compute task for {}" + e.getMessage(), ALERT_TASK_SCHEDULE, "consume compute task", alertNotifyRecordDTO); logger.error("fail to consume compute task for {}", e.getMessage(), e); diff --git a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/task/CacheAlertTask.java b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/task/CacheAlertTask.java index e56cfd720..068e92d0c 100644 --- a/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/task/CacheAlertTask.java +++ b/server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/service/task/CacheAlertTask.java @@ -10,7 +10,6 @@ import io.holoinsight.server.home.alert.service.converter.DoConvert; import io.holoinsight.server.home.alert.service.data.CacheData; import io.holoinsight.server.home.alert.service.event.RecordSucOrFailNotify; -import io.holoinsight.server.home.biz.service.CustomPluginService; import io.holoinsight.server.home.dal.mapper.AlarmRuleMapper; import io.holoinsight.server.home.dal.model.AlarmRule; import io.holoinsight.server.home.facade.AlertNotifyRecordDTO; @@ -19,7 +18,6 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -63,9 +61,6 @@ public class CacheAlertTask { @Resource private CacheData cacheData; - @Autowired - private CustomPluginService customPluginService; - @Resource private MetricInfoMapper metricInfoMapper; private Map logPatternCache = new HashMap<>(); @@ -168,7 +163,7 @@ public ComputeTaskPackage convert(List alarmRules) { RecordSucOrFailNotify.alertNotifyProcessSuc(ALARM_CONFIG, "convert alarmRule", computeTaskPackage.getAlertNotifyRecord()); } catch (Exception e) { - RecordSucOrFailNotify.alertNotifyProcess("fail to convert alarmRule", ALARM_CONFIG, + RecordSucOrFailNotify.alertNotifyProcessFail("fail to convert alarmRule", ALARM_CONFIG, "convert alarmRule", computeTaskPackage.getAlertNotifyRecord()); LOGGER.error("{} [CRITICAL] fail to convert alarmRules", computeTaskPackage.getTraceId(), e); } diff --git a/server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/converter/AlertNotifyRecordConverter.java b/server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/converter/AlertNotifyRecordConverter.java index aa848aaed..acfc95be4 100644 --- a/server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/converter/AlertNotifyRecordConverter.java +++ b/server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/converter/AlertNotifyRecordConverter.java @@ -4,17 +4,24 @@ package io.holoinsight.server.home.dal.converter; import io.holoinsight.server.home.dal.model.AlertNotifyRecord; -import io.holoinsight.server.common.dao.transformer.MapJsonMapper; +import io.holoinsight.server.home.dal.transformer.AlertNotifyErrorCodeMapper; +import io.holoinsight.server.home.dal.transformer.AlertNotifyStageMapper; +import io.holoinsight.server.home.dal.transformer.AlertNotifyUserMapper; import io.holoinsight.server.home.facade.AlertNotifyRecordDTO; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import java.util.List; -@Mapper(componentModel = "spring", uses = {MapJsonMapper.class}) +@Mapper(componentModel = "spring", uses = {AlertNotifyUserMapper.class, + AlertNotifyErrorCodeMapper.class, AlertNotifyStageMapper.class}) public interface AlertNotifyRecordConverter { + @Mapping(target = "notifyStage", source = "extra") AlertNotifyRecordDTO doToDTO(AlertNotifyRecord alertNotifyRecord); + @Mapping(target = "extra", source = "notifyStage") AlertNotifyRecord dtoToDO(AlertNotifyRecordDTO target); + @Mapping(target = "notifyStage", source = "extra") List dosToDTOs(List records); } diff --git a/server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/transformer/AlertNotifyErrorCodeMapper.java b/server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/transformer/AlertNotifyErrorCodeMapper.java new file mode 100644 index 000000000..df7226af6 --- /dev/null +++ b/server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/transformer/AlertNotifyErrorCodeMapper.java @@ -0,0 +1,27 @@ +/* + * Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0. + */ + +package io.holoinsight.server.home.dal.transformer; + +import com.google.gson.reflect.TypeToken; +import io.holoinsight.server.common.J; +import io.holoinsight.server.home.facade.NotifyErrorMsg; + +import java.lang.reflect.Type; +import java.util.List; + +/** + * @author jsy1001de + * @version 1.0: AlertNotifyErrorCodeMapper.java, Date: 2023-12-20 Time: 13:50 + */ +public class AlertNotifyErrorCodeMapper { + public static String asString(List notifyErrorNode) { + return J.toJson(notifyErrorNode); + } + + public static List asObj(String notifyErrorNode) { + Type t = new TypeToken>() {}.getType(); + return J.fromJson(notifyErrorNode, t); + } +} diff --git a/server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/transformer/AlertNotifyStageMapper.java b/server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/transformer/AlertNotifyStageMapper.java new file mode 100644 index 000000000..add2d3c65 --- /dev/null +++ b/server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/transformer/AlertNotifyStageMapper.java @@ -0,0 +1,27 @@ +/* + * Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0. + */ + +package io.holoinsight.server.home.dal.transformer; + +import com.google.gson.reflect.TypeToken; +import io.holoinsight.server.common.J; +import io.holoinsight.server.home.facade.NotifyStage; + +import java.lang.reflect.Type; +import java.util.List; + +/** + * @author jsy1001de + * @version 1.0: AlertNotifyStageMapper.java, Date: 2023-12-20 Time: 13:50 + */ +public class AlertNotifyStageMapper { + public static String asString(List notifyStage) { + return J.toJson(notifyStage); + } + + public static List asObj(String extra) { + Type t = new TypeToken>() {}.getType(); + return J.fromJson(extra, t); + } +} diff --git a/server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/transformer/AlertNotifyUserMapper.java b/server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/transformer/AlertNotifyUserMapper.java new file mode 100644 index 000000000..996052302 --- /dev/null +++ b/server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/transformer/AlertNotifyUserMapper.java @@ -0,0 +1,27 @@ +/* + * Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0. + */ + +package io.holoinsight.server.home.dal.transformer; + +import com.google.gson.reflect.TypeToken; +import io.holoinsight.server.common.J; +import io.holoinsight.server.home.facade.NotifyUser; + +import java.lang.reflect.Type; +import java.util.List; + +/** + * @author jsy1001de + * @version 1.0: AlertNotifyUserMapper.java, Date: 2023-12-20 Time: 13:50 + */ +public class AlertNotifyUserMapper { + public static String asString(List notifyUser) { + return J.toJson(notifyUser); + } + + public static List asObj(String notifyUser) { + Type t = new TypeToken>() {}.getType(); + return J.fromJson(notifyUser, t); + } +} diff --git a/server/home/home-facade/src/main/java/io/holoinsight/server/home/facade/AlertNotifyRecordDTO.java b/server/home/home-facade/src/main/java/io/holoinsight/server/home/facade/AlertNotifyRecordDTO.java index 7b81a69a1..d210aa9bc 100644 --- a/server/home/home-facade/src/main/java/io/holoinsight/server/home/facade/AlertNotifyRecordDTO.java +++ b/server/home/home-facade/src/main/java/io/holoinsight/server/home/facade/AlertNotifyRecordDTO.java @@ -59,12 +59,12 @@ public class AlertNotifyRecordDTO { /** * notify target detail */ - private String notifyUser; + private List notifyUser; /** * exception node */ - private String notifyErrorNode; + private List notifyErrorNode; /** * tenant @@ -74,7 +74,7 @@ public class AlertNotifyRecordDTO { /** * alert compute detail */ - private String extra; + private List notifyStage; /** * env type @@ -89,13 +89,5 @@ public class AlertNotifyRecordDTO { private String triggerResult; - private List notifyStage; - - private List notifyChannelList; - - private List notifyErrorMsgList; - - private List notifyUserList; - private Boolean isRecord; } diff --git a/server/home/home-facade/src/main/java/io/holoinsight/server/home/facade/NotifyErrorMsg.java b/server/home/home-facade/src/main/java/io/holoinsight/server/home/facade/NotifyErrorMsg.java index 77317213e..ad6b05bbf 100644 --- a/server/home/home-facade/src/main/java/io/holoinsight/server/home/facade/NotifyErrorMsg.java +++ b/server/home/home-facade/src/main/java/io/holoinsight/server/home/facade/NotifyErrorMsg.java @@ -17,8 +17,6 @@ public class NotifyErrorMsg { private String errMsg; - private Boolean isSuccess; - private String address; private String notifyUser; diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/AlertNotifyRecordService.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/AlertNotifyRecordService.java index b3ad96d11..516658fd5 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/AlertNotifyRecordService.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/AlertNotifyRecordService.java @@ -15,4 +15,6 @@ AlertNotifyRecordDTO queryByHistoryDetailId(Long historyDetailId, String tenant, MonitorPageResult getListByPage( MonitorPageRequest pageRequest); + + void insert(AlertNotifyRecordDTO alertNotifyRecordDTO); } diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/AlertNotifyRecordServiceImpl.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/AlertNotifyRecordServiceImpl.java index 08ab7cb14..b7052ffa3 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/AlertNotifyRecordServiceImpl.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/AlertNotifyRecordServiceImpl.java @@ -3,27 +3,21 @@ */ package io.holoinsight.server.home.biz.service.impl; -import com.alibaba.fastjson.JSONArray; 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.home.biz.service.AlertNotifyRecordService; import io.holoinsight.server.home.common.service.RequestContextAdapter; -import io.holoinsight.server.home.dal.mapper.AlertNotifyRecordMapper; import io.holoinsight.server.home.dal.converter.AlertNotifyRecordConverter; +import io.holoinsight.server.home.dal.mapper.AlertNotifyRecordMapper; import io.holoinsight.server.home.dal.model.AlertNotifyRecord; import io.holoinsight.server.home.facade.AlertNotifyRecordDTO; -import io.holoinsight.server.home.facade.NotifyErrorMsg; -import io.holoinsight.server.home.facade.NotifyStage; -import io.holoinsight.server.home.facade.NotifyUser; 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.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -34,7 +28,7 @@ public class AlertNotifyRecordServiceImpl extends @Autowired private RequestContextAdapter requestContextAdapter; - @Resource + @Autowired private AlertNotifyRecordConverter alertNotifyRecordConverter; @Override @@ -46,9 +40,7 @@ public AlertNotifyRecordDTO queryByHistoryDetailId(Long historyDetailId, String wrapper.eq("history_detail_id", historyDetailId); wrapper.last("LIMIT 1"); AlertNotifyRecord alertNotifyRecord = this.getOne(wrapper); - AlertNotifyRecordDTO alertNotifyRecordDTO = - alertNotifyRecordConverter.doToDTO(alertNotifyRecord); - return alertNotifyRecordDTO; + return alertNotifyRecordConverter.doToDTO(alertNotifyRecord); } @Override @@ -71,7 +63,7 @@ public MonitorPageResult getListByPage( alertNotifyRecord.getWorkspace()); if (null != alertNotifyRecord.getNotifyErrorTime()) { - wrapper.like("notify_error_time", alertNotifyRecord.getNotifyErrorTime()); + wrapper.ge("notify_error_time", alertNotifyRecord.getNotifyErrorTime()); } if (StringUtils.isNotBlank(alertNotifyRecord.getNotifyChannel())) { @@ -82,10 +74,6 @@ public MonitorPageResult getListByPage( wrapper.like("rule_name", alertNotifyRecord.getRuleName().trim()); } - if (StringUtils.isNotBlank(alertNotifyRecord.getNotifyUser())) { - wrapper.likeRight("notify_user", alertNotifyRecord.getNotifyUser().trim()); - } - if (null != alertNotifyRecord.getHistoryId()) { wrapper.eq("history_id", alertNotifyRecord.getHistoryId()); } @@ -118,8 +106,8 @@ public MonitorPageResult getListByPage( MonitorPageResult pageResult = new MonitorPageResult<>(); - List alertNotifyRecordDTOList = recordConverter(page.getRecords()); - + List alertNotifyRecordDTOList = + alertNotifyRecordConverter.dosToDTOs(page.getRecords()); pageResult.setItems(alertNotifyRecordDTOList); pageResult.setPageNum(pageRequest.getPageNum()); @@ -130,51 +118,10 @@ public MonitorPageResult getListByPage( return pageResult; } - private List recordConverter(List records) { - if (records == null) { - return null; - } - - List list = new ArrayList(records.size()); - for (AlertNotifyRecord alertNotifyRecord : records) { - list.add(dTOConverter(alertNotifyRecord)); - } - - return list; - } - - private AlertNotifyRecordDTO dTOConverter(AlertNotifyRecord alertNotifyRecord) { - if (alertNotifyRecord == null) { - return null; - } + @Override + public void insert(AlertNotifyRecordDTO alertNotifyRecordDTO) { + AlertNotifyRecord alertNotifyRecord = alertNotifyRecordConverter.dtoToDO(alertNotifyRecordDTO); - AlertNotifyRecordDTO alertNotifyRecordDTO = new AlertNotifyRecordDTO(); - - alertNotifyRecordDTO.setId(alertNotifyRecord.getId()); - alertNotifyRecordDTO.setGmtCreate(alertNotifyRecord.getGmtCreate()); - alertNotifyRecordDTO.setGmtModified(alertNotifyRecord.getGmtModified()); - alertNotifyRecordDTO.setHistoryDetailId(alertNotifyRecord.getHistoryDetailId()); - alertNotifyRecordDTO.setHistoryId(alertNotifyRecord.getHistoryId()); - alertNotifyRecordDTO.setNotifyErrorTime(alertNotifyRecord.getNotifyErrorTime()); - alertNotifyRecordDTO.setIsSuccess(alertNotifyRecord.getIsSuccess()); - alertNotifyRecordDTO.setNotifyChannel(alertNotifyRecord.getNotifyChannel()); - alertNotifyRecordDTO.setNotifyUser(alertNotifyRecord.getNotifyUser()); - alertNotifyRecordDTO.setNotifyErrorNode(alertNotifyRecord.getNotifyErrorNode()); - alertNotifyRecordDTO.setTenant(alertNotifyRecord.getTenant()); - alertNotifyRecordDTO.setExtra(alertNotifyRecord.getExtra()); - alertNotifyRecordDTO.setEnvType(alertNotifyRecord.getEnvType()); - alertNotifyRecordDTO.setWorkspace(alertNotifyRecord.getWorkspace()); - alertNotifyRecordDTO.setUniqueId(alertNotifyRecord.getUniqueId()); - alertNotifyRecordDTO.setRuleName(alertNotifyRecord.getRuleName()); - alertNotifyRecordDTO.setTriggerResult(alertNotifyRecord.getTriggerResult()); - alertNotifyRecordDTO - .setNotifyStage(JSONArray.parseArray(alertNotifyRecord.getExtra(), NotifyStage.class)); - alertNotifyRecordDTO.setNotifyErrorMsgList( - JSONArray.parseArray(alertNotifyRecord.getNotifyErrorNode(), NotifyErrorMsg.class)); - alertNotifyRecordDTO.setNotifyChannelList( - JSONArray.parseArray(alertNotifyRecord.getNotifyChannel(), String.class)); - alertNotifyRecordDTO.setNotifyUserList( - JSONArray.parseArray(alertNotifyRecord.getNotifyUser(), NotifyUser.class)); - return alertNotifyRecordDTO; + this.save(alertNotifyRecord); } } 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 9ea8b186b..0771c6c6c 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 @@ -126,11 +126,12 @@ public void doManage() { QueryResponse response = queryClientService.query(convertRequest(request)); JsonResult.createSuccessResult(result, response); } catch (Throwable t) { + log.error("query error", t); if (t.getMessage().contains("Evaluated points num") && t.getMessage().contains("larger than")) { - throw new MonitorException(ResultCodeEnum.EXCEED_SERIES_LIMIT, t); + throw new MonitorException(ResultCodeEnum.EXCEED_SERIES_LIMIT, t.getMessage()); } - throw new MonitorException(ResultCodeEnum.MONITOR_SYSTEM_ERROR, t); + throw new MonitorException(ResultCodeEnum.DOWNSTREAM_SYSTEM_ERROR, t.getMessage()); } } }); @@ -183,9 +184,9 @@ public void doManage() { } catch (Throwable t) { if (t.getMessage().contains("Evaluated points num") && t.getMessage().contains("larger than")) { - throw new MonitorException(ResultCodeEnum.EXCEED_SERIES_LIMIT, t); + throw new MonitorException(ResultCodeEnum.EXCEED_SERIES_LIMIT, t.getMessage()); } - throw new MonitorException(ResultCodeEnum.MONITOR_SYSTEM_ERROR, t); + throw new MonitorException(ResultCodeEnum.DOWNSTREAM_SYSTEM_ERROR, t.getMessage()); } } }); @@ -407,12 +408,12 @@ public void doManage() { .setStep(request.getStep()).build(); QueryResponse response = queryClientService.pqlRangeQuery(rangeRequest); JsonResult.createSuccessResult(result, response.getResults()); - } catch (Exception e) { - if (e.getMessage().contains("Evaluated points num") - && e.getMessage().contains("larger than")) { - throw new MonitorException(ResultCodeEnum.EXCEED_SERIES_LIMIT, e); + } catch (Throwable t) { + if (t.getMessage().contains("Evaluated points num") + && t.getMessage().contains("larger than")) { + throw new MonitorException(ResultCodeEnum.EXCEED_SERIES_LIMIT, t.getMessage()); } - throw new MonitorException(ResultCodeEnum.MONITOR_SYSTEM_ERROR, e); + throw new MonitorException(ResultCodeEnum.DOWNSTREAM_SYSTEM_ERROR, t.getMessage()); } } }); @@ -447,12 +448,12 @@ public void doManage() { .setTime(request.getTime()).build(); QueryResponse response = queryClientService.pqlInstantQuery(instantRequest); JsonResult.createSuccessResult(result, response.getResults()); - } catch (Exception e) { - if (e.getMessage().contains("Evaluated points num") - && e.getMessage().contains("larger than")) { - throw new MonitorException(ResultCodeEnum.EXCEED_SERIES_LIMIT, e); + } catch (Throwable t) { + if (t.getMessage().contains("Evaluated points num") + && t.getMessage().contains("larger than")) { + throw new MonitorException(ResultCodeEnum.EXCEED_SERIES_LIMIT, t.getMessage()); } - throw new MonitorException(ResultCodeEnum.MONITOR_SYSTEM_ERROR, e); + throw new MonitorException(ResultCodeEnum.DOWNSTREAM_SYSTEM_ERROR, t.getMessage()); } } });