Class: LogStash::Outputs::Application_insights::Clients
- Inherits:
-
Object
- Object
- LogStash::Outputs::Application_insights::Clients
- Defined in:
- lib/logstash/outputs/application_insights/clients.rb
Constant Summary collapse
- @@instance =
Clients.new
Class Method Summary collapse
Instance Method Summary collapse
- #active_storage_account(storage_account_name, force) ⇒ Object
- #create_blob_clients(configuration) ⇒ Object
- #failed_storage_account(storage_account_name, io_failed_reason) ⇒ Object
- #get_random_active_storage(exclude) ⇒ Object
-
#initialize ⇒ Clients
constructor
A new instance of Clients.
- #storage_account_state_on?(storage_account_name = nil) ⇒ Boolean
Constructor Details
#initialize ⇒ Clients
Returns a new instance of Clients.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/logstash/outputs/application_insights/clients.rb', line 27 def initialize configuration = Config.current @resurrect_delay = configuration[:resurrect_delay] @storage_accounts = { } @storage_account_names = [ ] @current_storage_account_names = [ ] @last_storage_account_key_index = 0 @state_semaphore = Mutex.new create_blob_clients( configuration ) end |
Class Method Details
.instance ⇒ Object
108 109 110 |
# File 'lib/logstash/outputs/application_insights/clients.rb', line 108 def self.instance @@instance end |
Instance Method Details
#active_storage_account(storage_account_name, force) ⇒ Object
39 40 41 42 |
# File 'lib/logstash/outputs/application_insights/clients.rb', line 39 def active_storage_account ( storage_account_name , force ) raise StorageAccountsOffError if 0 == @current_storage_account_names.length && force.nil? @storage_accounts[storage_account_name] end |
#create_blob_clients(configuration) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/logstash/outputs/application_insights/clients.rb', line 44 def create_blob_clients ( configuration ) configuration[:storage_account_name_key].each do |storage_account_name, storage_account_keys| clients_Q = Queue.new @storage_accounts[storage_account_name] = { :keys => storage_account_keys, :clients_Q => clients_Q, :valid_index => 0, :state => :on, :off_reason => [] } 40.times do # lazy creation, clients will be created when first needed clients_Q << [ nil, nil, nil] end @storage_account_names << storage_account_name end @current_storage_account_names = @storage_account_names.clone end |
#failed_storage_account(storage_account_name, io_failed_reason) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/logstash/outputs/application_insights/clients.rb', line 68 def failed_storage_account( storage_account_name, io_failed_reason ) storage_account = @storage_accounts[storage_account_name] @state_semaphore.synchronize { unless storage_account[:off_reason].include?( io_failed_reason ) storage_account[:off_reason] << io_failed_reason if storage_account[:off_reason].length == 1 current_storage_account_names = [ ] @current_storage_account_names.each do |account_name| current_storage_account_names << account_name unless account_name == storage_account_name end @current_storage_account_names = current_storage_account_names Thread.new( storage_account_name ) do |account_name| test_storage = Test_storage.new( account_name ) loop do sleep( @resurrect_delay ) if test_storage.test @state_semaphore.synchronize { storage_account = @storage_accounts[account_name] storage_account[:off_reason] = [ ] @current_storage_account_names << account_name } break end end end end end } end |
#get_random_active_storage(exclude) ⇒ Object
100 101 102 |
# File 'lib/logstash/outputs/application_insights/clients.rb', line 100 def get_random_active_storage( exclude ) @state_semaphore.synchronize { storage_account_name = ( @current_storage_account_names - exclude ).sample if @current_storage_account_names.length > 0 } end |
#storage_account_state_on?(storage_account_name = nil) ⇒ Boolean
60 61 62 63 64 65 66 |
# File 'lib/logstash/outputs/application_insights/clients.rb', line 60 def storage_account_state_on? ( storage_account_name = nil ) if storage_account_name @storage_accounts[storage_account_name][:off_reason].empty? else @current_storage_account_names.length > 0 end end |