Class: Cyclid::API::HealthController

Inherits:
ControllerBase show all
Includes:
Errors::HTTPErrors
Defined in:
app/cyclid/controllers/health.rb

Overview

Controller for all Health related API endpoints

Health collapse

Instance Method Summary collapse

Constructor Details

#initialize(_app) ⇒ HealthController

Returns a new instance of HealthController.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/cyclid/controllers/health.rb', line 27

def initialize(_app)
  super
  @checker = SinatraHealthCheck::Checker.new(logger: Cyclid.logger,
                                             timeout: 0)

  # Add internal health checks
  @checker.systems[:database] = Cyclid::API::Health::Database

  # Add each plugin, which can choose to provide a healthcheck by
  # implementing #status
  Cyclid.plugins.all.each do |plugin|
    name = "#{plugin.human_name}_#{plugin.name}".to_sym
    @checker.systems[name] = plugin
  end
end

Instance Method Details

#GET(/health/info) ⇒ Object

Return verbose information on the status of the individual checks; note that this method always returns 200 with a message body, so it is not suitable for general health checks unless the caller intends to parse the message body for the health status.

Returns:

  • JSON description of the individual health check statuses.



65
66
67
# File 'app/cyclid/controllers/health.rb', line 65

get '/health/info' do
  @checker.status.to_json
end

#GET(/health/status) ⇒ 200, 503

Return either 200 (healthy) or 503 (unhealthy) based on the status of the healthchecks. This is intended to be used by things like load balancers and active monitors.

Returns:

  • (200)

    Application is healthy.

  • (503)

    Application is unhealthy.



53
54
55
# File 'app/cyclid/controllers/health.rb', line 53

get '/health/status' do
  @checker.healthy? ? 200 : 503
end