* INFRA-2887 : SLA breach heads up cron refactor/reimplementation * INFRA-2887 : Code review comments
64 lines
2.0 KiB
Go
64 lines
2.0 KiB
Go
package impl
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"github.com/spf13/viper"
|
|
"houston/logger"
|
|
incidentModel "houston/model/incident"
|
|
"houston/model/severity"
|
|
service "houston/service/request"
|
|
)
|
|
|
|
const escalateLogTag = "[escalate]"
|
|
|
|
func (i *IncidentServiceV2) EscalateIncidents() error {
|
|
logger.Info(fmt.Sprintf("%s received request for escalating incidents", escalateLogTag))
|
|
|
|
incidents, err := i.incidentRepository.GetIncidentsForEscalation()
|
|
if err != nil {
|
|
logger.Error(fmt.Sprintf("%s failed to get incidents for escalation %v", escalateLogTag, err))
|
|
return err
|
|
}
|
|
|
|
escalationMap, err := i.severityService.GetSeverityEscalationMap()
|
|
if err != nil {
|
|
logger.Error(fmt.Sprintf("%s failed to get severity escalation map %v", escalateLogTag, err))
|
|
return err
|
|
}
|
|
|
|
return i.runEscalationOnIncidents(incidents, escalationMap)
|
|
}
|
|
|
|
func (i *IncidentServiceV2) runEscalationOnIncidents(incidents []incidentModel.IncidentEntity, escalationMap map[uint]*severity.SeverityDTO) error {
|
|
logger.Info(fmt.Sprintf("%s found %d incidents for escalation", escalateLogTag, len(incidents)))
|
|
|
|
var incidentsWithFailures []string
|
|
|
|
for _, incident := range incidents {
|
|
logger.Info(fmt.Sprintf("%s escalating incident with id: %d", escalateLogTag, incident.ID))
|
|
nextSeverity, ok := escalationMap[incident.SeverityId]
|
|
if !ok {
|
|
logger.Error(fmt.Sprintf("%s no escalation found for incident with id: %d", escalateLogTag, incident.ID))
|
|
incidentsWithFailures = append(incidentsWithFailures, incident.IncidentName)
|
|
continue
|
|
}
|
|
|
|
_, err := i.UpdateIncident(service.UpdateIncidentRequest{
|
|
Id: incident.ID,
|
|
SeverityId: fmt.Sprintf("%d", nextSeverity.ID),
|
|
}, viper.GetString("HOUSTON_BOT_SLACK_ID"))
|
|
|
|
if err != nil {
|
|
logger.Error(fmt.Sprintf("%s failed to escalate incident with id: %d %v", escalateLogTag, incident.ID, err))
|
|
incidentsWithFailures = append(incidentsWithFailures, incident.IncidentName)
|
|
}
|
|
}
|
|
|
|
if len(incidentsWithFailures) > 0 {
|
|
return errors.New(fmt.Sprintf("failed to escalate incidents: %v", incidentsWithFailures))
|
|
}
|
|
|
|
return nil
|
|
}
|