Commit b918d2ff authored by Eteri's avatar Eteri

Make timeouts configurable

parent 4dc6b905
...@@ -40,7 +40,10 @@ module Fluent ...@@ -40,7 +40,10 @@ module Fluent
config_param :use_keep_alive, :bool, :default => false config_param :use_keep_alive, :bool, :default => false
config_param :ssl_timeout, :integer, :default => 60
config_param :open_timeout, :integer, :default => 60
config_param :read_timeout, :integer, :default => 60
config_param :keep_alive_timeout, :integer, :default => 300
def configure(conf) def configure(conf)
super super
...@@ -50,7 +53,9 @@ module Fluent ...@@ -50,7 +53,9 @@ module Fluent
credentials['user'] = @user credentials['user'] = @user
credentials['password'] = @password credentials['password'] = @password
end end
@wendelin = WendelinClient.new(@streamtool_uri, credentials, @log) @wendelin = WendelinClient.new(@streamtool_uri, credentials, @log,
@ssl_timeout, @open_timeout,
@read_timeout, @keep_alive_timeout)
end end
def start def start
......
...@@ -24,18 +24,22 @@ class WendelinClient ...@@ -24,18 +24,22 @@ class WendelinClient
# `streamtool_uri` - URI pointing to portal_input_data_stream "mountpoint" # `streamtool_uri` - URI pointing to portal_input_data_stream "mountpoint"
# `credentials` # {'user' => _, 'password' => _} TODO change to certificate # `credentials` # {'user' => _, 'password' => _} TODO change to certificate
# `log` - logger to use # `log` - logger to use
def initialize(streamtool_uri, credentials, log) def initialize(streamtool_uri, credentials, log,
ssl_timeout, open_timeout, read_timeout, keep_alive_timeout)
@streamtool_uri = streamtool_uri @streamtool_uri = streamtool_uri
@credentials = credentials @credentials = credentials
@log = log @log = log
# @stop_timer = 0 @ssl_timeout = ssl_timeout
@open_timeout = open_timeout
@read_timeout = read_timeout
@keep_alive_timeout = keep_alive_timeout
end end
# start request in an independent function to keep the connection open # start request in an independent function to keep the connection open
def start_request(uri) def start_connection(uri)
puts " START NEW REQUEST" @log.debug "start new connection"
@http = Net::HTTP.start(uri.hostname, uri.port, @http = Net::HTTP.start(uri.hostname, uri.port,
:use_ssl => (uri.scheme == 'https'), :use_ssl => (uri.scheme == 'https'),
...@@ -45,23 +49,23 @@ class WendelinClient ...@@ -45,23 +49,23 @@ class WendelinClient
# in thread hang forever if other side does not fully # in thread hang forever if other side does not fully
# establish connection. Default read_timeout is 60 seconds. # establish connection. Default read_timeout is 60 seconds.
# We go safe way and make sure all timeouts are defined. # We go safe way and make sure all timeouts are defined.
:ssl_timeout => 60, :ssl_timeout => @ssl_timeout,
:open_timeout => 60, :open_timeout => @open_timeout,
:read_timeout => 60, :read_timeout => @read_timeout,
:keep_alive_timeout => 60,) :keep_alive_timeout => @keep_alive_timeout,)
end end
# ingest `data_chunk` to a stream referenced as `reference` # ingest `data_chunk` to a stream referenced as `reference`
def ingest_with_keep_alive(reference, data_chunk) def ingest_with_keep_alive(reference, data_chunk)
uri = URI("#{@streamtool_uri}/ingest?reference=#{reference}") uri = URI("#{@streamtool_uri}/ingest?reference=#{reference}")
puts "uri = " # call start_connection if http is undefined
puts uri if ! defined? @http
# call start_request if request is undefined start_connection(uri)
@request ||= start_request(uri) end
# connect again if the connection is not started # connect again if the connection is not started
if ! @http.started?() if ! @http.started?()
start_request(uri) start_connection(uri)
end end
@request = Net::HTTP::Post.new(uri) @request = Net::HTTP::Post.new(uri)
...@@ -150,9 +154,9 @@ class WendelinClient ...@@ -150,9 +154,9 @@ class WendelinClient
# in thread hang forever if other side does not fully # in thread hang forever if other side does not fully
# establish connection. Default read_timeout is 60 seconds. # establish connection. Default read_timeout is 60 seconds.
# We go safe way and make sure all timeouts are defined. # We go safe way and make sure all timeouts are defined.
:ssl_timeout => 60, :ssl_timeout => @ssl_timeout,
:open_timeout => 60, :open_timeout => @open_timeout,
:read_timeout => 60, :read_timeout => @read_timeout,
) do |http| ) do |http|
http.request(req) http.request(req)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment