Class: Mammoth::ObservabilitySnapshot
- Inherits:
-
Object
- Object
- Mammoth::ObservabilitySnapshot
- Includes:
- ObservabilityMetrics
- Defined in:
- lib/mammoth/observability_snapshot.rb
Overview
Builds health, readiness, and metrics snapshots from Mammoth's local operational state.
ObservabilitySnapshot is intentionally read-only. It does not start the relay, mutate checkpoints, replay dead letters, or inspect PostgreSQL. The health and metrics endpoints use this object to expose Mammoth process and operational-state adapter status in a predictable format.
Constant Summary
Constants included from ObservabilityMetrics
Mammoth::ObservabilityMetrics::DISPATCH_METRIC_NAMES
Instance Attribute Summary collapse
-
#clock ⇒ Object
readonly
Returns the value of attribute clock.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#dispatch_metrics ⇒ Object
readonly
Returns the value of attribute dispatch_metrics.
-
#state_adapter ⇒ Object
readonly
Returns the value of attribute state_adapter.
Instance Method Summary collapse
-
#health ⇒ Hash
Build a liveness response.
-
#initialize(config, state_adapter: nil, clock: -> { Time.now.utc }, dispatch_metrics: DispatchMetrics::INSTANCE) ⇒ ObservabilitySnapshot
constructor
A new instance of ObservabilitySnapshot.
-
#prometheus ⇒ String
Build a Prometheus text exposition document.
-
#readiness ⇒ Hash
Build a readiness response.
Constructor Details
#initialize(config, state_adapter: nil, clock: -> { Time.now.utc }, dispatch_metrics: DispatchMetrics::INSTANCE) ⇒ ObservabilitySnapshot
Returns a new instance of ObservabilitySnapshot.
22 23 24 25 26 27 |
# File 'lib/mammoth/observability_snapshot.rb', line 22 def initialize(config, state_adapter: nil, clock: -> { Time.now.utc }, dispatch_metrics: DispatchMetrics::INSTANCE) @config = config @state_adapter = state_adapter || OperationalState::Registry.build_configured(config) @clock = clock @dispatch_metrics = dispatch_metrics end |
Instance Attribute Details
#clock ⇒ Object (readonly)
Returns the value of attribute clock.
16 17 18 |
# File 'lib/mammoth/observability_snapshot.rb', line 16 def clock @clock end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
16 17 18 |
# File 'lib/mammoth/observability_snapshot.rb', line 16 def config @config end |
#dispatch_metrics ⇒ Object (readonly)
Returns the value of attribute dispatch_metrics.
16 17 18 |
# File 'lib/mammoth/observability_snapshot.rb', line 16 def dispatch_metrics @dispatch_metrics end |
#state_adapter ⇒ Object (readonly)
Returns the value of attribute state_adapter.
16 17 18 |
# File 'lib/mammoth/observability_snapshot.rb', line 16 def state_adapter @state_adapter end |
Instance Method Details
#health ⇒ Hash
Build a liveness response.
32 33 34 35 36 37 38 39 40 |
# File 'lib/mammoth/observability_snapshot.rb', line 32 def health { status: "ok", service: "mammoth", name: mammoth_name, version: Mammoth::VERSION, checked_at: checked_at } end |
#prometheus ⇒ String
Build a Prometheus text exposition document.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mammoth/observability_snapshot.rb', line 64 def prometheus return down_metrics unless state_adapter.ready? lines = metric_headers + aggregate_metric_lines( checkpoint_store: state_adapter.checkpoint_store, dead_letter_store: state_adapter.dead_letter_store, delivered_store: state_adapter.delivered_envelope_store ) + destination_metric_lines( dead_letter_store: state_adapter.dead_letter_store, delivered_store: state_adapter.delivered_envelope_store ) + dispatch_metric_lines "#{lines.join("\n")}\n" rescue Mammoth::Error down_metrics end |
#readiness ⇒ Hash
Build a readiness response.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mammoth/observability_snapshot.rb', line 45 def readiness return unready_payload unless state_adapter.ready? { status: "ready", service: "mammoth", name: mammoth_name, operational_state: "ok", adapter: state_summary.fetch(:adapter), summary: state_summary, checked_at: checked_at } rescue Mammoth::Error => e adapter_error_payload(e) end |