Commit 3f35eade authored by Sean Arnold's avatar Sean Arnold

Tighten up specs and extract method

parent 5df1be54
......@@ -120,15 +120,19 @@ module Gitlab
end
def parse_gitlab_alert_from_payload
alerts_found = matching_gitlab_alerts
return if alerts_found.blank? || alerts_found.size > 1
alerts_found.first
end
def matching_gitlab_alerts
return unless metric_id || gitlab_prometheus_alert_id
alerts_found = Projects::Prometheus::AlertsFinder
Projects::Prometheus::AlertsFinder
.new(project: project, metric: metric_id, id: gitlab_prometheus_alert_id)
.execute
return if alerts_found.empty? || alerts_found.size > 1
alerts_found.first
end
def parse_title_from_payload
......
......@@ -13,7 +13,10 @@ describe Gitlab::Alerting::Alert do
let(:gitlab_alert_id) { gitlab_alert.id }
before do
payload['labels'] = { 'gitlab_prometheus_alert_id' => gitlab_alert_id }
payload['labels'] = {
'gitlab_alert_id' => gitlab_alert.prometheus_metric_id.to_s,
'gitlab_prometheus_alert_id' => gitlab_alert_id
}
end
end
......@@ -81,7 +84,10 @@ describe Gitlab::Alerting::Alert do
context 'alert id given in params' do
before do
payload['labels'] = { 'gitlab_prometheus_alert_id' => second_gitlab_alert.id }
payload['labels'] = {
'gitlab_alert_id' => gitlab_alert.prometheus_metric_id.to_s,
'gitlab_prometheus_alert_id' => second_gitlab_alert.id
}
end
it { is_expected.to eq(second_gitlab_alert) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment