Class: Rails::HealthController

Inherits:
ActionController::Base show all
Defined in:
railties/lib/rails/health_controller.rb

Overview

Built-in Health Check Endpoint

Rails also comes with a built-in health check endpoint that is reachable at the /up path. This endpoint will return a 200 status code if the app has booted with no exceptions, and a 500 status code otherwise.

In production, many applications are required to report their status upstream, whether it’s to an uptime monitor that will page an engineer when things go wrong, or a load balancer or Kubernetes controller used to determine a pod’s health. This health check is designed to be a one-size fits all that will work in many situations.

While any newly generated Rails applications will have the health check at /up, you can configure the path to be anything you’d like in your "config/routes.rb":

Rails.application.routes.draw do
  get "healthz" => "rails/health#show", as: :rails_health_check
end

The health check will now be accessible via the /healthz path.

NOTE: This endpoint does not reflect the status of all of your application’s dependencies, such as the database or redis cluster. Replace "rails/health#show" with your own controller action if you have application specific needs.

Think carefully about what you want to check as it can lead to situations where your application is being restarted due to a third-party service going bad. Ideally, you should design your application to handle those outages gracefully.

Constant Summary

Constants inherited from ActionController::Base

ActionController::Base::MODULES, ActionController::Base::PROTECTED_IVARS

Instance Method Summary collapse

Methods inherited from ActionController::Base

without_modules

Methods included from ActionController::Testing::Functional

#clear_instance_variables_between_requests, #recycle!

Instance Method Details

#showObject



38
39
40
# File 'railties/lib/rails/health_controller.rb', line 38

def show
  render_up
end