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
f7fda715
Commit
f7fda715
authored
Dec 08, 2020
by
Sarah Yasonik
Committed by
Dmytro Zaporozhets (DZ)
Dec 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Process prometheus-formatted alerts via HTTP integrations
parent
77e068e2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
16 deletions
+21
-16
app/services/projects/prometheus/alerts/notify_service.rb
app/services/projects/prometheus/alerts/notify_service.rb
+7
-8
changelogs/unreleased/sy-process-prometheus-alerts-through-http-integrations.yml
...y-process-prometheus-alerts-through-http-integrations.yml
+5
-0
spec/factories/alert_management/http_integrations.rb
spec/factories/alert_management/http_integrations.rb
+4
-0
spec/services/projects/prometheus/alerts/notify_service_spec.rb
...ervices/projects/prometheus/alerts/notify_service_spec.rb
+5
-8
No files found.
app/services/projects/prometheus/alerts/notify_service.rb
View file @
f7fda715
...
...
@@ -17,10 +17,10 @@ module Projects
SUPPORTED_VERSION
=
'4'
def
execute
(
token
,
_
integration
=
nil
)
def
execute
(
token
,
integration
=
nil
)
return
bad_request
unless
valid_payload_size?
return
unprocessable_entity
unless
self
.
class
.
processable?
(
params
)
return
unauthorized
unless
valid_alert_manager_token?
(
token
)
return
unauthorized
unless
valid_alert_manager_token?
(
token
,
integration
)
process_prometheus_alerts
...
...
@@ -53,9 +53,9 @@ module Projects
params
[
'alerts'
]
end
def
valid_alert_manager_token?
(
token
)
def
valid_alert_manager_token?
(
token
,
integration
)
valid_for_manual?
(
token
)
||
valid_for_alerts_endpoint?
(
token
)
||
valid_for_alerts_endpoint?
(
token
,
integration
)
||
valid_for_managed?
(
token
)
end
...
...
@@ -70,11 +70,10 @@ module Projects
end
end
def
valid_for_alerts_endpoint?
(
token
)
return
false
unless
project
.
alerts_service_activated
?
def
valid_for_alerts_endpoint?
(
token
,
integration
)
return
false
unless
integration
&
.
active
?
# Here we are enforcing the existence of the token
compare_token
(
token
,
project
.
alerts_service
.
token
)
compare_token
(
token
,
integration
.
token
)
end
def
valid_for_managed?
(
token
)
...
...
changelogs/unreleased/sy-process-prometheus-alerts-through-http-integrations.yml
0 → 100644
View file @
f7fda715
---
title
:
Handle prometheus-formatted alert notifications through HTTP integrations
merge_request
:
49268
author
:
type
:
fixed
spec/factories/alert_management/http_integrations.rb
View file @
f7fda715
...
...
@@ -11,6 +11,10 @@ FactoryBot.define do
active
{
false
}
end
trait
:active
do
active
{
true
}
end
trait
:legacy
do
endpoint_identifier
{
'legacy'
}
end
...
...
spec/services/projects/prometheus/alerts/notify_service_spec.rb
View file @
f7fda715
...
...
@@ -138,10 +138,10 @@ RSpec.describe Projects::Prometheus::Alerts::NotifyService do
end
end
context
'with
generic alerts
integration'
do
context
'with
HTTP
integration'
do
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:a
lerts_servic
e
,
:token
,
:result
)
do
where
(
:a
ctiv
e
,
:token
,
:result
)
do
:active
|
:valid
|
:success
:active
|
:invalid
|
:failure
:active
|
nil
|
:failure
...
...
@@ -150,15 +150,12 @@ RSpec.describe Projects::Prometheus::Alerts::NotifyService do
end
with_them
do
let
(
:valid
)
{
project
.
alerts_service
.
token
}
let
(
:valid
)
{
integration
.
token
}
let
(
:invalid
)
{
'invalid token'
}
let
(
:token_input
)
{
public_send
(
token
)
if
token
}
let
(
:integration
)
{
create
(
:alert_management_http_integration
,
active
,
project:
project
)
if
active
}
before
do
if
alerts_service
create
(
:alerts_service
,
alerts_service
,
project:
project
)
end
end
let
(
:subject
)
{
service
.
execute
(
token_input
,
integration
)
}
case
result
=
params
[
:result
]
when
:success
...
...
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