Commit b918d2ff authored by Eteri's avatar Eteri

Make timeouts configurable

parent 4dc6b905
......@@ -40,7 +40,10 @@ module Fluent
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)
super
......@@ -50,7 +53,9 @@ module Fluent
credentials['user'] = @user
credentials['password'] = @password
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
def start
......
......@@ -24,18 +24,22 @@ class WendelinClient
# `streamtool_uri` - URI pointing to portal_input_data_stream "mountpoint"
# `credentials` # {'user' => _, 'password' => _} TODO change to certificate
# `log` - logger to use
def initialize(streamtool_uri, credentials, log)
@streamtool_uri = streamtool_uri
@credentials = credentials
@log = log
# @stop_timer = 0
def initialize(streamtool_uri, credentials, log,
ssl_timeout, open_timeout, read_timeout, keep_alive_timeout)
@streamtool_uri = streamtool_uri
@credentials = credentials
@log = log
@ssl_timeout = ssl_timeout
@open_timeout = open_timeout
@read_timeout = read_timeout
@keep_alive_timeout = keep_alive_timeout
end
# 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,
:use_ssl => (uri.scheme == 'https'),
......@@ -45,23 +49,23 @@ class WendelinClient
# in thread hang forever if other side does not fully
# establish connection. Default read_timeout is 60 seconds.
# We go safe way and make sure all timeouts are defined.
:ssl_timeout => 60,
:open_timeout => 60,
:read_timeout => 60,
:keep_alive_timeout => 60,)
:ssl_timeout => @ssl_timeout,
:open_timeout => @open_timeout,
:read_timeout => @read_timeout,
:keep_alive_timeout => @keep_alive_timeout,)
end
# ingest `data_chunk` to a stream referenced as `reference`
def ingest_with_keep_alive(reference, data_chunk)
uri = URI("#{@streamtool_uri}/ingest?reference=#{reference}")
puts "uri = "
puts uri
# call start_request if request is undefined
@request ||= start_request(uri)
# call start_connection if http is undefined
if ! defined? @http
start_connection(uri)
end
# connect again if the connection is not started
if ! @http.started?()
start_request(uri)
start_connection(uri)
end
@request = Net::HTTP::Post.new(uri)
......@@ -150,9 +154,9 @@ class WendelinClient
# in thread hang forever if other side does not fully
# establish connection. Default read_timeout is 60 seconds.
# We go safe way and make sure all timeouts are defined.
:ssl_timeout => 60,
:open_timeout => 60,
:read_timeout => 60,
:ssl_timeout => @ssl_timeout,
:open_timeout => @open_timeout,
:read_timeout => @read_timeout,
) do |http|
http.request(req)
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