Class: Philae::CollectionProbe

Inherits:
Object
  • Object
show all
Defined in:
lib/philae/collection_probe.rb

Direct Known Subclasses

EtcdClusterProbe, NSQClusterProbe

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CollectionProbe

Returns a new instance of CollectionProbe.

Raises:

  • (ArgumentError)


3
4
5
# File 'lib/philae/collection_probe.rb', line 3

def initialize(*args)
  raise ArgumentError, "can't be instantiate, use specialized class"
end

Instance Method Details

#checkObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/philae/collection_probe.rb', line 11

def check
  results = []
  result_queue = Queue.new
  probes.each do |probe|
    Thread.new do
      begin
        result = probe.check
      rescue StandardError => e
        result = {
          healthy: false,
          error: "probe #{probe.name} check failed: #{e.class} - #{e.message}",
        }
      end
      result[:probe] = probe
      result_queue.push result
    end
  end

  loop do
    results.push result_queue.pop
    break if results.count == probes.length
  end

  failed_results = results.select do |result|
    result[:healthy] == false
  end

  error = failed_results.map do |result|
    msg = "#{result[:probe].name}: #{result[:comment]} "
    msg += result[:code] if result[:code]
    msg += result[:error] if result[:error]
    next msg
  end.join(', ')

  if failed_results.count == probes.count
    return { healthy: false, comment: "All #{name} nodes are down", error: error }
  elsif failed_results.count > 0
    return { healthy: true, comment: "#{failed_results.count} #{name} nodes are down: #{error}" }
  else
    return { healthy: true, comment: '' }
  end
end

#probesObject

Raises:

  • (ArgumentError)


7
8
9
# File 'lib/philae/collection_probe.rb', line 7

def probes
  raise ArgumentError, 'specialized class should implement :probes'
end