Skip to content

Commit 057dad8

Browse files
committed
Add prepare_value parameter
1 parent b4383d6 commit 057dad8

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/fluent/plugin/filter_record_modifier.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ module Fluent
44
class Plugin::RecordModifierFilter < Plugin::Filter
55
Fluent::Plugin.register_filter('record_modifier', self)
66

7+
config_param :prepare_value, :string, default: nil,
8+
desc: <<-DESC
9+
Prepare values for filtering in configure phase. Prepared values can be used in <record>.
10+
You can write any ruby code.
11+
DESC
712
config_param :char_encoding, :string, default: nil,
813
desc: <<-DESC
914
Fluentd including some plugins treats the logs as a BINARY by default to forward.
@@ -26,7 +31,7 @@ class Plugin::RecordModifierFilter < Plugin::Filter
2631
This option is exclusive with `remove_keys`.
2732
DESC
2833

29-
BUILTIN_CONFIGURATIONS = %W(type @type log_level @log_level id @id char_encoding remove_keys whitelist_keys)
34+
BUILTIN_CONFIGURATIONS = %W(type @type log_level @log_level id @id char_encoding remove_keys whitelist_keys prepare_value)
3035

3136
def configure(conf)
3237
super
@@ -68,7 +73,7 @@ def configure(conf)
6873
check_config_placeholders(k, v)
6974
element.has_key?(k) # to suppress unread configuration warning
7075
@has_tag_parts = true if v.include?('tag_parts')
71-
@map[k] = DynamicExpander.new(k, v)
76+
@map[k] = DynamicExpander.new(k, v, @prepare_value)
7277
end
7378
end
7479

@@ -153,7 +158,7 @@ def check_config_placeholders(k, v)
153158
end
154159

155160
class DynamicExpander
156-
def initialize(param_key, param_value)
161+
def initialize(param_key, param_value, prepare_value)
157162
if param_value.include?('${')
158163
__str_eval_code__ = parse_parameter(param_value)
159164

@@ -169,6 +174,12 @@ def expand(tag, time, record, tag_parts)
169174
@param_value = param_value
170175
end
171176

177+
begin
178+
eval prepare_value if prepare_value
179+
rescue SyntaxError
180+
raise ConfigError, "Pass invalid syntax parameter : key = prepare_value, value = #{prepare_value}"
181+
end
182+
172183
begin
173184
# check eval genarates wrong code or not
174185
expand(nil, nil, nil, nil)

0 commit comments

Comments
 (0)