debian-mirror-gitlab/lib/gitlab/health_checks/simple_abstract_check.rb

51 lines
1.4 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
module HealthChecks
module SimpleAbstractCheck
include BaseAbstractCheck
def readiness
check_result = check
2019-12-21 20:55:43 +05:30
return if check_result.nil?
2018-03-17 18:26:18 +05:30
if successful?(check_result)
2019-12-21 20:55:43 +05:30
HealthChecks::Result.new(name, true)
2017-08-17 22:00:37 +05:30
elsif check_result.is_a?(Timeout::Error)
2019-12-21 20:55:43 +05:30
HealthChecks::Result.new(name, false, "#{human_name} check timed out")
2017-08-17 22:00:37 +05:30
else
2019-12-21 20:55:43 +05:30
HealthChecks::Result.new(name, false, "unexpected #{human_name} check result: #{check_result}")
2017-08-17 22:00:37 +05:30
end
2019-12-21 20:55:43 +05:30
rescue => e
HealthChecks::Result.new(name, false, "unexpected #{human_name} check result: #{e}")
2017-08-17 22:00:37 +05:30
end
def metrics
2017-09-10 17:25:29 +05:30
result, elapsed = with_timing(&method(:check))
2019-12-21 20:55:43 +05:30
return if result.nil?
2020-11-24 15:15:51 +05:30
Gitlab::AppLogger.error("#{human_name} check returned unexpected result #{result}") unless successful?(result)
2017-09-10 17:25:29 +05:30
[
metric("#{metric_prefix}_timeout", result.is_a?(Timeout::Error) ? 1 : 0),
2018-03-17 18:26:18 +05:30
metric("#{metric_prefix}_success", successful?(result) ? 1 : 0),
2017-09-10 17:25:29 +05:30
metric("#{metric_prefix}_latency_seconds", elapsed)
]
2017-08-17 22:00:37 +05:30
end
private
def metric_prefix
raise NotImplementedError
end
2018-03-17 18:26:18 +05:30
def successful?(result)
2017-08-17 22:00:37 +05:30
raise NotImplementedError
end
def check
raise NotImplementedError
end
end
end
end