use of io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver in project hopsworks by logicalclocks.
the class TestAlertManagerConfigTimer method createReceivers.
private List<AlertReceiver> createReceivers() throws JsonProcessingException {
List<AlertReceiver> alertReceivers = new ArrayList<>();
List<EmailConfig> emailConfigs = new ArrayList<>();
emailConfigs.add(new EmailConfig("test@hopsworks.ai"));
List<SlackConfig> slackConfigs = new ArrayList<>();
slackConfigs.add(new SlackConfig().withChannel("@test"));
List<PagerdutyConfig> pagerdutyConfigs = new ArrayList<>();
pagerdutyConfigs.add(new PagerdutyConfig("serviceKey"));
alertReceivers.add(createAlertReceiver(1, new Receiver("global-receiver__email").withEmailConfigs(emailConfigs), AlertType.GLOBAL_ALERT_EMAIL));
alertReceivers.add(createAlertReceiver(2, new Receiver("project1__slack").withSlackConfigs(slackConfigs), AlertType.PROJECT_ALERT));
alertReceivers.add(createAlertReceiver(3, new Receiver("global-receiver__slack").withSlackConfigs(slackConfigs), AlertType.GLOBAL_ALERT_SLACK));
alertReceivers.add(createAlertReceiver(4, new Receiver("project1__pagerduty").withPagerdutyConfigs(pagerdutyConfigs), AlertType.PROJECT_ALERT));
return alertReceivers;
}
use of io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver in project hopsworks by logicalclocks.
the class AlertManagerConfiguration method runFixConfig.
public void runFixConfig() throws AlertManagerConfigCtrlCreateException, AlertManagerConfigReadException, IOException, AlertManagerUnreachableException, AlertManagerConfigUpdateException, AlertManagerClientCreateException {
AlertManagerConfig alertManagerConfig = read();
ObjectMapper objectMapper = new ObjectMapper();
List<AlertReceiver> alertReceivers = alertReceiverFacade.findAll();
boolean updatedReceivers = fixReceivers(alertManagerConfig, objectMapper, alertReceivers);
boolean updatedRoutes = fixRoutes(alertManagerConfig, alertReceivers);
if (updatedReceivers || updatedRoutes) {
writeAndReload(alertManagerConfig);
}
}
use of io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver in project hopsworks by logicalclocks.
the class AlertManagerConfiguration method fixRoutes.
private boolean fixRoutes(AlertManagerConfig alertManagerConfig, List<AlertReceiver> alertReceivers) {
List<Route> routes = getRoutes(alertManagerConfig);
List<Route> routesToAdd = new ArrayList<>();
for (AlertReceiver alertReceiver : alertReceivers) {
if (!alertReceiver.getName().equals(AlertType.DEFAULT.getValue())) {
routesToAdd.addAll(getRoutesToAdd(alertReceiver, routes));
}
}
if (!routesToAdd.isEmpty()) {
alertManagerConfig.getRoute().getRoutes().addAll(routesToAdd);
LOGGER.log(Level.INFO, "Alert manager config updated. Added {0} routes.", routesToAdd.size());
return true;
}
return false;
}
use of io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver in project hopsworks by logicalclocks.
the class AlertManagerConfiguration method fixReceivers.
private boolean fixReceivers(AlertManagerConfig alertManagerConfig, ObjectMapper objectMapper, List<AlertReceiver> alertReceivers) throws IOException {
List<Route> routes = getRoutes(alertManagerConfig);
List<Receiver> receivers = alertManagerConfig.getReceivers() == null ? new ArrayList<>() : alertManagerConfig.getReceivers();
List<Receiver> receiversToAdd = new ArrayList<>();
for (AlertReceiver alertReceiver : alertReceivers) {
Receiver receiver = receiverToAdd(receivers, alertReceiver, objectMapper);
if (receiver != null && !receiversToAdd.contains(receiver)) {
receiversToAdd.add(receiver);
}
}
List<Receiver> receiversToRemove = new ArrayList<>();
for (Receiver receiver : receivers) {
Optional<AlertReceiver> alertReceiver = alertReceiverFacade.findByName(receiver.getName());
if (!alertReceiver.isPresent() && isNotSystemReceiver(alertManagerConfig, receiver)) {
receiversToRemove.add(receiver);
}
}
if (!receiversToAdd.isEmpty() || !receiversToRemove.isEmpty()) {
if (!receiversToAdd.isEmpty()) {
receivers.addAll(receiversToAdd);
LOGGER.log(Level.INFO, "Alert manager config updated. Added {0} receivers.", receiversToAdd.size());
}
if (!receiversToRemove.isEmpty()) {
List<Route> routesToRemove = new ArrayList<>();
for (Route route : routes) {
if (receiversToRemove.contains(new Receiver(route.getReceiver()))) {
routesToRemove.add(route);
}
}
if (!routesToRemove.isEmpty()) {
alertManagerConfig.getRoute().getRoutes().removeAll(routesToRemove);
LOGGER.log(Level.INFO, "Alert manager config updated. Removed {0} routes.", routesToRemove.size());
}
receivers.removeAll(receiversToRemove);
LOGGER.log(Level.INFO, "Alert manager config updated. Removed {0} receivers.", receiversToRemove.size());
}
alertManagerConfig.setReceivers(receivers);
return true;
}
return false;
}
use of io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver in project hopsworks by logicalclocks.
the class TestAlertManagerConfigTimer method createAlertReceiver.
private AlertReceiver createAlertReceiver(Integer id, Receiver receiver, AlertType alertType) throws JsonProcessingException {
AlertReceiver alertReceiver = new AlertReceiver();
alertReceiver.setId(id);
alertReceiver.setName(receiver.getName());
alertReceiver.setConfig(toJson(receiver));
Project project = new Project("project1");
Jobs job = new Jobs();
job.setProject(project);
job.setName("job1");
Featurestore featurestore = new Featurestore();
featurestore.setProject(project);
Featuregroup featuregroup = new Featuregroup();
featuregroup.setFeaturestore(featurestore);
featuregroup.setName("fg1");
List<JobAlert> jobAlerts = new ArrayList<>();
jobAlerts.add(new JobAlert(random.nextInt(1000), JobAlertStatus.FAILED, alertType, AlertSeverity.CRITICAL, new Date(), job, alertReceiver));
jobAlerts.add(new JobAlert(random.nextInt(1000), JobAlertStatus.KILLED, alertType, AlertSeverity.WARNING, new Date(), job, alertReceiver));
alertReceiver.setJobAlertCollection(jobAlerts);
List<FeatureGroupAlert> featureGroupAlerts = new ArrayList<>();
featureGroupAlerts.add(new FeatureGroupAlert(random.nextInt(1000), ValidationRuleAlertStatus.FAILURE, alertType, AlertSeverity.CRITICAL, new Date(), featuregroup, alertReceiver));
featureGroupAlerts.add(new FeatureGroupAlert(random.nextInt(1000), ValidationRuleAlertStatus.WARNING, alertType, AlertSeverity.WARNING, new Date(), featuregroup, alertReceiver));
alertReceiver.setFeatureGroupAlertCollection(featureGroupAlerts);
List<ProjectServiceAlert> projectServiceAlerts = new ArrayList<>();
projectServiceAlerts.add(new ProjectServiceAlert(random.nextInt(1000), ProjectServiceEnum.FEATURESTORE, ProjectServiceAlertStatus.VALIDATION_FAILURE, alertType, AlertSeverity.WARNING, new Date(), project, alertReceiver));
projectServiceAlerts.add(new ProjectServiceAlert(random.nextInt(1000), ProjectServiceEnum.JOBS, ProjectServiceAlertStatus.JOB_FAILED, alertType, AlertSeverity.WARNING, new Date(), project, alertReceiver));
alertReceiver.setProjectServiceAlertCollection(projectServiceAlerts);
return alertReceiver;
}
Aggregations