fluent-plugin-record-modifier 1.0.1 → 1.0.2
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.
- checksums.yaml +4 -4
- data/ChangeLog +6 -0
- data/README.md +14 -0
- data/VERSION +1 -1
- data/lib/fluent/plugin/filter_record_modifier.rb +19 -15
- data/test/test_filter_record_modifier.rb +23 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 290bea3c616897ac2b1125aabcebb421b3099863
|
4
|
+
data.tar.gz: f81e3ec261a75b79fd0ea5bac81698ffc6d9f357
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64ae991840fb9cb6eab3bc2be79ccbe3c368fd59110a400fa4329dcffa14b852e7c4df18e816458f0c3308bf3937ef679e1f2939e067e2dc354900383e9e7a64
|
7
|
+
data.tar.gz: e82a147fa6b1408bf49f21853d888a3b616df5bf474d675952767aeb003bcc58f3761f9a60a8d3f74a007abab6604fbe7725da85de3123d90a5ac70a4593a332
|
data/ChangeLog
CHANGED
data/README.md
CHANGED
@@ -62,6 +62,20 @@ But unlike `record_transformer`, `record_modifier` doesn't support following fea
|
|
62
62
|
- tag_suffix and tag_prefix
|
63
63
|
- dynamic key placeholder
|
64
64
|
|
65
|
+
### prepare_value
|
66
|
+
|
67
|
+
Prepare values for filtering. This ruby code is evaluated in `configure` phase and prepared values can be used in `<record>`. Here is an example:
|
68
|
+
|
69
|
+
<filter pattern>
|
70
|
+
@type record_modifier
|
71
|
+
prepare_value require 'foo'; @foo = Foo.new
|
72
|
+
<record>
|
73
|
+
key ${@foo.method1}
|
74
|
+
</record>
|
75
|
+
</filter>
|
76
|
+
|
77
|
+
This feature is useful for using external library.
|
78
|
+
|
65
79
|
### char_encoding
|
66
80
|
|
67
81
|
Fluentd including some plugins treats logs as a BINARY by default to forward.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.2
|
@@ -4,6 +4,11 @@ module Fluent
|
|
4
4
|
class Plugin::RecordModifierFilter < Plugin::Filter
|
5
5
|
Fluent::Plugin.register_filter('record_modifier', self)
|
6
6
|
|
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
|
7
12
|
config_param :char_encoding, :string, default: nil,
|
8
13
|
desc: <<-DESC
|
9
14
|
Fluentd including some plugins treats the logs as a BINARY by default to forward.
|
@@ -26,8 +31,6 @@ Modified events will have only specified keys (if exist in original events).
|
|
26
31
|
This option is exclusive with `remove_keys`.
|
27
32
|
DESC
|
28
33
|
|
29
|
-
BUILTIN_CONFIGURATIONS = %W(type @type log_level @log_level id @id char_encoding remove_keys whitelist_keys)
|
30
|
-
|
31
34
|
def configure(conf)
|
32
35
|
super
|
33
36
|
|
@@ -36,15 +39,6 @@ DESC
|
|
36
39
|
end
|
37
40
|
|
38
41
|
@map = {}
|
39
|
-
conf.each_pair { |k, v|
|
40
|
-
unless BUILTIN_CONFIGURATIONS.include?(k)
|
41
|
-
check_config_placeholders(k, v);
|
42
|
-
conf.has_key?(k)
|
43
|
-
$log.warn "top level definition is deprecated. Please put parameters inside <record>: '#{k} #{v}'"
|
44
|
-
@map[k] = DynamicExpander.new(k, v)
|
45
|
-
end
|
46
|
-
}
|
47
|
-
|
48
42
|
@to_enc = nil
|
49
43
|
if @char_encoding
|
50
44
|
from, to = @char_encoding.split(':', 2)
|
@@ -68,7 +62,7 @@ DESC
|
|
68
62
|
check_config_placeholders(k, v)
|
69
63
|
element.has_key?(k) # to suppress unread configuration warning
|
70
64
|
@has_tag_parts = true if v.include?('tag_parts')
|
71
|
-
@map[k] = DynamicExpander.new(k, v)
|
65
|
+
@map[k] = DynamicExpander.new(k, v, @prepare_value)
|
72
66
|
end
|
73
67
|
end
|
74
68
|
|
@@ -114,7 +108,7 @@ DESC
|
|
114
108
|
value.force_encoding(@from_enc)
|
115
109
|
elsif value.is_a?(Hash)
|
116
110
|
value.each_pair { |k, v|
|
117
|
-
if v.frozen?
|
111
|
+
if v.frozen? && v.is_a?(String)
|
118
112
|
value[k] = set_encoding(v.dup)
|
119
113
|
else
|
120
114
|
set_encoding(v)
|
@@ -122,6 +116,8 @@ DESC
|
|
122
116
|
}
|
123
117
|
elsif value.is_a?(Array)
|
124
118
|
value.each { |v| set_encoding(v) }
|
119
|
+
else
|
120
|
+
value
|
125
121
|
end
|
126
122
|
end
|
127
123
|
|
@@ -131,7 +127,7 @@ DESC
|
|
131
127
|
value.encode!(@to_enc, @from_enc, :invalid => :replace, :undef => :replace)
|
132
128
|
elsif value.is_a?(Hash)
|
133
129
|
value.each_pair { |k, v|
|
134
|
-
if v.frozen?
|
130
|
+
if v.frozen? && v.is_a?(String)
|
135
131
|
value[k] = convert_encoding(v.dup)
|
136
132
|
else
|
137
133
|
convert_encoding(v)
|
@@ -139,6 +135,8 @@ DESC
|
|
139
135
|
}
|
140
136
|
elsif value.is_a?(Array)
|
141
137
|
value.each { |v| convert_encoding(v) }
|
138
|
+
else
|
139
|
+
value
|
142
140
|
end
|
143
141
|
end
|
144
142
|
|
@@ -153,7 +151,7 @@ DESC
|
|
153
151
|
end
|
154
152
|
|
155
153
|
class DynamicExpander
|
156
|
-
def initialize(param_key, param_value)
|
154
|
+
def initialize(param_key, param_value, prepare_value)
|
157
155
|
if param_value.include?('${')
|
158
156
|
__str_eval_code__ = parse_parameter(param_value)
|
159
157
|
|
@@ -169,6 +167,12 @@ DESC
|
|
169
167
|
@param_value = param_value
|
170
168
|
end
|
171
169
|
|
170
|
+
begin
|
171
|
+
eval prepare_value if prepare_value
|
172
|
+
rescue SyntaxError
|
173
|
+
raise ConfigError, "Pass invalid syntax parameter : key = prepare_value, value = #{prepare_value}"
|
174
|
+
end
|
175
|
+
|
172
176
|
begin
|
173
177
|
# check eval genarates wrong code or not
|
174
178
|
expand(nil, nil, nil, nil)
|
@@ -126,6 +126,21 @@ class RecordModifierFilterTest < Test::Unit::TestCase
|
|
126
126
|
assert_equal [{"k1" => 'v', "k2" => 'v'}], d.filtered.map(&:last)
|
127
127
|
end
|
128
128
|
|
129
|
+
def test_prepare_values
|
130
|
+
d = create_driver %[
|
131
|
+
prepare_value @foo = 'foo'
|
132
|
+
<record>
|
133
|
+
test_key ${@foo}
|
134
|
+
</record>
|
135
|
+
]
|
136
|
+
|
137
|
+
d.run(default_tag: @tag) do
|
138
|
+
d.feed("k1" => 'v')
|
139
|
+
end
|
140
|
+
|
141
|
+
assert_equal [{"k1" => 'v', "test_key" => 'foo'}], d.filtered.map(&:last)
|
142
|
+
end
|
143
|
+
|
129
144
|
sub_test_case 'frozen check' do
|
130
145
|
def test_set_char_encoding
|
131
146
|
d = create_driver %[
|
@@ -133,13 +148,13 @@ class RecordModifierFilterTest < Test::Unit::TestCase
|
|
133
148
|
]
|
134
149
|
|
135
150
|
d.run(default_tag: @tag) do
|
136
|
-
d.feed("k" => 'v'.force_encoding('BINARY').freeze)
|
137
|
-
d.feed("k" => {"l" => 'v'.force_encoding('BINARY').freeze})
|
151
|
+
d.feed("k" => 'v'.force_encoding('BINARY').freeze, 'n' => 1)
|
152
|
+
d.feed("k" => {"l" => 'v'.force_encoding('BINARY').freeze, 'n' => 1})
|
138
153
|
end
|
139
154
|
|
140
155
|
assert_equal [
|
141
|
-
{"k" => 'v'.force_encoding('UTF-8')},
|
142
|
-
{"k" => {"l" => 'v'.force_encoding('UTF-8')}},
|
156
|
+
{"k" => 'v'.force_encoding('UTF-8'), 'n' => 1},
|
157
|
+
{"k" => {"l" => 'v'.force_encoding('UTF-8'), 'n' => 1}},
|
143
158
|
], d.filtered.map { |e| e.last }
|
144
159
|
end
|
145
160
|
|
@@ -149,13 +164,13 @@ class RecordModifierFilterTest < Test::Unit::TestCase
|
|
149
164
|
]
|
150
165
|
|
151
166
|
d.run(default_tag: @tag) do
|
152
|
-
d.feed("k" => 'v'.force_encoding('utf-8').freeze)
|
153
|
-
d.feed("k" => {"l" => 'v'.force_encoding('utf-8').freeze})
|
167
|
+
d.feed("k" => 'v'.force_encoding('utf-8').freeze, 'n' => 1)
|
168
|
+
d.feed("k" => {"l" => 'v'.force_encoding('utf-8').freeze, 'n' => 1})
|
154
169
|
end
|
155
170
|
|
156
171
|
assert_equal [
|
157
|
-
{"k" => 'v'.force_encoding('cp932')},
|
158
|
-
{"k" => {"l" => 'v'.force_encoding('cp932')}},
|
172
|
+
{"k" => 'v'.force_encoding('cp932'), 'n' => 1},
|
173
|
+
{"k" => {"l" => 'v'.force_encoding('cp932'), 'n' => 1}},
|
159
174
|
], d.filtered.map { |e| e.last }
|
160
175
|
end
|
161
176
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-record-modifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro Nakagawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|