2020-02-11 15:08:44 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module IncidentManagement
|
2020-02-19 18:09:10 +00:00
|
|
|
class ProcessAlertWorker # rubocop:disable Scalability/IdempotentWorker
|
2020-02-11 15:08:44 +00:00
|
|
|
include ApplicationWorker
|
|
|
|
|
|
|
|
queue_namespace :incident_management
|
|
|
|
feature_category :incident_management
|
|
|
|
|
2020-06-29 00:08:58 +00:00
|
|
|
# `project_id` and `alert_payload` are deprecated and can be removed
|
|
|
|
# starting from 14.0 release
|
|
|
|
# https://gitlab.com/gitlab-org/gitlab/-/issues/224500
|
|
|
|
def perform(_project_id = nil, _alert_payload = nil, alert_id = nil)
|
|
|
|
return unless alert_id
|
2020-02-11 15:08:44 +00:00
|
|
|
|
2020-06-29 00:08:58 +00:00
|
|
|
alert = find_alert(alert_id)
|
|
|
|
return unless alert
|
|
|
|
|
2020-07-23 12:09:23 +00:00
|
|
|
result = create_issue_for(alert)
|
2020-08-12 21:09:54 +00:00
|
|
|
return if result.success?
|
2020-04-29 12:10:00 +00:00
|
|
|
|
2020-08-12 21:09:54 +00:00
|
|
|
log_warning(alert, result)
|
2020-02-11 15:08:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-06-29 00:08:58 +00:00
|
|
|
def find_alert(alert_id)
|
|
|
|
AlertManagement::Alert.find_by_id(alert_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_issue_for(alert)
|
2020-08-12 21:09:54 +00:00
|
|
|
AlertManagement::CreateAlertIssueService
|
|
|
|
.new(alert, User.alert_bot)
|
2020-02-11 15:08:44 +00:00
|
|
|
.execute
|
|
|
|
end
|
2020-04-29 12:10:00 +00:00
|
|
|
|
2020-08-12 21:09:54 +00:00
|
|
|
def log_warning(alert, result)
|
|
|
|
issue_id = result.payload[:issue]&.id
|
2020-04-29 12:10:00 +00:00
|
|
|
|
2020-05-11 15:09:37 +00:00
|
|
|
Gitlab::AppLogger.warn(
|
2020-08-12 21:09:54 +00:00
|
|
|
message: 'Cannot process an Incident',
|
2020-04-29 12:10:00 +00:00
|
|
|
issue_id: issue_id,
|
2020-06-29 00:08:58 +00:00
|
|
|
alert_id: alert.id,
|
2020-08-12 21:09:54 +00:00
|
|
|
errors: result.message
|
2020-04-29 12:10:00 +00:00
|
|
|
)
|
|
|
|
end
|
2020-02-11 15:08:44 +00:00
|
|
|
end
|
|
|
|
end
|