Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter-record-transformer: remove old behaviours #1311

Merged
merged 3 commits into from
Nov 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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