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
0d80cfb5
Commit
0d80cfb5
authored
Jun 23, 2020
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Save Prometheus Alert and Environment on Alert
- Add specs for processing and saving
parent
d487d7a9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
4 deletions
+36
-4
lib/gitlab/alert_management/alert_params.rb
lib/gitlab/alert_management/alert_params.rb
+3
-1
spec/lib/gitlab/alert_management/alert_params_spec.rb
spec/lib/gitlab/alert_management/alert_params_spec.rb
+3
-1
spec/services/alert_management/process_prometheus_alert_service_spec.rb
...alert_management/process_prometheus_alert_service_spec.rb
+30
-2
No files found.
lib/gitlab/alert_management/alert_params.rb
View file @
0d80cfb5
...
...
@@ -34,7 +34,9 @@ module Gitlab
payload:
parsed_alert
.
payload
,
started_at:
parsed_alert
.
starts_at
,
ended_at:
parsed_alert
.
ends_at
,
fingerprint:
parsed_alert
.
gitlab_fingerprint
fingerprint:
parsed_alert
.
gitlab_fingerprint
,
environment:
parsed_alert
.
environment
,
prometheus_alert:
parsed_alert
.
gitlab_alert
}
end
end
...
...
spec/lib/gitlab/alert_management/alert_params_spec.rb
View file @
0d80cfb5
...
...
@@ -88,7 +88,9 @@ RSpec.describe Gitlab::AlertManagement::AlertParams do
payload:
payload
,
started_at:
parsed_alert
.
starts_at
,
ended_at:
parsed_alert
.
ends_at
,
fingerprint:
parsed_alert
.
gitlab_fingerprint
fingerprint:
parsed_alert
.
gitlab_fingerprint
,
environment:
parsed_alert
.
environment
,
prometheus_alert:
parsed_alert
.
gitlab_alert
)
end
end
...
...
spec/services/alert_management/process_prometheus_alert_service_spec.rb
View file @
0d80cfb5
...
...
@@ -35,9 +35,9 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do
}
end
context
'when Prometheus alert status is firing'
do
let
(
:status
)
{
'firing'
}
context
'when Prometheus alert status is firing'
do
context
'when alert with the same fingerprint already exists'
do
let!
(
:alert
)
{
create
(
:alert_management_alert
,
:resolved
,
project:
project
,
fingerprint:
parsed_alert
.
gitlab_fingerprint
)
}
...
...
@@ -144,6 +144,34 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do
it
{
is_expected
.
to
be_success
}
end
context
'environment given'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
it
'sets the environment'
do
payload
[
'labels'
][
'gitlab_environment_name'
]
=
environment
.
name
execute
alert
=
project
.
alert_management_alerts
.
last
expect
(
alert
.
environment
).
to
eq
(
environment
)
end
end
context
'prometheus alert given'
do
let
(
:prometheus_alert
)
{
create
(
:prometheus_alert
,
project:
project
)
}
it
'sets the prometheus alert and environment'
do
payload
[
'labels'
][
'gitlab_alert_id'
]
=
prometheus_alert
.
prometheus_metric_id
execute
alert
=
project
.
alert_management_alerts
.
last
expect
(
alert
.
prometheus_alert
).
to
eq
(
prometheus_alert
)
expect
(
alert
.
environment
).
to
eq
(
prometheus_alert
.
environment
)
end
end
end
context
'when alert payload is invalid'
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