Class: Gitlab::Database::HealthStatus::Indicators::PrometheusAlertIndicator

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/database/health_status/indicators/prometheus_alert_indicator.rb

Direct Known Subclasses

PatroniApdex, WalRate

Constant Summary collapse

ALERT_CONDITIONS =
{
  above: :above,
  below: :below
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ PrometheusAlertIndicator

Returns a new instance of PrometheusAlertIndicator.



15
16
17
# File 'lib/gitlab/database/health_status/indicators/prometheus_alert_indicator.rb', line 15

def initialize(context)
  @gitlab_schema = context.gitlab_schema.to_sym
end

Instance Method Details

#evaluateObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gitlab/database/health_status/indicators/prometheus_alert_indicator.rb', line 19

def evaluate
  return Signals::NotAvailable.new(self.class, reason: 'indicator disabled') unless enabled?

  connection_error_message = fetch_connection_error_message
  return unknown_signal(connection_error_message) if connection_error_message.present?

  sli = fetch_sli(sli_query)
  return unknown_signal("#{indicator_name} can not be calculated") unless sli.present?

  if alert_condition == ALERT_CONDITIONS[:above] ? sli.to_f > slo.to_f : sli.to_f < slo.to_f
    Signals::Normal.new(self.class, reason: "#{indicator_name} SLI condition met")
  else
    Signals::Stop.new(self.class, reason: "#{indicator_name} SLI condition not met")
  end
end