fluent-plugin-flume 0.1.1 → 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7572fd137da7ba6c6668e09fdb489ca58f417781
4
+ data.tar.gz: ec492fdb5fadfaddf89a21ea4b78f76c126bcd05
5
+ SHA512:
6
+ metadata.gz: b53cfe600d060d4537c2cac0b96b5cc4b020e9ad05b81b56e2bede3923836fb52612d7022cd6f90c64c211665c3499a07b1db8b97131188d19ef84b1c0fab1be
7
+ data.tar.gz: 7287e3c0988a562da41eac18cbbd535265d738af90b61015c639601b43c8bddcee5c9d2d476f7c15239242431f8b604869d208bdb3b7b136683189cd2940bf2e
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *~
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
data/ChangeLog CHANGED
@@ -1,4 +1,11 @@
1
+ Release 0.1.2 - 2015/11/30
2
+
3
+ * Updated thrift to 0.9.0
4
+ * Use latest flume thrift protocol in flume output
5
+
1
6
  Release 0.1.1 - 20XX/XX/XX
2
- * updated thrift to 0.8.0
7
+
8
+ * updated thrift to 0.8.0
9
+ * overrode buffer_chunk_limit for more reliability (ISSUE-1)
3
10
 
4
11
  Release 0.1.0 - 2012/05/02
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/README.rdoc CHANGED
@@ -1,8 +1,8 @@
1
- = Flume input/output plugin for Fluent
1
+ = Flume input/output plugin for Fluentd[http://fluentd.org/]
2
2
 
3
3
  == Overview
4
4
 
5
- This is a plugin for fluentd[https://github.com/fluentd] event collector. This plugin adds the Flume[https://github.com/apache/flume] compatible interface to fluentd.
5
+ This is a plugin for fluentd[http://fluentd.org/] data collector. This plugin adds the Flume[https://github.com/apache/flume] compatible interface to fluentd.
6
6
 
7
7
  == What's Flume?
8
8
 
@@ -79,6 +79,8 @@ These options are supported.
79
79
  * default_tag: default fluentd 'tag' (default: 'category')
80
80
  * add_prefix: prefix string, added to the tag (default: nil)
81
81
 
82
+ Use flume-ng-fluentd-sink[https://github.com/cosmo0920/flume-ng-fluentd-sink] to send events from flume-ng to fluentd.
83
+
82
84
  == Flume Output
83
85
 
84
86
  Please add the following configurations to fluent.conf. This allows fluentd to output its logs into another Flume server. Note that fluentd conveys semi-structured data while Flume conveys unstructured data. Thus the plugin translates semi-structured data into JSON data and conveys it to Flume.
@@ -101,5 +103,5 @@ These options are supported.
101
103
 
102
104
  == Copyright
103
105
 
104
- Copyright:: Copyright (c) 2012 Treasure Data, Inc.
106
+ Copyright:: Copyright (c) 2012 - 2013 Treasure Data, Inc.
105
107
  License:: Apache License, Version 2.0
data/Rakefile CHANGED
@@ -1,29 +1,10 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
1
4
  require 'rake'
2
5
  require 'rake/testtask'
3
6
  require 'rake/clean'
4
7
 
5
- begin
6
- require 'jeweler'
7
- Jeweler::Tasks.new do |gemspec|
8
- gemspec.name = "fluent-plugin-flume"
9
- gemspec.summary = "Flume Input/Output plugin for Fluentd event collector"
10
- gemspec.author = "Muga Nishizawa"
11
- gemspec.email = "muga.nishizawa@gmail.com"
12
- gemspec.homepage = "https://github.com/muga/fluent-plugin-flume"
13
- gemspec.has_rdoc = false
14
- gemspec.require_paths = ["lib"]
15
- gemspec.add_dependency "fluentd", "~> 0.10.16"
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-flume.gemspec]
20
- gemspec.executables = ['fluent-flume-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
8
  task "thrift_gen" do
28
9
  system "mkdir -p tmp"
29
10
  system "thrift --gen rb -o tmp lib/fluent/plugin/thrift/flume.thrift"
@@ -32,6 +13,7 @@ task "thrift_gen" do
32
13
  end
33
14
 
34
15
  Rake::TestTask.new(:test) do |t|
16
+ t.libs << 'lib' << 'test'
35
17
  t.test_files = Dir['test/plugin/*.rb']
36
18
  t.ruby_opts = ['-rubygems'] if defined? Gem
37
19
  t.ruby_opts << '-I.'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -4,15 +4,15 @@ require 'json'
4
4
  $:.unshift File.join(File.dirname(__FILE__), '../lib/fluent/plugin/thrift')
5
5
  require 'flume_types'
6
6
  require 'flume_constants'
7
- require 'thrift_flume_event_server'
7
+ require 'thrift_source_protocol'
8
8
 
9
9
  host = 'localhost'
10
10
  port = 3586
11
11
 
12
12
  socket = Thrift::Socket.new host, port.to_i
13
- transport = Thrift::BufferedTransport.new socket
14
- protocol = Thrift::BinaryProtocol.new transport
15
- client = ThriftFlumeEventServer::Client.new protocol
13
+ transport = Thrift::FramedTransport.new socket
14
+ protocol = Thrift::CompactProtocol.new transport
15
+ client = ThriftSourceProtocol::Client.new protocol
16
16
  transport.open
17
17
 
18
18
  # 2011/09/02 Kazuki Ohta <kazuki.ohta@gmail.com>
@@ -21,8 +21,10 @@ raw_sock = socket.to_io
21
21
  raw_sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
22
22
 
23
23
  entry = ThriftFlumeEvent.new(:body=>{'a'=>'b'}.to_json,
24
- :priority=>Priority::INFO,
25
- :timestamp=>(Time.now.to_i * 1000))
24
+ :headers => {
25
+ 'timestamp' => (Time.now.to_i * 1000).to_s,
26
+ 'tag' => tag,
27
+ })
26
28
  client.append entry
27
29
 
28
30
  transport.close
@@ -0,0 +1,10 @@
1
+ # Flume input
2
+ <source>
3
+ type flume
4
+ port 56789
5
+ </source>
6
+
7
+ # match tag=debug.** and dump to console
8
+ <match **>
9
+ type stdout
10
+ </match>
@@ -0,0 +1,11 @@
1
+ # built-in TCP input
2
+ # $ echo <json> | fluent-cat <tag>
3
+ <source>
4
+ type tcp
5
+ </source>
6
+
7
+ <match **>
8
+ type flume
9
+ host localhost
10
+ port 56789
11
+ </match>
@@ -1,56 +1,24 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ $:.push File.expand_path('../lib', __FILE__)
5
2
 
6
3
  Gem::Specification.new do |s|
7
- s.name = "fluent-plugin-flume"
8
- s.version = "0.1.1"
4
+ s.name = 'fluent-plugin-flume'
5
+ s.version = File.read("VERSION").strip
6
+ s.authors = ["Muga Nishizawa"]
7
+ s.email = ["muga.nishizawa@gmail.com"]
8
+ s.description = "Flume Input/Output plugin for Fluentd event collector"
9
+ s.summary = s.description
10
+ s.homepage = 'https://github.com/fluent/fluent-plugin-flume'
11
+ s.license = 'MIT'
12
+ s.has_rdoc = false
9
13
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Muga Nishizawa"]
12
- s.date = "2012-05-20"
13
- s.email = "muga.nishizawa@gmail.com"
14
- s.executables = ["fluent-flume-remote"]
15
- s.extra_rdoc_files = [
16
- "ChangeLog",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- "AUTHORS",
21
- "Rakefile",
22
- "VERSION",
23
- "bin/fluent-flume-remote",
24
- "fluent-plugin-flume.gemspec",
25
- "lib/fluent/plugin/in_flume.rb",
26
- "lib/fluent/plugin/out_flume.rb",
27
- "lib/fluent/plugin/thrift/flume.thrift",
28
- "lib/fluent/plugin/thrift/flume.thrift.orig",
29
- "lib/fluent/plugin/thrift/flume_constants.rb",
30
- "lib/fluent/plugin/thrift/flume_types.rb",
31
- "lib/fluent/plugin/thrift/thrift_flume_event_server.rb",
32
- "test/plugin/test_in_flume.rb",
33
- "test/plugin/test_out_flume.rb"
34
- ]
35
- s.homepage = "https://github.com/muga/fluent-plugin-flume"
36
- s.require_paths = ["lib"]
37
- s.rubygems_version = "1.8.15"
38
- s.summary = "Flume Input/Output plugin for Fluentd event collector"
39
- s.test_files = ["test/plugin/test_in_flume.rb", "test/plugin/test_out_flume.rb"]
14
+ s.files = `git ls-files`.split($/)
15
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
17
+ s.require_paths = ['lib']
40
18
 
41
- if s.respond_to? :specification_version then
42
- s.specification_version = 3
19
+ s.add_runtime_dependency 'fluentd', '>= 0.10.43'
20
+ s.add_runtime_dependency 'thrift', '~> 0.9.0'
43
21
 
44
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
- s.add_runtime_dependency(%q<fluentd>, ["~> 0.10.16"])
46
- s.add_runtime_dependency(%q<thrift>, ["~> 0.8.0"])
47
- else
48
- s.add_dependency(%q<fluentd>, ["~> 0.10.16"])
49
- s.add_dependency(%q<thrift>, ["~> 0.8.0"])
50
- end
51
- else
52
- s.add_dependency(%q<fluentd>, ["~> 0.10.16"])
53
- s.add_dependency(%q<thrift>, ["~> 0.8.0"])
54
- end
22
+ s.add_development_dependency 'rake', '>= 0.9.2'
23
+ s.add_development_dependency 'test-unit', '~> 3.1.0'
55
24
  end
56
-
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Fluent
3
3
  #
4
- # Copyright (C) 2012 Muga Nishizawa
4
+ # Copyright (C) 2012 - 2013 Muga Nishizawa
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -24,11 +24,15 @@ class FlumeInput < Input
24
24
  config_param :bind, :string, :default => '0.0.0.0'
25
25
  config_param :server_type, :string, :default => 'simple'
26
26
  config_param :is_framed, :bool, :default => false
27
- config_param :body_size_limit, :size, :default => 32*1024*1024 # TODO default
27
+ config_param :body_size_limit, :size, :default => 32 * 1024 * 1024
28
28
  config_param :tag_field, :string, :default => nil
29
29
  config_param :default_tag, :string, :default => 'category'
30
30
  config_param :add_prefix, :string, :default => nil
31
- config_param :message_format, :string, :default => 'text'
31
+ config_param :msg_format, :string, :default => 'text'
32
+
33
+ unless method_defined?(:log)
34
+ define_method(:log) { $log }
35
+ end
32
36
 
33
37
  def initialize
34
38
  require 'thrift'
@@ -45,13 +49,14 @@ class FlumeInput < Input
45
49
  end
46
50
 
47
51
  def start
48
- $log.debug "listening flume on #{@bind}:#{@port}"
52
+ log.debug "listening flume on #{@bind}:#{@port}"
49
53
 
50
54
  handler = FluentFlumeHandler.new
51
55
  handler.tag_field = @tag_field
52
56
  handler.default_tag = @default_tag
53
57
  handler.add_prefix = @add_prefix
54
- handler.message_format = @message_format
58
+ handler.msg_format = @msg_format
59
+ handler.log = log
55
60
  processor = ThriftFlumeEventServer::Processor.new handler
56
61
 
57
62
  @transport = Thrift::ServerSocket.new @bind, @port
@@ -61,8 +66,8 @@ class FlumeInput < Input
61
66
  raise ConfigError, "in_flume: unsupported is_framed '#{@is_framed}'"
62
67
  end
63
68
 
64
- unless ['text', 'json'].include? @message_format
65
- raise 'Unknown format: message_format=#{@message_format}'
69
+ unless ['text', 'json'].include? @msg_format
70
+ raise 'Unknown format: msg_format=#{@msg_format}'
66
71
  end
67
72
 
68
73
  # 2011/09/29 Kazuki Ohta <kazuki.ohta@gmail.com>
@@ -92,23 +97,24 @@ class FlumeInput < Input
92
97
  end
93
98
 
94
99
  def shutdown
95
- @transport.close unless @transport.closed? # TODO
96
- #@thread.join # TODO
100
+ @transport.close unless @transport.closed?
101
+ #@thread.join
97
102
  end
98
103
 
99
104
  def run
100
- $log.debug "starting server: #{@server}"
105
+ log.debug "starting server: #{@server}"
101
106
  @server.serve
102
107
  rescue
103
- $log.error "unexpected error", :error=>$!.to_s
104
- $log.error_backtrace
108
+ log.error "unexpected error", :error=>$!.to_s
109
+ log.error_backtrace
105
110
  end
106
111
 
107
112
  class FluentFlumeHandler
108
113
  attr_accessor :tag_field
109
114
  attr_accessor :default_tag
110
115
  attr_accessor :add_prefix
111
- attr_accessor :message_format
116
+ attr_accessor :msg_format
117
+ attr_accessor :log
112
118
 
113
119
  def append(evt)
114
120
  begin
@@ -128,18 +134,38 @@ class FlumeInput < Input
128
134
  Engine.emit(tag, timestamp, record)
129
135
  end
130
136
  rescue => e
131
- $log.error "unexpected error", :error=>$!.to_s
132
- $log.error_backtrace
137
+ log.error "unexpected error", :error=>$!.to_s
138
+ log.error_backtrace
133
139
  end
134
140
  end
135
141
 
136
142
  def rawAppend(evt)
137
- $log.error "rawAppend is not implemented yet: #{evt}"
143
+ log.error "rawAppend is not implemented yet: #{evt}"
138
144
  end
139
145
 
140
146
  def ackedAppend(evt)
141
- $log.error "ackedAppend is not implemented yet: #{evt}"
142
- EventStatus::OK
147
+ begin
148
+ record = create_record(evt)
149
+ if @tag_field
150
+ tag = evt.fieldss[@tag_field] || @default_tag
151
+ unless tag
152
+ return # ignore
153
+ end
154
+ else
155
+ tag = @default_tag
156
+ end
157
+ timestamp = evt.timestamp.to_i
158
+ if @add_prefix
159
+ Engine.emit(@add_prefix + '.' + tag, timestamp, record)
160
+ else
161
+ Engine.emit(tag, timestamp, record)
162
+ end
163
+ return EventStatus::ACK
164
+ rescue => e
165
+ log.error "unexpected error", :error=>$!.to_s
166
+ log.error_backtrace
167
+ return EventStatus::ERR
168
+ end
143
169
  end
144
170
 
145
171
  def close()
@@ -147,7 +173,7 @@ class FlumeInput < Input
147
173
 
148
174
  private
149
175
  def create_record(evt)
150
- case @message_format
176
+ case @msg_format
151
177
  when 'text'
152
178
  return {'message'=>evt.body.force_encoding('UTF-8')}
153
179
  when 'json'
@@ -155,7 +181,7 @@ class FlumeInput < Input
155
181
  raise 'body must be a Hash, if json_body=true' unless js.is_a?(Hash)
156
182
  return js
157
183
  else
158
- raise 'Invalid format: #{@message_format}'
184
+ raise 'Invalid format: #{@msg_format}'
159
185
  end
160
186
  end
161
187
  end
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Fluent
3
3
  #
4
- # Copyright (C) 2012 Muga Nishizawa
4
+ # Copyright (C) 2012 - 2013 Muga Nishizawa
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -26,17 +26,22 @@ class FlumeOutput < BufferedOutput
26
26
  config_param :remove_prefix, :string, :default => nil
27
27
  config_param :default_category, :string, :default => 'unknown'
28
28
 
29
+ unless method_defined?(:log)
30
+ define_method(:log) { $log }
31
+ end
32
+
29
33
  def initialize
30
34
  require 'thrift'
31
35
  $:.unshift File.join(File.dirname(__FILE__), 'thrift')
32
36
  require 'flume_types'
33
37
  require 'flume_constants'
34
- require 'thrift_flume_event_server'
35
-
38
+ require 'thrift_source_protocol'
36
39
  super
37
40
  end
38
41
 
39
42
  def configure(conf)
43
+ # override default buffer_chunk_limit
44
+ conf['buffer_chunk_limit'] ||= '1m'
40
45
  super
41
46
  end
42
47
 
@@ -64,30 +69,28 @@ class FlumeOutput < BufferedOutput
64
69
  end
65
70
 
66
71
  def write(chunk)
67
- records = []
68
- chunk.msgpack_each { |arr|
69
- records << arr
70
- }
71
-
72
- transport = Thrift::Socket.new @host, @port, @timeout
73
- #transport = Thrift::FramedTransport.new socket
72
+ socket = Thrift::Socket.new @host, @port, @timeout
73
+ transport = Thrift::FramedTransport.new socket
74
74
  #protocol = Thrift::BinaryProtocol.new transport, false, false
75
- protocol = Thrift::BinaryProtocol.new transport
76
- client = ThriftFlumeEventServer::Client.new protocol
75
+ protocol = Thrift::CompactProtocol.new transport
76
+ client = ThriftSourceProtocol::Client.new protocol
77
77
 
78
+ count = 0
78
79
  transport.open
79
- $log.debug "thrift client opend: #{client}"
80
+ log.debug "thrift client opened: #{client}"
80
81
  begin
81
- records.each { |r|
82
- tag, time, record = r
83
- entry = ThriftFlumeEvent.new(:body=>record.to_json.to_s.force_encoding('UTF-8'),
84
- :priority=>Priority::INFO,
85
- :timestamp=>time,
86
- :fieldss=>{'category'=>tag})
82
+ chunk.msgpack_each { |tag, time, record|
83
+ entry = ThriftFlumeEvent.new(:body => record.to_json.to_s.force_encoding('UTF-8'),
84
+ :headers => {
85
+ 'timestamp' => time.to_s,
86
+ 'tag' => tag,
87
+ })
87
88
  client.append entry
89
+ count += 1
88
90
  }
91
+ log.debug "Writing #{count} entries to flume"
89
92
  ensure
90
- $log.debug "thrift client closing: #{client}"
93
+ log.debug "thrift client closing: #{client}"
91
94
  transport.close
92
95
  end
93
96
  end