Class: Mammoth::ObservabilityServer

Inherits:
Object
  • Object
show all
Defined in:
lib/mammoth/observability_server.rb

Overview

Small HTTP server exposing Mammoth health, readiness, and metrics endpoints.

The server is intentionally independent from the replication loop. Operators may run it as a sidecar-like process or in a separate process that points at the same configured operational-state backend.

Constant Summary collapse

DEFAULT_HOST =

Default bind host for the observability server.

"0.0.0.0"
DEFAULT_PORT =

Default TCP port for the observability server.

9393

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, host: nil, port: nil, state_adapter: nil, slot_health_provider: nil, logger: nil) ⇒ ObservabilityServer

Returns a new instance of ObservabilityServer.

Parameters:

  • config (Mammoth::Configuration)

    loaded configuration

  • host (String, nil) (defaults to: nil)

    bind host override

  • port (Integer, nil) (defaults to: nil)

    bind port override

  • state_adapter (Mammoth::OperationalState::Adapter, nil) (defaults to: nil)

    operational state dependency

  • slot_health_provider (#slot_health, nil) (defaults to: nil)

    PostgreSQL slot health dependency

  • logger (WEBrick::Log, nil) (defaults to: nil)

    optional WEBrick logger



26
27
28
29
30
31
32
33
34
35
# File 'lib/mammoth/observability_server.rb', line 26

def initialize(config, host: nil, port: nil, state_adapter: nil, slot_health_provider: nil, logger: nil)
  @config = config
  @host = host || config.dig("observability", "host") || DEFAULT_HOST
  @port = port || config.dig("observability", "port") || DEFAULT_PORT
  @state_adapter = state_adapter || OperationalState::Registry.build_configured(config)
  @slot_health_provider = slot_health_provider || Sources::Postgres.new(config)
  @logger = logger || WEBrick::Log.new($stderr, WEBrick::Log::WARN)
  @server = build_server
  mount_endpoints
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



18
19
20
# File 'lib/mammoth/observability_server.rb', line 18

def config
  @config
end

#hostObject (readonly)

Returns the value of attribute host.



18
19
20
# File 'lib/mammoth/observability_server.rb', line 18

def host
  @host
end

#loggerObject (readonly)

Returns the value of attribute logger.



18
19
20
# File 'lib/mammoth/observability_server.rb', line 18

def logger
  @logger
end

#portObject (readonly)

Returns the value of attribute port.



18
19
20
# File 'lib/mammoth/observability_server.rb', line 18

def port
  @port
end

#serverObject (readonly)

Returns the value of attribute server.



18
19
20
# File 'lib/mammoth/observability_server.rb', line 18

def server
  @server
end

#slot_health_providerObject (readonly)

Returns the value of attribute slot_health_provider.



18
19
20
# File 'lib/mammoth/observability_server.rb', line 18

def slot_health_provider
  @slot_health_provider
end

#state_adapterObject (readonly)

Returns the value of attribute state_adapter.



18
19
20
# File 'lib/mammoth/observability_server.rb', line 18

def state_adapter
  @state_adapter
end

Instance Method Details

#shutdownvoid

This method returns an undefined value.

Stop the HTTP server.



47
48
49
# File 'lib/mammoth/observability_server.rb', line 47

def shutdown
  server.shutdown
end

#startvoid

This method returns an undefined value.

Start the blocking HTTP server.



40
41
42
# File 'lib/mammoth/observability_server.rb', line 40

def start
  server.start
end