Class: LogStash::Outputs::Application_insights::Blob
- Defined in:
- lib/logstash/outputs/application_insights/blob.rb
Direct Known Subclasses
Notification, State_table, Storage_cleanup, Test_storage, Upload_pipe
Constant Summary collapse
- CREATE_EXIST_ERRORS =
{ :container => [ :create_container, :container_exist ], :table => [ :create_table, :table_exist ] }
- @@closing =
false
Instance Attribute Summary collapse
-
#last_io_exception ⇒ Object
readonly
Returns the value of attribute last_io_exception.
Class Method Summary collapse
Instance Method Summary collapse
- #create_container_exist_recovery ⇒ Object
- #create_exist_recovery(type, name) ⇒ Object
- #create_table_exist_recovery ⇒ Object
-
#initialize(tuple = nil) ⇒ Blob
constructor
A new instance of Blob.
-
#state_table_delete(state = nil) ⇒ Object
return true on success.
-
#state_table_insert ⇒ Object
return true on success.
-
#state_table_query(storage_account_name, filter, token) ⇒ Object
return entities.
- #state_table_update ⇒ Object
- #update_commited_or_uncommited_list ⇒ Object
Methods inherited from Context
#clear_context, #context_to_table_entity, #context_to_tuple, #table_entity_to_context, #table_entity_to_tuple, #tuple_to_context
Constructor Details
#initialize(tuple = nil) ⇒ Blob
Returns a new instance of Blob.
38 39 40 41 42 43 44 45 46 |
# File 'lib/logstash/outputs/application_insights/blob.rb', line 38 def initialize ( tuple = nil ) @configuration = Config.current @logger = @configuration[:logger] @storage_recovery = Storage_recovery.instance @notification_recovery = Notification_recovery.instance @max_tries = @configuration[:io_max_retries] + 1 super( tuple ) end |
Instance Attribute Details
#last_io_exception ⇒ Object (readonly)
Returns the value of attribute last_io_exception.
24 25 26 |
# File 'lib/logstash/outputs/application_insights/blob.rb', line 24 def last_io_exception @last_io_exception end |
Class Method Details
.close ⇒ Object
30 31 32 |
# File 'lib/logstash/outputs/application_insights/blob.rb', line 30 def self.close @@closing = true end |
.stopped? ⇒ Boolean
34 35 36 |
# File 'lib/logstash/outputs/application_insights/blob.rb', line 34 def self.stopped? @@closing end |
Instance Method Details
#create_container_exist_recovery ⇒ Object
68 69 70 |
# File 'lib/logstash/outputs/application_insights/blob.rb', line 68 def create_container_exist_recovery create_exist_recovery( :container, @container_name ) { |name| @client.blobClient.create_container( name ) } end |
#create_exist_recovery(type, name) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/logstash/outputs/application_insights/blob.rb', line 49 def create_exist_recovery( type, name ) if CREATE_EXIST_ERRORS[type][0] == @recovery @prev_info = @info @info = "create #{type} #{@storage_account_name}/#{name}" # assume that exceptions can be raised due to this method: yield name @logger.info { "Successed to #{@info}" } @info = @prev_info elsif CREATE_EXIST_ERRORS[type][1] == @recovery @logger.info { "Successed (already exist) to #{@info}" } @info = @prev_info end end |
#create_table_exist_recovery ⇒ Object
64 65 66 |
# File 'lib/logstash/outputs/application_insights/blob.rb', line 64 def create_table_exist_recovery create_exist_recovery( :table, @configuration[:state_table_name] ) { |name| @client.tableClient.create_table( name ) } end |
#state_table_delete(state = nil) ⇒ Object
return true on success
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/logstash/outputs/application_insights/blob.rb', line 111 def state_table_delete ( state = nil ) state ||= @log_state @action = :state_table_delete @recoverable = [ :invalid_storage_key, :io_failure, :service_unavailable, :table_exist, :create_table, :table_busy, :create_resource ] @info = "#{@action} #{state} #{@storage_account_name}/#{@container_name}/#{@blob_name}" success = storage_io_block { create_table_exist_recovery if :create_resource == @recovery @logger.info { "Note: delete entity failed, already deleted, #{@info}, state: #{state}, log_state: #{@log_state}" } else @client.tableClient.delete_entity( @configuration[:state_table_name], "#{@configuration[:partition_key_prefix]}-#{state}", @blob_name.gsub( "/", "_" ) ) end } @storage_recovery.recover_later( context_to_tuple, :state_table_update, @storage_account_name ) unless success success end |
#state_table_insert ⇒ Object
return true on success
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/logstash/outputs/application_insights/blob.rb', line 73 def state_table_insert @action = :state_table_insert @recoverable = [ :invalid_storage_key, :io_failure, :service_unavailable, :table_exist, :create_table, :table_busy, :entity_exist ] @info = "#{@action} #{@log_state} #{@storage_account_name}/#{@container_name}/#{@blob_name}" success = storage_io_block { create_table_exist_recovery if :entity_exist == @recovery raise NotRecoverableError if :uploading == @log_state else entity_values = context_to_table_entity entity_values[:PartitionKey] = "#{@configuration[:partition_key_prefix]}-#{@log_state}" entity_values[:RowKey] = @blob_name.gsub("/","_") @client.tableClient.insert_entity( @configuration[:state_table_name], entity_values ) end } @storage_recovery.recover_later( context_to_tuple, :state_table_update, @storage_account_name ) unless success || :uploading == @log_state success end |
#state_table_query(storage_account_name, filter, token) ⇒ Object
return entities
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/logstash/outputs/application_insights/blob.rb', line 130 def state_table_query ( storage_account_name, filter , token ) @storage_account_name = storage_account_name @action = :state_table_query @recoverable = [ :invalid_storage_key, :io_failure, :service_unavailable, :table_exist, :create_table, :table_busy ] @info = "#{@action} #{@storage_account_name}/#{@configuration[:state_table_name]}" entities = nil success = storage_io_block { create_table_exist_recovery = { :filter => filter } [:continuation_token] = token if token entities = @client.tableClient.query_entities( @configuration[:state_table_name], ) } entities end |
#state_table_update ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/logstash/outputs/application_insights/blob.rb', line 92 def state_table_update if :uploading == @log_state state_table_delete elsif :committed == @log_state if state_table_insert && state_table_delete( :uploading ) State.instance.dec_pending_commits State.instance.inc_pending_notifications # this is not a recovery, it is actually enqueue to notify @notification_recovery.enqueue( context_to_tuple ) end elsif :notified == @log_state if (!@configuration[:save_notified_blobs_records] || state_table_insert) && state_table_delete( :committed ) State.instance.dec_pending_notifications end end end |
#update_commited_or_uncommited_list ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/logstash/outputs/application_insights/blob.rb', line 148 def update_commited_or_uncommited_list @action = :list_blob_blocks @recoverable = [ :invalid_storage_key, :io_failure, :service_unavailable, :container_exist, :create_container, :create_blob ] list_blob_blocks = nil success = storage_io_block { @info = "#{@action} #{@storage_account_name}/#{@container_name}/#{@blob_name}" create_container_exist_recovery if :create_blob == @recovery list_blob_blocks = { :uncommitted => [ ], :committed => [ ] } else list_blob_blocks = @client.blobClient.list_blob_blocks( @container_name, @blob_name, { :blocklist_type => :all } ) unless :create_blob == @recovery end } if list_blob_blocks blocks = ( list_blob_blocks[:uncommitted].empty? ? list_blob_blocks[:committed] : list_blob_blocks[:uncommitted] ) blocks.each do |block| @uploaded_block_ids << [ block.name ] @uploaded_bytesize += block.size end if 0 < @file_size && @uploaded_bytesize != @file_size type = :upload_empty else type = ( blocks.empty? || 0 == @uploaded_bytesize ? :upload_empty : blocks[0].type ) end @log_state = :committed if :committed == type { type => context_to_tuple } else nil end end |