Skip to content

Commit f55519e

Browse files
authored
Merge pull request #75 from kaorimatz/support-use_nil
Support use_nil for record values
2 parents f78a24a + f3e865c commit f55519e

File tree

5 files changed

+46
-6
lines changed

5 files changed

+46
-6
lines changed

.github/workflows/linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- ubuntu-latest
1515
experimental: [false]
1616
include:
17-
- ruby-version: head
17+
- ruby: head
1818
os: ubuntu-latest
1919
experimental: true
2020

lib/fluent/plugin/filter_record_modifier.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def configure(conf)
7474
conf.elements.select { |element| element.name == 'record' }.each do |element|
7575
element.each_pair do |k, v|
7676
element.has_key?(k) # to suppress unread configuration warning
77-
@has_tag_parts = true if v.include?('tag_parts')
77+
@has_tag_parts = true if v && v.include?('tag_parts')
7878
@map[k] = DynamicExpander.new(k, v, @prepare_value)
7979
end
8080
end
@@ -167,7 +167,7 @@ def convert_encoding(value)
167167

168168
class DynamicExpander
169169
def initialize(param_key, param_value, prepare_value)
170-
if param_value.include?('${')
170+
if param_value && param_value.include?('${')
171171
__str_eval_code__ = parse_parameter(param_value)
172172

173173
# Use class_eval with string instead of define_method for performance.

lib/fluent/plugin/out_record_modifier.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def configure(conf)
7777
conf.elements.select { |element| element.name == 'record' }.each do |element|
7878
element.each_pair do |k, v|
7979
element.has_key?(k) # to suppress unread configuration warning
80-
@has_tag_parts = true if v.include?('tag_parts')
80+
@has_tag_parts = true if v && v.include?('tag_parts')
8181
@map[k] = DynamicExpander.new(k, v, @prepare_value)
8282
end
8383
end
@@ -198,7 +198,7 @@ class DynamicExpander
198198
attr_reader :param_value
199199

200200
def initialize(param_key, param_value, prepare_value)
201-
if param_value.include?('${')
201+
if param_value && param_value.include?('${')
202202
__str_eval_code__ = parse_parameter(param_value)
203203

204204
# Use class_eval with string instead of define_method for performance.

test/test_filter_record_modifier.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,23 @@ def test_convert_char_encoding
226226
], d.filtered.map { |e| e.last }
227227
end
228228
end
229+
230+
def test_use_nil
231+
require "fluent/version"
232+
if Gem::Version.new(Fluent::VERSION) < Gem::Version.new("1.8.0")
233+
omit "use_nil is only available in Fluentd 1.8.0 and higher"
234+
end
235+
236+
d = create_driver %q[
237+
<record>
238+
test_key "#{use_nil}"
239+
</record>
240+
]
241+
242+
d.run(default_tag: @tag) do
243+
d.feed("k" => "v")
244+
end
245+
246+
assert_equal [{"k" => "v", "test_key" => nil}], d.filtered.map(&:last)
247+
end
229248
end

test/test_out_record_modifier.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
require 'fluent/test'
12
require 'fluent/test/driver/output'
23
require 'fluent/plugin/out_record_modifier'
3-
4+
require 'test/unit'
45

56
class RecordModifierOutputTest < Test::Unit::TestCase
67
def setup
@@ -139,4 +140,24 @@ def test_remove_non_whitelist_keys
139140

140141
assert_equal [{"k1" => 'v', "k2" => 'v', 'foo' => 'bar'}], d.events.map { |e| e.last }
141142
end
143+
144+
def test_use_nil
145+
require "fluent/version"
146+
if Gem::Version.new(Fluent::VERSION) < Gem::Version.new("1.8.0")
147+
omit "use_nil is only available in Fluentd 1.8.0 and higher"
148+
end
149+
150+
d = create_driver %q[
151+
tag foo.filtered
152+
<record>
153+
test_key "#{use_nil}"
154+
</record>
155+
]
156+
157+
d.run(default_tag: "test_tags") do
158+
d.feed("k" => "v")
159+
end
160+
161+
assert_equal [{"k" => "v", "test_key" => nil}], d.events.map(&:last)
162+
end
142163
end

0 commit comments

Comments
 (0)