fluent-plugin-grepcounter 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +22 -1
- data/fluent-plugin-grepcounter.gemspec +3 -1
- data/lib/fluent/plugin/out_grepcounter.rb +60 -24
- data/spec/out_grepcounter_spec.rb +120 -71
- data/spec/spec_helper.rb +6 -0
- metadata +47 -20
- data/.rdebugrc +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75e1b135258e27a199ad76aff3b150c6d898ca4e
|
4
|
+
data.tar.gz: ce4a20861ad649906f1439f94b0f55f13c6b4bb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3a5ace25e1e8a5a68e94e6862849671ce291b93c5c85ca13ee35a9f6c3504de1d71e1c39c400956c77e0d2304f9d1192b8669b274ff32d58a3c531d574fc1e2
|
7
|
+
data.tar.gz: 7dee91e123f491709e8e9fabe339f357cddb8192ac50a2c2150823f7ff1f46748e9f810d21f815735d2257fe39782662e624b86b4ede37dfa2fba28c9fff0789
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
# fluent-plugin-grepcounter
|
1
|
+
# fluent-plugin-grepcounter
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/sonots/fluent-plugin-grepcounter.png?branch=master)](http://travis-ci.org/sonots/fluent-plugin-grepcounter)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/sonots/fluent-plugin-grepcounter/badge.png?branch=master)](https://coveralls.io/r/sonots/fluent-plugin-grepcounter?branch=master)
|
2
5
|
|
3
6
|
Fluentd plugin to count the number of matched messages, and emit if exeeds the `threshold`.
|
4
7
|
|
@@ -123,6 +126,24 @@ Then, output bocomes as belows (indented). You can see the `message` field is jo
|
|
123
126
|
|
124
127
|
Remove tag suffix for output message
|
125
128
|
|
129
|
+
* remove_tag_slice *min..max*
|
130
|
+
|
131
|
+
Remove tag parts by slice function. FYI: This option behaves like `tag.split('.').slice(min..max)`.
|
132
|
+
|
133
|
+
For example,
|
134
|
+
|
135
|
+
remove_tag_slice 0..-2
|
136
|
+
|
137
|
+
changes an input tag `foo.bar.host1` to `foo.bar`.
|
138
|
+
|
139
|
+
* aggregate
|
140
|
+
|
141
|
+
Aggregation unit. One of `all`, `in_tag`, `out_tag` can be specified. Default is `all`.
|
142
|
+
|
143
|
+
* `all` counts summation for all input messages and emit one message in each interval.
|
144
|
+
* `in_tag` counts summation for each input tag seperately.
|
145
|
+
* `out_tag` counts summation for each tag *modified* by `add_tag_prefix`, `remove_tag_prefix`, or `remove_tag_slice`.
|
146
|
+
|
126
147
|
- delimiter
|
127
148
|
|
128
149
|
Output matched messages after `join`ed with the specified delimiter.
|
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "fluent-plugin-grepcounter"
|
6
|
-
s.version = "0.5.
|
6
|
+
s.version = "0.5.5"
|
7
7
|
s.authors = ["Naotoshi Seo"]
|
8
8
|
s.email = ["sonots@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/sonots/fluent-plugin-grepcounter"
|
@@ -21,6 +21,8 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_runtime_dependency "fluentd"
|
22
22
|
s.add_development_dependency "rake"
|
23
23
|
s.add_development_dependency "rspec"
|
24
|
+
s.add_development_dependency "rspec-its"
|
24
25
|
s.add_development_dependency "pry"
|
25
26
|
s.add_development_dependency "pry-nav"
|
27
|
+
s.add_development_dependency "coveralls"
|
26
28
|
end
|
@@ -32,6 +32,7 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
32
32
|
config_param :remove_tag_prefix, :string, :default => nil
|
33
33
|
config_param :add_tag_suffix, :string, :default => nil
|
34
34
|
config_param :remove_tag_suffix, :string, :default => nil
|
35
|
+
config_param :remove_tag_slice, :string, :default => nil
|
35
36
|
config_param :output_with_joined_delimiter, :string, :default => nil # obsolete
|
36
37
|
config_param :delimiter, :string, :default => nil
|
37
38
|
config_param :aggregate, :string, :default => 'tag'
|
@@ -94,7 +95,7 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
94
95
|
end
|
95
96
|
end
|
96
97
|
|
97
|
-
if @tag.nil? and @add_tag_prefix.nil? and @remove_tag_prefix.nil? and @add_tag_suffix.nil? and @remove_tag_suffix.nil?
|
98
|
+
if @tag.nil? and @add_tag_prefix.nil? and @remove_tag_prefix.nil? and @add_tag_suffix.nil? and @remove_tag_suffix.nil? and @remove_tag_slice.nil?
|
98
99
|
@add_tag_prefix = 'count' # not ConfigError to support lower version compatibility
|
99
100
|
end
|
100
101
|
@tag_proc = tag_proc
|
@@ -102,11 +103,14 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
102
103
|
case @aggregate
|
103
104
|
when 'all'
|
104
105
|
raise Fluent::ConfigError, "grepcounter: `tag` must be specified with aggregate all" if @tag.nil?
|
105
|
-
when 'tag'
|
106
|
-
|
106
|
+
when 'tag' # obsolete
|
107
|
+
@aggregate = 'in_tag'
|
108
|
+
when 'in_tag'
|
109
|
+
when 'out_tag'
|
107
110
|
else
|
108
|
-
raise Fluent::ConfigError, "grepcounter: aggregate allows
|
111
|
+
raise Fluent::ConfigError, "grepcounter: aggregate allows all/in_tag/out_tag"
|
109
112
|
end
|
113
|
+
@aggregate_proc = aggregate_proc(@tag_proc)
|
110
114
|
|
111
115
|
if @store_file
|
112
116
|
f = Pathname.new(@store_file)
|
@@ -156,12 +160,14 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
156
160
|
count += 1
|
157
161
|
end
|
158
162
|
end
|
163
|
+
|
164
|
+
aggregate_key = @aggregate_proc.call(tag)
|
159
165
|
# thread safe merge
|
160
|
-
@counts[
|
161
|
-
@matches[
|
166
|
+
@counts[aggregate_key] ||= 0
|
167
|
+
@matches[aggregate_key] ||= []
|
162
168
|
@mutex.synchronize do
|
163
|
-
@counts[
|
164
|
-
@matches[
|
169
|
+
@counts[aggregate_key] += count
|
170
|
+
@matches[aggregate_key] += matches
|
165
171
|
end
|
166
172
|
|
167
173
|
chain.next
|
@@ -192,22 +198,29 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
192
198
|
time = Fluent::Engine.now
|
193
199
|
flushed_counts, flushed_matches, @counts, @matches = @counts, @matches, {}, {}
|
194
200
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
matches += flushed_matches[tag]
|
200
|
-
end
|
201
|
+
case @aggregate
|
202
|
+
when 'all'
|
203
|
+
count = flushed_counts[:all]
|
204
|
+
matches = flushed_matches[:all]
|
201
205
|
output = generate_output(count, matches)
|
202
206
|
Fluent::Engine.emit(@tag, time, output) if output
|
203
|
-
|
207
|
+
when 'out_tag'
|
208
|
+
flushed_counts.keys.each do |out_tag|
|
209
|
+
count = flushed_counts[out_tag]
|
210
|
+
matches = flushed_matches[out_tag]
|
211
|
+
output = generate_output(count, matches)
|
212
|
+
if output
|
213
|
+
Fluent::Engine.emit(out_tag, time, output)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
else # in_tag
|
204
217
|
flushed_counts.keys.each do |tag|
|
205
218
|
count = flushed_counts[tag]
|
206
219
|
matches = flushed_matches[tag]
|
207
220
|
output = generate_output(count, matches, tag)
|
208
221
|
if output
|
209
|
-
|
210
|
-
Fluent::Engine.emit(
|
222
|
+
out_tag = @tag_proc.call(tag)
|
223
|
+
Fluent::Engine.emit(out_tag, time, output)
|
211
224
|
end
|
212
225
|
end
|
213
226
|
end
|
@@ -234,7 +247,30 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
234
247
|
output
|
235
248
|
end
|
236
249
|
|
250
|
+
def aggregate_proc(tag_proc)
|
251
|
+
case @aggregate
|
252
|
+
when 'all'
|
253
|
+
Proc.new {|tag| :all }
|
254
|
+
when 'in_tag'
|
255
|
+
Proc.new {|tag| tag }
|
256
|
+
when 'out_tag'
|
257
|
+
Proc.new {|tag| tag_proc.call(tag) }
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
237
261
|
def tag_proc
|
262
|
+
tag_slice_proc =
|
263
|
+
if @remove_tag_slice
|
264
|
+
lindex, rindex = @remove_tag_slice.split('..', 2)
|
265
|
+
if lindex.nil? or rindex.nil? or lindex !~ /^-?\d+$/ or rindex !~ /^-?\d+$/
|
266
|
+
raise Fluent::ConfigError, "out_grepcounter: remove_tag_slice must be formatted like [num]..[num]"
|
267
|
+
end
|
268
|
+
l, r = lindex.to_i, rindex.to_i
|
269
|
+
Proc.new {|tag| (tags = tag.split('.')[l..r]).nil? ? "" : tags.join('.') }
|
270
|
+
else
|
271
|
+
Proc.new {|tag| tag }
|
272
|
+
end
|
273
|
+
|
238
274
|
rstrip = Proc.new {|str, substr| str.chomp(substr) }
|
239
275
|
lstrip = Proc.new {|str, substr| str.start_with?(substr) ? str[substr.size..-1] : str }
|
240
276
|
tag_prefix = "#{rstrip.call(@add_tag_prefix, '.')}." if @add_tag_prefix
|
@@ -242,16 +278,16 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
242
278
|
tag_prefix_match = "#{rstrip.call(@remove_tag_prefix, '.')}." if @remove_tag_prefix
|
243
279
|
tag_suffix_match = ".#{lstrip.call(@remove_tag_suffix, '.')}" if @remove_tag_suffix
|
244
280
|
tag_fixed = @tag if @tag
|
245
|
-
if
|
246
|
-
Proc.new {|tag|
|
247
|
-
elsif tag_prefix_match and tag_suffix_match
|
248
|
-
Proc.new {|tag| "#{tag_prefix}#{rstrip.call(lstrip.call(tag, tag_prefix_match), tag_suffix_match)}#{tag_suffix}" }
|
281
|
+
if tag_prefix_match and tag_suffix_match
|
282
|
+
Proc.new {|tag| "#{tag_prefix}#{rstrip.call(lstrip.call(tag_slice_proc.call(tag), tag_prefix_match), tag_suffix_match)}#{tag_suffix}" }
|
249
283
|
elsif tag_prefix_match
|
250
|
-
Proc.new {|tag| "#{tag_prefix}#{lstrip.call(tag, tag_prefix_match)}#{tag_suffix}" }
|
284
|
+
Proc.new {|tag| "#{tag_prefix}#{lstrip.call(tag_slice_proc.call(tag), tag_prefix_match)}#{tag_suffix}" }
|
251
285
|
elsif tag_suffix_match
|
252
|
-
Proc.new {|tag| "#{tag_prefix}#{rstrip.call(tag, tag_suffix_match)}#{tag_suffix}" }
|
286
|
+
Proc.new {|tag| "#{tag_prefix}#{rstrip.call(tag_slice_proc.call(tag), tag_suffix_match)}#{tag_suffix}" }
|
287
|
+
elsif tag_prefix || @remove_tag_slice || tag_suffix
|
288
|
+
Proc.new {|tag| "#{tag_prefix}#{tag_slice_proc.call(tag)}#{tag_suffix}" }
|
253
289
|
else
|
254
|
-
Proc.new {|tag|
|
290
|
+
Proc.new {|tag| tag_fixed }
|
255
291
|
end
|
256
292
|
end
|
257
293
|
|
@@ -93,8 +93,8 @@ describe Fluent::GrepCounterOutput do
|
|
93
93
|
context 'default' do
|
94
94
|
let(:config) { CONFIG }
|
95
95
|
before do
|
96
|
-
Fluent::Engine.
|
97
|
-
Fluent::Engine.
|
96
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
97
|
+
expect(Fluent::Engine).to receive(:emit).with("count.#{tag}", time, expected)
|
98
98
|
end
|
99
99
|
it { emit }
|
100
100
|
end
|
@@ -102,8 +102,8 @@ describe Fluent::GrepCounterOutput do
|
|
102
102
|
context 'regexp' do
|
103
103
|
let(:config) { CONFIG + %[ regexp WARN ] }
|
104
104
|
before do
|
105
|
-
Fluent::Engine.
|
106
|
-
Fluent::Engine.
|
105
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
106
|
+
expect(Fluent::Engine).to receive(:emit).with("count.#{tag}", time, expected.merge({
|
107
107
|
"count"=>3,
|
108
108
|
"message"=>[
|
109
109
|
"2013/01/13T07:02:13.232645 WARN POST /auth",
|
@@ -118,8 +118,8 @@ describe Fluent::GrepCounterOutput do
|
|
118
118
|
context 'regexpN' do
|
119
119
|
let(:config) { %[ regexp1 message WARN ] }
|
120
120
|
before do
|
121
|
-
Fluent::Engine.
|
122
|
-
Fluent::Engine.
|
121
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
122
|
+
expect(Fluent::Engine).to receive(:emit).with("count.#{tag}", time, expected.merge({
|
123
123
|
"count"=>3,
|
124
124
|
}).delete!('message'))
|
125
125
|
end
|
@@ -129,8 +129,8 @@ describe Fluent::GrepCounterOutput do
|
|
129
129
|
context 'exclude' do
|
130
130
|
let(:config) { CONFIG + %[regexp WARN \n exclude favicon] }
|
131
131
|
before do
|
132
|
-
Fluent::Engine.
|
133
|
-
Fluent::Engine.
|
132
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
133
|
+
expect(Fluent::Engine).to receive(:emit).with("count.#{tag}", time, expected.merge({
|
134
134
|
"count"=>2,
|
135
135
|
"message"=>[
|
136
136
|
"2013/01/13T07:02:13.232645 WARN POST /auth",
|
@@ -144,8 +144,8 @@ describe Fluent::GrepCounterOutput do
|
|
144
144
|
context 'excludeN' do
|
145
145
|
let(:config) { %[regexp1 message WARN \n exclude1 message favicon] }
|
146
146
|
before do
|
147
|
-
Fluent::Engine.
|
148
|
-
Fluent::Engine.
|
147
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
148
|
+
expect(Fluent::Engine).to receive(:emit).with("count.#{tag}", time, expected.merge({
|
149
149
|
"count"=>2,
|
150
150
|
}).delete!('message'))
|
151
151
|
end
|
@@ -156,8 +156,8 @@ describe Fluent::GrepCounterOutput do
|
|
156
156
|
context '>= threshold' do
|
157
157
|
let(:config) { CONFIG + %[threshold 4] }
|
158
158
|
before do
|
159
|
-
Fluent::Engine.
|
160
|
-
Fluent::Engine.
|
159
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
160
|
+
expect(Fluent::Engine).to receive(:emit).with("count.#{tag}", time, expected)
|
161
161
|
end
|
162
162
|
it { emit }
|
163
163
|
end
|
@@ -165,8 +165,8 @@ describe Fluent::GrepCounterOutput do
|
|
165
165
|
context 'not >= threshold' do
|
166
166
|
let(:config) { CONFIG + %[threshold 5] }
|
167
167
|
before do
|
168
|
-
Fluent::Engine.
|
169
|
-
Fluent::Engine.
|
168
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
169
|
+
expect(Fluent::Engine).not_to receive(:emit)
|
170
170
|
end
|
171
171
|
it { emit }
|
172
172
|
end
|
@@ -174,8 +174,8 @@ describe Fluent::GrepCounterOutput do
|
|
174
174
|
context '<= threshold' do
|
175
175
|
let(:config) { CONFIG + %[threshold 4 \n comparator <=] }
|
176
176
|
before do
|
177
|
-
Fluent::Engine.
|
178
|
-
Fluent::Engine.
|
177
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
178
|
+
expect(Fluent::Engine).to receive(:emit).with("count.#{tag}", time, expected)
|
179
179
|
end
|
180
180
|
it { emit }
|
181
181
|
end
|
@@ -183,8 +183,8 @@ describe Fluent::GrepCounterOutput do
|
|
183
183
|
context 'not <= threshold' do
|
184
184
|
let(:config) { CONFIG + %[threshold 3 \n comparator <=] }
|
185
185
|
before do
|
186
|
-
Fluent::Engine.
|
187
|
-
Fluent::Engine.
|
186
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
187
|
+
expect(Fluent::Engine).not_to receive(:emit)
|
188
188
|
end
|
189
189
|
it { emit }
|
190
190
|
end
|
@@ -194,8 +194,8 @@ describe Fluent::GrepCounterOutput do
|
|
194
194
|
context 'greater_equal' do
|
195
195
|
let(:config) { CONFIG + %[greater_equal 4] }
|
196
196
|
before do
|
197
|
-
Fluent::Engine.
|
198
|
-
Fluent::Engine.
|
197
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
198
|
+
expect(Fluent::Engine).to receive(:emit).with("count.#{tag}", time, expected)
|
199
199
|
end
|
200
200
|
it { emit }
|
201
201
|
end
|
@@ -203,8 +203,8 @@ describe Fluent::GrepCounterOutput do
|
|
203
203
|
context 'not greater_equal' do
|
204
204
|
let(:config) { CONFIG + %[greater_equal 5] }
|
205
205
|
before do
|
206
|
-
Fluent::Engine.
|
207
|
-
Fluent::Engine.
|
206
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
207
|
+
expect(Fluent::Engine).not_to receive(:emit)
|
208
208
|
end
|
209
209
|
it { emit }
|
210
210
|
end
|
@@ -212,8 +212,8 @@ describe Fluent::GrepCounterOutput do
|
|
212
212
|
context 'greater_than' do
|
213
213
|
let(:config) { CONFIG + %[greater_than 3] }
|
214
214
|
before do
|
215
|
-
Fluent::Engine.
|
216
|
-
Fluent::Engine.
|
215
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
216
|
+
expect(Fluent::Engine).to receive(:emit).with("count.#{tag}", time, expected)
|
217
217
|
end
|
218
218
|
it { emit }
|
219
219
|
end
|
@@ -221,8 +221,8 @@ describe Fluent::GrepCounterOutput do
|
|
221
221
|
context 'not greater_than' do
|
222
222
|
let(:config) { CONFIG + %[greater_than 4] }
|
223
223
|
before do
|
224
|
-
Fluent::Engine.
|
225
|
-
Fluent::Engine.
|
224
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
225
|
+
expect(Fluent::Engine).not_to receive(:emit)
|
226
226
|
end
|
227
227
|
it { emit }
|
228
228
|
end
|
@@ -230,8 +230,8 @@ describe Fluent::GrepCounterOutput do
|
|
230
230
|
context 'less_equal' do
|
231
231
|
let(:config) { CONFIG + %[less_equal 4] }
|
232
232
|
before do
|
233
|
-
Fluent::Engine.
|
234
|
-
Fluent::Engine.
|
233
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
234
|
+
expect(Fluent::Engine).to receive(:emit).with("count.#{tag}", time, expected)
|
235
235
|
end
|
236
236
|
it { emit }
|
237
237
|
end
|
@@ -239,8 +239,8 @@ describe Fluent::GrepCounterOutput do
|
|
239
239
|
context 'not less_equal' do
|
240
240
|
let(:config) { CONFIG + %[less_equal 3] }
|
241
241
|
before do
|
242
|
-
Fluent::Engine.
|
243
|
-
Fluent::Engine.
|
242
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
243
|
+
expect(Fluent::Engine).not_to receive(:emit)
|
244
244
|
end
|
245
245
|
it { emit }
|
246
246
|
end
|
@@ -248,8 +248,8 @@ describe Fluent::GrepCounterOutput do
|
|
248
248
|
context 'less_than' do
|
249
249
|
let(:config) { CONFIG + %[less_than 5] }
|
250
250
|
before do
|
251
|
-
Fluent::Engine.
|
252
|
-
Fluent::Engine.
|
251
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
252
|
+
expect(Fluent::Engine).to receive(:emit).with("count.#{tag}", time, expected)
|
253
253
|
end
|
254
254
|
it { emit }
|
255
255
|
end
|
@@ -257,8 +257,8 @@ describe Fluent::GrepCounterOutput do
|
|
257
257
|
context 'not less_than' do
|
258
258
|
let(:config) { CONFIG + %[less_than 4] }
|
259
259
|
before do
|
260
|
-
Fluent::Engine.
|
261
|
-
Fluent::Engine.
|
260
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
261
|
+
expect(Fluent::Engine).not_to receive(:emit)
|
262
262
|
end
|
263
263
|
it { emit }
|
264
264
|
end
|
@@ -266,8 +266,8 @@ describe Fluent::GrepCounterOutput do
|
|
266
266
|
context 'between' do
|
267
267
|
let(:config) { CONFIG + %[greater_than 1 \n less_than 5] }
|
268
268
|
before do
|
269
|
-
Fluent::Engine.
|
270
|
-
Fluent::Engine.
|
269
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
270
|
+
expect(Fluent::Engine).to receive(:emit).with("count.#{tag}", time, expected)
|
271
271
|
end
|
272
272
|
it { emit }
|
273
273
|
end
|
@@ -275,8 +275,8 @@ describe Fluent::GrepCounterOutput do
|
|
275
275
|
context 'not between' do
|
276
276
|
let(:config) { CONFIG + %[greater_than 1 \n less_than 4] }
|
277
277
|
before do
|
278
|
-
Fluent::Engine.
|
279
|
-
Fluent::Engine.
|
278
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
279
|
+
expect(Fluent::Engine).not_to receive(:emit)
|
280
280
|
end
|
281
281
|
it { emit }
|
282
282
|
end
|
@@ -285,8 +285,8 @@ describe Fluent::GrepCounterOutput do
|
|
285
285
|
context 'output_tag (obsolete)' do
|
286
286
|
let(:config) { CONFIG + %[output_tag foo] }
|
287
287
|
before do
|
288
|
-
Fluent::Engine.
|
289
|
-
Fluent::Engine.
|
288
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
289
|
+
expect(Fluent::Engine).to receive(:emit).with("foo", time, expected)
|
290
290
|
end
|
291
291
|
it { emit }
|
292
292
|
end
|
@@ -294,8 +294,8 @@ describe Fluent::GrepCounterOutput do
|
|
294
294
|
context 'tag' do
|
295
295
|
let(:config) { CONFIG + %[tag foo] }
|
296
296
|
before do
|
297
|
-
Fluent::Engine.
|
298
|
-
Fluent::Engine.
|
297
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
298
|
+
expect(Fluent::Engine).to receive(:emit).with("foo", time, expected)
|
299
299
|
end
|
300
300
|
it { emit }
|
301
301
|
end
|
@@ -304,8 +304,8 @@ describe Fluent::GrepCounterOutput do
|
|
304
304
|
let(:config) { CONFIG + %[add_tag_prefix foo] }
|
305
305
|
let(:tag) { 'syslog.host1' }
|
306
306
|
before do
|
307
|
-
Fluent::Engine.
|
308
|
-
Fluent::Engine.
|
307
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
308
|
+
expect(Fluent::Engine).to receive(:emit).with("foo.#{tag}", time, expected)
|
309
309
|
end
|
310
310
|
it { emit }
|
311
311
|
end
|
@@ -314,8 +314,8 @@ describe Fluent::GrepCounterOutput do
|
|
314
314
|
let(:config) { CONFIG + %[remove_tag_prefix syslog] }
|
315
315
|
let(:tag) { 'syslog.host1' }
|
316
316
|
before do
|
317
|
-
Fluent::Engine.
|
318
|
-
Fluent::Engine.
|
317
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
318
|
+
expect(Fluent::Engine).to receive(:emit).with("host1", time, expected)
|
319
319
|
end
|
320
320
|
it { emit }
|
321
321
|
end
|
@@ -324,8 +324,8 @@ describe Fluent::GrepCounterOutput do
|
|
324
324
|
let(:config) { CONFIG + %[add_tag_suffix foo] }
|
325
325
|
let(:tag) { 'syslog.host1' }
|
326
326
|
before do
|
327
|
-
Fluent::Engine.
|
328
|
-
Fluent::Engine.
|
327
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
328
|
+
expect(Fluent::Engine).to receive(:emit).with("#{tag}.foo", time, expected)
|
329
329
|
end
|
330
330
|
it { emit }
|
331
331
|
end
|
@@ -334,8 +334,18 @@ describe Fluent::GrepCounterOutput do
|
|
334
334
|
let(:config) { CONFIG + %[remove_tag_suffix host1] }
|
335
335
|
let(:tag) { 'syslog.host1' }
|
336
336
|
before do
|
337
|
-
Fluent::Engine.
|
338
|
-
Fluent::Engine.
|
337
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
338
|
+
expect(Fluent::Engine).to receive(:emit).with("syslog", time, expected)
|
339
|
+
end
|
340
|
+
it { emit }
|
341
|
+
end
|
342
|
+
|
343
|
+
context 'remove_tag_slice' do
|
344
|
+
let(:config) { CONFIG + %[remove_tag_slice 0..-2] }
|
345
|
+
let(:tag) { 'syslog.host1' }
|
346
|
+
before do
|
347
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
348
|
+
expect(Fluent::Engine).to receive(:emit).with("syslog", time, expected)
|
339
349
|
end
|
340
350
|
it { emit }
|
341
351
|
end
|
@@ -349,8 +359,8 @@ describe Fluent::GrepCounterOutput do
|
|
349
359
|
]}
|
350
360
|
let(:tag) { 'syslog.foo.host1' }
|
351
361
|
before do
|
352
|
-
Fluent::Engine.
|
353
|
-
Fluent::Engine.
|
362
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
363
|
+
expect(Fluent::Engine).to receive(:emit).with("foo.foo.foo", time, expected)
|
354
364
|
end
|
355
365
|
it { emit }
|
356
366
|
end
|
@@ -359,8 +369,8 @@ describe Fluent::GrepCounterOutput do
|
|
359
369
|
let(:config) { CONFIG + %[add_tag_prefix foo.] }
|
360
370
|
let(:tag) { 'syslog.host1' }
|
361
371
|
before do
|
362
|
-
Fluent::Engine.
|
363
|
-
Fluent::Engine.
|
372
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
373
|
+
expect(Fluent::Engine).to receive(:emit).with("foo.#{tag}", time, expected)
|
364
374
|
end
|
365
375
|
it { emit }
|
366
376
|
end
|
@@ -369,8 +379,8 @@ describe Fluent::GrepCounterOutput do
|
|
369
379
|
let(:config) { CONFIG + %[remove_tag_prefix syslog.] }
|
370
380
|
let(:tag) { 'syslog.host1' }
|
371
381
|
before do
|
372
|
-
Fluent::Engine.
|
373
|
-
Fluent::Engine.
|
382
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
383
|
+
expect(Fluent::Engine).to receive(:emit).with("host1", time, expected)
|
374
384
|
end
|
375
385
|
it { emit }
|
376
386
|
end
|
@@ -379,8 +389,8 @@ describe Fluent::GrepCounterOutput do
|
|
379
389
|
let(:config) { CONFIG + %[add_tag_suffix .foo] }
|
380
390
|
let(:tag) { 'syslog.host1' }
|
381
391
|
before do
|
382
|
-
Fluent::Engine.
|
383
|
-
Fluent::Engine.
|
392
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
393
|
+
expect(Fluent::Engine).to receive(:emit).with("#{tag}.foo", time, expected)
|
384
394
|
end
|
385
395
|
it { emit }
|
386
396
|
end
|
@@ -389,8 +399,8 @@ describe Fluent::GrepCounterOutput do
|
|
389
399
|
let(:config) { CONFIG + %[remove_tag_suffix .host1] }
|
390
400
|
let(:tag) { 'syslog.host1' }
|
391
401
|
before do
|
392
|
-
Fluent::Engine.
|
393
|
-
Fluent::Engine.
|
402
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
403
|
+
expect(Fluent::Engine).to receive(:emit).with("syslog", time, expected)
|
394
404
|
end
|
395
405
|
it { emit }
|
396
406
|
end
|
@@ -399,9 +409,9 @@ describe Fluent::GrepCounterOutput do
|
|
399
409
|
# \\n shall be \n in config file
|
400
410
|
let(:config) { CONFIG + %[output_with_joined_delimiter \\n] }
|
401
411
|
before do
|
402
|
-
Fluent::Engine.
|
412
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
403
413
|
message = expected["message"].join('\n')
|
404
|
-
Fluent::Engine.
|
414
|
+
expect(Fluent::Engine).to receive(:emit).with("count.#{tag}", time, expected.merge("message" => message))
|
405
415
|
end
|
406
416
|
it { emit }
|
407
417
|
end
|
@@ -410,9 +420,9 @@ describe Fluent::GrepCounterOutput do
|
|
410
420
|
# \\n shall be \n in config file
|
411
421
|
let(:config) { CONFIG + %[delimiter \\n] }
|
412
422
|
before do
|
413
|
-
Fluent::Engine.
|
423
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
414
424
|
message = expected["message"].join('\n')
|
415
|
-
Fluent::Engine.
|
425
|
+
expect(Fluent::Engine).to receive(:emit).with("count.#{tag}", time, expected.merge("message" => message))
|
416
426
|
end
|
417
427
|
it { emit }
|
418
428
|
end
|
@@ -433,8 +443,47 @@ describe Fluent::GrepCounterOutput do
|
|
433
443
|
|
434
444
|
let(:config) { CONFIG + %[aggregate all \n output_tag count] }
|
435
445
|
before do
|
436
|
-
Fluent::Engine.
|
437
|
-
Fluent::Engine.
|
446
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
447
|
+
expect(Fluent::Engine).to receive(:emit).with("count", time, expected)
|
448
|
+
end
|
449
|
+
it { emit }
|
450
|
+
end
|
451
|
+
|
452
|
+
context 'aggregate in_tag' do
|
453
|
+
let(:messages) { ['foobar', 'foobar'] }
|
454
|
+
let(:emit) do
|
455
|
+
driver.run { messages.each {|message| driver.emit_with_tag({'message' => message}, time, 'foo.bar') } }
|
456
|
+
driver.run { messages.each {|message| driver.emit_with_tag({'message' => message}, time, 'foo.bar2') } }
|
457
|
+
driver.instance.flush_emit(0)
|
458
|
+
end
|
459
|
+
|
460
|
+
let(:config) { CONFIG + %[aggregate tag \n remove_tag_slice 0..-2] }
|
461
|
+
before do
|
462
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
463
|
+
expect(Fluent::Engine).to receive(:emit).with("foo", time, {
|
464
|
+
"count"=>2, "message"=>["foobar", "foobar"], "input_tag"=>"foo.bar", "input_tag_last"=>"bar"
|
465
|
+
})
|
466
|
+
expect(Fluent::Engine).to receive(:emit).with("foo", time, {
|
467
|
+
"count"=>2, "message"=>["foobar", "foobar"], "input_tag"=>"foo.bar2", "input_tag_last"=>"bar2"
|
468
|
+
})
|
469
|
+
end
|
470
|
+
it { emit }
|
471
|
+
end
|
472
|
+
|
473
|
+
context 'aggregate out_tag' do
|
474
|
+
let(:messages) { ['foobar', 'foobar'] }
|
475
|
+
let(:emit) do
|
476
|
+
driver.run { messages.each {|message| driver.emit_with_tag({'message' => message}, time, 'foo.bar') } }
|
477
|
+
driver.run { messages.each {|message| driver.emit_with_tag({'message' => message}, time, 'foo.bar2') } }
|
478
|
+
driver.instance.flush_emit(0)
|
479
|
+
end
|
480
|
+
|
481
|
+
let(:config) { CONFIG + %[aggregate out_tag \n remove_tag_slice 0..-2] }
|
482
|
+
before do
|
483
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
484
|
+
expect(Fluent::Engine).to receive(:emit).with("foo", time, {
|
485
|
+
"count"=>4, "message"=>["foobar", "foobar", "foobar", "foobar"]
|
486
|
+
})
|
438
487
|
end
|
439
488
|
it { emit }
|
440
489
|
end
|
@@ -443,7 +492,7 @@ describe Fluent::GrepCounterOutput do
|
|
443
492
|
let(:config) { CONFIG + %[regexp WARN \n replace_invalid_sequence true] }
|
444
493
|
let(:messages) { [ "\xff".force_encoding('UTF-8') ] }
|
445
494
|
before do
|
446
|
-
Fluent::Engine.
|
495
|
+
allow(Fluent::Engine).to receive(:now).and_return(time)
|
447
496
|
end
|
448
497
|
it { expect { emit }.not_to raise_error }
|
449
498
|
end
|
@@ -477,10 +526,10 @@ describe Fluent::GrepCounterOutput do
|
|
477
526
|
loaded_saved_at = driver.instance.saved_at
|
478
527
|
loaded_saved_duration = driver.instance.saved_duration
|
479
528
|
|
480
|
-
loaded_counts.
|
481
|
-
loaded_matches.
|
482
|
-
loaded_saved_at.
|
483
|
-
loaded_saved_duration.
|
529
|
+
expect(loaded_counts).to eql(stored_counts)
|
530
|
+
expect(loaded_matches).to eql(stored_matches)
|
531
|
+
expect(loaded_saved_at).to eql(stored_saved_at)
|
532
|
+
expect(loaded_saved_duration).to eql(stored_saved_duration)
|
484
533
|
end
|
485
534
|
end
|
486
535
|
|
data/spec/spec_helper.rb
CHANGED
@@ -4,8 +4,14 @@ require 'bundler'
|
|
4
4
|
Bundler.setup(:default, :test)
|
5
5
|
Bundler.require(:default, :test)
|
6
6
|
|
7
|
+
if ENV['TRAVIS']
|
8
|
+
require 'coveralls'
|
9
|
+
Coveralls.wear!
|
10
|
+
end
|
11
|
+
|
7
12
|
require 'fluent/test'
|
8
13
|
require 'rspec'
|
14
|
+
require 'rspec/its'
|
9
15
|
require 'pry'
|
10
16
|
# require 'delorean'
|
11
17
|
|
metadata
CHANGED
@@ -1,83 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-grepcounter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-its
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: pry
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- -
|
73
|
+
- - ">="
|
60
74
|
- !ruby/object:Gem::Version
|
61
75
|
version: '0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- -
|
80
|
+
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: pry-nav
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- -
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
74
102
|
- !ruby/object:Gem::Version
|
75
103
|
version: '0'
|
76
104
|
type: :development
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
|
-
- -
|
108
|
+
- - ">="
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: '0'
|
83
111
|
description: Fluentd plugin to count the number of matched messages, and emit if exceeds
|
@@ -88,11 +116,10 @@ executables: []
|
|
88
116
|
extensions: []
|
89
117
|
extra_rdoc_files: []
|
90
118
|
files:
|
91
|
-
- .coveralls.yml
|
92
|
-
- .gitignore
|
93
|
-
- .
|
94
|
-
- .
|
95
|
-
- .travis.yml
|
119
|
+
- ".coveralls.yml"
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- ".travis.yml"
|
96
123
|
- CHANGELOG.md
|
97
124
|
- Gemfile
|
98
125
|
- LICENSE
|
@@ -112,17 +139,17 @@ require_paths:
|
|
112
139
|
- lib
|
113
140
|
required_ruby_version: !ruby/object:Gem::Requirement
|
114
141
|
requirements:
|
115
|
-
- -
|
142
|
+
- - ">="
|
116
143
|
- !ruby/object:Gem::Version
|
117
144
|
version: '0'
|
118
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
146
|
requirements:
|
120
|
-
- -
|
147
|
+
- - ">="
|
121
148
|
- !ruby/object:Gem::Version
|
122
149
|
version: '0'
|
123
150
|
requirements: []
|
124
151
|
rubyforge_project: fluent-plugin-grepcounter
|
125
|
-
rubygems_version: 2.
|
152
|
+
rubygems_version: 2.2.2
|
126
153
|
signing_key:
|
127
154
|
specification_version: 4
|
128
155
|
summary: Fluentd plugin to count the number of matched messages, and emit if exceeds
|
data/.rdebugrc
DELETED