Search in sources :

Example 1 with AlertReceiver

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;
}
Also used : SlackConfig(io.hops.hopsworks.alerting.config.dto.SlackConfig) AlertReceiver(io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver) EmailConfig(io.hops.hopsworks.alerting.config.dto.EmailConfig) ArrayList(java.util.ArrayList) AlertReceiver(io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) PagerdutyConfig(io.hops.hopsworks.alerting.config.dto.PagerdutyConfig)

Example 2 with AlertReceiver

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);
    }
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) AlertReceiver(io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with AlertReceiver

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;
}
Also used : AlertReceiver(io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver) ArrayList(java.util.ArrayList) Route(io.hops.hopsworks.alerting.config.dto.Route)

Example 4 with AlertReceiver

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;
}
Also used : AlertReceiver(io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver) ArrayList(java.util.ArrayList) AlertReceiver(io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) Route(io.hops.hopsworks.alerting.config.dto.Route)

Example 5 with AlertReceiver

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;
}
Also used : FeatureGroupAlert(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.alert.FeatureGroupAlert) AlertReceiver(io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver) Featuregroup(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.Featuregroup) ArrayList(java.util.ArrayList) Date(java.util.Date) ProjectServiceAlert(io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert) Project(io.hops.hopsworks.persistence.entity.project.Project) Featurestore(io.hops.hopsworks.persistence.entity.featurestore.Featurestore) JobAlert(io.hops.hopsworks.persistence.entity.jobs.description.JobAlert) Jobs(io.hops.hopsworks.persistence.entity.jobs.description.Jobs)

Aggregations

AlertReceiver (io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver)7 ArrayList (java.util.ArrayList)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Receiver (io.hops.hopsworks.alerting.config.dto.Receiver)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 AlertManagerConfig (io.hops.hopsworks.alerting.config.dto.AlertManagerConfig)2 EmailConfig (io.hops.hopsworks.alerting.config.dto.EmailConfig)2 PagerdutyConfig (io.hops.hopsworks.alerting.config.dto.PagerdutyConfig)2 Route (io.hops.hopsworks.alerting.config.dto.Route)2 SlackConfig (io.hops.hopsworks.alerting.config.dto.SlackConfig)2 AlertManagerConfigUpdateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException)2 Featurestore (io.hops.hopsworks.persistence.entity.featurestore.Featurestore)2 Featuregroup (io.hops.hopsworks.persistence.entity.featurestore.featuregroup.Featuregroup)2 FeatureGroupAlert (io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.alert.FeatureGroupAlert)2 JobAlert (io.hops.hopsworks.persistence.entity.jobs.description.JobAlert)2 Jobs (io.hops.hopsworks.persistence.entity.jobs.description.Jobs)2 Project (io.hops.hopsworks.persistence.entity.project.Project)2 ProjectServiceAlert (io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert)2 Date (java.util.Date)2 JSONObject (org.json.JSONObject)2