blob: 4ed21108d3eaff4a9e95180a70241083157532db (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# frozen_string_literal: true
# Attribute mapping for alerts via prometheus alerting integration,
# and for which payload includes gitlab-controlled attributes.
module Gitlab
module AlertManagement
module Payload
class ManagedPrometheus < ::Gitlab::AlertManagement::Payload::Prometheus
attribute :gitlab_prometheus_alert_id,
paths: %w(labels gitlab_prometheus_alert_id),
type: :integer
attribute :metric_id,
paths: %w(labels gitlab_alert_id),
type: :integer
def gitlab_alert
strong_memoize(:gitlab_alert) do
next unless metric_id || gitlab_prometheus_alert_id
alerts = Projects::Prometheus::AlertsFinder
.new(project: project, metric: metric_id, id: gitlab_prometheus_alert_id)
.execute
next if alerts.blank? || alerts.size > 1
alerts.first
end
end
def full_query
gitlab_alert&.full_query || super
end
def environment
gitlab_alert&.environment || super
end
private
def plain_gitlab_fingerprint
[metric_id, starts_at_raw].join('/')
end
end
end
end
end
|