fluent-plugin-scribe 0.10.10 → 0.10.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c1fa97e1091c9a7b3864e658377226530c5796b8
4
+ data.tar.gz: 53a1f639942eaab9d0ec71c663b6947bce5eea95
5
+ SHA512:
6
+ metadata.gz: 5724cce9d7574385413afd56a28e078748a8936557a0aefa5f162aeb64058b17d6d5ae299a57ffa02149943ccb4c8fc9ac2e929cf8ef771e4a78e09ffbc39763
7
+ data.tar.gz: d32cf42a08d55bcb0678b85144b54f2411d5301c7ef273ac25eab37cb0a97f363b5f583e854dcf501ea0ddff32dc80f71b813967091d1ebab35e7a6aa9a8de3a
@@ -0,0 +1,2 @@
1
+ pkg/*
2
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-webhdfs.gemspec
4
+ gemspec
data/Rakefile CHANGED
@@ -1,29 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
1
4
  require 'rake'
2
- require 'rake/testtask'
3
5
  require 'rake/clean'
4
6
 
5
- begin
6
- require 'jeweler'
7
- Jeweler::Tasks.new do |gemspec|
8
- gemspec.name = "fluent-plugin-scribe"
9
- gemspec.summary = "Scribe Input/Output plugin for Fluentd event collector"
10
- gemspec.author = "Kazuki Ohta"
11
- gemspec.email = "kazuki.ohta@gmail.com"
12
- gemspec.homepage = "https://github.com/fluent/fluent-plugin-scribe"
13
- gemspec.has_rdoc = false
14
- gemspec.require_paths = ["lib"]
15
- gemspec.add_dependency "fluentd", "~> 0.10.0"
16
- gemspec.add_dependency "thrift", "~> 0.8.0"
17
- gemspec.test_files = Dir["test/**/*.rb"]
18
- gemspec.files = Dir["bin/**/*", "lib/**/*", "test/**/*.rb"] +
19
- %w[example.conf VERSION AUTHORS Rakefile fluent-plugin-scribe.gemspec]
20
- gemspec.executables = ['fluent-scribe-remote']
21
- end
22
- Jeweler::GemcutterTasks.new
23
- rescue LoadError
24
- puts "Jeweler not available. Install it with: gem install jeweler"
25
- end
26
-
27
7
  task "thrift_gen" do
28
8
  system "rm -f common.thrift jobtracker.thrift"
29
9
  system "wget https://raw.github.com/facebook/scribe/master/if/scribe.thrift"
@@ -38,27 +18,11 @@ task "thrift_gen" do
38
18
  system "rm -fR tmp"
39
19
  end
40
20
 
41
- Rake::TestTask.new(:test) do |t|
42
- t.test_files = Dir['test/plugin/*.rb']
43
- t.ruby_opts = ['-rubygems'] if defined? Gem
44
- t.ruby_opts << '-I.'
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
45
26
  end
46
27
 
47
- #VERSION_FILE = "lib/fluent/version.rb"
48
- #
49
- #file VERSION_FILE => ["VERSION"] do |t|
50
- # version = File.read("VERSION").strip
51
- # File.open(VERSION_FILE, "w") {|f|
52
- # f.write <<EOF
53
- #module Fluent
54
- #
55
- #VERSION = '#{version}'
56
- #
57
- #end
58
- #EOF
59
- # }
60
- #end
61
- #
62
- #task :default => [VERSION_FILE, :build]
63
-
64
- task :default => [:build]
28
+ task :default => :test
@@ -1,60 +1,22 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
- Gem::Specification.new do |s|
7
- s.name = "fluent-plugin-scribe"
8
- s.version = "0.10.10"
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "fluent-plugin-scribe"
5
+ gem.version = "0.10.11"
9
6
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Kazuki Ohta"]
12
- s.date = "2013-02-06"
13
- s.email = "kazuki.ohta@gmail.com"
14
- s.executables = ["fluent-scribe-remote"]
15
- s.extra_rdoc_files = [
16
- "ChangeLog",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- "AUTHORS",
21
- "Rakefile",
22
- "VERSION",
23
- "bin/fluent-scribe-remote",
24
- "example.conf",
25
- "fluent-plugin-scribe.gemspec",
26
- "lib/fluent/plugin/in_scribe.rb",
27
- "lib/fluent/plugin/out_scribe.rb",
28
- "lib/fluent/plugin/thrift/facebook_service.rb",
29
- "lib/fluent/plugin/thrift/fb303.thrift",
30
- "lib/fluent/plugin/thrift/fb303_constants.rb",
31
- "lib/fluent/plugin/thrift/fb303_types.rb",
32
- "lib/fluent/plugin/thrift/scribe.rb",
33
- "lib/fluent/plugin/thrift/scribe.thrift",
34
- "lib/fluent/plugin/thrift/scribe_constants.rb",
35
- "lib/fluent/plugin/thrift/scribe_types.rb",
36
- "test/plugin/in_scribe.rb",
37
- "test/plugin/out_scribe.rb"
38
- ]
39
- s.homepage = "https://github.com/fluent/fluent-plugin-scribe"
40
- s.require_paths = ["lib"]
41
- s.rubygems_version = "1.8.21"
42
- s.summary = "Scribe Input/Output plugin for Fluentd event collector"
43
- s.test_files = ["test/plugin/in_scribe.rb", "test/plugin/out_scribe.rb"]
7
+ gem.authors = ["Kazuki Ohta", "TAGOMORI Satoshi"]
8
+ gem.email = ["kazuki.ohta@gmail.com", "tagomoris@gmail.com"]
9
+ gem.summary = %q{Scribe Input/Output plugin for Fluentd event collector}
10
+ gem.description = %q{Fluentd input/output plugin to handle Facebook scribed thrift protocol}
11
+ gem.homepage = "https://github.com/fluent/fluent-plugin-scribe"
12
+ gem.license = "APLv2"
44
13
 
45
- if s.respond_to? :specification_version then
46
- s.specification_version = 3
14
+ gem.files = `git ls-files`.split($\)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
47
18
 
48
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
- s.add_runtime_dependency(%q<fluentd>, ["~> 0.10.0"])
50
- s.add_runtime_dependency(%q<thrift>, ["~> 0.8.0"])
51
- else
52
- s.add_dependency(%q<fluentd>, ["~> 0.10.0"])
53
- s.add_dependency(%q<thrift>, ["~> 0.8.0"])
54
- end
55
- else
56
- s.add_dependency(%q<fluentd>, ["~> 0.10.0"])
57
- s.add_dependency(%q<thrift>, ["~> 0.8.0"])
58
- end
19
+ gem.add_development_dependency "rake"
20
+ gem.add_runtime_dependency "fluentd"
21
+ gem.add_runtime_dependency "thrift", "~> 0.8.0"
59
22
  end
60
-
@@ -16,144 +16,142 @@
16
16
  # limitations under the License.
17
17
  #
18
18
  module Fluent
19
+ class ScribeInput < Input
20
+ Plugin.register_input('scribe', self)
21
+
22
+ config_param :port, :integer, :default => 1463
23
+ config_param :bind, :string, :default => '0.0.0.0'
24
+ config_param :server_type, :string, :default => 'nonblocking'
25
+ config_param :is_framed, :bool, :default => true
26
+ config_param :body_size_limit, :size, :default => 32*1024*1024 # TODO default
27
+ config_param :add_prefix, :string, :default => nil
28
+ config_param :remove_newline, :bool, :default => false
29
+ config_param :msg_format, :string, :default => 'text'
30
+
31
+ def initialize
32
+ require 'cgi'
33
+ require 'thrift'
34
+ $:.unshift File.join(File.dirname(__FILE__), 'thrift')
35
+ require 'fb303_types'
36
+ require 'fb303_constants'
37
+ require 'facebook_service'
38
+ require 'scribe_types'
39
+ require 'scribe_constants'
40
+ require 'scribe'
41
+ super
42
+ end
19
43
 
20
- class ScribeInput < Input
21
- Plugin.register_input('scribe', self)
44
+ def configure(conf)
45
+ super
46
+ end
22
47
 
23
- config_param :port, :integer, :default => 1463
24
- config_param :bind, :string, :default => '0.0.0.0'
25
- config_param :server_type, :string, :default => 'nonblocking'
26
- config_param :is_framed, :bool, :default => true
27
- config_param :body_size_limit, :size, :default => 32*1024*1024 # TODO default
28
- config_param :add_prefix, :string, :default => nil
29
- config_param :remove_newline, :bool, :default => false
30
- config_param :msg_format, :string, :default => 'text'
48
+ def start
49
+ $log.debug "listening scribe on #{@bind}:#{@port}"
31
50
 
32
- def initialize
33
- require 'cgi'
34
- require 'thrift'
35
- $:.unshift File.join(File.dirname(__FILE__), 'thrift')
36
- require 'fb303_types'
37
- require 'fb303_constants'
38
- require 'facebook_service'
39
- require 'scribe_types'
40
- require 'scribe_constants'
41
- require 'scribe'
42
- super
43
- end
51
+ handler = FluentScribeHandler.new
52
+ handler.add_prefix = @add_prefix
53
+ handler.remove_newline = @remove_newline
54
+ handler.msg_format = @msg_format
55
+ processor = Scribe::Processor.new handler
44
56
 
45
- def configure(conf)
46
- super
47
- end
48
-
49
- def start
50
- $log.debug "listening scribe on #{@bind}:#{@port}"
57
+ @transport = Thrift::ServerSocket.new @bind, @port
58
+ if @is_framed
59
+ transport_factory = Thrift::FramedTransportFactory.new
60
+ else
61
+ transport_factory = Thrift::BufferedTransportFactory.new
62
+ end
51
63
 
52
- handler = FluentScribeHandler.new
53
- handler.add_prefix = @add_prefix
54
- handler.remove_newline = @remove_newline
55
- handler.msg_format = @msg_format
56
- processor = Scribe::Processor.new handler
64
+ unless ['text', 'json', 'url_param'].include? @msg_format
65
+ raise 'Unknown format: msg_format=#{@msg_format}'
66
+ end
57
67
 
58
- @transport = Thrift::ServerSocket.new @bind, @port
59
- if @is_framed
60
- transport_factory = Thrift::FramedTransportFactory.new
61
- else
62
- transport_factory = Thrift::BufferedTransportFactory.new
68
+ # 2011/09/29 Kazuki Ohta <kazuki.ohta@gmail.com>
69
+ # This section is a workaround to set strict_read and strict_write option.
70
+ # Ruby-Thrift 0.7 set them both 'true' in default, but Scribe protocol set
71
+ # them both 'false'.
72
+ protocol_factory = Thrift::BinaryProtocolFactory.new
73
+ protocol_factory.instance_eval {|obj|
74
+ def get_protocol(trans) # override
75
+ return Thrift::BinaryProtocol.new(trans,
76
+ strict_read=false,
77
+ strict_write=false)
78
+ end
79
+ }
80
+
81
+ case @server_type
82
+ when 'simple'
83
+ @server = Thrift::SimpleServer.new processor, @transport, transport_factory, protocol_factory
84
+ when 'threaded'
85
+ @server = Thrift::ThreadedServer.new processor, @transport, transport_factory, protocol_factory
86
+ when 'thread_pool'
87
+ @server = Thrift::ThreadPoolServer.new processor, @transport, transport_factory, protocol_factory
88
+ when 'nonblocking'
89
+ @server = Thrift::NonblockingServer.new processor, @transport, transport_factory, protocol_factory
90
+ else
91
+ raise ConfigError, "in_scribe: unsupported server_type '#{@server_type}'"
92
+ end
93
+ @thread = Thread.new(&method(:run))
63
94
  end
64
95
 
65
- unless ['text', 'json', 'url_param'].include? @msg_format
66
- raise 'Unknown format: msg_format=#{@msg_format}'
96
+ def shutdown
97
+ @transport.close unless @transport.closed?
98
+ #@thread.join # TODO
67
99
  end
68
100
 
69
- # 2011/09/29 Kazuki Ohta <kazuki.ohta@gmail.com>
70
- # This section is a workaround to set strict_read and strict_write option.
71
- # Ruby-Thrift 0.7 set them both 'true' in default, but Scribe protocol set
72
- # them both 'false'.
73
- protocol_factory = Thrift::BinaryProtocolFactory.new
74
- protocol_factory.instance_eval {|obj|
75
- def get_protocol(trans) # override
76
- return Thrift::BinaryProtocol.new(trans,
77
- strict_read=false,
78
- strict_write=false)
79
- end
80
- }
81
-
82
- case @server_type
83
- when 'simple'
84
- @server = Thrift::SimpleServer.new processor, @transport, transport_factory, protocol_factory
85
- when 'threaded'
86
- @server = Thrift::ThreadedServer.new processor, @transport, transport_factory, protocol_factory
87
- when 'thread_pool'
88
- @server = Thrift::ThreadPoolServer.new processor, @transport, transport_factory, protocol_factory
89
- when 'nonblocking'
90
- @server = Thrift::NonblockingServer.new processor, @transport, transport_factory, protocol_factory
91
- else
92
- raise ConfigError, "in_scribe: unsupported server_type '#{@server_type}'"
101
+ def run
102
+ @server.serve
103
+ rescue
104
+ $log.error "unexpected error", :error=>$!.to_s
105
+ $log.error_backtrace
93
106
  end
94
- @thread = Thread.new(&method(:run))
95
- end
96
107
 
97
- def shutdown
98
- @transport.close unless @transport.closed?
99
- #@thread.join # TODO
100
- end
101
-
102
- def run
103
- @server.serve
104
- rescue
105
- $log.error "unexpected error", :error=>$!.to_s
106
- $log.error_backtrace
107
- end
108
-
109
- class FluentScribeHandler
110
- attr_accessor :add_prefix
111
- attr_accessor :remove_newline
112
- attr_accessor :msg_format
108
+ class FluentScribeHandler
109
+ attr_accessor :add_prefix
110
+ attr_accessor :remove_newline
111
+ attr_accessor :msg_format
112
+
113
+ def Log(msgs)
114
+ begin
115
+ msgs.each { |msg|
116
+ record = create_record(msg)
117
+ if @add_prefix
118
+ Engine.emit(@add_prefix + '.' + msg.category, Engine.now, record)
119
+ else
120
+ Engine.emit(msg.category, Engine.now, record)
121
+ end
122
+ }
123
+ return ResultCode::OK
124
+ rescue => e
125
+ $log.error "unexpected error", :error=>$!.to_s
126
+ $log.error_backtrace
127
+ return ResultCode::TRY_LATER
128
+ end
129
+ end
113
130
 
114
- def Log(msgs)
115
- begin
116
- msgs.each { |msg|
117
- record = create_record(msg)
118
- if @add_prefix
119
- Engine.emit(@add_prefix + '.' + msg.category, Engine.now, record)
131
+ private
132
+ def create_record(msg)
133
+ case @msg_format
134
+ when 'text'
135
+ if @remove_newline
136
+ return { 'message' => msg.message.force_encoding('UTF-8').chomp }
120
137
  else
121
- Engine.emit(msg.category, Engine.now, record)
138
+ return { 'message' => msg.message.force_encoding('UTF-8') }
122
139
  end
123
- }
124
- return ResultCode::OK
125
- rescue => e
126
- $log.error "unexpected error", :error=>$!.to_s
127
- $log.error_backtrace
128
- return ResultCode::TRY_LATER
129
- end
130
- end
131
-
132
- private
133
- def create_record(msg)
134
- case @msg_format
135
- when 'text'
136
- if @remove_newline
137
- return { 'message' => msg.message.force_encoding('UTF-8').chomp }
140
+ when 'json'
141
+ js = JSON.parse(msg.message.force_encoding('UTF-8'))
142
+ raise 'body must be a Hash, if json_body=true' unless js.is_a?(Hash)
143
+ return js
144
+ when 'url_param'
145
+ s = msg.message.force_encoding('UTF-8')
146
+ return Hash[ s.split('&').map { |kv|
147
+ k,v = kv.split('=', 2);
148
+ [CGI.unescape(k), CGI.unescape(v)]
149
+ }
150
+ ]
138
151
  else
139
- return { 'message' => msg.message.force_encoding('UTF-8') }
152
+ raise 'Invalid format: #{@msg_format}'
140
153
  end
141
- when 'json'
142
- js = JSON.parse(msg.message.force_encoding('UTF-8'))
143
- raise 'body must be a Hash, if json_body=true' unless js.is_a?(Hash)
144
- return js
145
- when 'url_param'
146
- s = msg.message.force_encoding('UTF-8')
147
- return Hash[ s.split('&').map { |kv|
148
- k,v = kv.split('=', 2);
149
- [CGI.unescape(k), CGI.unescape(v)]
150
- }
151
- ]
152
- else
153
- raise 'Invalid format: #{@msg_format}'
154
154
  end
155
155
  end
156
156
  end
157
157
  end
158
-
159
- end
@@ -16,93 +16,97 @@
16
16
  # limitations under the License.
17
17
  #
18
18
  module Fluent
19
+ class ScribeOutput < BufferedOutput
20
+ Fluent::Plugin.register_output('scribe', self)
21
+
22
+ config_param :host, :string, :default => 'localhost'
23
+ config_param :port, :integer, :default => 1463
24
+ config_param :field_ref, :string, :default => 'message'
25
+ config_param :timeout, :integer, :default => 30
26
+
27
+ config_param :remove_prefix, :string, :default => nil
28
+ config_param :add_newline, :bool, :default => false
29
+ config_param :default_category, :string, :default => 'unknown'
30
+ config_param :format_to_json, :bool, :default => false
31
+
32
+ def initialize
33
+ require 'thrift'
34
+ $:.unshift File.join(File.dirname(__FILE__), 'thrift')
35
+ require 'fb303_types'
36
+ require 'fb303_constants'
37
+ require 'facebook_service'
38
+ require 'scribe_types'
39
+ require 'scribe_constants'
40
+ require 'scribe'
41
+ super
42
+ end
19
43
 
20
- class ScribeOutput < BufferedOutput
21
- Fluent::Plugin.register_output('scribe', self)
22
-
23
- config_param :host, :string, :default => 'localhost'
24
- config_param :port, :integer, :default => 1463
25
- config_param :field_ref, :string, :default => 'message'
26
- config_param :timeout, :integer, :default => 30
27
-
28
- config_param :remove_prefix, :string, :default => nil
29
- config_param :add_newline, :bool, :default => false
30
- config_param :default_category, :string, :default => 'unknown'
31
-
32
- def initialize
33
- require 'thrift'
34
- $:.unshift File.join(File.dirname(__FILE__), 'thrift')
35
- require 'fb303_types'
36
- require 'fb303_constants'
37
- require 'facebook_service'
38
- require 'scribe_types'
39
- require 'scribe_constants'
40
- require 'scribe'
41
- super
42
- end
43
-
44
- def configure(conf)
45
- # override default buffer_chunk_limit
46
- conf['buffer_chunk_limit'] ||= '1m'
44
+ def configure(conf)
45
+ # override default buffer_chunk_limit
46
+ conf['buffer_chunk_limit'] ||= '1m'
47
47
 
48
- super
49
- end
48
+ super
49
+ end
50
50
 
51
- def start
52
- super
51
+ def start
52
+ super
53
53
 
54
- if @remove_prefix
55
- @removed_prefix_string = @remove_prefix + '.'
56
- @removed_length = @removed_prefix_string.length
54
+ if @remove_prefix
55
+ @removed_prefix_string = @remove_prefix + '.'
56
+ @removed_length = @removed_prefix_string.length
57
+ end
57
58
  end
58
- end
59
59
 
60
- def shutdown
61
- super
62
- end
60
+ def shutdown
61
+ super
62
+ end
63
63
 
64
- def format(tag, time, record)
65
- if @remove_prefix and
66
- ( (tag[0, @removed_length] == @removed_prefix_string and tag.length > @removed_length) or
64
+ def format(tag, time, record)
65
+ if @remove_prefix and
66
+ ( (tag[0, @removed_length] == @removed_prefix_string and tag.length > @removed_length) or
67
67
  tag == @remove_prefix)
68
- [(tag[@removed_length..-1] || @default_category), record].to_msgpack
69
- else
70
- [tag, record].to_msgpack
68
+ [(tag[@removed_length..-1] || @default_category), record].to_msgpack
69
+ else
70
+ [tag, record].to_msgpack
71
+ end
71
72
  end
72
- end
73
73
 
74
- def write(chunk)
75
- socket = Thrift::Socket.new @host, @port, @timeout
76
- transport = Thrift::FramedTransport.new socket
77
- protocol = Thrift::BinaryProtocol.new transport, false, false
78
- client = Scribe::Client.new protocol
74
+ def write(chunk)
75
+ socket = Thrift::Socket.new @host, @port, @timeout
76
+ transport = Thrift::FramedTransport.new socket
77
+ protocol = Thrift::BinaryProtocol.new transport, false, false
78
+ client = Scribe::Client.new protocol
79
+
80
+ transport.open
81
+ begin
82
+ entries = []
83
+
84
+ chunk.msgpack_each do |arr|
85
+ tag, record = arr
86
+ next unless @format_to_json || record.has_key?(@field_ref)
79
87
 
80
- transport.open
81
- begin
82
- entries = []
88
+ message = @format_to_json ? record : record[@field_ref]
83
89
 
84
- chunk.msgpack_each do |arr|
85
- tag, record = arr
86
- next unless record.has_key?(@field_ref)
90
+ if message.kind_of?(Array) or message.kind_of?(Hash)
91
+ message = message.to_json
92
+ end
87
93
 
88
- entry = LogEntry.new
89
- entry.category = tag
94
+ if @add_newline
95
+ message = message + "\n"
96
+ end
90
97
 
91
- if @add_newline
92
- entry.message = (record[@field_ref] + "\n").force_encoding('ASCII-8BIT')
93
- else
94
- entry.message = record[@field_ref].force_encoding('ASCII-8BIT')
98
+ entry = LogEntry.new
99
+ entry.category = tag
100
+ entry.message = message.force_encoding('ASCII-8BIT')
101
+
102
+ entries << entry
95
103
  end
96
104
 
97
- entries << entry
105
+ $log.debug "Writing #{entries.count} entries to scribe"
106
+ client.Log(entries)
107
+ ensure
108
+ transport.close
98
109
  end
99
-
100
- $log.debug "Writing #{entries.count} entries to scribe"
101
- client.Log(entries)
102
- ensure
103
- transport.close
104
110
  end
105
111
  end
106
112
  end
107
-
108
- end
@@ -1,6 +1,8 @@
1
1
  require 'test/unit'
2
2
  require 'fluent/test'
3
- require 'lib/fluent/plugin/in_scribe'
3
+ require 'fluent/plugin/in_scribe'
4
+
5
+ require 'thrift'
4
6
 
5
7
  class ScribeInputTest < Test::Unit::TestCase
6
8
  def setup
@@ -38,7 +40,7 @@ class ScribeInputTest < Test::Unit::TestCase
38
40
  ]
39
41
  d.run do
40
42
  emits.each { |tag, time, record|
41
- res = send(tag, record['message'])
43
+ res = message_send(tag, record['message'])
42
44
  assert_equal ResultCode::OK, res
43
45
  }
44
46
  end
@@ -61,7 +63,7 @@ class ScribeInputTest < Test::Unit::TestCase
61
63
  ]
62
64
  d.run do
63
65
  emits.each { |tag, time, record|
64
- res = send(tag, record['message'])
66
+ res = message_send(tag, record['message'])
65
67
  assert_equal ResultCode::OK, res
66
68
  }
67
69
  end
@@ -82,7 +84,7 @@ class ScribeInputTest < Test::Unit::TestCase
82
84
  ]
83
85
  d2.run do
84
86
  emits.each { |tag, time, record|
85
- res = send(tag, record['message'])
87
+ res = message_send(tag, record['message'])
86
88
  assert_equal ResultCode::OK, res
87
89
  }
88
90
  end
@@ -108,7 +110,7 @@ class ScribeInputTest < Test::Unit::TestCase
108
110
  ]
109
111
  d.run do
110
112
  emits.each { |tag, time, record|
111
- res = send(tag, record['message'])
113
+ res = message_send(tag, record['message'])
112
114
  assert_equal ResultCode::OK, res
113
115
  }
114
116
  end
@@ -134,7 +136,7 @@ class ScribeInputTest < Test::Unit::TestCase
134
136
  ]
135
137
  d.run do
136
138
  emits.each { |tag, time, message|
137
- res = send(tag, message)
139
+ res = message_send(tag, message)
138
140
  assert_equal ResultCode::OK, res
139
141
  }
140
142
  end
@@ -164,13 +166,13 @@ class ScribeInputTest < Test::Unit::TestCase
164
166
  ]
165
167
  d.run do
166
168
  emits.each { |tag, time, message|
167
- res = send(tag, message)
169
+ res = message_send(tag, message)
168
170
  assert_equal ResultCode::OK, res
169
171
  }
170
172
  end
171
173
  end
172
174
 
173
- def send(tag, msg)
175
+ def message_send(tag, msg)
174
176
  socket = Thrift::Socket.new '127.0.0.1', 14630
175
177
  transport = Thrift::FramedTransport.new socket
176
178
  protocol = Thrift::BinaryProtocol.new transport, false, false
@@ -1,12 +1,19 @@
1
1
  require 'test/unit'
2
2
  require 'fluent/test'
3
- require 'lib/fluent/plugin/out_scribe'
3
+ require 'fluent/plugin/out_scribe'
4
+
5
+ require 'thrift'
4
6
 
5
7
  class ScribeOutputTest < Test::Unit::TestCase
6
8
  CONFIG = %[
7
9
  host 127.0.0.1
8
10
  port 14630
9
11
  ]
12
+ CONFIG_TO_JSON = %[
13
+ host 127.0.0.1
14
+ port 14630
15
+ format_to_json yes
16
+ ]
10
17
 
11
18
  def create_driver(conf=CONFIG, tag='test')
12
19
  Fluent::Test::BufferedOutputTestDriver.new(Fluent::ScribeOutput, tag).configure(conf)
@@ -139,6 +146,26 @@ remove_prefix test
139
146
  assert_equal [[d.instance.default_category, 'zzz testing first another data']], $handler.last
140
147
  end
141
148
 
149
+ def test_write_to_json
150
+ time = Time.parse("2011-12-21 13:14:15 UTC").to_i
151
+
152
+ d = create_driver(CONFIG_TO_JSON)
153
+ e1 = {"message" => "testing first", "message2" => "testing first another data"}
154
+ e2 = {"message" => "testing second", "message2" => "testing second another data"}
155
+ e3 = {"message" => "testing third", "message2" => "testing third another data"}
156
+ [e1,e2,e3].each{|e| d.emit(e, time)}
157
+ result = d.run
158
+ assert_equal ResultCode::OK, result
159
+
160
+ events = $handler.last
161
+ assert_equal d.tag, events[0][0]
162
+ assert_equal e1, JSON.parse(events[0][1])
163
+ assert_equal d.tag, events[1][0]
164
+ assert_equal e2, JSON.parse(events[1][1])
165
+ assert_equal d.tag, events[2][0]
166
+ assert_equal e3, JSON.parse(events[2][1])
167
+ end
168
+
142
169
  def setup
143
170
  Fluent::Test.setup
144
171
  $handler = TestScribeServerHandler.new
metadata CHANGED
@@ -1,36 +1,47 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-scribe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.10
5
- prerelease:
4
+ version: 0.10.11
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kazuki Ohta
8
+ - TAGOMORI Satoshi
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-06 00:00:00.000000000 Z
12
+ date: 2013-09-04 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: fluentd
16
30
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
31
  requirements:
19
- - - ~>
32
+ - - '>='
20
33
  - !ruby/object:Gem::Version
21
- version: 0.10.0
34
+ version: '0'
22
35
  type: :runtime
23
36
  prerelease: false
24
37
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
38
  requirements:
27
- - - ~>
39
+ - - '>='
28
40
  - !ruby/object:Gem::Version
29
- version: 0.10.0
41
+ version: '0'
30
42
  - !ruby/object:Gem::Dependency
31
43
  name: thrift
32
44
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
45
  requirements:
35
46
  - - ~>
36
47
  - !ruby/object:Gem::Version
@@ -38,21 +49,24 @@ dependencies:
38
49
  type: :runtime
39
50
  prerelease: false
40
51
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
52
  requirements:
43
53
  - - ~>
44
54
  - !ruby/object:Gem::Version
45
55
  version: 0.8.0
46
- description:
47
- email: kazuki.ohta@gmail.com
56
+ description: Fluentd input/output plugin to handle Facebook scribed thrift protocol
57
+ email:
58
+ - kazuki.ohta@gmail.com
59
+ - tagomoris@gmail.com
48
60
  executables:
49
61
  - fluent-scribe-remote
50
62
  extensions: []
51
- extra_rdoc_files:
52
- - ChangeLog
53
- - README.rdoc
63
+ extra_rdoc_files: []
54
64
  files:
65
+ - .gitignore
55
66
  - AUTHORS
67
+ - ChangeLog
68
+ - Gemfile
69
+ - README.rdoc
56
70
  - Rakefile
57
71
  - VERSION
58
72
  - bin/fluent-scribe-remote
@@ -68,34 +82,33 @@ files:
68
82
  - lib/fluent/plugin/thrift/scribe.thrift
69
83
  - lib/fluent/plugin/thrift/scribe_constants.rb
70
84
  - lib/fluent/plugin/thrift/scribe_types.rb
71
- - test/plugin/in_scribe.rb
72
- - test/plugin/out_scribe.rb
73
- - ChangeLog
74
- - README.rdoc
85
+ - test/plugin/test_in_scribe.rb
86
+ - test/plugin/test_out_scribe.rb
75
87
  homepage: https://github.com/fluent/fluent-plugin-scribe
76
- licenses: []
88
+ licenses:
89
+ - APLv2
90
+ metadata: {}
77
91
  post_install_message:
78
92
  rdoc_options: []
79
93
  require_paths:
80
94
  - lib
81
95
  required_ruby_version: !ruby/object:Gem::Requirement
82
- none: false
83
96
  requirements:
84
- - - ! '>='
97
+ - - '>='
85
98
  - !ruby/object:Gem::Version
86
99
  version: '0'
87
100
  required_rubygems_version: !ruby/object:Gem::Requirement
88
- none: false
89
101
  requirements:
90
- - - ! '>='
102
+ - - '>='
91
103
  - !ruby/object:Gem::Version
92
104
  version: '0'
93
105
  requirements: []
94
106
  rubyforge_project:
95
- rubygems_version: 1.8.21
107
+ rubygems_version: 2.0.3
96
108
  signing_key:
97
- specification_version: 3
109
+ specification_version: 4
98
110
  summary: Scribe Input/Output plugin for Fluentd event collector
99
111
  test_files:
100
- - test/plugin/in_scribe.rb
101
- - test/plugin/out_scribe.rb
112
+ - test/plugin/test_in_scribe.rb
113
+ - test/plugin/test_out_scribe.rb
114
+ has_rdoc: