2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class HealthController < ActionController::Base
|
2018-12-13 13:39:08 +05:30
|
|
|
protect_from_forgery with: :exception, prepend: true
|
2017-09-10 17:25:29 +05:30
|
|
|
include RequiresWhitelistedMonitoringClient
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
CHECKS = [
|
|
|
|
Gitlab::HealthChecks::DbCheck,
|
2017-09-10 17:25:29 +05:30
|
|
|
Gitlab::HealthChecks::Redis::RedisCheck,
|
|
|
|
Gitlab::HealthChecks::Redis::CacheCheck,
|
|
|
|
Gitlab::HealthChecks::Redis::QueuesCheck,
|
|
|
|
Gitlab::HealthChecks::Redis::SharedStateCheck,
|
2018-03-17 18:26:18 +05:30
|
|
|
Gitlab::HealthChecks::GitalyCheck
|
2017-08-17 22:00:37 +05:30
|
|
|
].freeze
|
|
|
|
|
|
|
|
def readiness
|
|
|
|
results = CHECKS.map { |check| [check.name, check.readiness] }
|
|
|
|
|
|
|
|
render_check_results(results)
|
|
|
|
end
|
|
|
|
|
|
|
|
def liveness
|
|
|
|
results = CHECKS.map { |check| [check.name, check.liveness] }
|
|
|
|
|
|
|
|
render_check_results(results)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def render_check_results(results)
|
|
|
|
flattened = results.flat_map do |name, result|
|
|
|
|
if result.is_a?(Gitlab::HealthChecks::Result)
|
|
|
|
[[name, result]]
|
|
|
|
else
|
|
|
|
result.map { |r| [name, r] }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
success = flattened.all? { |name, r| r.success }
|
|
|
|
|
|
|
|
response = flattened.map do |name, r|
|
|
|
|
info = { status: r.success ? 'ok' : 'failed' }
|
|
|
|
info['message'] = r.message if r.message
|
|
|
|
info[:labels] = r.labels if r.labels
|
|
|
|
[name, info]
|
|
|
|
end
|
|
|
|
render json: response.to_h, status: success ? :ok : :service_unavailable
|
|
|
|
end
|
|
|
|
end
|