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

56 lines
1.2 KiB
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
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
ServiceResponse.success
end
private
2021-02-22 17:27:13 +05:30
attr_reader :project, :payload
2021-03-11 19:13:27 +05:30
override :process_new_alert
def process_new_alert
return if resolving_alert?
2020-07-28 23:09:34 +05:30
2021-03-11 19:13:27 +05:30
super
2020-11-24 15:15:51 +05:30
end
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
2021-03-11 19:13:27 +05:30
override :resolving_alert?
def resolving_alert?
incoming_payload.resolved?
end
2020-05-24 23:13:21 +05:30
def bad_request
ServiceResponse.error(message: 'Bad Request', http_status: :bad_request)
end
end
end