Module: Cuniculus::Plugins::HealthCheck

Defined in:
lib/cuniculus/plugins/health_check.rb

Overview

The HealthCheck plugin starts a Rack server after consumers are initialized, for health probing. It currently does not perform any additional checks and returns ‘200 OK’ regardless of whether

  • the node can connect to RabbitMQ;

  • consumers are stuck.

The healthcheck stays up as long as the supervisor module is also running.

Enable the plugin with: “‘ruby Cuniculus.plugin(:health_check) “`

Options may be passed as well: “‘ruby opts =

"bind_to" => "127.0.0.1", # Default: "0.0.0.0"
"port" => 8080            # Default: 3000
"path" => "alive"         # Default: "healtcheck"

Cuniculus.plugin(:health_check, opts) “‘ This starts the server bound to 127.0.0.1 and port 8080, and responds on path “alive”. The server responds with 404 when requests are made to different paths.

Defined Under Namespace

Modules: SupervisorMethods

Constant Summary collapse

DEFAULTS =
{
  "bind_to" => "0.0.0.0",
  "path" => "healthcheck",
  "port" => 3000,
  "quiet" => false,
  "server" => "webrick",
  "block" => nil
}.freeze
OPTS_KEY =

Key in the global plugin options where ‘:health_check` plugin options are stored.

"__health_check_opts"

Class Method Summary collapse

Class Method Details

.configure(plugins_cfg, opts = {}, &block) ⇒ Object

Configure ‘health_check` plugin

Parameters:

  • plugins_cfg (Hash)

    Global plugin config hash, passed by Cuniculus. This should not be modified by plugin users.

  • opts (Hash) (defaults to: {})

    Plugin specific options.

Options Hash (opts):

  • "bind_to" (String) — default: "0.0.0.0"

    IP address to bind to.

  • "path" (String) — default: "healthcheck"

    Request path to respond to. Requests to other paths will get a 404 response.

  • "port" (Numeric) — default: 3000

    Port number to bind to.

  • "quiet" (Boolean) — default: false

    Disable server logging to STDOUT and STDERR.

  • "server" (String) — default: "webrick"

    Rack server handler to use .

Raises:



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cuniculus/plugins/health_check.rb', line 53

def self.configure(plugins_cfg, opts = {}, &block)
  opts = opts.transform_keys(&:to_s)
  invalid_opts = opts.keys - DEFAULTS.keys
  raise Cuniculus::Error, "Invalid option keys for :health_check plugin: #{invalid_opts}" unless invalid_opts.empty?

  plugins_cfg[OPTS_KEY] = h = opts.slice("bind_to", "path", "port", "quiet", "server")
  h["block"] = block if block
  DEFAULTS.each do |k, v|
    h[k] = v if v && !h.key?(k)
  end
end