Skip to content

Commit

Permalink
Extracted alerting logic for goal violation in a separate function fo…
Browse files Browse the repository at this point in the history
…r reuse
  • Loading branch information
ecojan committed Nov 19, 2021
1 parent c80f3a1 commit 0278353
Showing 1 changed file with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,27 +245,22 @@ private void alertBrokerFailure(AnomalyType anomalyType, final String localHostn

private void alertGoalViolation(AnomalyType anomalyType, final String localHostname,
List<AlertaMessage> alertaMessages, GoalViolations goalViolations) {
Map<Boolean, List<String>> violations = goalViolations.violatedGoalsByFixability();
for (Entry<Boolean, List<String>> entry : violations.entrySet()) {
entry.getValue().forEach(goal -> {
AlertaMessage alertaMessage = new AlertaMessage(localHostname, anomalyType.toString() + " - " + goal);
alertaMessage.setSeverity(NotifierUtils.getAlertSeverity(anomalyType).toString());
alertaMessage.setGroup(AlertaAlertGroup.PERFORMANCE.toString());
alertaMessage.setCreateTime(CruiseControlUtils.utcDateFor(goalViolations.detectionTimeMs(), 3, ChronoUnit.SECONDS));
alertaMessages.add(alertaMessage);
});
}
alertGoalViolationLogic(anomalyType, localHostname, alertaMessages, goalViolations.violatedGoalsByFixability(), goalViolations.detectionTimeMs());
}

private void alertIntraBrokerGoalViolation(AnomalyType anomalyType, final String localHostname,
List<AlertaMessage> alertaMessages, IntraBrokerGoalViolations goalViolations) {
Map<Boolean, List<String>> violations = goalViolations.violatedGoalsByFixability();
alertGoalViolationLogic(anomalyType, localHostname, alertaMessages, goalViolations.violatedGoalsByFixability(), goalViolations.detectionTimeMs());
}

private void alertGoalViolationLogic(AnomalyType anomalyType, final String localHostname,
List<AlertaMessage> alertaMessages, Map<Boolean, List<String>> violations, long detectionTime) {
for (Entry<Boolean, List<String>> entry : violations.entrySet()) {
entry.getValue().forEach(goal -> {
AlertaMessage alertaMessage = new AlertaMessage(localHostname, anomalyType.toString() + " - " + goal);
alertaMessage.setSeverity(NotifierUtils.getAlertSeverity(anomalyType).toString());
alertaMessage.setGroup(AlertaAlertGroup.PERFORMANCE.toString());
alertaMessage.setCreateTime(CruiseControlUtils.utcDateFor(goalViolations.detectionTimeMs(), 3, ChronoUnit.SECONDS));
alertaMessage.setCreateTime(CruiseControlUtils.utcDateFor(detectionTime, 3, ChronoUnit.SECONDS));
alertaMessages.add(alertaMessage);
});
}
Expand Down

0 comments on commit 0278353

Please sign in to comment.