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
41833edb
Commit
41833edb
authored
Jul 27, 2020
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for Prometheus alert processing
Refactor process alert worker spec
parent
105f3b6d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
36 deletions
+59
-36
app/services/alert_management/process_prometheus_alert_service.rb
...ices/alert_management/process_prometheus_alert_service.rb
+1
-1
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 @
41833edb
...
@@ -96,7 +96,7 @@ module AlertManagement
...
@@ -96,7 +96,7 @@ module AlertManagement
return
unless
am_alert
return
unless
am_alert
return
if
am_alert
.
issue
return
if
am_alert
.
issue
IncidentManagement
::
ProcessAlertWorker
.
new
.
perform
(
nil
,
nil
,
am_alert
.
id
)
IncidentManagement
::
ProcessAlertWorker
.
perform_async
(
nil
,
nil
,
am_alert
.
id
)
end
end
def
logger
def
logger
...
...
spec/services/alert_management/process_prometheus_alert_service_spec.rb
View file @
41833edb
...
@@ -83,6 +83,15 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do
...
@@ -83,6 +83,15 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do
context
'when alert does not exist'
do
context
'when alert does not exist'
do
context
'when alert can be created'
do
context
'when alert can be created'
do
it_behaves_like
'creates an alert management alert'
it_behaves_like
'creates an alert management alert'
it
'creates an incident issue'
do
expect
(
IncidentManagement
::
ProcessAlertWorker
)
.
to
receive
(
:perform_async
)
.
with
(
nil
,
nil
,
kind_of
(
Integer
))
.
once
expect
(
subject
).
to
be_success
end
end
end
context
'when alert cannot be created'
do
context
'when alert cannot be created'
do
...
@@ -102,6 +111,13 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do
...
@@ -102,6 +111,13 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do
execute
execute
end
end
it
'does not create incident issue'
do
expect
(
IncidentManagement
::
ProcessAlertWorker
)
.
not_to
receive
(
:perform_async
)
expect
(
subject
).
to
be_success
end
end
end
it
{
is_expected
.
to
be_success
}
it
{
is_expected
.
to
be_success
}
...
...
spec/workers/incident_management/process_alert_worker_spec.rb
View file @
41833edb
...
@@ -16,66 +16,73 @@ RSpec.describe IncidentManagement::ProcessAlertWorker do
...
@@ -16,66 +16,73 @@ RSpec.describe IncidentManagement::ProcessAlertWorker do
subject
{
described_class
.
new
.
perform
(
nil
,
nil
,
alert
.
id
)
}
subject
{
described_class
.
new
.
perform
(
nil
,
nil
,
alert
.
id
)
}
before
do
before
do
allow
(
Gitlab
::
AppLogger
).
to
receive
(
:warn
).
and_call_original
allow
(
IncidentManagement
::
CreateIssueService
)
allow
(
IncidentManagement
::
CreateIssueService
)
.
to
receive
(
:new
).
with
(
alert
.
project
,
parsed_payload
)
.
to
receive
(
:new
).
with
(
alert
.
project
,
parsed_payload
)
.
and_call_original
.
and_call_original
end
end
it
'creates an issue'
do
shared_examples
'creates issue successfully'
do
expect
(
IncidentManagement
::
CreateIssueService
)
it
'creates an issue'
do
.
to
receive
(
:new
).
with
(
alert
.
project
,
parsed_payload
)
expect
(
IncidentManagement
::
CreateIssueService
)
.
to
receive
(
:new
).
with
(
alert
.
project
,
parsed_payload
)
expect
{
subject
}.
to
change
{
Issue
.
count
}.
by
(
1
)
expect
{
subject
}.
to
change
{
Issue
.
count
}.
by
(
1
)
end
end
context
'with invalid alert
'
do
it
'updates AlertManagement::Alert#issue_id
'
do
let
(
:invalid_alert_id
)
{
non_existing_record_id
}
subject
subject
{
described_class
.
new
.
perform
(
nil
,
nil
,
invalid_alert_id
)
}
expect
(
alert
.
reload
.
issue_id
).
to
eq
(
created_issue
.
id
)
end
it
'does not
create issues
'
do
it
'does not
write a warning to log
'
do
expect
(
IncidentManagement
::
CreateIssueService
).
not_to
receive
(
:new
)
subject
expect
{
subject
}.
not_to
change
{
Issue
.
count
}
expect
(
Gitlab
::
AppLogger
).
not_to
have_received
(
:warn
)
end
end
end
end
context
'with valid alert'
do
context
'with valid alert'
do
before
do
it_behaves_like
'creates issue successfully'
allow
(
Gitlab
::
AppLogger
).
to
receive
(
:warn
).
and_call_original
end
context
'when alert can be updated'
do
context
'when alert cannot be updated'
do
it
'updates AlertManagement::Alert#issue_id'
do
let_it_be
(
:alert
)
{
create
(
:alert_management_alert
,
:with_validation_errors
,
project:
project
,
payload:
payload
)
}
subject
expect
(
alert
.
reload
.
issue_id
).
to
eq
(
created_issue
.
id
)
it
'updates AlertManagement::Alert#issue_id'
do
expect
{
subject
}.
not_to
change
{
alert
.
reload
.
issue_id
}
end
end
it
'
does not write a warning to lo
g'
do
it
'
logs a warnin
g'
do
subject
subject
expect
(
Gitlab
::
AppLogger
).
not_to
have_received
(
:warn
)
expect
(
Gitlab
::
AppLogger
).
to
have_received
(
:warn
).
with
(
message:
'Cannot link an Issue with Alert'
,
issue_id:
created_issue
.
id
,
alert_id:
alert
.
id
,
alert_errors:
{
hosts:
[
'hosts array is over 255 chars'
]
}
)
end
end
end
context
'when alert cannot be updated'
do
context
'prometheus alert'
do
let_it_be
(
:alert
)
{
create
(
:alert_management_alert
,
:with_validation_errors
,
project:
project
,
payload:
payload
)
}
let_it_be
(
:alert
)
{
create
(
:alert_management_alert
,
:prometheus
,
project:
project
,
started_at:
started_at
)
}
let_it_be
(
:parsed_payload
)
{
alert
.
payload
}
it
'updates AlertManagement::Alert#issue_id'
do
it_behaves_like
'creates issue successfully'
expect
{
subject
}.
not_to
change
{
alert
.
reload
.
issue_id
}
end
end
end
it
'logs a warning
'
do
context
'with invalid alert
'
do
subject
let
(
:invalid_alert_id
)
{
non_existing_record_id
}
expect
(
Gitlab
::
AppLogger
).
to
have_received
(
:warn
).
with
(
subject
{
described_class
.
new
.
perform
(
nil
,
nil
,
invalid_alert_id
)
}
message:
'Cannot link an Issue with Alert'
,
issue_id:
created_issue
.
id
,
it
'does not create issues'
do
alert_id:
alert
.
id
,
expect
(
IncidentManagement
::
CreateIssueService
).
not_to
receive
(
:new
)
alert_errors:
{
hosts:
[
'hosts array is over 255 chars'
]
}
)
expect
{
subject
}.
not_to
change
{
Issue
.
count
}
end
end
end
end
end
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