Class: Mammoth::ObservabilitySnapshot
- Inherits:
-
Object
- Object
- Mammoth::ObservabilitySnapshot
- 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 SQLite operational-state status in a predictable format.
Instance Attribute Summary collapse
-
#clock ⇒ Object
readonly
Returns the value of attribute clock.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#sqlite_store ⇒ Object
readonly
Returns the value of attribute sqlite_store.
Instance Method Summary collapse
-
#health ⇒ Hash
Build a liveness response.
-
#initialize(config, sqlite_store: nil, clock: -> { Time.now.utc }) ⇒ 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, sqlite_store: nil, clock: -> { Time.now.utc }) ⇒ ObservabilitySnapshot
Returns a new instance of ObservabilitySnapshot.
19 20 21 22 23 |
# File 'lib/mammoth/observability_snapshot.rb', line 19 def initialize(config, sqlite_store: nil, clock: -> { Time.now.utc }) @config = config @sqlite_store = sqlite_store @clock = clock end |
Instance Attribute Details
#clock ⇒ Object (readonly)
Returns the value of attribute clock.
14 15 16 |
# File 'lib/mammoth/observability_snapshot.rb', line 14 def clock @clock end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
14 15 16 |
# File 'lib/mammoth/observability_snapshot.rb', line 14 def config @config end |
#sqlite_store ⇒ Object (readonly)
Returns the value of attribute sqlite_store.
14 15 16 |
# File 'lib/mammoth/observability_snapshot.rb', line 14 def sqlite_store @sqlite_store end |
Instance Method Details
#health ⇒ Hash
Build a liveness response.
28 29 30 31 32 33 34 35 36 |
# File 'lib/mammoth/observability_snapshot.rb', line 28 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.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/mammoth/observability_snapshot.rb', line 68 def prometheus store = operational_store.bootstrap! checkpoint_store = CheckpointStore.new(store) dead_letter_store = DeadLetterStore.new(store) delivered_store = DeliveredEnvelopeStore.new(store) lines = metric_headers + aggregate_metric_lines( checkpoint_store: checkpoint_store, dead_letter_store: dead_letter_store, delivered_store: delivered_store ) + destination_metric_lines(dead_letter_store:, delivered_store:) "#{lines.join("\n")}\n" rescue Mammoth::Error, SQLite3::Exception "#{(metric_headers + [metric_line("mammoth_up", 0)]).join("\n")}\n" end |
#readiness ⇒ Hash
Build a readiness response.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/mammoth/observability_snapshot.rb', line 41 def readiness store = operational_store store.bootstrap! { status: "ready", service: "mammoth", name: mammoth_name, sqlite: "ok", tables: store.tables, checked_at: checked_at } rescue Mammoth::Error, SQLite3::Exception => e { status: "unready", service: "mammoth", name: mammoth_name, sqlite: "error", error_class: e.class.name, error_message: e., checked_at: checked_at } end |