diff options
Diffstat (limited to 'app/controllers/health_controller.rb')
-rw-r--r-- | app/controllers/health_controller.rb | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/app/controllers/health_controller.rb b/app/controllers/health_controller.rb index 84b4932ba7a..99840e40af1 100644 --- a/app/controllers/health_controller.rb +++ b/app/controllers/health_controller.rb @@ -4,19 +4,15 @@ class HealthController < ActionController::Base protect_from_forgery with: :exception, prepend: true include RequiresWhitelistedMonitoringClient - CHECKS = [ - Gitlab::HealthChecks::DbCheck, - Gitlab::HealthChecks::Redis::RedisCheck, - Gitlab::HealthChecks::Redis::CacheCheck, - Gitlab::HealthChecks::Redis::QueuesCheck, - Gitlab::HealthChecks::Redis::SharedStateCheck, - Gitlab::HealthChecks::GitalyCheck - ].freeze - def readiness - results = CHECKS.map { |check| [check.name, check.readiness] } + results = checks.flat_map(&:readiness) + success = results.all?(&:success) - render_check_results(results) + # disable static error pages at the gitlab-workhorse level, we want to see this error response even in production + headers["X-GitLab-Custom-Error"] = 1 unless success + + response = results.map { |result| [result.name, result.payload] }.to_h + render json: response, status: success ? :ok : :service_unavailable end def liveness @@ -25,26 +21,7 @@ class HealthController < ActionController::Base 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 - - # disable static error pages at the gitlab-workhorse level, we want to see this error response even in production - headers["X-GitLab-Custom-Error"] = 1 unless success - - render json: response.to_h, status: success ? :ok : :service_unavailable + def checks + ::Gitlab::HealthChecks::CHECKS end end |