debian-mirror-gitlab/app/services/alert_management/process_prometheus_alert_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
906 B
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
module AlertManagement
2021-02-22 17:27:13 +05:30
class ProcessPrometheusAlertService
2021-03-11 19:13:27 +05:30
extend ::Gitlab::Utils::Override
include ::AlertManagement::AlertProcessing
2021-12-11 22:18:48 +05:30
include ::AlertManagement::Responses
2020-05-24 23:13:21 +05:30
2021-02-22 17:27:13 +05:30
def initialize(project, payload)
@project = project
@payload = payload
end
2020-05-24 23:13:21 +05:30
def execute
2020-11-24 15:15:51 +05:30
return bad_request unless incoming_payload.has_required_attributes?
2020-05-24 23:13:21 +05:30
2021-03-11 19:13:27 +05:30
process_alert
2021-01-29 00:20:46 +05:30
return bad_request unless alert.persisted?
2021-03-11 19:13:27 +05:30
complete_post_processing_tasks
2020-05-24 23:13:21 +05:30
2021-12-11 22:18:48 +05:30
success(alert)
2020-05-24 23:13:21 +05:30
end
private
2021-02-22 17:27:13 +05:30
attr_reader :project, :payload
2021-03-11 19:13:27 +05:30
override :incoming_payload
2020-11-24 15:15:51 +05:30
def incoming_payload
strong_memoize(:incoming_payload) do
Gitlab::AlertManagement::Payload.parse(
project,
2021-02-22 17:27:13 +05:30
payload,
2020-11-24 15:15:51 +05:30
monitoring_tool: Gitlab::AlertManagement::Payload::MONITORING_TOOLS[:prometheus]
)
2020-08-18 19:51:02 +05:30
end
2020-05-24 23:13:21 +05:30
end
end
end