2020-07-28 23:09:34 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
RSpec.shared_examples 'alerts service responds with an error and takes no actions' do |http_status|
|
|
|
|
include_examples 'alerts service responds with an error', http_status
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it_behaves_like 'does not create an alert management alert'
|
|
|
|
it_behaves_like 'does not create a system note for alert'
|
|
|
|
it_behaves_like 'does not process incident issues'
|
|
|
|
it_behaves_like 'does not send alert notification emails'
|
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
RSpec.shared_examples 'alerts service responds with an error' do |http_status|
|
|
|
|
specify do
|
|
|
|
expect(subject).to be_error
|
|
|
|
expect(subject.http_status).to eq(http_status)
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
# This shared_example requires the following variables:
|
2021-06-08 01:23:25 +05:30
|
|
|
# - `service`, a service which includes ::IncidentManagement::Settings
|
|
|
|
RSpec.shared_context 'incident management settings enabled' do
|
|
|
|
let(:auto_close_incident) { true }
|
|
|
|
let(:create_issue) { true }
|
|
|
|
let(:send_email) { true }
|
|
|
|
|
|
|
|
let(:incident_management_setting) do
|
|
|
|
double(
|
|
|
|
auto_close_incident?: auto_close_incident,
|
|
|
|
create_issue?: create_issue,
|
|
|
|
send_email?: send_email
|
2021-02-22 17:27:13 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
before do
|
|
|
|
allow(ProjectServiceWorker).to receive(:perform_async)
|
|
|
|
allow(service)
|
|
|
|
.to receive(:incident_management_setting)
|
|
|
|
.and_return(incident_management_setting)
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
RSpec.shared_examples 'processes never-before-seen alert' do
|
|
|
|
it_behaves_like 'creates an alert management alert or errors'
|
|
|
|
it_behaves_like 'creates expected system notes for alert', :new_alert
|
|
|
|
it_behaves_like 'processes incident issues if enabled'
|
|
|
|
it_behaves_like 'sends alert notification emails if enabled'
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
RSpec.shared_examples 'processes never-before-seen recovery alert' do
|
|
|
|
it_behaves_like 'creates an alert management alert or errors'
|
|
|
|
it_behaves_like 'creates expected system notes for alert', :new_alert, :recovery_alert, :resolve_alert
|
|
|
|
it_behaves_like 'sends alert notification emails if enabled'
|
|
|
|
it_behaves_like 'does not process incident issues'
|
|
|
|
it_behaves_like 'writes a warning to the log for a failed alert status update' do
|
|
|
|
let(:alert) { nil } # Ensure the next alert id is used
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it 'resolves the alert' do
|
|
|
|
subject
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(AlertManagement::Alert.last.ended_at).to be_present
|
|
|
|
expect(AlertManagement::Alert.last.resolved?).to be(true)
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
RSpec.shared_examples 'processes one firing and one resolved prometheus alerts' do
|
|
|
|
it 'creates AlertManagement::Alert' do
|
|
|
|
expect(Gitlab::AppLogger).not_to receive(:warn)
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
expect { subject }
|
|
|
|
.to change(AlertManagement::Alert, :count).by(2)
|
|
|
|
.and change(Note, :count).by(4)
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it_behaves_like 'processes incident issues'
|
|
|
|
it_behaves_like 'sends alert notification emails', count: 2
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|