Skip to content

Commit

Permalink
Merge pull request #1311 from fluent/record-transformer-remove-old-be…
Browse files Browse the repository at this point in the history
…haviours

filter-record-transformer: remove old behaviours
  • Loading branch information
repeatedly authored Nov 15, 2016
2 parents e3edf3e + 6367d0c commit d3ae96b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
11 changes: 4 additions & 7 deletions lib/fluent/plugin/filter_record_transformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RecordTransformerFilter < Fluent::Plugin::Filter
desc 'When set to true, the full Ruby syntax is enabled in the ${...} expression.'
config_param :enable_ruby, :bool, default: false
desc 'Use original value type.'
config_param :auto_typecast, :bool, default: false # false for lower version compatibility
config_param :auto_typecast, :bool, default: true

def configure(conf)
super
Expand Down Expand Up @@ -95,10 +95,9 @@ def filter_stream(tag, es)
last_record = nil
es.each do |time, record|
last_record = record # for debug log
placeholder_values.merge!({
'time' => @placeholder_expander.time_value(time),
'record' => record,
})
placeholder_values['time'] = @placeholder_expander.time_value(time)
placeholder_values['record'] = record

new_record = reform(record, placeholder_values)
if @renew_time_key && new_record.has_key?(@renew_time_key)
time = Fluent::EventTime.from_time(Time.at(new_record[@renew_time_key].to_f))
Expand Down Expand Up @@ -316,8 +315,6 @@ def expand(str, placeholders, force_stringify = false)

class CleanroomExpander
def expand(__str_to_eval__, tag, time, record, tag_parts, tag_prefix, tag_suffix, hostname)
tags = tag_parts # for old version compatibility
_ = tags # to suppress "unused variable" warning for tags
Thread.current[:record_transformer_record] = record # for old version compatibility
instance_eval(__str_to_eval__)
end
Expand Down
14 changes: 11 additions & 3 deletions test/plugin/test_filter_record_transformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ def filter(config, msgs = [''])
]
filtered = filter(config)
filtered.each do |t, r|
assert_equal(Time.at(@time).localtime.to_s, r['message'])
if enable_ruby == "yes"
assert_equal(Time.at(@time).localtime, r['message'])
else
assert_equal(Time.at(@time).localtime.to_s, r['message'])
end
end
end

Expand Down Expand Up @@ -499,15 +503,19 @@ def filter(config, msgs = [''])
}
end

test 'failed to expand (enable_ruby yes)' do
data(auto_typecast_yes: ["yes", "unknown['bar']"],
auto_typecast_no: ["no", "%Q[\#{unknown['bar']}]"])
test 'failed to expand (enable_ruby yes)' do |(param, expected_log)|

config = %[
enable_ruby yes
auto_typecast #{param}
<record>
message ${unknown['bar']}
</record>
]
filtered = filter(config) { |d|
mock(d.instance.log).warn("failed to expand `%Q[\#{unknown['bar']}]`", anything)
mock(d.instance.log).warn("failed to expand `#{expected_log}`", anything)
}
filtered.each do |t, r|
assert_nil(r['message'])
Expand Down

0 comments on commit d3ae96b

Please sign in to comment.