2018-09-14 01:42:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-07 06:27:15 -04:00
|
|
|
class HealthController < ActionController::Base
|
2018-10-09 01:59:42 -04:00
|
|
|
protect_from_forgery with: :exception, prepend: true
|
2017-07-03 11:09:34 -04:00
|
|
|
include RequiresWhitelistedMonitoringClient
|
2017-04-07 06:27:15 -04:00
|
|
|
|
2019-10-16 14:08:01 -04:00
|
|
|
CHECKS = [
|
2019-11-07 10:06:33 -05:00
|
|
|
Gitlab::HealthChecks::MasterCheck
|
|
|
|
].freeze
|
|
|
|
|
|
|
|
ALL_CHECKS = [
|
|
|
|
*CHECKS,
|
2019-10-16 14:08:01 -04:00
|
|
|
Gitlab::HealthChecks::DbCheck,
|
|
|
|
Gitlab::HealthChecks::Redis::RedisCheck,
|
|
|
|
Gitlab::HealthChecks::Redis::CacheCheck,
|
|
|
|
Gitlab::HealthChecks::Redis::QueuesCheck,
|
|
|
|
Gitlab::HealthChecks::Redis::SharedStateCheck,
|
2021-06-09 02:10:29 -04:00
|
|
|
Gitlab::HealthChecks::Redis::TraceChunksCheck,
|
2021-09-30 14:11:31 -04:00
|
|
|
Gitlab::HealthChecks::Redis::RateLimitingCheck,
|
2021-10-15 11:10:09 -04:00
|
|
|
Gitlab::HealthChecks::Redis::SessionsCheck,
|
2019-10-16 14:08:01 -04:00
|
|
|
Gitlab::HealthChecks::GitalyCheck
|
|
|
|
].freeze
|
|
|
|
|
2017-04-07 06:27:15 -04:00
|
|
|
def readiness
|
2019-11-07 10:06:33 -05:00
|
|
|
# readiness check is a collection of application-level checks
|
|
|
|
# and optionally all service checks
|
|
|
|
render_checks(params[:all] ? ALL_CHECKS : CHECKS)
|
2017-04-07 06:27:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def liveness
|
2019-10-16 14:08:01 -04:00
|
|
|
# liveness check is a collection without additional checks
|
|
|
|
render_checks
|
2017-04-07 06:27:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-11-07 10:06:33 -05:00
|
|
|
def render_checks(checks = [])
|
2019-10-16 14:08:01 -04:00
|
|
|
result = Gitlab::HealthChecks::Probes::Collection
|
|
|
|
.new(*checks)
|
|
|
|
.execute
|
2019-10-07 11:05:59 -04:00
|
|
|
|
|
|
|
# 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 result.success?
|
|
|
|
|
|
|
|
render json: result.json, status: result.http_status
|
2017-04-07 06:27:15 -04:00
|
|
|
end
|
|
|
|
end
|