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
0a5d9c10
Commit
0a5d9c10
authored
Jun 02, 2020
by
Peter Leitzen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix multiple issue creation for Generic Alerts
parent
0a18cc26
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
18 deletions
+25
-18
app/workers/incident_management/process_alert_worker.rb
app/workers/incident_management/process_alert_worker.rb
+2
-1
changelogs/unreleased/pl-alert-management-fix-multiple-issue-creation.yml
...eased/pl-alert-management-fix-multiple-issue-creation.yml
+5
-0
spec/workers/incident_management/process_alert_worker_spec.rb
.../workers/incident_management/process_alert_worker_spec.rb
+18
-17
No files found.
app/workers/incident_management/process_alert_worker.rb
View file @
0a5d9c10
...
...
@@ -12,7 +12,7 @@ module IncidentManagement
return
unless
project
new_issue
=
create_issue
(
project
,
alert_payload
)
return
unless
am_alert_id
&&
new_issue
.
persisted?
return
unless
am_alert_id
&&
new_issue
&
.
persisted?
link_issue_with_alert
(
am_alert_id
,
new_issue
.
id
)
end
...
...
@@ -27,6 +27,7 @@ module IncidentManagement
IncidentManagement
::
CreateIssueService
.
new
(
project
,
alert_payload
)
.
execute
.
dig
(
:issue
)
end
def
link_issue_with_alert
(
alert_id
,
issue_id
)
...
...
changelogs/unreleased/pl-alert-management-fix-multiple-issue-creation.yml
0 → 100644
View file @
0a5d9c10
---
title
:
Fix linking alerts to created issues for the Generic alerts intergration
merge_request
:
33647
author
:
type
:
fixed
spec/workers/incident_management/process_alert_worker_spec.rb
View file @
0a5d9c10
...
...
@@ -7,40 +7,39 @@ describe IncidentManagement::ProcessAlertWorker do
describe
'#perform'
do
let
(
:alert_management_alert_id
)
{
nil
}
let
(
:alert_payload
)
{
{
alert:
'payload'
}
}
let
(
:new_issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:create_issue_service
)
{
instance_double
(
IncidentManagement
::
CreateIssueService
,
execute:
new_issue
)
}
let
(
:alert_payload
)
do
{
'annotations'
=>
{
'title'
=>
'title'
},
'startsAt'
=>
Time
.
now
.
rfc3339
}
end
let
(
:created_issue
)
{
Issue
.
last
}
subject
{
described_class
.
new
.
perform
(
project
.
id
,
alert_payload
,
alert_management_alert_id
)
}
before
do
allow
(
IncidentManagement
::
CreateIssueService
)
.
to
receive
(
:new
).
with
(
project
,
alert_payload
)
.
and_
return
(
create_issue_service
)
.
and_
call_original
end
it
'calls create issue service'
do
expect
(
Project
).
to
receive
(
:find_by_id
).
and_call_original
it
'creates an issue'
do
expect
(
IncidentManagement
::
CreateIssueService
)
.
to
receive
(
:new
).
with
(
project
,
alert_payload
)
.
and_return
(
create_issue_service
)
expect
(
create_issue_service
).
to
receive
(
:execute
)
subject
expect
{
subject
}.
to
change
{
Issue
.
count
}.
by
(
1
)
end
context
'with invalid project'
do
let
(
:invalid_project_id
)
{
0
}
let
(
:invalid_project_id
)
{
non_existing_record_id
}
subject
{
described_class
.
new
.
perform
(
invalid_project_id
,
alert_payload
)
}
it
'does not create issues'
do
expect
(
Project
).
to
receive
(
:find_by_id
).
and_call_original
expect
(
IncidentManagement
::
CreateIssueService
).
not_to
receive
(
:new
)
subject
expect
{
subject
}.
not_to
change
{
Issue
.
count
}
end
end
...
...
@@ -59,7 +58,9 @@ describe IncidentManagement::ProcessAlertWorker do
context
'when alert can be updated'
do
it
'updates AlertManagement::Alert#issue_id'
do
expect
{
subject
}.
to
change
{
alert
.
reload
.
issue_id
}.
to
(
new_issue
.
id
)
subject
expect
(
alert
.
reload
.
issue_id
).
to
eq
(
created_issue
.
id
)
end
it
'does not write a warning to log'
do
...
...
@@ -76,12 +77,12 @@ describe IncidentManagement::ProcessAlertWorker do
expect
{
subject
}.
not_to
change
{
alert
.
reload
.
issue_id
}
end
it
'
writes a worning to lo
g'
do
it
'
logs a warnin
g'
do
subject
expect
(
Gitlab
::
AppLogger
).
to
have_received
(
:warn
).
with
(
message:
'Cannot link an Issue with Alert'
,
issue_id:
new
_issue
.
id
,
issue_id:
created
_issue
.
id
,
alert_id:
alert_management_alert_id
,
alert_errors:
{
hosts:
[
'hosts array is over 255 chars'
]
}
)
...
...
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