Commit 59abe43f authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch '329347-ff-removal_escalation_policies_mvc' into 'master'

Introduce escalation policies [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!64101
parents 5a162364 16dcac56
---
name: escalation_policies_mvc
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/60524
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/329347
milestone: '13.12'
type: development
group: group::monitor
default_enabled: false
......@@ -25,41 +25,10 @@ module IncidentManagement
delegate :name, to: :project, prefix: true
after_create :backfill_escalation_policy
def default_escalation_rule
EscalationRule.new(
elapsed_time_seconds: 0,
oncall_schedule: self,
status: :acknowledged
)
end
private
def timezones
@timezones ||= ActiveSupport::TimeZone.all.map { |tz| tz.tzinfo.identifier }
end
# While escalation policies are in development, we want to
# backfill a policy for any project with an OncallSchedule.
# Once escalation policies are enabled, users will need to
# configure a policy directly in order to direct alerts
# to a schedule.
def backfill_escalation_policy
return if ::Feature.enabled?(:escalation_policies_mvc, project, default_enabled: :yaml)
return if ::Feature.disabled?(:escalation_policies_backfill, project, default_enabled: :yaml)
if policy = project.incident_management_escalation_policies.first
policy.rules << default_escalation_rule
else
EscalationPolicy.create!(
project: project,
name: 'On-call Escalation Policy',
description: "Immediately notify #{name}",
rules: project.incident_management_oncall_schedules.map(&:default_escalation_rule)
)
end
end
end
end
---
name: escalation_policies_backfill
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/62233
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/268066#implementation-plan
milestone: '14.0'
type: development
group: group::monitor
default_enabled: true
......@@ -7,9 +7,7 @@ module Gitlab
end
def self.escalation_policies_available?(project)
oncall_schedules_available?(project) &&
project.feature_available?(:escalation_policies) &&
::Feature.enabled?(:escalation_policies_mvc, project, default_enabled: :yaml)
oncall_schedules_available?(project) && project.feature_available?(:escalation_policies)
end
end
end
......@@ -55,18 +55,6 @@ RSpec.describe Projects::IncidentManagement::EscalationPoliciesController do
end
end
context 'with feature flag off' do
before do
stub_feature_flags(escalation_policies_mvc: false)
end
it 'responds with 404' do
request
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'with unavailable feature' do
before do
stub_licensed_features(escalation_policies: false)
......
......@@ -16,7 +16,6 @@ RSpec.describe IncidentManagement::EscalationPoliciesFinder do
context 'when feature is available' do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
end
context 'when user has permissions' do
......@@ -43,7 +42,6 @@ RSpec.describe IncidentManagement::EscalationPoliciesFinder do
context 'when feature is not avaiable' do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: false)
stub_feature_flags(escalation_policies_mvc: project)
end
it { is_expected.to eq(IncidentManagement::EscalationPolicy.none) }
......
......@@ -58,7 +58,6 @@ RSpec.describe Mutations::IncidentManagement::EscalationPolicy::Create do
context 'project has feature' do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
end
context 'user has access to project' do
......
......@@ -13,7 +13,6 @@ RSpec.describe Mutations::IncidentManagement::EscalationPolicy::Destroy do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
end
describe '#resolve' do
......
......@@ -30,7 +30,6 @@ RSpec.describe Mutations::IncidentManagement::EscalationPolicy::Update do
project.add_reporter(reporter)
stub_licensed_features(oncall_schedules: true, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
end
describe '#resolve' do
......
......@@ -16,7 +16,6 @@ RSpec.describe Resolvers::IncidentManagement::EscalationPoliciesResolver do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
project.add_reporter(current_user)
end
......
......@@ -28,19 +28,10 @@ RSpec.describe Gitlab::IncidentManagement do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
end
it { is_expected.to be_truthy }
context 'when feature flag disabled' do
before do
stub_feature_flags(escalation_policies_mvc: false)
end
it { is_expected.to be_falsey }
end
context 'when escalation policies not avaialble' do
before do
stub_licensed_features(escalation_policies: false)
......
......@@ -62,96 +62,4 @@ RSpec.describe IncidentManagement::OncallSchedule do
expect(described_class.for_iid(oncall_schedule1.iid)).to contain_exactly(oncall_schedule1)
end
end
describe '#backfill_escalation_policy' do
subject(:schedule) { create(:incident_management_oncall_schedule, project: project) }
context 'when the escalation policies feature is disabled' do
before do
stub_feature_flags(escalation_policies_mvc: false)
end
context 'with an existing escalation policy' do
let_it_be(:policy) { create(:incident_management_escalation_policy, project: project) }
let_it_be(:rule) { policy.rules.first }
it 'creates an new escalation rule on the existing policy' do
expect { schedule }
.to change(::IncidentManagement::EscalationPolicy, :count).by(0)
.and change(::IncidentManagement::EscalationRule, :count).by(1)
expect(policy.reload.rules.length).to eq(2)
expect(policy.rules.first).to eq(rule)
expect(policy.rules.second).to have_attributes(
elapsed_time_seconds: 0,
oncall_schedule: schedule,
status: 'acknowledged'
)
end
end
context 'without an existing escalation policy' do
let(:policy) { ::IncidentManagement::EscalationPolicy.last! }
it 'creates a new escalation policy and rule' do
expect { schedule }
.to change(::IncidentManagement::EscalationPolicy, :count).by(1)
.and change(::IncidentManagement::EscalationRule, :count).by(1)
expect(policy).to have_attributes(
name: 'On-call Escalation Policy',
description: "Immediately notify #{schedule.name}"
)
expect(policy.rules.length).to eq(1)
expect(policy.rules.first).to have_attributes(
elapsed_time_seconds: 0,
oncall_schedule: schedule,
status: 'acknowledged'
)
end
context 'with a previously created schedule which has not yet been backfilled' do
let_it_be(:existing_schedule) { create(:incident_management_oncall_schedule, project: project) }
it 'creates an new escalation rule on the existing policy' do
expect { schedule }
.to change(::IncidentManagement::EscalationPolicy, :count).by(1)
.and change(::IncidentManagement::EscalationRule, :count).by(2)
expect(policy.rules.length).to eq(2)
expect(policy.rules.first).to have_attributes(
elapsed_time_seconds: 0,
oncall_schedule: existing_schedule,
status: 'acknowledged'
)
expect(policy.rules.second).to have_attributes(
elapsed_time_seconds: 0,
oncall_schedule: schedule,
status: 'acknowledged'
)
end
end
end
context 'when the backfill is disabled directly' do
before do
stub_feature_flags(escalation_policies_mvc: false, escalation_policies_backfill: false)
end
it 'does not alter the escalation policies' do
expect { schedule }
.to not_change(::IncidentManagement::EscalationPolicy, :count)
.and not_change(::IncidentManagement::EscalationRule, :count)
end
end
end
context 'when the escalation policies feature is enabled' do
it 'does not alter the escalation policies' do
expect { schedule }
.to not_change(::IncidentManagement::EscalationPolicy, :count)
.and not_change(::IncidentManagement::EscalationRule, :count)
end
end
end
end
......@@ -34,7 +34,6 @@ RSpec.describe 'creating escalation policy' do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
project.add_maintainer(current_user)
end
......@@ -82,18 +81,6 @@ RSpec.describe 'creating escalation policy' do
expect(mutation_response['errors'][0]).to eq('Escalation policies must have at least one rule')
end
end
context 'feature flag disabled' do
before do
stub_feature_flags(escalation_policies_mvc: false)
end
it 'raises an error' do
resolve
expect_graphql_errors_to_include('Escalation policies are not supported for this project')
end
end
end
def mutation_response
......
......@@ -29,7 +29,6 @@ RSpec.describe 'Removing an escalation policy' do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
project.add_maintainer(user)
end
......
......@@ -49,7 +49,6 @@ RSpec.describe 'Updating an escalation policy' do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
project.add_maintainer(user)
end
......
......@@ -29,7 +29,6 @@ RSpec.describe 'getting Incident Management escalation policies' do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
end
context 'without project permissions' do
......
......@@ -53,7 +53,6 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
end
it_behaves_like 'does not send on-call notification'
......@@ -65,14 +64,6 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do
let!(:pending_escalation) { create(:incident_management_pending_alert_escalation, alert: target) }
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"
end
end
end
end
......
......@@ -15,7 +15,6 @@ RSpec.describe AlertManagement::Alerts::UpdateService do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
end
before_all do
......@@ -44,14 +43,6 @@ RSpec.describe AlertManagement::Alerts::UpdateService do
let(:target) { alert }
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"
end
end
context 'moving from a status of the same group' do
......
......@@ -11,7 +11,6 @@ RSpec.describe IncidentManagement::EscalationPolicies::CreateService do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
end
before_all do
......
......@@ -14,7 +14,6 @@ RSpec.describe IncidentManagement::EscalationPolicies::DestroyService do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
end
before_all do
......@@ -51,14 +50,6 @@ RSpec.describe IncidentManagement::EscalationPolicies::DestroyService do
it_behaves_like 'error response', 'You have insufficient permissions to configure escalation policies for this project'
end
context 'when feature is not available' do
before do
stub_feature_flags(escalation_policies_mvc: false)
end
it_behaves_like 'error response', 'You have insufficient permissions to configure escalation policies for this project'
end
context 'when an error occurs during removal' do
before do
allow(escalation_policy).to receive(:destroy).and_return(false)
......
......@@ -41,7 +41,6 @@ RSpec.describe IncidentManagement::EscalationPolicies::UpdateService do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
end
before_all do
......@@ -89,14 +88,6 @@ RSpec.describe IncidentManagement::EscalationPolicies::UpdateService do
it_behaves_like 'error response', 'You have insufficient permissions to configure escalation policies for this project'
end
context 'when feature is not available' do
before do
stub_feature_flags(escalation_policies_mvc: false)
end
it_behaves_like 'error response', 'You have insufficient permissions to configure escalation policies for this project'
end
context 'when only new rules are added' do
let(:expected_rules) { [*escalation_rules, new_rule] }
......
......@@ -23,7 +23,6 @@ RSpec.describe IncidentManagement::PendingEscalations::CreateService do
context 'feature available' do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
end
context 'target is resolved' do
......
......@@ -21,7 +21,6 @@ RSpec.describe IncidentManagement::PendingEscalations::ProcessService do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
end
describe '#execute' do
......@@ -56,14 +55,6 @@ RSpec.describe IncidentManagement::PendingEscalations::ProcessService do
expect { execute }.to change(Note, :count).by(1)
end
context 'feature flag is off' do
before do
stub_feature_flags(escalation_policies_mvc: false)
end
it_behaves_like 'it does not escalate'
end
end
context 'target is already resolved' do
......
......@@ -16,10 +16,6 @@ RSpec.describe Projects::Alerting::NotifyService do
}
end
before do
stub_feature_flags(escalation_policies_mvc: false)
end
subject { service.execute(token, integration) }
context 'existing alert with same payload fingerprint' do
......@@ -101,7 +97,6 @@ RSpec.describe Projects::Alerting::NotifyService do
before do
stub_licensed_features(oncall_schedules: project, escalation_policies: true)
stub_feature_flags(escalation_policies_mvc: project)
end
it_behaves_like 'does not send on-call notification'
......@@ -129,14 +124,6 @@ RSpec.describe Projects::Alerting::NotifyService do
let(:target) { alert }
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"
end
end
end
end
......
......@@ -9,10 +9,9 @@ RSpec.shared_examples 'sends on-call notification if enabled' do
it_behaves_like 'sends on-call notification'
context 'escalation policy features are disabled' do
context 'with escalation policy feature disabled' do
before do
stub_licensed_features(oncall_schedules: true, escalation_policies: false)
stub_feature_flags(escalation_policies_mvc: false)
end
it_behaves_like 'sends on-call notification'
......
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