fluent-plugin-couch 0.8.1 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +2 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/fluent/plugin/out_couch.rb +50 -26
- data/test/test_out_couch.rb +84 -17
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2265d0d8be3afe5dc1f6cd28ba5549074e3f0ae
|
4
|
+
data.tar.gz: 50019c927b4c3c10c3720f28a1968ee66df77631
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11c2d55d39f2c4c7deaa9d40ca7fb6d80a5c2f09ce16005fae476e48fb4ba8ed903391a8bdab2f53e4f6ea7c9bb3349c2f45150e686f89c95561c6330d47e873
|
7
|
+
data.tar.gz: 8babbc84df2b416d688862fdde07eed04503610d702b4d61ead825c41e86cd50c6f4a6f55eed6e4748fb78331fd0025bbbaff642de1d877e2e8d6b2d265fe0e2
|
data/README.rdoc
CHANGED
@@ -31,8 +31,8 @@ Store fluent-event as CouchDB Document to CouchDB database.
|
|
31
31
|
protocol https #default:http
|
32
32
|
|
33
33
|
update_docs true #default:false
|
34
|
-
doc_key_field doc_id #default:nil
|
35
|
-
doc_key_jsonpath $.event.key #default:nil
|
34
|
+
doc_key_field doc_id #default:nil. ${tag} will be replaced with actual event's tag.
|
35
|
+
doc_key_jsonpath $.event.key #default:nil. ${tag} will be replaced with actual event's tag.
|
36
36
|
|
37
37
|
refresh_view_index viewname #default:nil
|
38
38
|
|
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ begin
|
|
12
12
|
gemspec.homepage = "http://github.com/ixixi/fluent-plugin-couch"
|
13
13
|
gemspec.has_rdoc = false
|
14
14
|
gemspec.require_paths = ["lib"]
|
15
|
-
gemspec.add_dependency "fluentd", [">= 0.
|
15
|
+
gemspec.add_dependency "fluentd", [">= 0.14.0", "< 2"]
|
16
16
|
gemspec.add_dependency "couchrest", "~> 1.1.2"
|
17
17
|
gemspec.add_dependency "jsonpath", "~> 0.4.2"
|
18
18
|
gemspec.test_files = Dir["test/**/*.rb"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.9.1
|
@@ -1,46 +1,55 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require "fluent/plugin/output"
|
2
|
+
|
3
|
+
module Fluent::Plugin
|
4
|
+
class CouchOutput < Output
|
3
5
|
attr_reader :db # for tests
|
4
6
|
|
5
|
-
|
7
|
+
DEFAULT_BUFFER_TYPE = "memory"
|
8
|
+
|
9
|
+
helpers :compat_parameters, :inject
|
10
|
+
|
6
11
|
config_set_default :include_tag_key, false
|
7
|
-
|
8
|
-
include SetTimeKeyMixin
|
9
12
|
config_set_default :include_time_key, true
|
10
|
-
|
13
|
+
|
11
14
|
Fluent::Plugin.register_output('couch', self)
|
12
|
-
|
15
|
+
|
13
16
|
config_param :database, :string
|
14
|
-
|
17
|
+
|
15
18
|
config_param :host, :string, :default => 'localhost'
|
16
19
|
config_param :port, :string, :default => '5984'
|
17
20
|
config_param :protocol, :string, :default => 'http'
|
18
|
-
|
21
|
+
|
19
22
|
config_param :refresh_view_index , :string, :default => nil
|
20
|
-
|
23
|
+
|
21
24
|
config_param :user, :string, :default => nil
|
22
25
|
config_param :password, :string, :default => nil, :secret => true
|
23
|
-
|
26
|
+
|
24
27
|
config_param :update_docs, :bool, :default => false
|
25
28
|
config_param :doc_key_field, :string, :default => nil
|
26
29
|
config_param :doc_key_jsonpath, :string, :default => nil
|
27
|
-
|
30
|
+
|
31
|
+
config_section :buffer do
|
32
|
+
config_set_default :@type, DEFAULT_BUFFER_TYPE
|
33
|
+
config_set_default :chunk_keys, ['tag']
|
34
|
+
end
|
35
|
+
|
28
36
|
def initialize
|
29
37
|
super
|
30
|
-
|
38
|
+
|
31
39
|
require 'msgpack'
|
32
40
|
require 'jsonpath'
|
33
41
|
Encoding.default_internal = 'UTF-8'
|
34
42
|
require 'couchrest'
|
35
43
|
Encoding.default_internal = 'ASCII-8BIT'
|
36
44
|
end
|
37
|
-
|
45
|
+
|
38
46
|
def configure(conf)
|
47
|
+
compat_parameters_convert(conf, :buffer, :inject)
|
39
48
|
super
|
40
49
|
account = "#{@user}:#{@password}@" if @user && @password
|
41
50
|
@db = CouchRest.database!("#{@protocol}://#{account}#{@host}:#{@port}/#{@database}")
|
42
51
|
end
|
43
|
-
|
52
|
+
|
44
53
|
def start
|
45
54
|
super
|
46
55
|
@views = []
|
@@ -50,25 +59,31 @@ module Fluent
|
|
50
59
|
@views.push([@refresh_view_index,view_name])
|
51
60
|
end
|
52
61
|
rescue
|
53
|
-
|
62
|
+
log.error 'design document not found!'
|
54
63
|
end
|
55
64
|
end
|
56
65
|
end
|
57
|
-
|
66
|
+
|
58
67
|
def shutdown
|
59
68
|
super
|
60
69
|
end
|
61
|
-
|
70
|
+
|
62
71
|
def format(tag, time, record)
|
72
|
+
record = inject_values_to_record(tag, time, record)
|
63
73
|
record.to_msgpack
|
64
74
|
end
|
65
|
-
|
75
|
+
|
76
|
+
def formatted_to_msgpack_binary
|
77
|
+
true
|
78
|
+
end
|
79
|
+
|
66
80
|
def write(chunk)
|
67
81
|
records = []
|
82
|
+
doc_key_field, doc_key_jsonpath = expand_placeholders(chunk.metadata)
|
68
83
|
chunk.msgpack_each {|record|
|
69
|
-
|
70
|
-
id = record[
|
71
|
-
id = JsonPath.new(
|
84
|
+
|
85
|
+
id = record[doc_key_field]
|
86
|
+
id = JsonPath.new(doc_key_jsonpath).first(record) if id.nil? && !doc_key_jsonpath.nil?
|
72
87
|
record['_id'] = id unless id.nil?
|
73
88
|
records << record
|
74
89
|
}
|
@@ -79,7 +94,7 @@ module Fluent
|
|
79
94
|
end
|
80
95
|
update_view_index
|
81
96
|
end
|
82
|
-
|
97
|
+
|
83
98
|
def update_docs(records)
|
84
99
|
if records.length > 0
|
85
100
|
records.each{|record|
|
@@ -89,16 +104,25 @@ module Fluent
|
|
89
104
|
rescue
|
90
105
|
end
|
91
106
|
record['_rev']=doc['_rev'] unless doc.nil?
|
92
|
-
|
93
|
-
@db.save_doc(record)
|
107
|
+
log.debug record
|
108
|
+
@db.save_doc(record)
|
94
109
|
}
|
95
110
|
end
|
96
111
|
end
|
97
|
-
|
112
|
+
|
98
113
|
def update_view_index()
|
99
114
|
@views.each do |design,view|
|
100
115
|
@db.view("#{design}/#{view}",{"limit"=>"0"})
|
101
116
|
end
|
102
117
|
end
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
def expand_placeholders(metadata)
|
122
|
+
field = jsonpath = nil
|
123
|
+
field = extract_placeholders(@doc_key_field, metadata) if @doc_key_field
|
124
|
+
jsonpath = extract_placeholders(@doc_key_jsonpath, metadata) if @doc_key_jsonpath
|
125
|
+
return field, jsonpath
|
126
|
+
end
|
103
127
|
end
|
104
128
|
end
|
data/test/test_out_couch.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
require "fluent/test"
|
2
|
+
require "fluent/test/driver/output"
|
3
|
+
require "fluent/test/helpers"
|
2
4
|
require "fluent/plugin/out_couch"
|
3
5
|
|
4
6
|
class CouchOutputTest < Test::Unit::TestCase
|
7
|
+
include Fluent::Test::Helpers
|
8
|
+
|
5
9
|
def setup
|
6
10
|
Fluent::Test.setup
|
7
11
|
end
|
@@ -19,12 +23,24 @@ class CouchOutputTest < Test::Unit::TestCase
|
|
19
23
|
update_docs true
|
20
24
|
]
|
21
25
|
|
26
|
+
CONFIG_UPDATE_DOC_WITH_TAG_PLACEHOLDER = %[
|
27
|
+
database #{DATABASE_NAME}
|
28
|
+
doc_key_field ${tag}
|
29
|
+
update_docs true
|
30
|
+
]
|
31
|
+
|
22
32
|
CONFIG_JSONPATH = %[
|
23
33
|
database #{DATABASE_NAME}
|
24
34
|
doc_key_field key
|
25
35
|
doc_key_jsonpath $.nested.key
|
26
36
|
]
|
27
37
|
|
38
|
+
CONFIG_JSONPATH_WITH_TAG_PLACEHOLDER = %[
|
39
|
+
database #{DATABASE_NAME}
|
40
|
+
doc_key_field key
|
41
|
+
doc_key_jsonpath $.${tag}.key
|
42
|
+
]
|
43
|
+
|
28
44
|
CONFIG_DESIGN = %[
|
29
45
|
database #{DATABASE_NAME}
|
30
46
|
doc_key_field key
|
@@ -39,7 +55,7 @@ class CouchOutputTest < Test::Unit::TestCase
|
|
39
55
|
end
|
40
56
|
|
41
57
|
def create_driver(config = CONFIG)
|
42
|
-
Fluent::Test::
|
58
|
+
Fluent::Test::Driver::Output.new(Fluent::Plugin::CouchOutput).configure(config)
|
43
59
|
end
|
44
60
|
|
45
61
|
def test_configure
|
@@ -68,9 +84,10 @@ class CouchOutputTest < Test::Unit::TestCase
|
|
68
84
|
|
69
85
|
def test_write
|
70
86
|
previous_rows = @d.instance.db.all_docs["total_rows"]
|
71
|
-
time =
|
72
|
-
@d.
|
73
|
-
|
87
|
+
time = event_time
|
88
|
+
@d.run(default_tag: "tag") do
|
89
|
+
@d.feed(time, {"message" => "record"})
|
90
|
+
end
|
74
91
|
rows = @d.instance.db.all_docs["total_rows"]
|
75
92
|
assert_equal(rows, previous_rows + 1)
|
76
93
|
end
|
@@ -87,19 +104,46 @@ class CouchOutputTest < Test::Unit::TestCase
|
|
87
104
|
end
|
88
105
|
|
89
106
|
def test_write
|
90
|
-
time =
|
91
|
-
|
92
|
-
@d.run
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
107
|
+
time = event_time
|
108
|
+
previous_rows = rows = 0
|
109
|
+
@d.run(default_tag: "test") do
|
110
|
+
@d.feed(time, {"key" => "record-1", "message" => "record"})
|
111
|
+
previous_rows = @d.instance.db.all_docs["total_rows"]
|
112
|
+
@d.feed(time, {"key" => "record-1", "message" => "record-mod"})
|
113
|
+
rows = @d.instance.db.all_docs["total_rows"]
|
114
|
+
end
|
97
115
|
record = @d.instance.db.get("record-1")
|
98
116
|
assert_equal(rows, previous_rows)
|
99
117
|
assert_equal("record-mod", record["message"])
|
100
118
|
end
|
101
119
|
end
|
102
120
|
|
121
|
+
class WriteWithUpdateDocWithTagPlaceHolderTest < self
|
122
|
+
def setup
|
123
|
+
@d = create_driver(CONFIG_UPDATE_DOC_WITH_TAG_PLACEHOLDER)
|
124
|
+
prepare_db
|
125
|
+
end
|
126
|
+
|
127
|
+
def teardown
|
128
|
+
@db.delete!
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_write
|
132
|
+
time = event_time
|
133
|
+
tag = "replace.placeholder"
|
134
|
+
previous_rows = rows = 0
|
135
|
+
@d.run(default_tag: tag) do
|
136
|
+
@d.feed(time, {tag => "record-placeholder", "message" => "record"})
|
137
|
+
previous_rows = @d.instance.db.all_docs["total_rows"]
|
138
|
+
@d.feed(time, {tag => "record-placeholder", "message" => "record-placeholder"})
|
139
|
+
rows = @d.instance.db.all_docs["total_rows"]
|
140
|
+
end
|
141
|
+
assert_equal(rows, previous_rows)
|
142
|
+
record = @d.instance.db.get("record-placeholder")
|
143
|
+
assert_equal("record-placeholder", record["message"])
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
103
147
|
class WriteWithJsonpathTest < self
|
104
148
|
def setup
|
105
149
|
@d = create_driver(CONFIG_JSONPATH)
|
@@ -111,14 +155,36 @@ class CouchOutputTest < Test::Unit::TestCase
|
|
111
155
|
end
|
112
156
|
|
113
157
|
def test_write
|
114
|
-
time =
|
115
|
-
@d.
|
116
|
-
|
158
|
+
time = event_time
|
159
|
+
@d.run(default_tag: "test") do
|
160
|
+
@d.feed(time, {"nested" => {"key" => "record-nested", "message" => "record"}})
|
161
|
+
end
|
117
162
|
record = @d.instance.db.get("record-nested")
|
118
163
|
assert_equal({"key" => "record-nested", "message" => "record"}, record["nested"])
|
119
164
|
end
|
120
165
|
end
|
121
166
|
|
167
|
+
class WriteWithJsonpathWithTagPlaceholderTest < self
|
168
|
+
def setup
|
169
|
+
@d = create_driver(CONFIG_JSONPATH_WITH_TAG_PLACEHOLDER)
|
170
|
+
prepare_db
|
171
|
+
end
|
172
|
+
|
173
|
+
def teardown
|
174
|
+
@db.delete!
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_write
|
178
|
+
time = event_time
|
179
|
+
tag = "couchrecord"
|
180
|
+
@d.run(default_tag: tag) do
|
181
|
+
@d.feed(time, {tag => {"key" => "record-nested", "message" => "record"}})
|
182
|
+
end
|
183
|
+
record = @d.instance.db.get("record-nested")
|
184
|
+
assert_equal({"key" => "record-nested", "message" => "record"}, record["couchrecord"])
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
122
188
|
class WriteWithDesignTest < self
|
123
189
|
def setup
|
124
190
|
@d = create_driver(CONFIG_DESIGN)
|
@@ -148,9 +214,10 @@ class CouchOutputTest < Test::Unit::TestCase
|
|
148
214
|
end
|
149
215
|
|
150
216
|
def test_write
|
151
|
-
time =
|
152
|
-
@d.
|
153
|
-
|
217
|
+
time = event_time
|
218
|
+
@d.run(default_tag: "test") do
|
219
|
+
@d.feed(time, {"key" => "record-design", "message" => "record"})
|
220
|
+
end
|
154
221
|
record = @d.instance.db.get("record-design")
|
155
222
|
assert_equal("record", record["message"])
|
156
223
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-couch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuri Odagiri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '2'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.
|
22
|
+
version: 0.14.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '2'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.
|
32
|
+
version: 0.14.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: couchrest
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
version: '0'
|
91
91
|
requirements: []
|
92
92
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.
|
93
|
+
rubygems_version: 2.4.1
|
94
94
|
signing_key:
|
95
95
|
specification_version: 4
|
96
96
|
summary: CouchDB output plugin for Fluentd event collector
|