Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
06efa9fa
Commit
06efa9fa
authored
Dec 17, 2021
by
Sean Arnold
Committed by
Bob Van Landuyt
Dec 17, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle syncing alert escalation status to incident
parent
42cd0687
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
220 additions
and
5 deletions
+220
-5
app/models/concerns/incident_management/escalatable.rb
app/models/concerns/incident_management/escalatable.rb
+2
-0
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+4
-0
app/models/incident_management/issuable_escalation_status.rb
app/models/incident_management/issuable_escalation_status.rb
+3
-0
app/services/incident_management/issuable_escalation_statuses/create_service.rb
...management/issuable_escalation_statuses/create_service.rb
+36
-0
app/services/issues/create_service.rb
app/services/issues/create_service.rb
+5
-0
ee/app/models/concerns/ee/incident_management/escalatable.rb
ee/app/models/concerns/ee/incident_management/escalatable.rb
+13
-0
ee/app/models/concerns/ee/issuable.rb
ee/app/models/concerns/ee/issuable.rb
+0
-4
ee/app/services/ee/incident_management/issuable_escalation_statuses/create_service.rb
...management/issuable_escalation_statuses/create_service.rb
+22
-0
ee/spec/models/ee/alert_management/alert_spec.rb
ee/spec/models/ee/alert_management/alert_spec.rb
+16
-0
ee/spec/models/incident_management/issuable_escalation_status_spec.rb
...ls/incident_management/issuable_escalation_status_spec.rb
+16
-0
ee/spec/services/ee/incident_management/issuable_escalation_statuses/create_service_spec.rb
...ement/issuable_escalation_statuses/create_service_spec.rb
+64
-0
ee/spec/support/shared_examples/models/incident_management/pending_escalations_shared_examples.rb
...ncident_management/pending_escalations_shared_examples.rb
+1
-1
spec/models/incident_management/issuable_escalation_status_spec.rb
...ls/incident_management/issuable_escalation_status_spec.rb
+1
-0
spec/services/incident_management/issuable_escalation_statuses/create_service_spec.rb
...ement/issuable_escalation_statuses/create_service_spec.rb
+30
-0
spec/services/issues/create_service_spec.rb
spec/services/issues/create_service_spec.rb
+7
-0
No files found.
app/models/concerns/incident_management/escalatable.rb
View file @
06efa9fa
...
...
@@ -102,3 +102,5 @@ module IncidentManagement
end
end
end
::
IncidentManagement
::
Escalatable
.
prepend_mod
app/models/concerns/issuable.rb
View file @
06efa9fa
...
...
@@ -183,6 +183,10 @@ module Issuable
incident?
end
def
supports_escalation?
incident?
end
def
incident?
is_a?
(
Issue
)
&&
super
end
...
...
app/models/incident_management/issuable_escalation_status.rb
View file @
06efa9fa
...
...
@@ -7,8 +7,11 @@ module IncidentManagement
self
.
table_name
=
'incident_management_issuable_escalation_statuses'
belongs_to
:issue
has_one
:project
,
through: :issue
,
inverse_of: :incident_management_issuable_escalation_status
validates
:issue
,
presence:
true
,
uniqueness:
true
delegate
:project
,
to: :issue
end
end
...
...
app/services/incident_management/issuable_escalation_statuses/create_service.rb
0 → 100644
View file @
06efa9fa
# frozen_string_literal: true
module
IncidentManagement
module
IssuableEscalationStatuses
class
CreateService
<
BaseService
def
initialize
(
issue
)
@issue
=
issue
@alert
=
issue
.
alert_management_alert
end
def
execute
escalation_status
=
::
IncidentManagement
::
IssuableEscalationStatus
.
new
(
issue:
issue
,
**
alert_params
)
if
escalation_status
.
save
ServiceResponse
.
success
(
payload:
{
escalation_status:
escalation_status
})
else
ServiceResponse
.
error
(
message:
escalation_status
.
errors
&
.
full_messages
)
end
end
private
attr_reader
:issue
,
:alert
def
alert_params
return
{}
unless
alert
{
status_event:
alert
.
status_event_for
(
alert
.
status_name
)
}
end
end
end
end
IncidentManagement
::
IssuableEscalationStatuses
::
CreateService
.
prepend_mod
app/services/issues/create_service.rb
View file @
06efa9fa
...
...
@@ -50,6 +50,7 @@ module Issues
def
after_create
(
issue
)
user_agent_detail_service
.
create
resolve_discussions_with_issue
(
issue
)
create_escalation_status
(
issue
)
super
end
...
...
@@ -80,6 +81,10 @@ module Issues
attr_reader
:spam_params
def
create_escalation_status
(
issue
)
::
IncidentManagement
::
IssuableEscalationStatuses
::
CreateService
.
new
(
issue
).
execute
if
issue
.
supports_escalation?
end
def
user_agent_detail_service
UserAgentDetailService
.
new
(
spammable:
@issue
,
spam_params:
spam_params
)
end
...
...
ee/app/models/concerns/ee/incident_management/escalatable.rb
0 → 100644
View file @
06efa9fa
# frozen_string_literal: true
module
EE
module
IncidentManagement
module
Escalatable
extend
ActiveSupport
::
Concern
def
escalation_policy
project
.
incident_management_escalation_policies
.
first
end
end
end
end
ee/app/models/concerns/ee/issuable.rb
View file @
06efa9fa
...
...
@@ -48,10 +48,6 @@ module EE
incident?
end
def
supports_escalation?
incident?
end
def
supports_iterations?
false
end
...
...
ee/app/services/ee/incident_management/issuable_escalation_statuses/create_service.rb
0 → 100644
View file @
06efa9fa
# frozen_string_literal: true
module
EE
module
IncidentManagement
module
IssuableEscalationStatuses
module
CreateService
extend
::
Gitlab
::
Utils
::
Override
override
:alert_params
def
alert_params
return
super
unless
issue
.
escalation_policies_available?
return
super
unless
alert
&
.
escalation_policy
super
.
merge
(
policy:
alert
.
escalation_policy
,
escalations_started_at:
alert
.
created_at
)
end
end
end
end
end
ee/spec/models/ee/alert_management/alert_spec.rb
View file @
06efa9fa
...
...
@@ -80,4 +80,20 @@ RSpec.describe AlertManagement::Alert do
end
end
end
describe
'#escalation_policy'
do
let
(
:alert
)
{
create
(
:alert_management_alert
,
project:
project
)
}
subject
{
alert
.
escalation_policy
}
it
{
is_expected
.
to
eq
(
nil
)
}
context
'when escalation policy exists on the project'
do
it
'returns the projects first (only) escalation policy'
do
policy
=
create
(
:incident_management_escalation_policy
,
project:
project
)
expect
(
subject
).
to
eq
(
policy
)
end
end
end
end
ee/spec/models/incident_management/issuable_escalation_status_spec.rb
View file @
06efa9fa
...
...
@@ -67,4 +67,20 @@ RSpec.describe IncidentManagement::IssuableEscalationStatus do
end
end
end
describe
'#escalation_policy'
do
let_it_be
(
:escalation_status
,
reload:
true
)
{
create
(
:incident_management_issuable_escalation_status
)
}
subject
{
escalation_status
.
escalation_policy
}
it
{
is_expected
.
to
eq
(
nil
)
}
context
'when escalation policy exists on the project'
do
it
'returns the projects first (only) escalation policy'
do
policy
=
create
(
:incident_management_escalation_policy
,
project:
escalation_status
.
issue
.
project
)
expect
(
subject
).
to
eq
(
policy
)
end
end
end
end
ee/spec/services/ee/incident_management/issuable_escalation_statuses/create_service_spec.rb
0 → 100644
View file @
06efa9fa
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
IncidentManagement
::
IssuableEscalationStatuses
::
CreateService
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let
(
:incident
)
{
create
(
:incident
,
project:
project
)
}
let
(
:service
)
{
described_class
.
new
(
incident
)
}
let
(
:alert_status_name
)
{
:triggered
}
subject
(
:execute
)
{
service
.
execute
}
before
do
stub_licensed_features
(
oncall_schedules:
true
,
escalation_policies:
true
)
stub_feature_flags
(
incident_escalations:
true
)
end
shared_examples
'creates an escalation status for the incident with no policy set'
do
specify
do
expect
{
execute
}.
to
change
{
incident
.
reload
.
incident_management_issuable_escalation_status
}.
from
(
nil
)
status
=
incident
.
incident_management_issuable_escalation_status
expect
(
status
.
policy
).
to
eq
(
nil
)
expect
(
status
.
escalations_started_at
).
to
eq
(
nil
)
expect
(
status
.
status_name
).
to
eq
(
alert_status_name
)
end
end
it_behaves_like
'creates an escalation status for the incident with no policy set'
context
'when incident is associated to an alert'
do
let
(
:alert
)
{
create
(
:alert_management_alert
,
:acknowledged
,
project:
project
)
}
let
(
:incident
)
{
create
(
:incident
,
alert_management_alert:
alert
,
project:
project
)
}
let
(
:alert_status_name
)
{
alert
.
status_name
}
context
'when no policy exists'
do
it_behaves_like
'creates an escalation status for the incident with no policy set'
end
context
'when policy exists'
do
let_it_be
(
:policy
)
{
create
(
:incident_management_escalation_policy
,
project:
project
)
}
it
'creates an escalation status with the policy info'
do
expect
{
execute
}.
to
change
{
incident
.
reload
.
incident_management_issuable_escalation_status
}
status
=
incident
.
incident_management_issuable_escalation_status
expect
(
status
.
policy
).
to
eq
(
policy
)
expect
(
status
.
escalations_started_at
).
to
be_like_time
(
alert
.
created_at
)
expect
(
status
.
status_name
).
to
eq
(
alert
.
status_name
)
end
context
'when feature flag is disabled'
do
before
do
stub_feature_flags
(
incident_escalations:
false
)
end
it_behaves_like
'creates an escalation status for the incident with no policy set'
end
end
end
end
ee/spec/support/shared_examples/models/incident_management/pending_escalations_shared_examples.rb
View file @
06efa9fa
...
...
@@ -32,7 +32,7 @@ RSpec.shared_examples 'IncidentManagement::PendingEscalation model' do
let_it_be
(
:three_days_ago_escalation
)
{
create_escalation
(
rule:
rule
,
process_at:
3
.
days
.
ago
)
}
let_it_be
(
:future_escalation
)
{
create_escalation
(
rule:
rule
,
process_at:
5
.
minutes
.
from_now
)
}
it
{
is_expected
.
to
eq
[
three_weeks_ago_escalation
,
three_days_ago_escalation
]
}
it
{
is_expected
.
to
match_array
[
three_weeks_ago_escalation
,
three_days_ago_escalation
]
}
end
end
...
...
spec/models/incident_management/issuable_escalation_status_spec.rb
View file @
06efa9fa
...
...
@@ -11,6 +11,7 @@ RSpec.describe IncidentManagement::IssuableEscalationStatus do
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:issue
)
}
it
{
is_expected
.
to
have_one
(
:project
).
through
(
:issue
)
}
end
describe
'validatons'
do
...
...
spec/services/incident_management/issuable_escalation_statuses/create_service_spec.rb
0 → 100644
View file @
06efa9fa
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
IncidentManagement
::
IssuableEscalationStatuses
::
CreateService
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let
(
:incident
)
{
create
(
:incident
,
project:
project
)
}
let
(
:service
)
{
described_class
.
new
(
incident
)
}
subject
(
:execute
)
{
service
.
execute
}
it
'creates an escalation status for the incident with no policy set'
do
expect
{
execute
}.
to
change
{
incident
.
reload
.
incident_management_issuable_escalation_status
}.
from
(
nil
)
status
=
incident
.
incident_management_issuable_escalation_status
expect
(
status
.
policy_id
).
to
eq
(
nil
)
expect
(
status
.
escalations_started_at
).
to
eq
(
nil
)
expect
(
status
.
status_name
).
to
eq
(
:triggered
)
end
context
'existing escalation status'
do
let!
(
:existing_status
)
{
create
(
:incident_management_issuable_escalation_status
,
issue:
incident
)
}
it
'exits without changing anything'
do
expect
{
execute
}.
not_to
change
{
incident
.
reload
.
incident_management_issuable_escalation_status
}
end
end
end
spec/services/issues/create_service_spec.rb
View file @
06efa9fa
...
...
@@ -108,6 +108,13 @@ RSpec.describe Issues::CreateService do
.
to
change
{
Label
.
where
(
incident_label_attributes
).
count
}.
by
(
1
)
end
it
'calls IncidentManagement::Incidents::CreateEscalationStatusService'
do
expect_next
(
::
IncidentManagement
::
IssuableEscalationStatuses
::
CreateService
,
a_kind_of
(
Issue
))
.
to
receive
(
:execute
)
issue
end
context
'when invalid'
do
before
do
opts
.
merge!
(
title:
''
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment