Skip to content

Commit

Permalink
Make some parameter names more specific
Browse files Browse the repository at this point in the history
Signed-off-by: Daijiro Fukuda <[email protected]>
  • Loading branch information
daipom committed Apr 30, 2024
1 parent d57402e commit 6763f3d
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions lib/fluent/plugin/out_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class HTTPOutput < Output

class RetryableResponse < StandardError; end

CacheEntry = Struct.new(:uri, :conn)
ConnectionCache = Struct.new(:uri, :conn)

helpers :formatter

Expand Down Expand Up @@ -111,22 +111,21 @@ def initialize
@proxy_uri = nil
@formatter = nil

@cache = []
@cache_id_mutex = Mutex.new
@connection_cache = []
@connection_cache_id_mutex = Mutex.new
end

def close
super

# Close all open connections
@cache.each {|entry| entry.conn.finish if entry.conn&.started? }
@connection_cache.each {|entry| entry.conn.finish if entry.conn&.started? }
end

def configure(conf)
super

@cache = Array.new(actual_flush_thread_count, CacheEntry.new("", nil)) if @reuse_connections
@cache_id = 0
@connection_cache = Array.new(actual_flush_thread_count, ConnectionCache.new("", nil)) if @reuse_connections
@connection_cache_id = 0

if @retryable_response_codes.nil?
log.warn('Status code 503 is going to be removed from default `retryable_response_codes` from fluentd v2. Please add it by yourself if you wish')
Expand Down Expand Up @@ -322,23 +321,23 @@ def create_request(chunk, uri)
def make_request_cached(uri, req)
id = Thread.current.thread_variable_get(plugin_id)
if id.nil?
@cache_id_mutex.synchronize {
id = @cache_id
@cache_id += 1
@connection_cache_id_mutex.synchronize {
id = @connection_cache_id
@connection_cache_id += 1
}
Thread.current.thread_variable_set(plugin_id, id)
end
uri_str = uri.to_s
if @cache[id].uri != uri_str
@cache[id].conn.finish if @cache[id].conn&.started?
if @connection_cache[id].uri != uri_str
@connection_cache[id].conn.finish if @connection_cache[id].conn&.started?
http = if @proxy_uri
Net::HTTP.start(uri.host, uri.port, @proxy_uri.host, @proxy_uri.port, @proxy_uri.user, @proxy_uri.password, @http_opt)
else
Net::HTTP.start(uri.host, uri.port, @http_opt)
end
@cache[id] = CacheEntry.new(uri_str, http)
@connection_cache[id] = ConnectionCache.new(uri_str, http)
end
@cache[id].conn.request(req)
@connection_cache[id].conn.request(req)
end

def make_request(uri, req, &block)
Expand Down

0 comments on commit 6763f3d

Please sign in to comment.