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

43 lines
1.1 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
module Gitlab
module HealthChecks
module SimpleAbstractCheck
include BaseAbstractCheck
def readiness
check_result = check
if is_successful?(check_result)
HealthChecks::Result.new(true)
elsif check_result.is_a?(Timeout::Error)
HealthChecks::Result.new(false, "#{human_name} check timed out")
else
HealthChecks::Result.new(false, "unexpected #{human_name} check result: #{check_result}")
end
end
def metrics
2017-09-10 17:25:29 +05:30
result, elapsed = with_timing(&method(:check))
Rails.logger.error("#{human_name} check returned unexpected result #{result}") unless is_successful?(result)
[
metric("#{metric_prefix}_timeout", result.is_a?(Timeout::Error) ? 1 : 0),
metric("#{metric_prefix}_success", is_successful?(result) ? 1 : 0),
metric("#{metric_prefix}_latency_seconds", elapsed)
]
2017-08-17 22:00:37 +05:30
end
private
def metric_prefix
raise NotImplementedError
end
def is_successful?(result)
raise NotImplementedError
end
def check
raise NotImplementedError
end
end
end
end