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
2a388984
Commit
2a388984
authored
Nov 12, 2019
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Limit input size for Prometheus alert JSON payload
parent
333d4236
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
3 deletions
+29
-3
ee/app/services/projects/prometheus/alerts/notify_service.rb
ee/app/services/projects/prometheus/alerts/notify_service.rb
+13
-3
ee/spec/services/projects/prometheus/alerts/notify_service_spec.rb
...ervices/projects/prometheus/alerts/notify_service_spec.rb
+16
-0
No files found.
ee/app/services/projects/prometheus/alerts/notify_service.rb
View file @
2a388984
...
...
@@ -4,6 +4,8 @@ module Projects
module
Prometheus
module
Alerts
class
NotifyService
<
BaseService
BadPayloadError
=
Class
.
new
(
StandardError
)
include
Gitlab
::
Utils
::
StrongMemoize
def
execute
(
token
)
...
...
@@ -15,10 +17,18 @@ module Projects
process_incident_issues
if
process_issues?
true
rescue
BadPayloadError
false
end
private
def
payload
raise
BadPayloadError
,
'The payload is too big'
unless
Gitlab
::
Utils
::
DeepSize
.
new
(
params
).
valid?
params
end
def
incident_management_available?
project
.
feature_available?
(
:incident_management
)
end
...
...
@@ -56,11 +66,11 @@ module Projects
end
def
alerts
pa
rams
[
'alerts'
]
pa
yload
[
'alerts'
]
end
def
valid_version?
pa
rams
[
'version'
]
==
'4'
pa
yload
[
'version'
]
==
'4'
end
def
valid_alert_manager_token?
(
token
)
...
...
@@ -134,7 +144,7 @@ module Projects
end
def
persist_events
CreateEventsService
.
new
(
project
,
nil
,
pa
rams
).
execute
CreateEventsService
.
new
(
project
,
nil
,
pa
yload
).
execute
end
end
end
...
...
ee/spec/services/projects/prometheus/alerts/notify_service_spec.rb
View file @
2a388984
...
...
@@ -338,6 +338,22 @@ describe Projects::Prometheus::Alerts::NotifyService do
it_behaves_like
'no notifications'
end
context
'when the payload is too big'
do
let
(
:payload
)
{
{
'the-payload-is-too-big'
=>
true
}
}
let
(
:deep_size_object
)
{
instance_double
(
Gitlab
::
Utils
::
DeepSize
,
valid?:
false
)
}
before
do
allow
(
Gitlab
::
Utils
::
DeepSize
).
to
receive
(
:new
).
and_return
(
deep_size_object
)
end
it_behaves_like
'no notifications'
it
'does not process issues'
do
expect
(
IncidentManagement
::
ProcessPrometheusAlertWorker
)
.
not_to
receive
(
:perform_async
)
end
end
end
private
...
...
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