Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fluent-plugin-wendelin
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Klaus Wölfel
fluent-plugin-wendelin
Commits
67e761e4
Commit
67e761e4
authored
May 18, 2018
by
Eteri
Committed by
Klaus Wölfel
Jul 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fluent-plugin-wendelin: add keep_alive as an option
parent
3bbc0908
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
169 additions
and
83 deletions
+169
-83
README.md
README.md
+1
-0
example/to_wendelin.conf
example/to_wendelin.conf
+2
-0
lib/fluent/plugin/out_wendelin.rb
lib/fluent/plugin/out_wendelin.rb
+8
-1
lib/fluent/plugin/wendelin_client.rb
lib/fluent/plugin/wendelin_client.rb
+158
-82
No files found.
README.md
View file @
67e761e4
...
@@ -20,6 +20,7 @@ A sample configuration to setup ingestion of data for a tag to Wendelin:
...
@@ -20,6 +20,7 @@ A sample configuration to setup ingestion of data for a tag to Wendelin:
streamtool_uri <Wendelin_URL>/erp5/portal_ingestion_policies/<YOUR_INGESTION_POLICY_ID>
streamtool_uri <Wendelin_URL>/erp5/portal_ingestion_policies/<YOUR_INGESTION_POLICY_ID>
user
<your_wendelin_user>
user
<your_wendelin_user>
password <your_wendelin_password>
password <your_wendelin_password>
use_keep_alive <true/false>
# all parameters of BufferedOutput & Output classes are supported too, e.g.
# all parameters of BufferedOutput & Output classes are supported too, e.g.
# `buffer_type`, `flush_interval`, `num_threads`, `log_level`, etc - see
# `buffer_type`, `flush_interval`, `num_threads`, `log_level`, etc - see
...
...
example/to_wendelin.conf
View file @
67e761e4
...
@@ -28,6 +28,8 @@
...
@@ -28,6 +28,8 @@
user
<
your_wendelin_user
>
user
<
your_wendelin_user
>
password
<
your_wendelin_password
>
password
<
your_wendelin_password
>
use_keep_alive
true
# all parameters of BufferedOutput & Output classes are supported too, e.g.
# all parameters of BufferedOutput & Output classes are supported too, e.g.
# `buffer_type`, `flush_interval`, `num_threads`, `log_level`, etc - see
# `buffer_type`, `flush_interval`, `num_threads`, `log_level`, etc - see
# their code near:
# their code near:
...
...
lib/fluent/plugin/out_wendelin.rb
View file @
67e761e4
...
@@ -38,6 +38,9 @@ module Fluent
...
@@ -38,6 +38,9 @@ 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
:use_keep_alive
,
:bool
,
:default
=>
true
def
configure
(
conf
)
def
configure
(
conf
)
super
super
...
@@ -80,7 +83,11 @@ module Fluent
...
@@ -80,7 +83,11 @@ module Fluent
# further on server by Wendelin
# further on server by Wendelin
reference
=
tag
reference
=
tag
@wendelin
.
ingest
(
reference
,
data_chunk
)
if
@use_keep_alive
@wendelin
.
ingest_with_keep_alive
(
reference
,
data_chunk
)
else
@wendelin
.
ingest
(
reference
,
data_chunk
)
end
end
end
end
end
...
...
lib/fluent/plugin/wendelin_client.rb
View file @
67e761e4
...
@@ -20,89 +20,165 @@ require 'openssl'
...
@@ -20,89 +20,165 @@ 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"
# `credentials` # {'user' => _, 'password' => _} TODO change to certificate
# `streamtool_uri` - URI pointing to portal_input_data_stream "mountpoint"
# `log` - logger to use
# `credentials` # {'user' => _, 'password' => _} TODO change to certificate
def
initialize
(
streamtool_uri
,
credentials
,
log
)
# `log` - logger to use
@streamtool_uri
=
streamtool_uri
def
initialize
(
streamtool_uri
,
credentials
,
log
)
@credentials
=
credentials
@streamtool_uri
=
streamtool_uri
@log
=
log
@credentials
=
credentials
end
@log
=
log
# @stop_timer = 0
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_request
(
uri
)
puts
' START NEW REQUEST'
puts
" START NEW REQUEST"
@http
=
Net
::
HTTP
.
start
(
uri
.
hostname
,
uri
.
port
,
use_ssl:
(
uri
.
scheme
==
'https'
),
@http
=
Net
::
HTTP
.
start
(
uri
.
hostname
,
uri
.
port
,
verify_mode:
OpenSSL
::
SSL
::
VERIFY_NONE
,
:use_ssl
=>
(
uri
.
scheme
==
'https'
),
: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
# Net::HTTP default open timeout is infinity, which results
# establish connection. Default read_timeout is 60 seconds.
# in thread hang forever if other side does not fully
# We go safe way and make sure all timeouts are defined.
# establish connection. Default read_timeout is 60 seconds.
ssl_timeout:
60
,
# We go safe way and make sure all timeouts are defined.
open_timeout:
60
,
:ssl_timeout
=>
60
,
read_timeout:
60
,
:open_timeout
=>
60
,
keep_alive_timeout:
60
)
:read_timeout
=>
60
,
end
:keep_alive_timeout
=>
60
,)
end
# ingest `data_chunk` to a stream referenced as `reference`
def
ingest
(
reference
,
data_chunk
)
# ingest `data_chunk` to a stream referenced as `reference`
uri
=
URI
(
"
#{
@streamtool_uri
}
/ingest?reference=
#{
reference
}
"
)
def
ingest_with_keep_alive
(
reference
,
data_chunk
)
puts
'uri = '
uri
=
URI
(
"
#{
@streamtool_uri
}
/ingest?reference=
#{
reference
}
"
)
puts
"uri = "
puts
uri
puts
uri
# call start_request if request is undefined
# call start_request if request is undefined
@request
||=
start_request
(
uri
)
@request
||=
start_request
(
uri
)
# connect again if the connection is not started
# connect again if the connection is not started
start_request
(
uri
)
unless
@http
.
started?
if
!
@http
.
started?
()
start_request
(
uri
)
@request
=
Net
::
HTTP
::
Post
.
new
(
uri
)
end
# When using 'application/x-www-form-urlencoded', Ruby encodes with regex
@request
=
Net
::
HTTP
::
Post
.
new
(
uri
)
# and it is far too slow. Such POST is legit:
# https://stackoverflow.com/a/14710450
# When using 'application/x-www-form-urlencoded', Ruby encodes with regex
@request
.
body
=
data_chunk
# and it is far too slow. Such POST is legit:
@request
.
content_type
=
'application/octet-stream'
# https://stackoverflow.com/a/14710450
@request
.
body
=
data_chunk
if
@credentials
.
key?
(
'user'
)
@request
.
content_type
=
'application/octet-stream'
@request
.
basic_auth
@credentials
[
'user'
],
@credentials
[
'password'
]
end
if
@credentials
.
has_key?
(
'user'
)
@request
.
basic_auth
@credentials
[
'user'
],
@credentials
[
'password'
]
@log
.
on_trace
do
end
@log
.
trace
'>>> REQUEST'
@log
.
trace
"method
\t
=>
#{
@request
.
method
}
"
@log
.
on_trace
do
@log
.
trace
"path
\t
=>
#{
@request
.
path
}
"
@log
.
trace
'>>> REQUEST'
@log
.
trace
"uri
\t
=>
#{
@request
.
uri
}
"
@log
.
trace
"method
\t
=>
#{
@request
.
method
}
"
@log
.
trace
"body
\t
=>
#{
@request
.
body
}
"
@log
.
trace
"path
\t
=>
#{
@request
.
path
}
"
@log
.
trace
"body_stream
\t
=>
#{
@request
.
body_stream
}
"
@log
.
trace
"uri
\t
=>
#{
@request
.
uri
}
"
@request
.
each
{
|
h
|
@log
.
trace
"
#{
h
}
:
\t
#{
@request
[
h
]
}
"
}
@log
.
trace
"body
\t
=>
#{
@request
.
body
}
"
@log
.
trace
@log
.
trace
"body_stream
\t
=>
#{
@request
.
body_stream
}
"
end
@request
.
each
{
|
h
|
@log
.
trace
"
#{
h
}
:
\t
#{
@request
[
h
]
}
"
}
@log
.
trace
begin
end
res
=
@http
.
request
(
@request
)
# Net::HTTPResponse object
end
begin
rescue
StandardError
res
=
@http
.
request
(
@request
)
# Net::HTTPResponse object
# some http/ssl/other connection error
end
@log
.
warn
'HTTP ERROR:'
raise
rescue
else
# some http/ssl/other connection error
@log
.
on_trace
do
@log
.
warn
"HTTP ERROR:"
@log
.
trace
'>>> RESPONSE'
raise
res
.
each
{
|
h
|
@log
.
trace
"
#{
h
}
:
\t
#{
res
[
h
]
}
"
}
else
@log
.
trace
"code
\t
=>
#{
res
.
code
}
"
@log
.
on_trace
do
@log
.
trace
"msg
\t
=>
#{
res
.
message
}
"
@log
.
trace
'>>> RESPONSE'
@log
.
trace
"class
\t
=>
#{
res
.
class
}
"
res
.
each
{
|
h
|
@log
.
trace
"
#{
h
}
:
\t
#{
res
[
h
]
}
"
}
@log
.
trace
'body:'
,
res
.
body
@log
.
trace
"code
\t
=>
#{
res
.
code
}
"
end
@log
.
trace
"msg
\t
=>
#{
res
.
message
}
"
@log
.
trace
"class
\t
=>
#{
res
.
class
}
"
if
res
.
is_a?
(
Net
::
HTTPSuccess
)
# res.code is 2XX
@log
.
trace
"body:"
,
res
.
body
# @log.info "ingested ok"
end
else
@log
.
warn
'FAIL:'
if
res
.
kind_of?
(
Net
::
HTTPSuccess
)
# res.code is 2XX
res
.
value
#@log.info "ingested ok"
end
else
end
@log
.
warn
"FAIL:"
res
.
value
end
end
def
ingest
(
reference
,
data_chunk
)
uri
=
URI
(
"
#{
@streamtool_uri
}
/ingest?reference=
#{
reference
}
"
)
req
=
Net
::
HTTP
::
Post
.
new
(
uri
)
if
@credentials
.
has_key?
(
'user'
)
req
.
basic_auth
@credentials
[
'user'
],
@credentials
[
'password'
]
end
# When using 'application/x-www-form-urlencoded', Ruby encodes with regex
# and it is far too slow. Such POST is legit:
# https://stackoverflow.com/a/14710450
req
.
body
=
data_chunk
req
.
content_type
=
'application/octet-stream'
@log
.
on_trace
do
@log
.
trace
'>>> REQUEST'
@log
.
trace
"method
\t
=>
#{
req
.
method
}
"
@log
.
trace
"path
\t
=>
#{
req
.
path
}
"
@log
.
trace
"uri
\t
=>
#{
req
.
uri
}
"
@log
.
trace
"body
\t
=>
#{
req
.
body
}
"
@log
.
trace
"body_stream
\t
=>
#{
req
.
body_stream
}
"
req
.
each
{
|
h
|
@log
.
trace
"
#{
h
}
:
\t
#{
req
[
h
]
}
"
}
@log
.
trace
end
begin
# TODO keep connection open (so that every new ingest does not do
# full connect again)
res
=
Net
::
HTTP
.
start
(
uri
.
hostname
,
uri
.
port
,
:use_ssl
=>
(
uri
.
scheme
==
'https'
),
# NOTE = "do not check server cert"
# TODO move this out to conf parameters
: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
,
:open_timeout
=>
60
,
:read_timeout
=>
60
,
)
do
|
http
|
http
.
request
(
req
)
end
rescue
# some http/ssl/other connection error
@log
.
warn
"HTTP ERROR:"
raise
else
@log
.
on_trace
do
@log
.
trace
'>>> RESPONSE'
res
.
each
{
|
h
|
@log
.
trace
"
#{
h
}
:
\t
#{
res
[
h
]
}
"
}
@log
.
trace
"code
\t
=>
#{
res
.
code
}
"
@log
.
trace
"msg
\t
=>
#{
res
.
message
}
"
@log
.
trace
"class
\t
=>
#{
res
.
class
}
"
@log
.
trace
"body:"
,
res
.
body
end
if
res
.
kind_of?
(
Net
::
HTTPSuccess
)
# res.code is 2XX
#@log.info "ingested ok"
else
@log
.
warn
"FAIL:"
res
.
value
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment