Commit 78a758bb authored by Eteri's avatar Eteri Committed by Klaus Wölfel

fluent-plugin-wendelin: fix configuration parameters, check for closed connections

parent 72f1a151
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
require 'fluent/output' require 'fluent/output'
require_relative 'wendelin_client' require_relative 'wendelin_client'
module Fluent module Fluent
class WendelinOutput < ObjectBufferedOutput # XXX verify base class class WendelinOutput < ObjectBufferedOutput # XXX verify base class
...@@ -37,8 +38,6 @@ module Fluent ...@@ -37,8 +38,6 @@ module Fluent
config_param :user, :string, :default => nil config_param :user, :string, :default => nil
config_param :password, :string, :default => nil config_param :password, :string, :default => nil
config_param :reference, :string
def configure(conf) def configure(conf)
super super
...@@ -48,7 +47,7 @@ module Fluent ...@@ -48,7 +47,7 @@ module Fluent
credentials['user'] = @user credentials['user'] = @user
credentials['password'] = @password credentials['password'] = @password
end end
@wendelin = WendelinClient.new(@streamtool_uri, credentials, @log, @reference) @wendelin = WendelinClient.new(@streamtool_uri, credentials, @log)
end end
def start def start
...@@ -80,8 +79,8 @@ module Fluent ...@@ -80,8 +79,8 @@ module Fluent
# for input_stream_ref use tag as-is - it will be processed/translated # for input_stream_ref use tag as-is - it will be processed/translated
# further on server by Wendelin # further on server by Wendelin
reference = tag reference = tag
@wendelin.ingest(data_chunk)
@wendelin.ingest(reference, data_chunk)
end end
end end
......
...@@ -19,27 +19,31 @@ ...@@ -19,27 +19,31 @@
require 'net/http' require 'net/http'
require 'openssl' require 'openssl'
# class representing a Wendelin client # class representing a Wendelin client
class WendelinClient 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, reference) def initialize(streamtool_uri, credentials, log)
@streamtool_uri = streamtool_uri @streamtool_uri = streamtool_uri
@credentials = credentials @credentials = credentials
@log = log @log = log
@reference = reference
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 def start_request(uri)
uri = URI("#{@streamtool_uri}/ingest?reference=#{@reference}")
@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'),
:verify_mode => OpenSSL::SSL::VERIFY_NONE, :verify_mode => OpenSSL::SSL::VERIFY_NONE,
# Net::HTTP default open timeout is infinity, which results
# 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, :ssl_timeout => 60,
:open_timeout => 60, :open_timeout => 60,
:read_timeout => 60, :read_timeout => 60,
...@@ -49,14 +53,23 @@ class WendelinClient ...@@ -49,14 +53,23 @@ class WendelinClient
end end
# ingest `data_chunk` to a stream referenced as `reference` # ingest `data_chunk` to a stream referenced as `reference`
def ingest(data_chunk) def ingest(reference, data_chunk)
uri = URI("#{@streamtool_uri}/ingest?reference=#{reference}")
# call start_request if request is undefined
@request ||= start_request(uri)
# connect again if the connection is not started
if ! @http.started?()
start_request(uri)
end
# When using 'application/x-www-form-urlencoded', Ruby encodes with regex # When using 'application/x-www-form-urlencoded', Ruby encodes with regex
# and it is far too slow. Such POST is legit: # and it is far too slow. Such POST is legit:
# https://stackoverflow.com/a/14710450 # https://stackoverflow.com/a/14710450
@request ||= start_request # call start_request if request is undefined
@request.body = data_chunk @request.body = data_chunk
@request.content_type = 'application/octet-stream' @request.content_type = 'application/octet-stream'
if @credentials.has_key?('user') if @credentials.has_key?('user')
@request.basic_auth @credentials['user'], @credentials['password'] @request.basic_auth @credentials['user'], @credentials['password']
end end
...@@ -80,7 +93,6 @@ class WendelinClient ...@@ -80,7 +93,6 @@ class WendelinClient
# some http/ssl/other connection error # some http/ssl/other connection error
@log.warn "HTTP ERROR:" @log.warn "HTTP ERROR:"
raise raise
else else
@log.on_trace do @log.on_trace do
@log.trace '>>> RESPONSE' @log.trace '>>> RESPONSE'
...@@ -97,6 +109,7 @@ class WendelinClient ...@@ -97,6 +109,7 @@ class WendelinClient
@log.warn "FAIL:" @log.warn "FAIL:"
res.value res.value
end end
end end
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