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
c3af42c3
Commit
c3af42c3
authored
Apr 09, 2020
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only return PrometheusAlert if singular found
parent
af0b0094
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
5 deletions
+23
-5
lib/gitlab/alerting/alert.rb
lib/gitlab/alerting/alert.rb
+5
-2
spec/lib/gitlab/alerting/alert_spec.rb
spec/lib/gitlab/alerting/alert_spec.rb
+18
-3
No files found.
lib/gitlab/alerting/alert.rb
View file @
c3af42c3
...
...
@@ -122,10 +122,13 @@ module Gitlab
def
parse_gitlab_alert_from_payload
return
unless
metric_id
||
gitlab_prometheus_alert_id
Projects
::
Prometheus
::
AlertsFinder
alerts_found
=
Projects
::
Prometheus
::
AlertsFinder
.
new
(
project:
project
,
metric:
metric_id
,
id:
gitlab_prometheus_alert_id
)
.
execute
.
first
return
if
alerts_found
.
empty?
||
alerts_found
.
size
>
1
alerts_found
.
first
end
def
parse_title_from_payload
...
...
spec/lib/gitlab/alerting/alert_spec.rb
View file @
c3af42c3
...
...
@@ -79,11 +79,26 @@ describe Gitlab::Alerting::Alert do
)
end
before
do
payload
[
'labels'
]
=
{
'gitlab_prometheus_alert_id'
=>
second_gitlab_alert
.
id
}
context
'alert id given in params'
do
before
do
payload
[
'labels'
]
=
{
'gitlab_prometheus_alert_id'
=>
second_gitlab_alert
.
id
}
end
it
{
is_expected
.
to
eq
(
second_gitlab_alert
)
}
end
it
{
is_expected
.
to
eq
(
second_gitlab_alert
)
}
context
'metric id given in params'
do
# This tests the case when two alerts are found, as metric id
# is not unique.
# Note the metric id was incorrectly named as 'gitlab_alert_id'
# in PrometheusAlert#to_param.
before
do
payload
[
'labels'
]
=
{
'gitlab_alert_id'
=>
gitlab_alert
.
prometheus_metric_id
}
end
it
{
is_expected
.
to
be_nil
}
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