Commit 687343bf authored by Vitali Tatarintev's avatar Vitali Tatarintev

Check Prometheus Alert payload size only once

parent 176e9b87
...@@ -4,11 +4,10 @@ module Projects ...@@ -4,11 +4,10 @@ module Projects
module Prometheus module Prometheus
module Alerts module Alerts
class NotifyService < BaseService class NotifyService < BaseService
BadPayloadError = Class.new(StandardError)
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
def execute(token) def execute(token)
return false unless valid_payload_size?
return false unless valid_version? return false unless valid_version?
return false unless valid_alert_manager_token?(token) return false unless valid_alert_manager_token?(token)
...@@ -17,16 +16,12 @@ module Projects ...@@ -17,16 +16,12 @@ module Projects
process_incident_issues if process_issues? process_incident_issues if process_issues?
true true
rescue BadPayloadError
false
end end
private private
def payload def valid_payload_size?
raise BadPayloadError, 'The payload is too big' unless Gitlab::Utils::DeepSize.new(params).valid? Gitlab::Utils::DeepSize.new(params).valid?
params
end end
def incident_management_available? def incident_management_available?
...@@ -66,11 +61,11 @@ module Projects ...@@ -66,11 +61,11 @@ module Projects
end end
def alerts def alerts
payload['alerts'] params['alerts']
end end
def valid_version? def valid_version?
payload['version'] == '4' params['version'] == '4'
end end
def valid_alert_manager_token?(token) def valid_alert_manager_token?(token)
...@@ -144,7 +139,7 @@ module Projects ...@@ -144,7 +139,7 @@ module Projects
end end
def persist_events def persist_events
CreateEventsService.new(project, nil, payload).execute CreateEventsService.new(project, nil, params).execute
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment