Class: TopologicalInventory::Providers::Common::CollectorsPool

Inherits:
Object
  • Object
show all
Defined in:
lib/topological_inventory/providers/common/collectors_pool.rb

Constant Summary collapse

SECRET_FILENAME =
"credentials".freeze
COLLECTOR_POLL_TIME =
ENV['COLLECTOR_POLL_TIME']&.to_i || 300

Instance Method Summary collapse

Constructor Details

#initialize(config_name, metrics, collector_poll_time: COLLECTOR_POLL_TIME, thread_pool_size: 2) ⇒ CollectorsPool

Returns a new instance of CollectorsPool.



10
11
12
13
14
15
16
17
18
# File 'lib/topological_inventory/providers/common/collectors_pool.rb', line 10

def initialize(config_name, metrics, collector_poll_time: COLLECTOR_POLL_TIME, thread_pool_size: 2)
  self.config_name         = config_name
  self.collector_status    = Concurrent::Map.new
  self.metrics             = metrics
  self.collector_poll_time = collector_poll_time
  self.secrets             = nil
  self.thread_pool         = Concurrent::FixedThreadPool.new(thread_pool_size)
  self.updated_at          = {}
end

Instance Method Details

#run!Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/topological_inventory/providers/common/collectors_pool.rb', line 20

def run!
  loop do
    reload_config
    reload_secrets

    # Secret is deployed just after config map, we should wait for it
    queue_collectors if secrets_newer_than_config?

    sleep(5)
  end
end

#stop!Object



32
33
34
35
36
37
38
# File 'lib/topological_inventory/providers/common/collectors_pool.rb', line 32

def stop!
  collectors.each_value(&:stop)

  thread_pool.shutdown
  # Wait for end of collectors to ensure metrics are stopped after them
  thread_pool.wait_for_termination
end