fluent-plugin-record-reformer 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ ## 0.2.8 (2014/04/12)
2
+
3
+ Changes:
4
+
5
+ * Deprecate `output_tag` option. Use `tag` option instead.
6
+
1
7
  ## 0.2.7 (2014/03/26)
2
8
 
3
9
  Fixes:
data/README.md CHANGED
@@ -20,7 +20,7 @@ Example:
20
20
  renew_record false
21
21
  enable_ruby false
22
22
 
23
- output_tag reformed.${tag}
23
+ tag reformed.${tag}
24
24
  <record>
25
25
  hostname ${hostname}
26
26
  input_tag ${tag}
@@ -58,7 +58,7 @@ Example:
58
58
  remove_keys remove_me
59
59
  renew_record false
60
60
  enable_ruby false
61
- output_tag reformed.${tag}
61
+ tag reformed.${tag}
62
62
 
63
63
  hostname ${hostname}
64
64
  input_tag ${tag}
@@ -69,9 +69,13 @@ This results in same, but please note that following option parameters are reser
69
69
 
70
70
  ## Option Parameters
71
71
 
72
- - output_tag
72
+ - output_tag (obsolete)
73
73
 
74
- The output tag name
74
+ The output tag name. This option is deprecated. Use `tag` option instead
75
+
76
+ - tag
77
+
78
+ The output tag name.
75
79
 
76
80
  - remove_keys
77
81
 
@@ -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.7"
6
+ gem.version = "0.2.8"
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"
@@ -9,12 +9,13 @@ module Fluent
9
9
  super
10
10
  end
11
11
 
12
- config_param :output_tag, :string
12
+ config_param :output_tag, :string, :default => nil # obsolete
13
+ config_param :tag, :string, :default => nil
13
14
  config_param :remove_keys, :string, :default => nil
14
15
  config_param :renew_record, :bool, :default => false
15
16
  config_param :enable_ruby, :bool, :default => true # true for lower version compatibility
16
17
 
17
- BUILTIN_CONFIGURATIONS = %W(type output_tag remove_keys renew_record enable_ruby)
18
+ BUILTIN_CONFIGURATIONS = %W(type tag output_tag remove_keys renew_record enable_ruby)
18
19
 
19
20
  # To support log_level option implemented by Fluentd v0.10.43
20
21
  unless method_defined?(:log)
@@ -42,6 +43,14 @@ module Fluent
42
43
  @remove_keys = @remove_keys.split(',')
43
44
  end
44
45
 
46
+ if @output_tag and @tag.nil? # for lower version compatibility
47
+ log.warn "out_record_reformer: `output_tag` is deprecated. Use `tag` option instead."
48
+ @tag = @output_tag
49
+ end
50
+ if @tag.nil?
51
+ raise Fluent::ConfigError, "out_record_reformer: `tag` must be specified"
52
+ end
53
+
45
54
  @placeholder_expander =
46
55
  if @enable_ruby
47
56
  # require utilities which would be used in ruby placeholders
@@ -71,20 +80,20 @@ module Fluent
71
80
  last_record = nil
72
81
  es.each {|time, record|
73
82
  last_record = record # for debug log
74
- new_tag, new_record = reform(@output_tag, time, record, placeholders)
83
+ new_tag, new_record = reform(@tag, time, record, placeholders)
75
84
  Engine.emit(new_tag, time, new_record)
76
85
  }
77
86
  chain.next
78
87
  rescue => e
79
88
  log.warn "record_reformer: #{e.class} #{e.message} #{e.backtrace.first}"
80
- log.debug "record_reformer: output_tag:#{@output_tag} map:#{@map} record:#{last_record} placeholders:#{placeholders}"
89
+ log.debug "record_reformer: tag:#{@tag} map:#{@map} record:#{last_record} placeholders:#{placeholders}"
81
90
  end
82
91
 
83
92
  private
84
93
 
85
- def reform(output_tag, time, record, opts)
94
+ def reform(tag, time, record, opts)
86
95
  @placeholder_expander.prepare_placeholders(time, record, opts)
87
- new_tag = @placeholder_expander.expand(output_tag)
96
+ new_tag = @placeholder_expander.expand(tag)
88
97
 
89
98
  new_record = @renew_record ? {} : record.dup
90
99
  @map.each_pair { |k, v| new_record[k] = @placeholder_expander.expand(v) }
@@ -4,11 +4,10 @@ require_relative 'spec_helper'
4
4
  describe Fluent::RecordReformerOutput do
5
5
  before { Fluent::Test.setup }
6
6
  CONFIG = %[
7
- type reformed
8
- output_tag reformed.${tag}
7
+ tag reformed.${tag}
9
8
 
10
9
  hostname ${hostname}
11
- tag ${tag}
10
+ input_tag ${tag}
12
11
  time ${time.strftime('%S')}
13
12
  message ${hostname} ${tag_parts.last} ${URI.escape(message)}
14
13
  ]
@@ -23,6 +22,12 @@ describe Fluent::RecordReformerOutput do
23
22
 
24
23
  context "check default" do
25
24
  let(:config) { CONFIG }
25
+ it { expect { subject }.not_to raise_error }
26
+ end
27
+
28
+ context "tag is not specified" do
29
+ let(:config) { %[] }
30
+ it { expect { subject }.to raise_error(Fluent::ConfigError) }
26
31
  end
27
32
  end
28
33
  end
@@ -30,27 +35,30 @@ describe Fluent::RecordReformerOutput do
30
35
  describe 'test emit' do
31
36
  let(:time) { Time.now }
32
37
  let(:emit) do
33
- driver.run do
34
- driver.emit({'foo'=>'bar', 'message' => '1'}, time.to_i)
35
- driver.emit({'foo'=>'bar', 'message' => '2'}, time.to_i)
36
- end
38
+ driver.run { driver.emit({'foo'=>'bar', 'message' => '1'}, time.to_i) }
37
39
  end
38
40
 
39
41
  context 'typical usage' do
42
+ let(:emit) do
43
+ driver.run do
44
+ driver.emit({'foo'=>'bar', 'message' => '1'}, time.to_i)
45
+ driver.emit({'foo'=>'bar', 'message' => '2'}, time.to_i)
46
+ end
47
+ end
40
48
  let(:config) { CONFIG }
41
49
  before do
42
50
  Fluent::Engine.stub(:now).and_return(time)
43
51
  Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
44
52
  'foo' => 'bar',
45
53
  'hostname' => hostname,
46
- 'tag' => tag,
54
+ 'input_tag' => tag,
47
55
  'time' => time.strftime('%S'),
48
56
  'message' => "#{hostname} #{tag_parts.last} 1",
49
57
  })
50
58
  Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
51
59
  'foo' => 'bar',
52
60
  'hostname' => hostname,
53
- 'tag' => tag,
61
+ 'input_tag' => tag,
54
62
  'time' => time.strftime('%S'),
55
63
  'message' => "#{hostname} #{tag_parts.last} 2",
56
64
  })
@@ -58,19 +66,15 @@ describe Fluent::RecordReformerOutput do
58
66
  it { emit }
59
67
  end
60
68
 
61
- context 'support old ${tags} placeholder' do
62
- let(:config) { %[
63
- type reformed
69
+ context 'obsolete output_tag' do
70
+ let(:config) {%[
64
71
  output_tag reformed.${tag}
65
-
66
- message ${tags[1]}
67
72
  ]}
68
-
69
73
  before do
70
74
  Fluent::Engine.stub(:now).and_return(time)
71
- Fluent::Engine.should_receive(:emit).twice.with("reformed.#{tag}", time.to_i, {
75
+ Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
72
76
  'foo' => 'bar',
73
- 'message' => "#{tag_parts[1]}",
77
+ 'message' => "1",
74
78
  })
75
79
  end
76
80
  it { emit }
@@ -78,12 +82,11 @@ describe Fluent::RecordReformerOutput do
78
82
 
79
83
  context 'record directive' do
80
84
  let(:config) {%[
81
- type reformed
82
- output_tag reformed.${tag}
85
+ tag reformed.${tag}
83
86
 
84
87
  <record>
85
88
  hostname ${hostname}
86
- output_tag ${tag}
89
+ tag ${tag}
87
90
  time ${time.strftime('%S')}
88
91
  message ${hostname} ${tag_parts.last} ${message}
89
92
  </record>
@@ -93,17 +96,10 @@ describe Fluent::RecordReformerOutput do
93
96
  Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
94
97
  'foo' => 'bar',
95
98
  'hostname' => hostname,
96
- 'output_tag' => tag,
99
+ 'tag' => tag,
97
100
  'time' => time.strftime('%S'),
98
101
  'message' => "#{hostname} #{tag_parts.last} 1",
99
102
  })
100
- Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
101
- 'foo' => 'bar',
102
- 'hostname' => hostname,
103
- 'output_tag' => tag,
104
- 'time' => time.strftime('%S'),
105
- 'message' => "#{hostname} #{tag_parts.last} 2",
106
- })
107
103
  end
108
104
  it { emit }
109
105
  end
@@ -114,12 +110,7 @@ describe Fluent::RecordReformerOutput do
114
110
  Fluent::Engine.stub(:now).and_return(time)
115
111
  Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
116
112
  'hostname' => hostname,
117
- 'tag' => tag,
118
- 'time' => time.strftime('%S'),
119
- })
120
- Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
121
- 'hostname' => hostname,
122
- 'tag' => tag,
113
+ 'input_tag' => tag,
123
114
  'time' => time.strftime('%S'),
124
115
  })
125
116
  end
@@ -132,60 +123,21 @@ describe Fluent::RecordReformerOutput do
132
123
  Fluent::Engine.stub(:now).and_return(time)
133
124
  Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
134
125
  'hostname' => hostname,
135
- 'tag' => tag,
136
- 'time' => time.strftime('%S'),
137
- 'message' => "#{hostname} #{tag_parts.last} 1",
138
- })
139
- Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
140
- 'hostname' => hostname,
141
- 'tag' => tag,
126
+ 'input_tag' => tag,
142
127
  'time' => time.strftime('%S'),
143
- 'message' => "#{hostname} #{tag_parts.last} 2",
144
- })
145
- end
146
- it { emit }
147
- end
148
-
149
- context 'enable_ruby no' do
150
- let(:config) {%[
151
- type reformed
152
- output_tag reformed.${tag}
153
- enable_ruby no
154
-
155
- hostname ${hostname}
156
- tag ${tag}
157
- time ${time}
158
- message ${hostname} ${tag_parts[-1]} ${message}
159
- ]}
160
- before do
161
- Fluent::Engine.stub(:now).and_return(time)
162
- Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
163
- 'foo' => 'bar',
164
- 'hostname' => hostname,
165
- 'tag' => tag,
166
- 'time' => time.to_s,
167
128
  'message' => "#{hostname} #{tag_parts.last} 1",
168
129
  })
169
- Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
170
- 'foo' => 'bar',
171
- 'hostname' => hostname,
172
- 'tag' => tag,
173
- 'time' => time.to_s,
174
- 'message' => "#{hostname} #{tag_parts.last} 2",
175
- })
176
130
  end
177
131
  it { emit }
178
132
  end
179
133
 
180
- context 'enable_ruby no (unknown placeholder)' do
134
+ context 'unknown placeholder (enable_ruby no)' do
181
135
  let(:emit) do
182
- driver.run { driver.emit({'foo'=>'bar', 'message' => '1'}, time.to_i) }
136
+ driver.run { driver.emit({}, time.to_i) }
183
137
  end
184
138
  let(:config) {%[
185
- type reformed
186
- output_tag reformed.${tag}
139
+ tag reformed.${tag}
187
140
  enable_ruby no
188
-
189
141
  message ${unknown}
190
142
  ]}
191
143
  before do
@@ -193,66 +145,118 @@ describe Fluent::RecordReformerOutput do
193
145
  end
194
146
  it { emit }
195
147
  end
148
+ end
196
149
 
197
- context '${tag_prefix[N]} and ${tag_suffix[N]}' do
198
- let(:config) {%[
199
- type reformed
200
- output_tag ${tag_suffix[-2]}
201
- enable_ruby no
150
+ describe 'test placeholders' do
151
+ let(:time) { Time.now }
152
+ let(:emit) do
153
+ driver.run { driver.emit({}, time.to_i) }
154
+ end
202
155
 
203
- hostname ${hostname}
204
- tag ${tag}
205
- time ${time}
206
- message ${tag_prefix[1]} ${tag_prefix[-2]} ${tag_suffix[2]} ${tag_suffix[-3]} ${message}
207
- ]}
208
- let(:tag) { 'prefix.test.tag.suffix' }
209
- let(:tag_parts) { tag.split('.') }
210
- before do
211
- Fluent::Engine.stub(:now).and_return(time)
212
- Fluent::Engine.should_receive(:emit).with("tag.suffix", time.to_i, {
213
- 'foo' => 'bar',
214
- 'message' => "prefix.test prefix.test.tag tag.suffix test.tag.suffix 1",
215
- 'hostname' => hostname,
216
- 'tag' => tag,
217
- 'time' => time.to_s,
218
- })
219
- Fluent::Engine.should_receive(:emit).with("tag.suffix", time.to_i, {
220
- 'foo' => 'bar',
221
- 'message' => "prefix.test prefix.test.tag tag.suffix test.tag.suffix 2",
222
- 'hostname' => hostname,
223
- 'tag' => tag,
224
- 'time' => time.to_s,
225
- })
156
+ %w[yes no].each do |enable_ruby|
157
+ context "hostname with enble_ruby #{enable_ruby}" do
158
+ let(:config) {%[
159
+ tag tag
160
+ enable_ruby #{enable_ruby}
161
+ message ${hostname}
162
+ ]}
163
+ before do
164
+ Fluent::Engine.stub(:now).and_return(time)
165
+ Fluent::Engine.should_receive(:emit).with("tag", time.to_i, {'message' => hostname})
166
+ end
167
+ it { emit }
226
168
  end
227
- it { emit }
228
- end
229
169
 
230
- context '${tag_prefix[N]} and ${tag_suffix[N]} with ruby enabled' do
231
- let(:config) { CONFIG + %[
232
- test_tag ${tag_prefix[1]} ${tag_prefix[-2]} ${tag_suffix[2]} ${tag_suffix[-3]}
233
- ]}
234
- let(:tag) { 'prefix.test.tag.suffix' }
235
- let(:tag_parts) { tag.split('.') }
236
- before do
237
- Fluent::Engine.stub(:now).and_return(time)
238
- Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
239
- 'foo' => 'bar',
240
- 'message' => "#{hostname} #{tag_parts.last} 1",
241
- 'hostname' => hostname,
242
- 'tag' => tag,
243
- 'time' => time.strftime('%S'),
244
- 'test_tag' => "prefix.test prefix.test.tag tag.suffix test.tag.suffix",
245
- })
246
- Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
247
- 'foo' => 'bar',
248
- 'message' => "#{hostname} #{tag_parts.last} 2",
249
- 'hostname' => hostname,
250
- 'tag' => tag,
251
- 'time' => time.strftime('%S'),
252
- 'test_tag' => "prefix.test prefix.test.tag tag.suffix test.tag.suffix",
253
- })
170
+ context "tag with enable_ruby #{enable_ruby}" do
171
+ let(:config) {%[
172
+ tag tag
173
+ enable_ruby #{enable_ruby}
174
+ message ${tag}
175
+ ]}
176
+ before do
177
+ Fluent::Engine.stub(:now).and_return(time)
178
+ Fluent::Engine.should_receive(:emit).with("tag", time.to_i, {'message' => tag})
179
+ end
180
+ it { emit }
181
+ end
182
+
183
+ context "tag_parts with enable_ruby #{enable_ruby}" do
184
+ let(:config) {%[
185
+ tag tag
186
+ enable_ruby #{enable_ruby}
187
+ message ${tag_parts[0]} ${tag_parts[-1]}
188
+ ]}
189
+ let(:expected) { "#{tag.split('.').first} #{tag.split('.').last}" }
190
+ before do
191
+ Fluent::Engine.stub(:now).and_return(time)
192
+ Fluent::Engine.should_receive(:emit).with("tag", time.to_i, {'message' => expected})
193
+ end
194
+ it { emit }
195
+ end
196
+
197
+ context "support old tags with enable_ruby #{enable_ruby}" do
198
+ let(:config) {%[
199
+ tag tag
200
+ enable_ruby #{enable_ruby}
201
+ message ${tags[0]} ${tags[-1]}
202
+ ]}
203
+ let(:expected) { "#{tag.split('.').first} #{tag.split('.').last}" }
204
+ before do
205
+ Fluent::Engine.stub(:now).and_return(time)
206
+ Fluent::Engine.should_receive(:emit).with("tag", time.to_i, {'message' => expected})
207
+ end
208
+ it { emit }
209
+ end
210
+
211
+ context "${tag_prefix[N]} and ${tag_suffix[N]} with enable_ruby #{enable_ruby}" do
212
+ let(:config) {%[
213
+ tag ${tag_suffix[-2]}
214
+ enable_ruby #{enable_ruby}
215
+ message ${tag_prefix[1]} ${tag_prefix[-2]} ${tag_suffix[2]} ${tag_suffix[-3]}
216
+ ]}
217
+ let(:tag) { 'prefix.test.tag.suffix' }
218
+ let(:expected) { "prefix.test prefix.test.tag tag.suffix test.tag.suffix" }
219
+ before do
220
+ Fluent::Engine.stub(:now).and_return(time)
221
+ Fluent::Engine.should_receive(:emit).with("tag.suffix", time.to_i, { 'message' => "prefix.test prefix.test.tag tag.suffix test.tag.suffix" })
222
+ end
223
+ it { emit }
224
+ end
225
+
226
+ context "time with enable_ruby #{enable_ruby}" do
227
+ let(:config) {%[
228
+ tag tag
229
+ enable_ruby #{enable_ruby}
230
+ time ${time}
231
+ ]}
232
+ before do
233
+ Fluent::Engine.stub(:now).and_return(time)
234
+ Fluent::Engine.should_receive(:emit).with("tag", time.to_i, {'time' => time.to_s})
235
+ end
236
+ it { emit }
237
+ end
238
+
239
+ context "record with enable_ruby #{enable_ruby}" do
240
+ let(:emit) do
241
+ driver.run do
242
+ driver.emit({'message' => '1'}, time.to_i)
243
+ driver.emit({'message' => '2'}, time.to_i)
244
+ end
245
+ end
246
+ let(:config) {%[
247
+ tag tag
248
+ enable_ruby #{enable_ruby}
249
+ message bar ${message}
250
+ ]}
251
+ let(:tag) { 'prefix.test.tag.suffix' }
252
+ let(:tag_parts) { tag.split('.') }
253
+ before do
254
+ Fluent::Engine.stub(:now).and_return(time)
255
+ Fluent::Engine.should_receive(:emit).with("tag", time.to_i, { 'message' => "bar 1", })
256
+ Fluent::Engine.should_receive(:emit).with("tag", time.to_i, { 'message' => "bar 2", })
257
+ end
258
+ it { emit }
254
259
  end
255
- it { emit }
256
260
  end
257
261
  end
258
262
  end
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.7
4
+ version: 0.2.8
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-03-25 00:00:00.000000000 Z
12
+ date: 2014-04-12 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: -974723697
128
+ hash: -1062048915
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: -974723697
137
+ hash: -1062048915
138
138
  requirements: []
139
139
  rubyforge_project:
140
140
  rubygems_version: 1.8.23