fluent-plugin-groonga 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -53,6 +53,11 @@ contributed patches.)
53
53
  * English: [groonga-talk](https://lists.sourceforge.net/lists/listinfo/groonga-talk)
54
54
  * Japanese: [groonga-dev](http://lists.sourceforge.jp/mailman/listinfo/groonga-dev)
55
55
 
56
+ ## Source
57
+
58
+ The repository for fluent-plugin-groonga is on
59
+ [GitHub](https://github.com/groonga/fluent-plugin-groonga/).
60
+
56
61
  ## Thanks
57
62
 
58
63
  * ...
@@ -2,6 +2,13 @@
2
2
 
3
3
  # News
4
4
 
5
+ ## 1.0.2: 2013-08-08
6
+
7
+ ### Improvements
8
+
9
+ * Supported non-buffer mode.
10
+ * Required gqtp gem >= 1.0.3.
11
+
5
12
  ## 1.0.1: 2012-12-29
6
13
 
7
14
  ### Improvements
@@ -1,6 +1,6 @@
1
1
  # -*- mode: ruby; coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -17,7 +17,7 @@
17
17
 
18
18
  Gem::Specification.new do |spec|
19
19
  spec.name = "fluent-plugin-groonga"
20
- spec.version = "1.0.1"
20
+ spec.version = "1.0.2"
21
21
  spec.authors = ["Kouhei Sutou"]
22
22
  spec.email = ["kou@clear-code.com"]
23
23
  spec.summary = "Fluentd plugin collection for groonga users"
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.require_paths = ["lib"]
35
35
 
36
36
  spec.add_runtime_dependency("fluentd")
37
- spec.add_runtime_dependency("gqtp")
37
+ spec.add_runtime_dependency("gqtp", ">= 1.0.3")
38
38
  spec.add_runtime_dependency("groonga-command")
39
39
 
40
40
  spec.add_development_dependency("rake")
@@ -18,73 +18,132 @@
18
18
  require "fileutils"
19
19
 
20
20
  module Fluent
21
- class GroongaOutput < BufferedOutput
21
+ class GroongaOutput < Output
22
22
  Plugin.register_output("groonga", self)
23
23
 
24
24
  def initialize
25
25
  super
26
26
  end
27
27
 
28
+ BufferedOutput.config_params.each do |name, (block, options)|
29
+ if options[:type]
30
+ config_param(name, options[:type], options)
31
+ else
32
+ config_param(name, options, &block)
33
+ end
34
+ end
35
+
28
36
  config_param :protocol, :string, :default => "http"
29
37
  config_param :table, :string, :default => nil
30
38
 
31
39
  def configure(conf)
32
40
  super
33
- case @protocol
34
- when "http"
35
- @client = HTTPClient.new
36
- when "gqtp"
37
- @client = GQTPClient.new
38
- when "command"
39
- @client = CommandClient.new
40
- end
41
+ @client = create_client(@protocol)
41
42
  @client.configure(conf)
43
+
44
+ @emitter = Emitter.new(@client, @table)
45
+ @output = create_output(@buffer_type, @emitter)
46
+ @output.configure(conf)
42
47
  end
43
48
 
44
49
  def start
45
50
  super
46
51
  @client.start
52
+ @output.start
47
53
  end
48
54
 
49
55
  def shutdown
50
56
  super
57
+ @output.shutdown
51
58
  @client.shutdown
52
59
  end
53
60
 
54
- def format(tag, time, record)
55
- [tag, time, record].to_msgpack
61
+ def emit(tag, event_stream, chain)
62
+ @output.emit(tag, event_stream, chain)
63
+ end
64
+
65
+ def create_client(protocol)
66
+ case protocol
67
+ when "http"
68
+ HTTPClient.new
69
+ when "gqtp"
70
+ GQTPClient.new
71
+ when "command"
72
+ CommandClient.new
73
+ end
74
+ end
75
+
76
+ def create_output(buffer_type, emitter)
77
+ if buffer_type == "none"
78
+ RawGroongaOutput.new(emitter)
79
+ else
80
+ BufferedGroongaOutput.new(emitter)
81
+ end
56
82
  end
57
83
 
58
- def write(chunk)
59
- chunk.msgpack_each do |tag, time, arguments|
84
+ class Emitter
85
+ def initialize(client, table)
86
+ @client = client
87
+ @table = table
88
+ end
89
+
90
+ def emit(tag, record)
60
91
  if /\Agroonga\.command\./ =~ tag
61
92
  name = $POSTMATCH
62
- send_command(name, arguments)
93
+ send_command(name, record)
63
94
  else
64
- store_chunk(chunk)
95
+ store_chunk(data)
65
96
  end
66
97
  end
98
+
99
+ private
100
+ def send_command(name, arguments)
101
+ command_class = Groonga::Command.find(name)
102
+ command = command_class.new(name, arguments)
103
+ @client.send(command)
104
+ end
105
+
106
+ def store_chunk(value)
107
+ return if @table.nil?
108
+
109
+ values = [value]
110
+ arguments = {
111
+ "table" => @table,
112
+ "values" => Yajl::Enocder.encode(values),
113
+ }
114
+ send_command("load", arguments)
115
+ end
67
116
  end
68
117
 
69
- private
70
- def send_command(name, arguments)
71
- command_class = Groonga::Command.find(name)
72
- command = command_class.new(name, arguments)
73
- @client.send(command)
118
+ class RawGroongaOutput < Output
119
+ def initialize(emitter)
120
+ @emitter = emitter
121
+ super()
122
+ end
123
+
124
+ def emit(tag, event_stream, chain)
125
+ event_stream.each do |time, record|
126
+ @emitter.emit(tag, record)
127
+ end
128
+ chain.next
129
+ end
74
130
  end
75
131
 
76
- def store_chunk(chunk)
77
- return if @table.nil?
132
+ class BufferedGroongaOutput < BufferedOutput
133
+ def initialize(emitter)
134
+ @emitter = emitter
135
+ super()
136
+ end
137
+
138
+ def format(tag, time, record)
139
+ [tag, time, record].to_msgpack
140
+ end
78
141
 
79
- values = []
80
- chunk.each do |time, value|
81
- values << value
142
+ def write(chunk)
143
+ chunk.msgpack_each do |tag, time, record|
144
+ @emitter.emit(tag, record)
145
+ end
82
146
  end
83
- arguments = {
84
- "table" => @table,
85
- "values" => Yajl::Enocder.encode(values),
86
- }
87
- send_command("load", arguments)
88
147
  end
89
148
 
90
149
  class HTTPClient
@@ -133,7 +192,7 @@ module Fluent
133
192
  end
134
193
 
135
194
  def send(command)
136
- @client ||= GQTP::Client.new(:host => @host,
195
+ @client ||= GQTP::Client.new(:address => @host,
137
196
  :port => @port,
138
197
  :connection => :coolio,
139
198
  :loop => @loop)
@@ -34,8 +34,7 @@ class GroongaOutputTest < Test::Unit::TestCase
34
34
 
35
35
  private
36
36
  def create_driver(tag)
37
- driver = Fluent::Test::BufferedOutputTestDriver.new(Fluent::GroongaOutput,
38
- tag)
37
+ driver = Fluent::Test::OutputTestDriver.new(Fluent::GroongaOutput, tag)
39
38
  driver.configure(configuration)
40
39
  driver
41
40
  end
@@ -99,8 +98,9 @@ EOC
99
98
  def test_basic_command
100
99
  driver = create_driver("groonga.command.table_create")
101
100
  time = Time.parse("2012-10-26T08:45:42Z").to_i
102
- driver.emit({"name" => "Users"}, time)
103
- driver.run
101
+ driver.run do
102
+ driver.emit({"name" => "Users"}, time)
103
+ end
104
104
  # p @request_headers
105
105
  # p @request_body
106
106
  end
@@ -193,8 +193,9 @@ EOC
193
193
  def test_basic_command
194
194
  driver = create_driver("groonga.command.table_create")
195
195
  time = Time.parse("2012-10-26T08:45:42Z")
196
- driver.emit({"name" => "Users"}, time)
197
- driver.run
196
+ driver.run do
197
+ driver.emit({"name" => "Users"}, time)
198
+ end
198
199
  assert_equal([
199
200
  [
200
201
  "--input-fd", actual_input_fd,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-groonga
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-28 00:00:00.000000000 Z
12
+ date: 2013-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: '0'
37
+ version: 1.0.3
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: '0'
45
+ version: 1.0.3
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: groonga-command
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -169,15 +169,15 @@ files:
169
169
  - lib/fluent/plugin/out_groonga.rb
170
170
  - lib/fluent/plugin/in_groonga.rb
171
171
  - sample/gqtp.conf
172
- - sample/command.conf
173
172
  - sample/http.conf
173
+ - sample/command.conf
174
+ - doc/text/configuration.md
174
175
  - doc/text/news.md
175
176
  - doc/text/constitution.md
176
177
  - doc/text/lgpl-2.1.txt
177
- - doc/text/configuration.md
178
+ - test/test_output.rb
178
179
  - test/run-test.rb
179
180
  - test/test_input.rb
180
- - test/test_output.rb
181
181
  homepage: https://github.com/groonga/fluent-plugin-groonga
182
182
  licenses: []
183
183
  post_install_message:
@@ -190,18 +190,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
190
  - - ! '>='
191
191
  - !ruby/object:Gem::Version
192
192
  version: '0'
193
- segments:
194
- - 0
195
- hash: -1000993838467277328
196
193
  required_rubygems_version: !ruby/object:Gem::Requirement
197
194
  none: false
198
195
  requirements:
199
196
  - - ! '>='
200
197
  - !ruby/object:Gem::Version
201
198
  version: '0'
202
- segments:
203
- - 0
204
- hash: -1000993838467277328
205
199
  requirements: []
206
200
  rubyforge_project:
207
201
  rubygems_version: 1.8.23
@@ -209,7 +203,7 @@ signing_key:
209
203
  specification_version: 3
210
204
  summary: Fluentd plugin collection for groonga users
211
205
  test_files:
206
+ - test/test_output.rb
212
207
  - test/run-test.rb
213
208
  - test/test_input.rb
214
- - test/test_output.rb
215
209
  has_rdoc: