Class: Prometheus::CreateDefaultAlertsService

Inherits:
BaseService
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/prometheus/create_default_alerts_service.rb

Constant Summary collapse

DEFAULT_ALERTS =
[
  {
    identifier: 'response_metrics_nginx_ingress_16_http_error_rate',
    operator: 'gt',
    threshold: 0.1
  },
  {
    identifier: 'response_metrics_nginx_ingress_http_error_rate',
    operator: 'gt',
    threshold: 0.1
  },
  {
    identifier: 'response_metrics_nginx_http_error_percentage',
    operator: 'gt',
    threshold: 0.1
  }
].freeze

Instance Attribute Summary collapse

Attributes inherited from BaseService

#current_user, #params

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

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

#initialize(project:) ⇒ CreateDefaultAlertsService

Returns a new instance of CreateDefaultAlertsService.


27
28
29
# File 'app/services/prometheus/create_default_alerts_service.rb', line 27

def initialize(project:)
  @project = project
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project


7
8
9
# File 'app/services/prometheus/create_default_alerts_service.rb', line 7

def project
  @project
end

Instance Method Details

#executeObject


31
32
33
34
35
36
37
38
39
# File 'app/services/prometheus/create_default_alerts_service.rb', line 31

def execute
  return ServiceResponse.error(message: 'Invalid project') unless project
  return ServiceResponse.error(message: 'Invalid environment') unless environment

  create_alerts
  schedule_prometheus_update

  ServiceResponse.success
end