fluent-plugin-record-modifier 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/ChangeLog +5 -0
- data/README.md +42 -6
- data/VERSION +1 -1
- data/fluent-plugin-record-modifier.gemspec +0 -1
- data/lib/fluent/plugin/filter_record_modifier.rb +25 -0
- data/test/test_filter_record_modifier.rb +37 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3b44157dfddde7eefc70b4798674e499834fad6f52fafc8da7289696944ec9ca
|
4
|
+
data.tar.gz: faa3f952b7bb41eaa46719494d3aed58bf8f59ed0d7fa476ff2491c700c5ff73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e69f8b91068b1998c60a41449d97471aca548fd7eb002bf8e26048895b95af6cd64c17c771d4a85ef1bcecf63138d404bc1a56ed6a6c052047f5d85db57820f
|
7
|
+
data.tar.gz: b47c9e3a4f054a663e96b7b7ac548ba2877edc941cfcc2e123a7d832239ae1be136baf8a330cdebed391523b92f2b737a68ceb6187211b79ec15e3f17843471f
|
data/ChangeLog
CHANGED
data/README.md
CHANGED
@@ -148,6 +148,48 @@ then you got new record like below:
|
|
148
148
|
{"key1":"hoge", "key2":"foo"}
|
149
149
|
```
|
150
150
|
|
151
|
+
### replace_keys_value
|
152
|
+
|
153
|
+
If you want to replace specific value for keys you can use `replace` section.
|
154
|
+
|
155
|
+
```conf
|
156
|
+
<filter pattern>
|
157
|
+
@type record_modifier
|
158
|
+
|
159
|
+
# replace key key1
|
160
|
+
<replace>
|
161
|
+
# your key name
|
162
|
+
key key1
|
163
|
+
# your regexp
|
164
|
+
expression /^(?<start>.+).{2}(?<end>.+)$/
|
165
|
+
# replace string
|
166
|
+
replace \\k<start>ors\\k<end>
|
167
|
+
</replace>
|
168
|
+
# replace key key2
|
169
|
+
<replace>
|
170
|
+
# your key name
|
171
|
+
key key2
|
172
|
+
# your regexp
|
173
|
+
expression /^(.{1}).{2}(.{1})$/
|
174
|
+
# replace string
|
175
|
+
replace \\1ors\\2
|
176
|
+
</replace>
|
177
|
+
</filter>
|
178
|
+
```
|
179
|
+
|
180
|
+
If following record is passed:
|
181
|
+
|
182
|
+
```js
|
183
|
+
{"key1":"hoge", "key2":"hoge", "key3":"bar"}
|
184
|
+
```
|
185
|
+
|
186
|
+
then you got new record like below:
|
187
|
+
|
188
|
+
```js
|
189
|
+
{"key1":"horse", "key2":"horse", "key3":"bar"}
|
190
|
+
```
|
191
|
+
|
192
|
+
|
151
193
|
### Ruby code trick for complex logic
|
152
194
|
|
153
195
|
If you need own complex logic in filter, writing filter plugin is better. But if you don't want to write new plugin, you can use temporal key trick like below:
|
@@ -174,12 +216,6 @@ In v0.10, you can use `record_modifier` output to emulate filter. `record_modifi
|
|
174
216
|
foo bar
|
175
217
|
</match>
|
176
218
|
|
177
|
-
## TODO
|
178
|
-
|
179
|
-
* Adding following features if needed
|
180
|
-
|
181
|
-
* Replace record value
|
182
|
-
|
183
219
|
## Copyright
|
184
220
|
|
185
221
|
<table>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
@@ -9,7 +9,6 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.version = File.read("VERSION").strip
|
10
10
|
gem.authors = ["Masahiro Nakagawa"]
|
11
11
|
gem.email = "repeatedly@gmail.com"
|
12
|
-
gem.has_rdoc = false
|
13
12
|
#gem.platform = Gem::Platform::RUBY
|
14
13
|
gem.license = 'MIT'
|
15
14
|
gem.files = `git ls-files`.split("\n")
|
@@ -31,6 +31,22 @@ Modified events will have only specified keys (if exist in original events).
|
|
31
31
|
This option is exclusive with `remove_keys`.
|
32
32
|
DESC
|
33
33
|
|
34
|
+
config_section :replace, param_name: :replaces, multi: true do
|
35
|
+
desc "The field name to which the regular expression is applied"
|
36
|
+
config_param :key, :string
|
37
|
+
desc "The regular expression"
|
38
|
+
config_param :expression do |value|
|
39
|
+
if value.start_with?("/") && value.end_with?("/")
|
40
|
+
Regexp.compile(value[1..-2])
|
41
|
+
else
|
42
|
+
$log.warn "You should use \"pattern /#{value}/\" instead of \"pattern #{value}\""
|
43
|
+
Regexp.compile(value)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
desc "The replacement string"
|
47
|
+
config_param :replace, :string
|
48
|
+
end
|
49
|
+
|
34
50
|
def configure(conf)
|
35
51
|
super
|
36
52
|
|
@@ -97,6 +113,15 @@ DESC
|
|
97
113
|
record = modified
|
98
114
|
end
|
99
115
|
|
116
|
+
unless @replaces.empty?
|
117
|
+
@replaces.each { |replace|
|
118
|
+
target_key = replace.key
|
119
|
+
if record.include?(target_key) && replace.expression.match(record[target_key])
|
120
|
+
record[target_key] = record[target_key].gsub(replace.expression, replace.replace)
|
121
|
+
end
|
122
|
+
}
|
123
|
+
end
|
124
|
+
|
100
125
|
record = change_encoding(record) if @char_encoding
|
101
126
|
record
|
102
127
|
end
|
@@ -141,6 +141,43 @@ class RecordModifierFilterTest < Test::Unit::TestCase
|
|
141
141
|
assert_equal [{"k1" => 'v', "test_key" => 'foo'}], d.filtered.map(&:last)
|
142
142
|
end
|
143
143
|
|
144
|
+
def test_replace_values
|
145
|
+
d = create_driver %[
|
146
|
+
<replace>
|
147
|
+
key k1
|
148
|
+
expression /^(?<start>.+).{2}(?<end>.+)$/
|
149
|
+
replace \\k<start>ors\\k<end>
|
150
|
+
</replace>
|
151
|
+
<replace>
|
152
|
+
key k2
|
153
|
+
expression /^(.{1}).{2}(.{1})$/
|
154
|
+
replace \\1ors\\2
|
155
|
+
</replace>
|
156
|
+
]
|
157
|
+
|
158
|
+
d.run(default_tag: @tag) do
|
159
|
+
d.feed("k1" => 'hoge', "k2" => 'hoge', "k3" => 'bar')
|
160
|
+
end
|
161
|
+
|
162
|
+
assert_equal [{"k1" => 'horse', "k2" => 'horse', "k3" => 'bar'}], d.filtered.map(&:last)
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_does_not_replace
|
166
|
+
d = create_driver %[
|
167
|
+
<replace>
|
168
|
+
key k1
|
169
|
+
expression /^(?<start>.+).{2}(?<end>.+)$/
|
170
|
+
replace \\k<start>ors\\k<end>
|
171
|
+
</replace>
|
172
|
+
]
|
173
|
+
|
174
|
+
d.run(default_tag: @tag) do
|
175
|
+
d.feed("k1" => 'hog')
|
176
|
+
end
|
177
|
+
|
178
|
+
assert_equal [{"k1" => 'hog'}], d.filtered.map(&:last)
|
179
|
+
end
|
180
|
+
|
144
181
|
sub_test_case 'frozen check' do
|
145
182
|
def test_set_char_encoding
|
146
183
|
d = create_driver %[
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro Nakagawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.6
|
98
|
+
rubygems_version: 2.7.6
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: Filter plugin for modifying event record
|