summaryrefslogtreecommitdiff
path: root/app/controllers/health_controller.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-03 21:07:29 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-03 21:07:29 +0000
commit1da3754b25657f49afdcb0b942506d365b1ee89d (patch)
tree9f4bfa94fdd1762ef99e6a61bf180ac8cd7b5616 /app/controllers/health_controller.rb
parent25521def84a6987fe9d4265b560e930bfb32c195 (diff)
downloadgitlab-ce-1da3754b25657f49afdcb0b942506d365b1ee89d.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/controllers/health_controller.rb')
-rw-r--r--app/controllers/health_controller.rb41
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