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
127dbc24
Commit
127dbc24
authored
Sep 14, 2020
by
Vitali Tatarintev
Committed by
Bob Van Landuyt
Sep 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Populate an Incident's severity when it's created from an Alert
parent
cb3da621
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
3 deletions
+64
-3
app/services/alert_management/create_alert_issue_service.rb
app/services/alert_management/create_alert_issue_service.rb
+2
-1
app/services/incident_management/incidents/create_service.rb
app/services/incident_management/incidents/create_service.rb
+5
-2
changelogs/unreleased/238571-populate-severity-for-incident-created-from-alert.yml
...571-populate-severity-for-incident-created-from-alert.yml
+5
-0
spec/services/alert_management/create_alert_issue_service_spec.rb
...vices/alert_management/create_alert_issue_service_spec.rb
+24
-0
spec/services/incident_management/incidents/create_service_spec.rb
...ices/incident_management/incidents/create_service_spec.rb
+28
-0
No files found.
app/services/alert_management/create_alert_issue_service.rb
View file @
127dbc24
...
...
@@ -41,7 +41,8 @@ module AlertManagement
project
,
user
,
title:
alert_presenter
.
title
,
description:
alert_presenter
.
issue_description
description:
alert_presenter
.
issue_description
,
severity:
alert
.
severity
).
execute
end
...
...
app/services/incident_management/incidents/create_service.rb
View file @
127dbc24
...
...
@@ -5,11 +5,12 @@ module IncidentManagement
class
CreateService
<
BaseService
ISSUE_TYPE
=
'incident'
def
initialize
(
project
,
current_user
,
title
:,
description
:)
def
initialize
(
project
,
current_user
,
title
:,
description
:
,
severity:
IssuableSeverity
::
DEFAULT
)
super
(
project
,
current_user
)
@title
=
title
@description
=
description
@severity
=
severity
end
def
execute
...
...
@@ -24,12 +25,14 @@ module IncidentManagement
return
error
(
issue
.
errors
.
full_messages
.
to_sentence
,
issue
)
unless
issue
.
valid?
issue
.
update_severity
(
severity
)
success
(
issue
)
end
private
attr_reader
:title
,
:description
attr_reader
:title
,
:description
,
:severity
def
find_or_create_incident_label
IncidentManagement
::
CreateIncidentLabelService
...
...
changelogs/unreleased/238571-populate-severity-for-incident-created-from-alert.yml
0 → 100644
View file @
127dbc24
---
title
:
Set incident severity when it is created from an alert.
merge_request
:
42072
author
:
type
:
added
spec/services/alert_management/create_alert_issue_service_spec.rb
View file @
127dbc24
...
...
@@ -82,6 +82,30 @@ RSpec.describe AlertManagement::CreateAlertIssueService do
expect
(
user
).
to
have_received
(
:can?
).
with
(
:create_issue
,
project
)
end
context
'with alert severity'
do
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:alert_severity
,
:incident_severity
)
do
'critical'
|
'critical'
'high'
|
'high'
'medium'
|
'medium'
'low'
|
'low'
'info'
|
'unknown'
'unknown'
|
'unknown'
end
with_them
do
before
do
alert
.
update!
(
severity:
alert_severity
)
execute
end
it
'sets the correct severity level'
do
expect
(
created_issue
.
severity
).
to
eq
(
incident_severity
)
end
end
end
context
'when the alert is prometheus alert'
do
let
(
:alert
)
{
prometheus_alert
}
let
(
:issue
)
{
subject
.
payload
[
:issue
]
}
...
...
spec/services/incident_management/incidents/create_service_spec.rb
View file @
127dbc24
...
...
@@ -34,6 +34,34 @@ RSpec.describe IncidentManagement::Incidents::CreateService do
end
end
context
'with default severity'
do
it
'sets the correct severity level to "unknown"'
do
create_incident
expect
(
new_issue
.
severity
).
to
eq
(
IssuableSeverity
::
DEFAULT
)
end
end
context
'with severity'
do
using
RSpec
::
Parameterized
::
TableSyntax
subject
(
:create_incident
)
{
described_class
.
new
(
project
,
user
,
title:
title
,
description:
description
,
severity:
severity
).
execute
}
where
(
:severity
,
:incident_severity
)
do
'critical'
|
'critical'
'high'
|
'high'
'medium'
|
'medium'
'low'
|
'low'
'unknown'
|
'unknown'
end
with_them
do
it
'sets the correct severity level'
do
create_incident
expect
(
new_issue
.
severity
).
to
eq
(
incident_severity
)
end
end
end
context
'when incident label does not exists'
do
it
'creates incident label'
do
expect
{
create_incident
}.
to
change
{
project
.
labels
.
where
(
title:
label_title
).
count
}.
by
(
1
)
...
...
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