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
8c21e230
Commit
8c21e230
authored
Aug 10, 2020
by
GitLab Bot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
parent
0a3f1f55
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
96 additions
and
42 deletions
+96
-42
app/services/alert_management/process_prometheus_alert_service.rb
...ices/alert_management/process_prometheus_alert_service.rb
+17
-5
app/workers/incident_management/process_alert_worker.rb
app/workers/incident_management/process_alert_worker.rb
+5
-1
changelogs/unreleased/sarnold-fix-prometheus-issue-creation.yml
...logs/unreleased/sarnold-fix-prometheus-issue-creation.yml
+5
-0
doc/user/project/web_ide/index.md
doc/user/project/web_ide/index.md
+1
-1
spec/factories/alert_management/alerts.rb
spec/factories/alert_management/alerts.rb
+10
-0
spec/services/alert_management/process_prometheus_alert_service_spec.rb
...alert_management/process_prometheus_alert_service_spec.rb
+16
-0
spec/workers/incident_management/process_alert_worker_spec.rb
.../workers/incident_management/process_alert_worker_spec.rb
+42
-35
No files found.
app/services/alert_management/process_prometheus_alert_service.rb
View file @
8c21e230
...
...
@@ -34,6 +34,8 @@ module AlertManagement
else
create_alert_management_alert
end
process_incident_alert
end
def
reset_alert_management_alert_status
...
...
@@ -47,16 +49,17 @@ module AlertManagement
end
def
create_alert_management_alert
am_alert
=
AlertManagement
::
Alert
.
new
(
am_alert_params
.
merge
(
ended_at:
nil
))
if
am_alert
.
save
am_alert
.
execute_services
new_alert
=
AlertManagement
::
Alert
.
new
(
am_alert_params
.
merge
(
ended_at:
nil
))
if
new_alert
.
save
new_alert
.
execute_services
@am_alert
=
new_alert
return
end
logger
.
warn
(
message:
'Unable to create AlertManagement::Alert'
,
project_id:
project
.
id
,
alert_errors:
am
_alert
.
errors
.
messages
alert_errors:
new
_alert
.
errors
.
messages
)
end
...
...
@@ -89,12 +92,21 @@ module AlertManagement
SystemNoteService
.
auto_resolve_prometheus_alert
(
issue
,
project
,
User
.
alert_bot
)
if
issue
.
reset
.
closed?
end
def
process_incident_alert
return
unless
am_alert
return
if
am_alert
.
issue
IncidentManagement
::
ProcessAlertWorker
.
perform_async
(
nil
,
nil
,
am_alert
.
id
)
end
def
logger
@logger
||=
Gitlab
::
AppLogger
end
def
am_alert
@am_alert
||=
AlertManagement
::
Alert
.
not_resolved
.
for_fingerprint
(
project
,
gitlab_fingerprint
).
first
strong_memoize
(
:am_alert
)
do
AlertManagement
::
Alert
.
not_resolved
.
for_fingerprint
(
project
,
gitlab_fingerprint
).
first
end
end
def
bad_request
...
...
app/workers/incident_management/process_alert_worker.rb
View file @
8c21e230
...
...
@@ -29,8 +29,12 @@ module IncidentManagement
end
def
parsed_payload
(
alert
)
if
alert
.
prometheus?
alert
.
payload
else
Gitlab
::
Alerting
::
NotificationPayloadParser
.
call
(
alert
.
payload
.
to_h
,
alert
.
project
)
end
end
def
create_issue_for
(
alert
)
IncidentManagement
::
CreateIssueService
...
...
changelogs/unreleased/sarnold-fix-prometheus-issue-creation.yml
0 → 100644
View file @
8c21e230
---
title
:
Fix automatic issue creation via Prometheus alerts
merge_request
:
37884
author
:
type
:
fixed
doc/user/project/web_ide/index.md
View file @
8c21e230
...
...
@@ -24,7 +24,7 @@ file path fragments to start seeing results.
## Syntax highlighting
> Support for `.gitlab
.
ci.yml` validation [introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/218472) in GitLab 13.2.
> Support for `.gitlab
-
ci.yml` validation [introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/218472) in GitLab 13.2.
As expected from an IDE, syntax highlighting for many languages within
the Web IDE will make your direct editing even easier.
...
...
spec/factories/alert_management/alerts.rb
View file @
8c21e230
...
...
@@ -101,6 +101,16 @@ FactoryBot.define do
trait
:prometheus
do
monitoring_tool
{
Gitlab
::
AlertManagement
::
AlertParams
::
MONITORING_TOOLS
[
:prometheus
]
}
payload
do
{
annotations:
{
title:
'This is a prometheus error'
,
summary:
'Summary of the error'
,
description:
'Description of the error'
},
startsAt:
started_at
}.
with_indifferent_access
end
end
trait
:all_fields
do
...
...
spec/services/alert_management/process_prometheus_alert_service_spec.rb
View file @
8c21e230
...
...
@@ -83,6 +83,15 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do
context
'when alert does not exist'
do
context
'when alert can be created'
do
it_behaves_like
'creates an alert management alert'
it
'processes the incident alert'
do
expect
(
IncidentManagement
::
ProcessAlertWorker
)
.
to
receive
(
:perform_async
)
.
with
(
nil
,
nil
,
kind_of
(
Integer
))
.
once
expect
(
subject
).
to
be_success
end
end
context
'when alert cannot be created'
do
...
...
@@ -102,6 +111,13 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do
execute
end
it
'does not create incident issue'
do
expect
(
IncidentManagement
::
ProcessAlertWorker
)
.
not_to
receive
(
:perform_async
)
expect
(
subject
).
to
be_success
end
end
it
{
is_expected
.
to
be_success
}
...
...
spec/workers/incident_management/process_alert_worker_spec.rb
View file @
8c21e230
...
...
@@ -16,11 +16,14 @@ RSpec.describe IncidentManagement::ProcessAlertWorker do
subject
{
described_class
.
new
.
perform
(
nil
,
nil
,
alert
.
id
)
}
before
do
allow
(
Gitlab
::
AppLogger
).
to
receive
(
:warn
).
and_call_original
allow
(
IncidentManagement
::
CreateIssueService
)
.
to
receive
(
:new
).
with
(
alert
.
project
,
parsed_payload
)
.
and_call_original
end
shared_examples
'creates issue successfully'
do
it
'creates an issue'
do
expect
(
IncidentManagement
::
CreateIssueService
)
.
to
receive
(
:new
).
with
(
alert
.
project
,
parsed_payload
)
...
...
@@ -28,24 +31,6 @@ RSpec.describe IncidentManagement::ProcessAlertWorker do
expect
{
subject
}.
to
change
{
Issue
.
count
}.
by
(
1
)
end
context
'with invalid alert'
do
let
(
:invalid_alert_id
)
{
non_existing_record_id
}
subject
{
described_class
.
new
.
perform
(
nil
,
nil
,
invalid_alert_id
)
}
it
'does not create issues'
do
expect
(
IncidentManagement
::
CreateIssueService
).
not_to
receive
(
:new
)
expect
{
subject
}.
not_to
change
{
Issue
.
count
}
end
end
context
'with valid alert'
do
before
do
allow
(
Gitlab
::
AppLogger
).
to
receive
(
:warn
).
and_call_original
end
context
'when alert can be updated'
do
it
'updates AlertManagement::Alert#issue_id'
do
subject
...
...
@@ -57,6 +42,10 @@ RSpec.describe IncidentManagement::ProcessAlertWorker do
expect
(
Gitlab
::
AppLogger
).
not_to
have_received
(
:warn
)
end
end
context
'with valid alert'
do
it_behaves_like
'creates issue successfully'
context
'when alert cannot be updated'
do
let_it_be
(
:alert
)
{
create
(
:alert_management_alert
,
:with_validation_errors
,
project:
project
,
payload:
payload
)
}
...
...
@@ -76,6 +65,24 @@ RSpec.describe IncidentManagement::ProcessAlertWorker do
)
end
end
context
'prometheus alert'
do
let_it_be
(
:alert
)
{
create
(
:alert_management_alert
,
:prometheus
,
project:
project
,
started_at:
started_at
)
}
let_it_be
(
:parsed_payload
)
{
alert
.
payload
}
it_behaves_like
'creates issue successfully'
end
end
context
'with invalid alert'
do
let
(
:invalid_alert_id
)
{
non_existing_record_id
}
subject
{
described_class
.
new
.
perform
(
nil
,
nil
,
invalid_alert_id
)
}
it
'does not create issues'
do
expect
(
IncidentManagement
::
CreateIssueService
).
not_to
receive
(
:new
)
expect
{
subject
}.
not_to
change
{
Issue
.
count
}
end
end
end
...
...
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