fluent-plugin-msgpack-rpc 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ Nobuyuki Kubota <nobu.k.jp+github _at_ gmail.com>
data/README.rst ADDED
@@ -0,0 +1,41 @@
1
+ About This Plugin
2
+ -----------------
3
+
4
+ This plugin is an input plugin for Fluent.
5
+ All applications using MessagePack-RPC client can send events to Fluent by using this plugin.
6
+
7
+ How to Configure
8
+ ----------------
9
+
10
+ ::
11
+
12
+ <source>
13
+ type msgpack_rpc
14
+ port 9000
15
+ bind 0.0.0.0
16
+ </source>
17
+
18
+ 'bind' is an optional parameter.
19
+
20
+ Interface of the Server
21
+ -----------------------
22
+
23
+ The server has following interface::
24
+
25
+ def log(tag, time, record)
26
+ def logs(tag, entries)
27
+
28
+ 'time' is a time when the event occurred. 'record' is a Hash having information of the event.
29
+ 'entries' argument is an array of lists having [time, record].
30
+ When passing 0 to 'time', the server automatically use the current time as 'time'.
31
+ See also a sample client code below.
32
+
33
+ Sample Client Code
34
+ ------------------
35
+
36
+ ::
37
+
38
+ require 'msgpack/rpc'
39
+ cli = MessagePack::RPC::Client.new('127.0.0.1', 9000)
40
+ cli.call(:log, 'debug.tag', 0, { 'key' => 'value' })
41
+ cli.call(:logs, 'debug.tag', [[0, {'key' => 'value'}], [Time.now.to_i, {'red' => 'bull'}]])
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/clean'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gemspec|
8
+ gemspec.name = "fluent-plugin-msgpack-rpc"
9
+ gemspec.summary = "Input plugin for Fluent using MessagePack-RPC"
10
+ gemspec.author = "Nobuyuki Kubota"
11
+ gemspec.email = "nobu.k.jp+github@gmail.com"
12
+ gemspec.homepage = "http://github.com/fluent"
13
+ gemspec.has_rdoc = false
14
+ gemspec.require_paths = ["lib"]
15
+ gemspec.add_dependency "fluent", "~> 0.10.0"
16
+ gemspec.add_dependency "msgpack-rpc", "~> 0.4.5"
17
+ gemspec.test_files = Dir["test/**/*.rb"]
18
+ gemspec.files = Dir["bin/**/*", "lib/**/*", "test/**/*.rb"] + %w[VERSION AUTHORS Rakefile]
19
+ gemspec.executables = []
20
+ end
21
+ Jeweler::GemcutterTasks.new
22
+ rescue LoadError
23
+ puts "Jeweler not available. Install it with: gem install jeweler"
24
+ end
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.test_files = Dir['test/*_test.rb']
28
+ t.ruby_opts = ['-rubygems'] if defined? Gem
29
+ t.ruby_opts << '-I.'
30
+ end
31
+
32
+ task :test => [:base_test]
33
+
34
+ Rake::TestTask.new(:base_test) do |t|
35
+ t.libs << "test"
36
+ t.test_files = Dir["test/plugin/*.rb"]
37
+ t.verbose = true
38
+ end
39
+
40
+ task :default => [:build]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.1
@@ -0,0 +1,67 @@
1
+ #
2
+ # Input plugin for Fluent using MessagePack-RPC
3
+ #
4
+ # Copyright (C) 2011 Nobuyuki Kubota
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module Fluent
19
+
20
+ class MessagePackRPCInput < Input
21
+ Plugin.register_input('msgpack_rpc', self)
22
+
23
+ def initialize
24
+ require 'msgpack/rpc'
25
+ super
26
+ end
27
+
28
+ config_param :port, :integer
29
+ config_param :bind, :string, :default => '0.0.0.0'
30
+
31
+ def configure(conf)
32
+ # TODO: Reject invalid bind parameter
33
+ super
34
+ end
35
+
36
+ def start
37
+ @server = MessagePack::RPC::Server.new
38
+ @server.listen @bind, @port, Server.new
39
+ @thread = Thread.new {
40
+ @server.run
41
+ }
42
+ end
43
+
44
+ def shutdown
45
+ @server.close
46
+ @thread.join
47
+ end
48
+
49
+ class Server
50
+ def log(tag, time, record)
51
+ time = Engine.now if time == 0
52
+ Engine.emit(tag, time, record)
53
+ nil
54
+ end
55
+
56
+ def logs(tag, entries)
57
+ current = Engine.now
58
+ # TODO: need type validation for entries?
59
+ Engine.emit_array(tag, entries.map { |e|
60
+ e[0] = current if e[0] == 0
61
+ e
62
+ })
63
+ end
64
+ end
65
+ end
66
+
67
+ end
@@ -0,0 +1,90 @@
1
+ require 'fluent/test'
2
+ require 'fluent/plugin/in_msgpack_rpc'
3
+
4
+ class MessagePackRPCInputTest < Test::Unit::TestCase
5
+ def setup
6
+ Fluent::Test.setup
7
+ @default_time = Time.parse("2011-10-05 12:24:48 UTC").to_i
8
+ Fluent::Engine.now = @default_time
9
+ end
10
+
11
+ CONFIG = %[
12
+ port 9123
13
+ bind 127.0.0.1
14
+ ]
15
+
16
+ def create_driver(conf = CONFIG)
17
+ Fluent::Test::InputTestDriver.new(Fluent::MessagePackRPCInput).configure(conf)
18
+ end
19
+
20
+ def test_configure
21
+ d = create_driver
22
+ assert_equal 9123, d.instance.port
23
+ assert_equal '127.0.0.1', d.instance.bind
24
+ end
25
+
26
+ def test_missing_port
27
+ assert_raise(Fluent::ConfigError){
28
+ d = create_driver(%[
29
+ bind 127.0.0.1
30
+ ])
31
+ }
32
+ end
33
+
34
+ # TODO: Add test for invalid 'bind' parameter
35
+
36
+ def test_default_time
37
+ d = create_driver
38
+
39
+ d.expect_emit "tag1", @default_time, {"a" => 1}
40
+ d.expect_emit "tag2", @default_time, {"a" => 2}
41
+ d.run do
42
+ d.expected_emits.each { |tag, time, record|
43
+ post(tag, 0, record)
44
+ }
45
+ end
46
+ end
47
+
48
+ def test_time
49
+ d = create_driver
50
+
51
+ d.expect_emit "tag1", 12345, {"a" => 1}
52
+ d.expect_emit "tag2", 20, {"a" => 2}
53
+ d.run do
54
+ post("tag1", 12345, {"a" => 1})
55
+ post("tag2", 20, {"a" => 2})
56
+ end
57
+ end
58
+
59
+ def test_default_time_with_array
60
+ d = create_driver
61
+
62
+ d.expect_emit "tag", @default_time, {"a" => 1}
63
+ d.expect_emit "tag", @default_time, {"a" => 2}
64
+ d.run do
65
+ post_array("tag", d.expected_emits.map { |tag, time, record| [0, record] })
66
+ end
67
+ end
68
+
69
+ def test_time_with_array
70
+ d = create_driver
71
+
72
+ d.expect_emit "tag", 54321, {"a" => 1}
73
+ d.expect_emit "tag", 128, {"a" => 2}
74
+ d.run do
75
+ post_array("tag", [[54321, {"a" => 1}], [128, {"a" => 2}]])
76
+ end
77
+ end
78
+
79
+ def post(tag, time, record)
80
+ cli = MessagePack::RPC::Client.new('127.0.0.1', 9123)
81
+ cli.call(:log, tag, time, record)
82
+ cli.close
83
+ end
84
+
85
+ def post_array(tag, events)
86
+ cli = MessagePack::RPC::Client.new('127.0.0.1', 9123)
87
+ cli.call(:logs, tag, events)
88
+ cli.close
89
+ end
90
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-msgpack-rpc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nobuyuki Kubota
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-16 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluent
16
+ requirement: &24305680 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.10.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *24305680
25
+ - !ruby/object:Gem::Dependency
26
+ name: msgpack-rpc
27
+ requirement: &24305180 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.4.5
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *24305180
36
+ description:
37
+ email: nobu.k.jp+github@gmail.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files:
41
+ - README.rst
42
+ files:
43
+ - AUTHORS
44
+ - Rakefile
45
+ - VERSION
46
+ - lib/fluent/plugin/in_msgpack_rpc.rb
47
+ - test/plugin/in_msgpack_rpc.rb
48
+ - README.rst
49
+ homepage: http://github.com/fluent
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.6
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Input plugin for Fluent using MessagePack-RPC
73
+ test_files:
74
+ - test/plugin/in_msgpack_rpc.rb