fluent-plugin-record-reformer 0.2.8 → 0.2.9
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.
- data/CHANGELOG.md +6 -0
- data/README.md +18 -9
- data/fluent-plugin-record-reformer.gemspec +1 -1
- data/lib/fluent/plugin/out_record_reformer.rb +10 -3
- data/spec/out_record_reformer_spec.rb +20 -0
- metadata +4 -4
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -20,11 +20,12 @@ Example:
|
|
20
20
|
renew_record false
|
21
21
|
enable_ruby false
|
22
22
|
|
23
|
-
tag reformed.${
|
23
|
+
tag reformed.${tag_prefix[-2]}
|
24
24
|
<record>
|
25
25
|
hostname ${hostname}
|
26
26
|
input_tag ${tag}
|
27
|
-
|
27
|
+
last_tag ${tag_parts[-1]}
|
28
|
+
message ${message}, yay!
|
28
29
|
</record>
|
29
30
|
</match>
|
30
31
|
|
@@ -33,7 +34,7 @@ Assume following input is coming (indented):
|
|
33
34
|
```js
|
34
35
|
foo.bar {
|
35
36
|
"remove_me":"bar",
|
36
|
-
"
|
37
|
+
"not_remove_me":"bar",
|
37
38
|
"message":"Hello world!"
|
38
39
|
}
|
39
40
|
```
|
@@ -41,11 +42,12 @@ foo.bar {
|
|
41
42
|
then output becomes as below (indented):
|
42
43
|
|
43
44
|
```js
|
44
|
-
reformed.foo
|
45
|
-
"
|
45
|
+
reformed.foo {
|
46
|
+
"not_remove_me":"bar",
|
46
47
|
"hostname":"YOUR_HOSTNAME",
|
47
48
|
"input_tag":"foo.bar",
|
48
|
-
"
|
49
|
+
"last_tag":"bar",
|
50
|
+
"message":"Hello world!, yay!",
|
49
51
|
}
|
50
52
|
```
|
51
53
|
|
@@ -58,11 +60,12 @@ Example:
|
|
58
60
|
remove_keys remove_me
|
59
61
|
renew_record false
|
60
62
|
enable_ruby false
|
61
|
-
tag reformed.${
|
63
|
+
tag reformed.${tag_prefix[-2]}
|
62
64
|
|
63
65
|
hostname ${hostname}
|
64
66
|
input_tag ${tag}
|
65
|
-
|
67
|
+
last_tag ${tag_parts[-1]}
|
68
|
+
message ${message}, yay!
|
66
69
|
</match>
|
67
70
|
|
68
71
|
This results in same, but please note that following option parameters are reserved, so can not be used as a record key.
|
@@ -85,7 +88,13 @@ This results in same, but please note that following option parameters are reser
|
|
85
88
|
|
86
89
|
- renew_record *bool*
|
87
90
|
|
88
|
-
|
91
|
+
`renew_record true` creates an output record newly without extending (merging) the input record fields. Default is `false`.
|
92
|
+
|
93
|
+
- keep_keys
|
94
|
+
|
95
|
+
You may use with `renew_record true`. Specify record keys to be kept by a string separated by , (comma) like
|
96
|
+
|
97
|
+
keep_keys message,foo
|
89
98
|
|
90
99
|
- enable_ruby *bool*
|
91
100
|
|
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.name = "fluent-plugin-record-reformer"
|
6
|
-
gem.version = "0.2.
|
6
|
+
gem.version = "0.2.9"
|
7
7
|
gem.authors = ["Naotoshi Seo"]
|
8
8
|
gem.email = "sonots@gmail.com"
|
9
9
|
gem.homepage = "https://github.com/sonots/fluent-plugin-record-reformer"
|
@@ -12,10 +12,11 @@ module Fluent
|
|
12
12
|
config_param :output_tag, :string, :default => nil # obsolete
|
13
13
|
config_param :tag, :string, :default => nil
|
14
14
|
config_param :remove_keys, :string, :default => nil
|
15
|
+
config_param :keep_keys, :string, :default => nil
|
15
16
|
config_param :renew_record, :bool, :default => false
|
16
17
|
config_param :enable_ruby, :bool, :default => true # true for lower version compatibility
|
17
18
|
|
18
|
-
BUILTIN_CONFIGURATIONS = %W(type tag output_tag remove_keys renew_record enable_ruby)
|
19
|
+
BUILTIN_CONFIGURATIONS = %W(type tag output_tag remove_keys renew_record keep_keys enable_ruby)
|
19
20
|
|
20
21
|
# To support log_level option implemented by Fluentd v0.10.43
|
21
22
|
unless method_defined?(:log)
|
@@ -43,6 +44,11 @@ module Fluent
|
|
43
44
|
@remove_keys = @remove_keys.split(',')
|
44
45
|
end
|
45
46
|
|
47
|
+
if @keep_keys
|
48
|
+
raise Fluent::ConfigError, "out_record_reformer: `renew_record` must be true to use `keep_keys`" unless @renew_record
|
49
|
+
@keep_keys = @keep_keys.split(',')
|
50
|
+
end
|
51
|
+
|
46
52
|
if @output_tag and @tag.nil? # for lower version compatibility
|
47
53
|
log.warn "out_record_reformer: `output_tag` is deprecated. Use `tag` option instead."
|
48
54
|
@tag = @output_tag
|
@@ -96,8 +102,9 @@ module Fluent
|
|
96
102
|
new_tag = @placeholder_expander.expand(tag)
|
97
103
|
|
98
104
|
new_record = @renew_record ? {} : record.dup
|
99
|
-
@
|
100
|
-
@
|
105
|
+
@keep_keys.each {|k| new_record[k] = record[k]} if @keep_keys and @renew_record
|
106
|
+
@map.each_pair {|k, v| new_record[k] = @placeholder_expander.expand(v) }
|
107
|
+
@remove_keys.each {|k| new_record.delete(k) } if @remove_keys
|
101
108
|
|
102
109
|
[new_tag, new_record]
|
103
110
|
end
|
@@ -29,6 +29,11 @@ describe Fluent::RecordReformerOutput do
|
|
29
29
|
let(:config) { %[] }
|
30
30
|
it { expect { subject }.to raise_error(Fluent::ConfigError) }
|
31
31
|
end
|
32
|
+
|
33
|
+
context "keep_keys must be specified togerther with renew_record true" do
|
34
|
+
let(:config) { %[keep_keys a] }
|
35
|
+
it { expect { subject }.to raise_error(Fluent::ConfigError) }
|
36
|
+
end
|
32
37
|
end
|
33
38
|
end
|
34
39
|
|
@@ -131,6 +136,21 @@ describe Fluent::RecordReformerOutput do
|
|
131
136
|
it { emit }
|
132
137
|
end
|
133
138
|
|
139
|
+
context 'keep_keys' do
|
140
|
+
let(:emit) do
|
141
|
+
driver.run { driver.emit({'foo'=>'bar', 'message' => 1}, time.to_i) }
|
142
|
+
end
|
143
|
+
let(:config) { %[tag reformed.${tag}\nrenew_record true\nkeep_keys foo,message] }
|
144
|
+
before do
|
145
|
+
Fluent::Engine.stub(:now).and_return(time)
|
146
|
+
Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
|
147
|
+
'foo' => 'bar',
|
148
|
+
'message' => 1, # this keep type
|
149
|
+
})
|
150
|
+
end
|
151
|
+
it { emit }
|
152
|
+
end
|
153
|
+
|
134
154
|
context 'unknown placeholder (enable_ruby no)' do
|
135
155
|
let(:emit) do
|
136
156
|
driver.run { driver.emit({}, time.to_i) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-record-reformer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-05-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|
@@ -125,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
segments:
|
127
127
|
- 0
|
128
|
-
hash:
|
128
|
+
hash: 689323407
|
129
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
130
|
none: false
|
131
131
|
requirements:
|
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
version: '0'
|
135
135
|
segments:
|
136
136
|
- 0
|
137
|
-
hash:
|
137
|
+
hash: 689323407
|
138
138
|
requirements: []
|
139
139
|
rubyforge_project:
|
140
140
|
rubygems_version: 1.8.23
|