From ed6dd70a816638bc4e8cce99be3aa3b32eefb4d6 Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Sun, 15 May 2022 21:57:45 +0800 Subject: [PATCH] [alerter]bugfix nextEvalInterval npe --- .../com/usthe/alert/calculate/CalculateAlarm.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/alerter/src/main/java/com/usthe/alert/calculate/CalculateAlarm.java b/alerter/src/main/java/com/usthe/alert/calculate/CalculateAlarm.java index c6fc13e35cb..772eb826e44 100644 --- a/alerter/src/main/java/com/usthe/alert/calculate/CalculateAlarm.java +++ b/alerter/src/main/java/com/usthe/alert/calculate/CalculateAlarm.java @@ -70,7 +70,9 @@ public CalculateAlarm (AlerterWorkerPool workerPool, AlerterDataQueue dataQueue, .target(CommonConstants.AVAILABLE) .content(this.bundle.getString("alerter.availability.emergency") + ": " + CollectRep.Code.UN_AVAILABLE.name()) .firstTriggerTime(System.currentTimeMillis()) - .lastTriggerTime(System.currentTimeMillis()); + .lastTriggerTime(System.currentTimeMillis()) + .nextEvalInterval(0L) + .times(0); if (monitor.getStatus() == CommonConstants.UN_REACHABLE_CODE) { alertBuilder .target(CommonConstants.REACHABLE) @@ -194,7 +196,8 @@ private void calculate(CollectRep.MetricsData metricsData) { int times = triggeredAlert.getTimes() + 1; triggeredAlert.setTimes(times); triggeredAlert.setLastTriggerTime(currentTimeMilli); - if (times >= define.getTimes()) { + int defineTimes = define.getTimes() == null ? 0 : define.getTimes(); + if (times >= defineTimes) { triggeredAlertMap.remove(monitorAlertKey); dataQueue.addAlertData(triggeredAlert); } @@ -218,7 +221,8 @@ private void calculate(CollectRep.MetricsData metricsData) { // 模板中关键字匹配替换 .content(AlertTemplateUtil.render(define.getTemplate(), fieldValueMap)) .build(); - if (times >= define.getTimes()) { + int defineTimes = define.getTimes() == null ? 0 : define.getTimes(); + if (times >= defineTimes) { dataQueue.addAlertData(alert); } else { triggeredAlertMap.put(monitorAlertKey, alert); @@ -272,7 +276,7 @@ private void handlerMonitorStatusAlert(String monitorId, String app, CollectRep. preAlert.setTimes(preAlert.getTimes() + 1); preAlert.setLastTriggerTime(currentTimeMill); long nextEvalInterval = preAlert.getNextEvalInterval() * 2; - if (preAlert.getNextEvalInterval() == 0) { + if (preAlert.getNextEvalInterval() == 0L) { nextEvalInterval = alerterProperties.getAlertEvalIntervalBase(); } nextEvalInterval = Math.min(nextEvalInterval, alerterProperties.getMaxAlertEvalInterval());