summaryrefslogtreecommitdiff
path: root/app/workers/incident_management/process_alert_worker.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/workers/incident_management/process_alert_worker.rb')
-rw-r--r--app/workers/incident_management/process_alert_worker.rb36
1 files changed, 21 insertions, 15 deletions
diff --git a/app/workers/incident_management/process_alert_worker.rb b/app/workers/incident_management/process_alert_worker.rb
index 0af34fa35d5..bc23dbda693 100644
--- a/app/workers/incident_management/process_alert_worker.rb
+++ b/app/workers/incident_management/process_alert_worker.rb
@@ -7,39 +7,45 @@ module IncidentManagement
queue_namespace :incident_management
feature_category :incident_management
- def perform(project_id, alert_payload, am_alert_id = nil)
- project = find_project(project_id)
- return unless project
+ # `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
- new_issue = create_issue(project, alert_payload)
- return unless am_alert_id && new_issue&.persisted?
+ alert = find_alert(alert_id)
+ return unless alert
+
+ new_issue = create_issue_for(alert)
+ return unless new_issue&.persisted?
- link_issue_with_alert(am_alert_id, new_issue.id)
+ link_issue_with_alert(alert, new_issue.id)
end
private
- def find_project(project_id)
- Project.find_by_id(project_id)
+ def find_alert(alert_id)
+ AlertManagement::Alert.find_by_id(alert_id)
+ end
+
+ def parsed_payload(alert)
+ Gitlab::Alerting::NotificationPayloadParser.call(alert.payload.to_h, alert.project)
end
- def create_issue(project, alert_payload)
+ def create_issue_for(alert)
IncidentManagement::CreateIssueService
- .new(project, alert_payload)
+ .new(alert.project, parsed_payload(alert))
.execute
.dig(:issue)
end
- def link_issue_with_alert(alert_id, issue_id)
- alert = AlertManagement::Alert.find_by_id(alert_id)
- return unless alert
-
+ def link_issue_with_alert(alert, issue_id)
return if alert.update(issue_id: issue_id)
Gitlab::AppLogger.warn(
message: 'Cannot link an Issue with Alert',
issue_id: issue_id,
- alert_id: alert_id,
+ alert_id: alert.id,
alert_errors: alert.errors.messages
)
end