Skip to content

Commit

Permalink
fix: alarm history (#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
masaimu authored Jun 20, 2024
1 parent 3ad1bd1 commit 15cac3d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.holoinsight.server.common.EventBusHolder;
import io.holoinsight.server.common.service.AlarmHistoryService;
import io.holoinsight.server.common.service.RequestContextAdapter;
import io.holoinsight.server.common.MonitorPageRequest;
import io.holoinsight.server.common.MonitorPageResult;
import io.holoinsight.server.common.dao.converter.AlarmHistoryConverter;
import io.holoinsight.server.common.dao.mapper.AlarmHistoryMapper;
import io.holoinsight.server.common.dao.entity.AlarmHistory;
import io.holoinsight.server.common.dao.entity.dto.AlarmHistoryDTO;
import io.holoinsight.server.common.MonitorPageRequest;
import io.holoinsight.server.common.MonitorPageResult;
import io.holoinsight.server.common.dao.mapper.AlarmHistoryMapper;
import io.holoinsight.server.common.service.AlarmHistoryService;
import io.holoinsight.server.common.service.RequestContextAdapter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -122,6 +122,7 @@ public MonitorPageResult<AlarmHistoryDTO> getListByPage(
if (alarmHistory.getRecoverTime() == null) {
if (alarmHistory.getDuration() != null && alarmHistory.getDuration() == 0) {
wrapper.isNull("recover_time");
wrapper.eq("deleted", false);
}
} else if (alarmHistory.getDuration() != null && alarmHistory.getDuration() == 1) {
wrapper.isNotNull("recover_time");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
*/
package io.holoinsight.server.home.alert.service.calculate;

import io.holoinsight.server.common.dao.emuns.BoolOperationEnum;
import io.holoinsight.server.common.dao.entity.dto.AlertNotifyRecordDTO;
import io.holoinsight.server.common.dao.entity.dto.InspectConfig;
import io.holoinsight.server.common.dao.entity.dto.alarm.AlarmRuleConf;
import io.holoinsight.server.common.dao.entity.dto.alarm.PqlRule;
import io.holoinsight.server.common.dao.entity.dto.alarm.trigger.CompareConfig;
import io.holoinsight.server.common.dao.entity.dto.alarm.trigger.DataSource;
import io.holoinsight.server.common.dao.entity.dto.alarm.trigger.Trigger;
import io.holoinsight.server.common.dao.entity.dto.alarm.trigger.TriggerDataResult;
import io.holoinsight.server.common.dao.entity.dto.alarm.trigger.TriggerResult;
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;
import io.holoinsight.server.home.alert.model.function.FunctionConfigAIParam;
import io.holoinsight.server.home.alert.model.function.FunctionConfigParam;
import io.holoinsight.server.home.alert.model.function.FunctionLogic;
import io.holoinsight.server.home.alert.service.event.RecordSucOrFailNotify;
import io.holoinsight.server.common.dao.entity.dto.AlertNotifyRecordDTO;
import io.holoinsight.server.common.dao.entity.dto.alarm.trigger.TriggerDataResult;
import io.holoinsight.server.common.dao.entity.dto.InspectConfig;
import io.holoinsight.server.common.dao.entity.dto.alarm.PqlRule;
import io.holoinsight.server.common.dao.emuns.BoolOperationEnum;
import io.holoinsight.server.common.dao.entity.dto.alarm.trigger.CompareConfig;
import io.holoinsight.server.common.dao.entity.dto.alarm.trigger.DataSource;
import io.holoinsight.server.common.dao.entity.dto.alarm.trigger.Trigger;
import io.holoinsight.server.common.dao.entity.dto.alarm.trigger.TriggerResult;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -155,6 +155,9 @@ public EventInfo runRule(InspectConfig inspectConfig, long period,

Map<Trigger, List<TriggerResult>> triggerMap = new HashMap<>();// 告警
// List<TriggerResult> noEventGeneratedList = new ArrayList<>();// 不告警
if (inspectConfig == null || inspectConfig.getRule() == null) {
return null;
}
for (Trigger trigger : inspectConfig.getRule().getTriggers()) {
// 后续考虑增加tags比较
List<TriggerDataResult> triggerDataResultList = trigger.getDataResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
import com.google.gson.reflect.TypeToken;
import io.holoinsight.server.common.J;
import io.holoinsight.server.common.dao.entity.dto.alarm.AlarmRuleConf;
import io.holoinsight.server.common.service.AlarmMetricService;
import io.holoinsight.server.common.EventBusHolder;
import io.holoinsight.server.common.dao.mapper.AlarmHistoryMapper;
import io.holoinsight.server.common.J;
import io.holoinsight.server.common.dao.entity.AlarmHistory;
import io.holoinsight.server.common.dao.entity.AlarmMetric;
import io.holoinsight.server.common.dao.entity.AlarmRule;
import io.holoinsight.server.common.dao.entity.dto.AlarmRuleDTO;
import io.holoinsight.server.common.dao.entity.dto.alarm.AlarmRuleConf;
import io.holoinsight.server.common.dao.entity.dto.alarm.trigger.DataSource;
import io.holoinsight.server.common.dao.entity.dto.alarm.trigger.Trigger;
import io.holoinsight.server.common.dao.mapper.AlarmHistoryMapper;
import io.holoinsight.server.common.dao.mapper.AlarmRuleMapper;
import io.holoinsight.server.common.service.AlarmMetricService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -40,6 +42,8 @@ public class AlarmRuleUpdateListener {
private AlarmMetricService alarmMetricService;
@Resource
private AlarmHistoryMapper alarmHistoryMapper;
@Resource
private AlarmRuleMapper alarmRuleMapper;

@PostConstruct
void register() {
Expand All @@ -50,8 +54,15 @@ void register() {
@AllowConcurrentEvents
public void onEvent(AlarmRuleDTO alarmRuleDTO) {

log.info("AlarmRuleUpdateListener status {} bool {}", alarmRuleDTO.getStatus(),
alarmRuleDTO.getStatus() == 0);
if (alarmRuleDTO.getStatus() == 0) {
deleteAlarmHistory(alarmRuleDTO.getId(), alarmRuleDTO.getRuleType());
AlarmRule alarmRule = alarmRuleMapper.selectById(alarmRuleDTO.getId());
if (alarmRule == null) {
log.error("cannot find alarm rule for id {}", alarmRuleDTO.getId());
return;
}
deleteAlarmHistory(alarmRuleDTO.getId(), alarmRule.getRuleType());
}

if (CollectionUtils.isEmpty(alarmRuleDTO.getRule())) {
Expand Down Expand Up @@ -97,6 +108,8 @@ private void deleteAlarmHistory(Long alarmRuleId, String ruleType) {
QueryWrapper<AlarmHistory> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("unique_id", String.join("_", ruleType, String.valueOf(alarmRuleId)));
List<AlarmHistory> alarmHistoryList = this.alarmHistoryMapper.selectList(queryWrapper);
log.info("select history empty {}, unique_id {}", CollectionUtils.isEmpty(alarmHistoryList),
String.join("_", ruleType, String.valueOf(alarmRuleId)));
if (CollectionUtils.isEmpty(alarmHistoryList)) {
return;
}
Expand Down

0 comments on commit 15cac3d

Please sign in to comment.