2017-04-07 06:27:15 -04:00
|
|
|
module Gitlab
|
|
|
|
module HealthChecks
|
|
|
|
module SimpleAbstractCheck
|
|
|
|
include BaseAbstractCheck
|
|
|
|
|
|
|
|
def readiness
|
|
|
|
check_result = check
|
2017-08-24 13:02:27 -04:00
|
|
|
if successful?(check_result)
|
2017-04-07 06:27:15 -04:00
|
|
|
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-07-25 09:17:05 -04:00
|
|
|
result, elapsed = with_timing(&method(:check))
|
2017-08-24 13:02:27 -04:00
|
|
|
Rails.logger.error("#{human_name} check returned unexpected result #{result}") unless successful?(result)
|
2017-07-25 09:17:05 -04:00
|
|
|
[
|
|
|
|
metric("#{metric_prefix}_timeout", result.is_a?(Timeout::Error) ? 1 : 0),
|
2017-08-24 13:02:27 -04:00
|
|
|
metric("#{metric_prefix}_success", successful?(result) ? 1 : 0),
|
2017-07-25 09:17:05 -04:00
|
|
|
metric("#{metric_prefix}_latency_seconds", elapsed)
|
|
|
|
]
|
2017-04-07 06:27:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def metric_prefix
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2017-08-24 13:02:27 -04:00
|
|
|
def successful?(result)
|
2017-04-07 06:27:15 -04:00
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
def check
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|