Class: LogStash::Outputs::Application_insights::Clients

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/application_insights/clients.rb

Constant Summary collapse

@@instance =
Clients.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClients

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

.instanceObject



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  (  , force )
  raise StorageAccountsOffError if 0 == @current_storage_account_names.length && force.nil?
  @storage_accounts[]
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 |, |

    clients_Q = Queue.new
    @storage_accounts[] = { :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 << 
  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 ( , io_failed_reason )
   = @storage_accounts[]
  @state_semaphore.synchronize {
    unless [:off_reason].include?( io_failed_reason )
      [:off_reason] << io_failed_reason
      if [:off_reason].length == 1
         = [  ]
        @current_storage_account_names.each do ||
           <<  unless  == 
        end
        @current_storage_account_names = 

        Thread.new(  ) do ||
          test_storage = Test_storage.new(  )
          loop do
            sleep( @resurrect_delay )
            if test_storage.test
              @state_semaphore.synchronize {
                 = @storage_accounts[]
                [:off_reason] = [  ]
                @current_storage_account_names << 
              }
              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 {  = ( @current_storage_account_names - exclude ).sample if @current_storage_account_names.length > 0 }
end

#storage_account_state_on?(storage_account_name = nil) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
64
65
66
# File 'lib/logstash/outputs/application_insights/clients.rb', line 60

def  (  = nil )
  if 
    @storage_accounts[][:off_reason].empty?
  else
    @current_storage_account_names.length > 0
  end
end