Read about our upcoming Code of Conduct on this issue

health_controller.rb 746 Bytes
Newer Older
1
2
# frozen_string_literal: true

3
class HealthController < ActionController::Base
4
  protect_from_forgery with: :exception, prepend: true
5
  include RequiresWhitelistedMonitoringClient
6
7

  def readiness
8
9
    results = checks.flat_map(&:readiness)
    success = results.all?(&:success)
10

11
12
13
14
15
    # 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
16
17
18
  end

  def liveness
19
    render json: { status: 'ok' }, status: :ok
20
21
22
23
  end

  private

24
25
  def checks
    ::Gitlab::HealthChecks::CHECKS
26
27
  end
end