Class: Usps::Support::HealthController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Usps::Support::HealthController
- Defined in:
- app/controllers/usps/support/health_controller.rb
Overview
Base controller for external synthetic health probes (see the infrastructure repo’s doc/application_health_probes.md). Unlike Rails’ /up (boot-only) and nginx’s static /instance-health-check, this exercises an app’s *critical dependencies* and returns the sentinel “HEALTHCHECK_OK <app>” only when every check passes — a Route 53 HTTPS_STR_MATCH probe asserts the “HEALTHCHECK_OK” prefix, so a quiet app-level failure flips the Statuspage component even with no organic traffic.
Host apps subclass this and override #checks to pick which dependencies to probe, e.g.
class HealthController < Usps::Support::HealthController
private
def checks = { database: check_database, redis: check_redis }
end
and route to it (‘get ’health’ => ‘health#show’‘). The check_* primitives below each return a boolean and never raise, so the action always responds. Apps run only the checks for the dependencies they actually configure — admin-console has no HQ connection, so it omits check_hq_database; an iMIS-backed app adds check_imis; a custom downstream is check_http(url).
Inherits ActionController::Base directly — NOT the host’s ApplicationController — to bypass Devise auth, Pundit authorization, PaperTrail, and especially ‘allow_browser`, whose modern-browser gate would 406 Route 53’s non-browser prober and fail the probe for the wrong reason.
Constant Summary collapse
- SENTINEL_PREFIX =
rubocop:disable Rails/ApplicationController
'HEALTHCHECK_OK'
Instance Method Summary collapse
Instance Method Details
#show ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/usps/support/health_controller.rb', line 32 def show results = checks healthy = results.values.all? body = "#{healthy ? "#{SENTINEL_PREFIX} #{app_name}" : "HEALTHCHECK_FAIL #{app_name}"}\n" results.each { |name, ok| body << "#{name}=#{ok ? 'ok' : 'fail'}\n" } response.set_header('Cache-Control', 'no-store') response.set_header('Retry-After', '30') unless healthy render(plain: body, content_type: 'text/plain', status: healthy ? :ok : :service_unavailable) end |