Commit 153df2a5 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Use gitlab_fingerprint in prometheus alert worker

`ProcessPrometheusAlertWorker` now uses `Alert#gitlab_fingerprint`
to find `PrometheusAlertEvent` and `SelfManagedPrometheusAlertEvent`
records
parent 7d72d038
...@@ -41,23 +41,11 @@ module IncidentManagement ...@@ -41,23 +41,11 @@ module IncidentManagement
end end
def find_gitlab_managed_event(alert) def find_gitlab_managed_event(alert)
payload_key = payload_key_for_alert(alert) PrometheusAlertEvent.find_by_payload_key(alert.gitlab_fingerprint)
PrometheusAlertEvent.find_by_payload_key(payload_key)
end end
def find_self_managed_event(alert) def find_self_managed_event(alert)
payload_key = payload_key_for_alert(alert) SelfManagedPrometheusAlertEvent.find_by_payload_key(alert.gitlab_fingerprint)
SelfManagedPrometheusAlertEvent.find_by_payload_key(payload_key)
end
def payload_key_for_alert(alert)
if alert.gitlab_managed?
PrometheusAlertEvent.payload_key_for(alert.metric_id, alert.starts_at_raw)
else
SelfManagedPrometheusAlertEvent.payload_key_for(alert.starts_at_raw, alert.title, alert.full_query)
end
end end
def create_issue(project, alert) def create_issue(project, alert)
......
...@@ -6,7 +6,7 @@ describe IncidentManagement::ProcessPrometheusAlertWorker do ...@@ -6,7 +6,7 @@ describe IncidentManagement::ProcessPrometheusAlertWorker do
describe '#perform' do describe '#perform' do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:prometheus_alert) { create(:prometheus_alert, project: project) } let_it_be(:prometheus_alert) { create(:prometheus_alert, project: project) }
let_it_be(:payload_key) { PrometheusAlertEvent.payload_key_for(prometheus_alert.prometheus_metric_id, prometheus_alert.created_at.rfc3339) } let(:payload_key) { Gitlab::Alerting::Alert.new(project: project, payload: alert_params).gitlab_fingerprint }
let!(:prometheus_alert_event) { create(:prometheus_alert_event, prometheus_alert: prometheus_alert, payload_key: payload_key) } let!(:prometheus_alert_event) { create(:prometheus_alert_event, prometheus_alert: prometheus_alert, payload_key: payload_key) }
let(:alert_params) do let(:alert_params) do
...@@ -107,7 +107,6 @@ describe IncidentManagement::ProcessPrometheusAlertWorker do ...@@ -107,7 +107,6 @@ describe IncidentManagement::ProcessPrometheusAlertWorker do
let(:starts_at) { Time.now.rfc3339 } let(:starts_at) { Time.now.rfc3339 }
let!(:prometheus_alert_event) do let!(:prometheus_alert_event) do
payload_key = SelfManagedPrometheusAlertEvent.payload_key_for(starts_at, alert_name, 'vector(1)')
create(:self_managed_prometheus_alert_event, project: project, payload_key: payload_key) create(:self_managed_prometheus_alert_event, project: project, payload_key: payload_key)
end end
......
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