fluent-plugin-mongo 0.6.12 → 0.6.13
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.
- data/ChangeLog +5 -0
- data/README.rdoc +19 -0
- data/VERSION +1 -1
- data/lib/fluent/plugin/out_mongo.rb +8 -0
- data/test/plugin/out_mongo.rb +32 -2
- metadata +8 -2
data/ChangeLog
CHANGED
data/README.rdoc
CHANGED
@@ -169,6 +169,8 @@ You can deserialize broken data using Mongo and Marshal.load. Sample code is bel
|
|
169
169
|
p Marshal.load(doc['__broken_data'].to_s) #=> {"key1": "invalid value", "key2": "valid value"}
|
170
170
|
end
|
171
171
|
|
172
|
+
=== ignore_invalid_record
|
173
|
+
|
172
174
|
If you want to ignore an invalid record, set _true_ to _ignore_invalid_record_ parameter in match.
|
173
175
|
|
174
176
|
<match forward.*>
|
@@ -180,6 +182,23 @@ If you want to ignore an invalid record, set _true_ to _ignore_invalid_record_ p
|
|
180
182
|
...
|
181
183
|
</match>
|
182
184
|
|
185
|
+
=== exclude_broken_fields
|
186
|
+
|
187
|
+
If you want to exclude some fields from broken data marshaling, use _exclude_broken_fields_ to specfiy the keys.
|
188
|
+
|
189
|
+
<match forward.*>
|
190
|
+
...
|
191
|
+
|
192
|
+
# key2 is excluded from __broken_data.
|
193
|
+
# e.g. {"__broken_data": BinData(0, Marshal.dump result of {"key1": "invalid value"}), "key2": "valid value", "time": ISODate("2012-01-15T21:09:53Z")
|
194
|
+
exclude_broken_fields key2
|
195
|
+
|
196
|
+
...
|
197
|
+
</match>
|
198
|
+
|
199
|
+
Specified value is a comma separated keys(e.g. key1,key2,key3).
|
200
|
+
This parameter is useful for excluding shard keys in shard environment.
|
201
|
+
|
183
202
|
== Buffer size limitation
|
184
203
|
|
185
204
|
Mongo plugin has the limitation of buffer size.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.13
|
@@ -20,6 +20,7 @@ class MongoOutput < BufferedOutput
|
|
20
20
|
config_param :ignore_invalid_record, :bool, :default => false
|
21
21
|
config_param :disable_collection_check, :bool, :default => nil
|
22
22
|
config_param :safe, :bool, :default => true
|
23
|
+
config_param :exclude_broken_fields, :string, :default => nil
|
23
24
|
|
24
25
|
# tag mapping mode
|
25
26
|
config_param :tag_mapped, :bool, :default => false
|
@@ -52,6 +53,8 @@ class MongoOutput < BufferedOutput
|
|
52
53
|
@remove_tag_prefix = Regexp.new('^' + Regexp.escape(remove_tag_prefix))
|
53
54
|
end
|
54
55
|
|
56
|
+
@exclude_broken_fields = @exclude_broken_fields.split(',') if @exclude_broken_fields
|
57
|
+
|
55
58
|
# capped configuration
|
56
59
|
if conf.has_key?('capped')
|
57
60
|
raise ConfigError, "'capped_size' parameter is required on <store> of Mongo output" unless conf.has_key?('capped_size')
|
@@ -136,6 +139,11 @@ class MongoOutput < BufferedOutput
|
|
136
139
|
new_record = {}
|
137
140
|
new_record[@tag_key] = record.delete(@tag_key) if @include_tag_key
|
138
141
|
new_record[@time_key] = record.delete(@time_key)
|
142
|
+
if @exclude_broken_fields
|
143
|
+
@exclude_broken_fields.each { |key|
|
144
|
+
new_record[key] = record.delete(key)
|
145
|
+
}
|
146
|
+
end
|
139
147
|
new_record[BROKEN_DATA_KEY] = BSON::Binary.new(Marshal.dump(record))
|
140
148
|
new_record
|
141
149
|
}
|
data/test/plugin/out_mongo.rb
CHANGED
@@ -106,8 +106,8 @@ class MongoOutputTest < Test::Unit::TestCase
|
|
106
106
|
|
107
107
|
def emit_invalid_documents(d)
|
108
108
|
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
109
|
-
d.emit({'a' => 3, '$last' => '石動'}, time)
|
110
|
-
d.emit({'a' => 4, 'first' => '菖蒲'.encode('EUC-JP').force_encoding('UTF-8')}, time)
|
109
|
+
d.emit({'a' => 3, 'b' => "c", '$last' => '石動'}, time)
|
110
|
+
d.emit({'a' => 4, 'b' => "d", 'first' => '菖蒲'.encode('EUC-JP').force_encoding('UTF-8')}, time)
|
111
111
|
time
|
112
112
|
end
|
113
113
|
|
@@ -126,6 +126,36 @@ class MongoOutputTest < Test::Unit::TestCase
|
|
126
126
|
}.sort)
|
127
127
|
end
|
128
128
|
|
129
|
+
def test_write_with_invalid_recoreds_with_exclude_one_broken_fields
|
130
|
+
d = create_driver(default_config + %[
|
131
|
+
exclude_broken_fields a
|
132
|
+
])
|
133
|
+
t = emit_documents(d)
|
134
|
+
t = emit_invalid_documents(d)
|
135
|
+
|
136
|
+
d.run
|
137
|
+
documents = get_documents
|
138
|
+
assert_equal(4, documents.size)
|
139
|
+
assert_equal(2, documents.select { |e| e.has_key?(Fluent::MongoOutput::BROKEN_DATA_KEY) }.size)
|
140
|
+
assert_equal([1, 2, 3, 4], documents.select { |e| e.has_key?('a') }.map { |e| e['a'] }.sort)
|
141
|
+
assert_equal(0, documents.select { |e| e.has_key?('b') }.size)
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_write_with_invalid_recoreds_with_exclude_two_broken_fields
|
145
|
+
d = create_driver(default_config + %[
|
146
|
+
exclude_broken_fields a,b
|
147
|
+
])
|
148
|
+
t = emit_documents(d)
|
149
|
+
t = emit_invalid_documents(d)
|
150
|
+
|
151
|
+
d.run
|
152
|
+
documents = get_documents
|
153
|
+
assert_equal(4, documents.size)
|
154
|
+
assert_equal(2, documents.select { |e| e.has_key?(Fluent::MongoOutput::BROKEN_DATA_KEY) }.size)
|
155
|
+
assert_equal([1, 2, 3, 4], documents.select { |e| e.has_key?('a') }.map { |e| e['a'] }.sort)
|
156
|
+
assert_equal(["c", "d"], documents.select { |e| e.has_key?('b') }.map { |e| e['b'] }.sort)
|
157
|
+
end
|
158
|
+
|
129
159
|
def test_write_with_invalid_recoreds_at_ignore
|
130
160
|
d = create_driver(default_config + %[
|
131
161
|
ignore_invalid_record true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.13
|
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:
|
12
|
+
date: 2013-01-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|
@@ -134,12 +134,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
134
|
- - ! '>='
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '0'
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
hash: 1797874939389521588
|
137
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
141
|
none: false
|
139
142
|
requirements:
|
140
143
|
- - ! '>='
|
141
144
|
- !ruby/object:Gem::Version
|
142
145
|
version: '0'
|
146
|
+
segments:
|
147
|
+
- 0
|
148
|
+
hash: 1797874939389521588
|
143
149
|
requirements: []
|
144
150
|
rubyforge_project:
|
145
151
|
rubygems_version: 1.8.23
|