Commit 0d80cfb5 authored by Sean Arnold's avatar Sean Arnold

Save Prometheus Alert and Environment on Alert

- Add specs for processing and saving
parent d487d7a9
......@@ -34,7 +34,9 @@ module Gitlab
payload: parsed_alert.payload,
started_at: parsed_alert.starts_at,
ended_at: parsed_alert.ends_at,
fingerprint: parsed_alert.gitlab_fingerprint
fingerprint: parsed_alert.gitlab_fingerprint,
environment: parsed_alert.environment,
prometheus_alert: parsed_alert.gitlab_alert
}
end
end
......
......@@ -88,7 +88,9 @@ RSpec.describe Gitlab::AlertManagement::AlertParams do
payload: payload,
started_at: parsed_alert.starts_at,
ended_at: parsed_alert.ends_at,
fingerprint: parsed_alert.gitlab_fingerprint
fingerprint: parsed_alert.gitlab_fingerprint,
environment: parsed_alert.environment,
prometheus_alert: parsed_alert.gitlab_alert
)
end
end
......
......@@ -35,9 +35,9 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do
}
end
context 'when Prometheus alert status is firing' do
let(:status) { 'firing' }
context 'when Prometheus alert status is firing' do
context 'when alert with the same fingerprint already exists' do
let!(:alert) { create(:alert_management_alert, :resolved, project: project, fingerprint: parsed_alert.gitlab_fingerprint) }
......@@ -144,6 +144,34 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do
it { is_expected.to be_success }
end
context 'environment given' do
let(:project) { create(:project, :repository) }
let(:environment) { create(:environment, project: project) }
it 'sets the environment' do
payload['labels']['gitlab_environment_name'] = environment.name
execute
alert = project.alert_management_alerts.last
expect(alert.environment).to eq(environment)
end
end
context 'prometheus alert given' do
let(:prometheus_alert) { create(:prometheus_alert, project: project) }
it 'sets the prometheus alert and environment' do
payload['labels']['gitlab_alert_id'] = prometheus_alert.prometheus_metric_id
execute
alert = project.alert_management_alerts.last
expect(alert.prometheus_alert).to eq(prometheus_alert)
expect(alert.environment).to eq(prometheus_alert.environment)
end
end
end
context 'when alert payload is invalid' do
......
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