Class: RoundhouseUi::Health

Inherits:
Object
  • Object
show all
Defined in:
lib/roundhouse_ui/health.rb

Overview

A composite health verdict for the dashboard. Instead of a static green dot, it rolls up the signals an on-call engineer actually checks — error rate, queue latency, worker utilization — into one status + a human reason, and exposes the sub-signals so the banner can explain why.

Defined Under Namespace

Classes: Signal

Constant Summary collapse

RANK =
{ ok: 0, warn: 1, crit: 2 }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(stats:, queues:, metrics:) ⇒ Health

Returns a new instance of Health.



11
12
13
14
15
# File 'lib/roundhouse_ui/health.rb', line 11

def initialize(stats:, queues:, metrics:)
  @stats = stats
  @queues = queues
  @metrics = metrics
end

Instance Method Details

#failing_countObject



24
25
26
# File 'lib/roundhouse_ui/health.rb', line 24

def failing_count
  signals.count { |s| s.status != :ok }
end

#healthy?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/roundhouse_ui/health.rb', line 44

def healthy?
  status == :ok
end

#ranked_signalsObject

Signals worst-first, the same rule the Queues page sorts by: the order is information, so a failing check should never sit below a healthy one. Ties break on label, so the order is stable between polls.



20
21
22
# File 'lib/roundhouse_ui/health.rb', line 20

def ranked_signals
  signals.sort_by { |s| [ -RANK.fetch(s.status, 0), s.label.to_s ] }
end

#reasonObject



37
38
39
40
41
42
# File 'lib/roundhouse_ui/health.rb', line 37

def reason
  worst = signals.max_by { |s| RANK[s.status] }
  return "all signals nominal" if worst.nil? || worst.status == :ok

  worst.detail
end

#signalsObject



28
29
30
# File 'lib/roundhouse_ui/health.rb', line 28

def signals
  @signals ||= [ error_rate_signal, latency_signal, utilization_signal ].compact
end

#statusObject

Worst sub-signal wins.



33
34
35
# File 'lib/roundhouse_ui/health.rb', line 33

def status
  signals.map(&:status).max_by { |s| RANK[s] } || :ok
end