Class: Projects::Prometheus::Alerts::NotifyService

Inherits:
BaseService
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize, IncidentManagement::Settings
Defined in:
app/services/projects/prometheus/alerts/notify_service.rb

Constant Summary collapse

REQUIRED_PAYLOAD_KEYS =

This set of keys identifies a payload as a valid Prometheus payload and thus processable by this service. See also prometheus.io/docs/alerting/configuration/#webhook_config

%w[
  version groupKey status receiver groupLabels commonLabels
  commonAnnotations externalURL alerts
].to_set.freeze
SUPPORTED_VERSION =
'4'

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IncidentManagement::Settings

#auto_close_incident?, #incident_management_setting, #process_issues?

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from BaseService

Class Method Details

.processable?(params) ⇒ Boolean

Returns:

  • (Boolean)

31
32
33
34
35
36
37
# File 'app/services/projects/prometheus/alerts/notify_service.rb', line 31

def self.processable?(params)
  # Workaround for https://gitlab.com/gitlab-org/gitlab/-/issues/220496
  return false unless params

  REQUIRED_PAYLOAD_KEYS.subset?(params.keys.to_set) &&
    params['version'] == SUPPORTED_VERSION
end

Instance Method Details

#execute(token) ⇒ Object


20
21
22
23
24
25
26
27
28
29
# File 'app/services/projects/prometheus/alerts/notify_service.rb', line 20

def execute(token)
  return bad_request unless valid_payload_size?
  return unprocessable_entity unless self.class.processable?(params)
  return unauthorized unless valid_alert_manager_token?(token)

  process_prometheus_alerts
  send_alert_email if send_email?

  ServiceResponse.success
end