fluent-plugin-fedmsg 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/Rakefile +11 -0
- data/fluent-plugin-fedmsg.gemspec +22 -0
- data/lib/fluent/plugin/in_fedmsg.rb +89 -0
- data/test/helper.rb +28 -0
- data/test/plugin/test_in_fedmsg.rb +97 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b1f278f7df87e6c3ce1080d07f25a18f08affe1
|
4
|
+
data.tar.gz: 6343aadf248afa6a0c9573f31d6b8b6fd4ed52b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81059067eb76f509a78c630b0df9c8fdbe4952ef6da751213958c2d4e695fd0cba2d14f512297c1b2a5d55d4ea8c2a0644ad1eed5615afb52247a20173c6eea3
|
7
|
+
data.tar.gz: fc2808158c63f12f0180394a661280ee56d6c83a64ced70795fee5df7410d21a6b67deffd9313b1c1b1be515b145121002a0b91582020c4faa0d761527098387
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Anton Sherkhonov"]
|
6
|
+
gem.email = ["sherkhonov@gmail.com"]
|
7
|
+
gem.description = %q{FedMsg subscriber plugin for fluentd}
|
8
|
+
gem.summary = %q{FedMsg subscriber plugin for fluentd, use 0MQ v3.2 or greater version}
|
9
|
+
gem.homepage = ""
|
10
|
+
gem.licenses = ["Apache License, Version 2.0"]
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = "fluent-plugin-fedmsg"
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.version = "0.0.2"
|
18
|
+
gem.add_development_dependency "rake"
|
19
|
+
gem.add_development_dependency "test-unit", "~> 3.2.0"
|
20
|
+
gem.add_runtime_dependency "fluentd"
|
21
|
+
gem.add_runtime_dependency "ffi-rzmq"
|
22
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'fluent/input'
|
2
|
+
|
3
|
+
module Fluent
|
4
|
+
|
5
|
+
class ZmqSubInput < Fluent::Input
|
6
|
+
Fluent::Plugin.register_input('fedmsg', self)
|
7
|
+
|
8
|
+
config_param :subkey, :string, :default => ""
|
9
|
+
config_param :publisher, :string, :default => "tcp://127.0.0.1:5556"
|
10
|
+
config_param :tag_prefix, :string, :default => ""
|
11
|
+
config_param :drop_fields, :string, :default => "username,certificate,i,crypto,signature"
|
12
|
+
|
13
|
+
attr_reader :subkeys
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
super
|
17
|
+
require 'ffi-rzmq'
|
18
|
+
end
|
19
|
+
|
20
|
+
def configure(conf)
|
21
|
+
super
|
22
|
+
@subkeys = @subkey.split(",")
|
23
|
+
@drop_fields_arr = @drop_fields.split(",")
|
24
|
+
end
|
25
|
+
|
26
|
+
def start
|
27
|
+
super
|
28
|
+
@context =ZMQ::Context.new()
|
29
|
+
@thread = Thread.new(&method(:run))
|
30
|
+
end
|
31
|
+
|
32
|
+
def shutdown
|
33
|
+
Thread.kill(@thread)
|
34
|
+
@thread.join
|
35
|
+
@context.terminate
|
36
|
+
super
|
37
|
+
end
|
38
|
+
|
39
|
+
def run
|
40
|
+
begin
|
41
|
+
@subscriber = @context.socket(ZMQ::SUB)
|
42
|
+
@subscriber.connect(@publisher)
|
43
|
+
@subscriber.setsockopt(ZMQ::SNDHWM, 100)
|
44
|
+
@subscriber.setsockopt(ZMQ::RCVHWM, 100)
|
45
|
+
if @subkeys.size > 0
|
46
|
+
@subkeys.each do |k|
|
47
|
+
@subscriber.setsockopt(ZMQ::SUBSCRIBE,k)
|
48
|
+
end
|
49
|
+
else
|
50
|
+
@subscriber.setsockopt(ZMQ::SUBSCRIBE,'')
|
51
|
+
end
|
52
|
+
loop do
|
53
|
+
msg = ''
|
54
|
+
while @subscriber.recv_string(msg,ZMQ::DONTWAIT) && msg.size > 0
|
55
|
+
begin
|
56
|
+
record = JSON.parse(msg)
|
57
|
+
rescue JSON::ParserError => e
|
58
|
+
log.trace "Ignoring non-JSON message '#{msg}'"
|
59
|
+
next
|
60
|
+
rescue => e
|
61
|
+
log.warn "Unknown error parsing JSON message.",:error_class => e.class, :error => e
|
62
|
+
log.warn_backtrace
|
63
|
+
end
|
64
|
+
begin
|
65
|
+
tag = @tag_prefix + "." + record['topic']
|
66
|
+
time = record['timestamp']
|
67
|
+
record.delete_if { |key, value| @drop_fields_arr.include? key}
|
68
|
+
Engine.emit(tag, time, record)
|
69
|
+
rescue => e
|
70
|
+
log.warn "Error in processing message.",:error_class => e.class, :error => e
|
71
|
+
log.warn_backtrace
|
72
|
+
end
|
73
|
+
msg = ''
|
74
|
+
end
|
75
|
+
sleep(0.1)
|
76
|
+
end
|
77
|
+
rescue => e
|
78
|
+
log.error "error occurred while executing plugin.", :error_class => e.class, :error => e
|
79
|
+
log.warn_backtrace
|
80
|
+
ensure
|
81
|
+
if @subscriber
|
82
|
+
@subscriber.close
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
|
+
require 'fluent/test'
|
15
|
+
unless ENV.has_key?('VERBOSE')
|
16
|
+
nulllogger = Object.new
|
17
|
+
nulllogger.instance_eval {|obj|
|
18
|
+
def method_missing(method, *args)
|
19
|
+
# pass
|
20
|
+
end
|
21
|
+
}
|
22
|
+
$log = nulllogger
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'fluent/plugin/in_fedmsg'
|
26
|
+
|
27
|
+
class Test::Unit::TestCase
|
28
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'ffi-rzmq'
|
3
|
+
|
4
|
+
class FedMsgIntputTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Fluent::Test.setup
|
7
|
+
@context = ZMQ::Context.new()
|
8
|
+
@publisher = @context.socket(ZMQ::PUB)
|
9
|
+
@publisher.bind("tcp://*:5556")
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
@publisher.close
|
14
|
+
@context.terminate
|
15
|
+
end
|
16
|
+
|
17
|
+
PUBLISHER = "tcp://127.0.0.1:5556"
|
18
|
+
CONFIG = %[
|
19
|
+
publisher #{PUBLISHER}
|
20
|
+
subkey test1.,test2.
|
21
|
+
]
|
22
|
+
|
23
|
+
|
24
|
+
def create_driver(conf=CONFIG)
|
25
|
+
Fluent::Test::InputTestDriver.new(Fluent::ZmqSubInput).configure(conf)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_configure
|
29
|
+
d = create_driver(CONFIG + "tag_prefix fed_msg_stuff")
|
30
|
+
assert_equal PUBLISHER, d.instance.publisher
|
31
|
+
assert_equal ["test1.","test2."], d.instance.subkeys
|
32
|
+
assert_equal "fed_msg_stuff", d.instance.tag_prefix
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_receive
|
36
|
+
d = create_driver
|
37
|
+
|
38
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
39
|
+
Fluent::Engine.now = time
|
40
|
+
|
41
|
+
d.expect_emit "test1.aa", time, {"a"=>1}
|
42
|
+
d.expect_emit "test2.bb", time, {"a"=>2}
|
43
|
+
|
44
|
+
d.run do
|
45
|
+
d.expected_emits.each {|tag,time,record|
|
46
|
+
send_record("dummy",time,record) # This record should not be received.
|
47
|
+
send_record(tag,time,record)
|
48
|
+
}
|
49
|
+
sleep 1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_no_subkey
|
54
|
+
d = create_driver("")
|
55
|
+
|
56
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
57
|
+
Fluent::Engine.now = time
|
58
|
+
|
59
|
+
d.expect_emit "test1.aa", time, {"a"=>1}
|
60
|
+
d.expect_emit "test2.bb", time, {"a"=>2}
|
61
|
+
|
62
|
+
d.run do
|
63
|
+
d.expected_emits.each {|tag,time,record|
|
64
|
+
send_record(tag,time,record)
|
65
|
+
}
|
66
|
+
sleep 1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def test_receive_bulk
|
72
|
+
d = create_driver(CONFIG + "bulk_send true")
|
73
|
+
|
74
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
75
|
+
Fluent::Engine.now = time
|
76
|
+
|
77
|
+
d.expect_emit "test3.aa", time, {"a"=>1}
|
78
|
+
d.expect_emit "test4.bb", time, {"a"=>2}
|
79
|
+
|
80
|
+
d.run do
|
81
|
+
record_to_send = []
|
82
|
+
d.expected_emits.each {|tag,time,record|
|
83
|
+
record_to_send << [tag,time,record]
|
84
|
+
}
|
85
|
+
send_record_bulk("test1.aa",record_to_send)
|
86
|
+
sleep 1
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def send_record(tag,time,record)
|
91
|
+
@publisher.send_string(tag + " " + [tag,time,record].to_msgpack)
|
92
|
+
end
|
93
|
+
|
94
|
+
def send_record_bulk(tag,records)
|
95
|
+
@publisher.send_string(tag + " " + records.to_msgpack)
|
96
|
+
end
|
97
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-fedmsg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Sherkhonov
|
@@ -74,8 +74,14 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- .gitignore
|
77
|
+
- Gemfile
|
77
78
|
- LICENSE
|
78
79
|
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- fluent-plugin-fedmsg.gemspec
|
82
|
+
- lib/fluent/plugin/in_fedmsg.rb
|
83
|
+
- test/helper.rb
|
84
|
+
- test/plugin/test_in_fedmsg.rb
|
79
85
|
homepage: ''
|
80
86
|
licenses:
|
81
87
|
- Apache License, Version 2.0
|
@@ -100,4 +106,6 @@ rubygems_version: 2.0.14.1
|
|
100
106
|
signing_key:
|
101
107
|
specification_version: 4
|
102
108
|
summary: FedMsg subscriber plugin for fluentd, use 0MQ v3.2 or greater version
|
103
|
-
test_files:
|
109
|
+
test_files:
|
110
|
+
- test/helper.rb
|
111
|
+
- test/plugin/test_in_fedmsg.rb
|