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
621788fe
Commit
621788fe
authored
Jun 29, 2020
by
Sean Arnold
Committed by
Michael Kozono
Jun 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auto close related alert issue on recovery
- Limited to prometheus alerts right now
parent
227d1fee
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
3 deletions
+40
-3
app/services/alert_management/process_prometheus_alert_service.rb
...ices/alert_management/process_prometheus_alert_service.rb
+15
-1
changelogs/unreleased/222253-close-issue-on-resolved-alert.yml
...elogs/unreleased/222253-close-issue-on-resolved-alert.yml
+6
-0
spec/factories/alert_management/alerts.rb
spec/factories/alert_management/alerts.rb
+3
-1
spec/requests/api/graphql/project/alert_management/alerts_spec.rb
...uests/api/graphql/project/alert_management/alerts_spec.rb
+1
-1
spec/services/alert_management/process_prometheus_alert_service_spec.rb
...alert_management/process_prometheus_alert_service_spec.rb
+15
-0
No files found.
app/services/alert_management/process_prometheus_alert_service.rb
View file @
621788fe
...
...
@@ -66,7 +66,11 @@ module AlertManagement
def
process_resolved_alert_management_alert
return
if
am_alert
.
blank?
return
if
am_alert
.
resolve
(
ends_at
)
if
am_alert
.
resolve
(
ends_at
)
close_issue
(
am_alert
.
issue
)
return
end
logger
.
warn
(
message:
'Unable to update AlertManagement::Alert status to resolved'
,
...
...
@@ -75,6 +79,16 @@ module AlertManagement
)
end
def
close_issue
(
issue
)
return
if
issue
.
blank?
||
issue
.
closed?
Issues
::
CloseService
.
new
(
project
,
User
.
alert_bot
)
.
execute
(
issue
,
system_note:
false
)
SystemNoteService
.
auto_resolve_prometheus_alert
(
issue
,
project
,
User
.
alert_bot
)
if
issue
.
reset
.
closed?
end
def
logger
@logger
||=
Gitlab
::
AppLogger
end
...
...
changelogs/unreleased/222253-close-issue-on-resolved-alert.yml
0 → 100644
View file @
621788fe
---
title
:
Automatically close related issue when resolving Alert Management Prometheus
Alert
merge_request
:
35208
author
:
type
:
added
spec/factories/alert_management/alerts.rb
View file @
621788fe
...
...
@@ -16,7 +16,9 @@ FactoryBot.define do
end
trait
:with_issue
do
issue
after
(
:create
)
do
|
alert
|
create
(
:issue
,
alert_management_alert:
alert
,
project:
alert
.
project
)
end
end
trait
:with_assignee
do
|
alert
|
...
...
spec/requests/api/graphql/project/alert_management/alerts_spec.rb
View file @
621788fe
...
...
@@ -78,7 +78,7 @@ RSpec.describe 'getting Alert Management Alerts' do
expect
(
second_alert
).
to
include
(
'iid'
=>
resolved_alert
.
iid
.
to_s
,
'issueIid'
=>
nil
,
'issueIid'
=>
resolved_alert
.
issue_iid
.
to_s
,
'status'
=>
'RESOLVED'
,
'endedAt'
=>
resolved_alert
.
ended_at
.
strftime
(
'%Y-%m-%dT%H:%M:%SZ'
)
)
...
...
spec/services/alert_management/process_prometheus_alert_service_spec.rb
View file @
621788fe
...
...
@@ -123,6 +123,21 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do
it
'resolves an existing alert'
do
expect
{
execute
}.
to
change
{
alert
.
reload
.
resolved?
}.
to
(
true
)
end
context
'existing issue'
do
let!
(
:alert
)
{
create
(
:alert_management_alert
,
:with_issue
,
project:
project
,
fingerprint:
parsed_alert
.
gitlab_fingerprint
)
}
it
'closes the issue'
do
issue
=
alert
.
issue
expect
{
execute
}
.
to
change
{
issue
.
reload
.
state
}
.
from
(
'opened'
)
.
to
(
'closed'
)
end
specify
{
expect
{
execute
}.
to
change
(
Note
,
:count
).
by
(
1
)
}
end
end
context
'when status change did not succeed'
do
...
...
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