Commit 6249f4e3 authored by Sean Arnold's avatar Sean Arnold

Don't create escalations for existing alerts

- Reorder specs to test this
parent 938fdcec
......@@ -18,7 +18,7 @@ module EE
def process_escalations
if alert.resolved? || alert.ignored?
delete_pending_escalations
else
elsif alert.previously_new_record?
create_pending_escalations
end
end
......
......@@ -5,9 +5,7 @@ require 'spec_helper'
RSpec.describe IncidentManagement::PendingEscalations::ProcessService do
let_it_be(:project) { create(:project) }
let_it_be(:schedule_1) { create(:incident_management_oncall_schedule, :with_rotation, project: project) }
let_it_be(:schedule_2) { create(:incident_management_oncall_schedule, :with_rotation, project: project) }
let_it_be(:schedule_1_users) { schedule_1.participants.map(&:user) }
let_it_be(:schedule_2_users) { schedule_2.participants.map(&:user) }
let(:escalation_rule) { build(:incident_management_escalation_rule, oncall_schedule: schedule_1 ) }
let!(:escalation_policy) { create(:incident_management_escalation_policy, project: project, rules: [escalation_rule]) }
......
......@@ -85,6 +85,17 @@ RSpec.describe Projects::Alerting::NotifyService do
include_examples 'oncall users are correctly notified of firing alert'
context 'with resolving payload' do
let(:payload) do
{
'fingerprint' => fingerprint,
'end_time' => Time.current.iso8601
}
end
include_examples 'oncall users are correctly notified of recovery alert'
end
context 'with escalation policies ready' do
let_it_be(:policy) { create(:incident_management_escalation_policy, project: project) }
......@@ -95,32 +106,38 @@ RSpec.describe Projects::Alerting::NotifyService do
it_behaves_like 'does not send on-call notification'
include_examples 'creates an escalation', 1
end
context 'with resolving payload' do
let(:payload) do
{
'fingerprint' => fingerprint,
'end_time' => Time.current.iso8601
}
end
context 'existing alert with same payload fingerprint' do
let_it_be(:alert) { create(:alert_management_alert, fingerprint: gitlab_fingerprint, project: project) }
let_it_be(:pending_escalation) { create(:incident_management_pending_alert_escalation, alert: alert) }
include_examples 'oncall users are correctly notified of recovery alert'
it 'does not create an escalation' do
expect { subject }.not_to change { alert.pending_escalations.count }
end
context 'with existing alert escalation' do
let_it_be(:alert) { create(:alert_management_alert, :ignored, fingerprint: gitlab_fingerprint, project: project) }
let_it_be(:pending_escalation) { create(:incident_management_pending_alert_escalation, alert: alert) }
context 'with resolving payload' do
let(:payload) do
{
'fingerprint' => fingerprint,
'end_time' => Time.current.iso8601
}
end
let(:target) { alert }
context 'with existing alert escalation' do
let_it_be(:pending_escalation) { create(:incident_management_pending_alert_escalation, alert: alert) }
include_examples "deletes the target's escalations"
let(:target) { alert }
context 'with escalation policy feature disabled' do
before do
stub_feature_flags(escalation_policies_mvc: false)
end
include_examples "deletes the target's escalations"
context 'with escalation policy feature disabled' do
before do
stub_feature_flags(escalation_policies_mvc: false)
end
include_examples "deletes the target's escalations"
include_examples "deletes the target's escalations"
end
end
end
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