fluent-plugin-groupcounter 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8cc4bf62fb23f54f31a2538cdf2ec1218e2970e
4
- data.tar.gz: 8fe568adf912877846f3c26c0bb1426c2c0dba34
3
+ metadata.gz: 0eae1a0bcfc8a083aae95ca82cf3870d3ec1055c
4
+ data.tar.gz: 14201fa360defd334687a6ee18aa3722fdba9791
5
5
  SHA512:
6
- metadata.gz: 13d484566258d0a0ce4b260baaebdfabb2763dcb5df908c684be4a8577173b6dbd2ddd590bbbf16ac170a080bb4b8a7675eefea15c72eed2152cd8c374b204e8
7
- data.tar.gz: 93178c805d0fe9a19a206cfd3098a64cc51685f4daa0fb767a2bec45b25dc77b3f0656f85d075f2157b7b41ec63e83d0f88b05e17d1a0cd5d8e437b854e5461f
6
+ metadata.gz: 089d7eec6dc0e3206e105610b9e28b8f6813c927d79d006c5ec04abcdb1870adc7a4d18808fc821a3050af86ce352557cfc48da51e50d9572fdc1ee465558e3c
7
+ data.tar.gz: ccc024bf4414587322556d0a9725ad475786b8ac7e71c9c6cd5d07c24bf73b307a5d0169542a0e4cfd7333a566fc898b5d7653991ece26a53449cedfb0ace0d9
@@ -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-groupcounter"
6
- s.version = "0.2.1"
6
+ s.version = "0.2.2"
7
7
  s.authors = ["Ryosuke IWANAGA", "Naotoshi SEO"]
8
8
  s.email = ["@riywo", "sonots@gmail.com"]
9
9
  s.homepage = "https://github.com/riywo/fluent-plugin-groupcounter"
@@ -37,10 +37,6 @@ class Fluent::GroupCounterOutput < Fluent::Output
37
37
  def configure(conf)
38
38
  super
39
39
 
40
- if @group_by_keys.nil? and @group_by_expression.nil?
41
- raise Fluent::ConfigError, "Either of group_by_keys or group_by_expression must be specified"
42
- end
43
-
44
40
  if @count_interval
45
41
  @count_interval = @count_interval.to_i
46
42
  else
@@ -114,12 +110,13 @@ class Fluent::GroupCounterOutput < Fluent::Output
114
110
  # total_count = counts_per_tag.delete('__total_count')
115
111
 
116
112
  counts_per_tag.each do |group_key, count|
113
+ group_key_with = group_key.empty? ? "" : group_key + @delimiter
117
114
  output[key_prefix + group_key + @count_suffix] = count[:count] if count[:count]
118
- output[key_prefix + group_key + "#{@delimiter}#{@min_key}#{@min_suffix}"] = count[:min] if count[:min]
119
- output[key_prefix + group_key + "#{@delimiter}#{@max_key}#{@max_suffix}"] = count[:max] if count[:max]
120
- output[key_prefix + group_key + "#{@delimiter}#{@avg_key}#{@avg_suffix}"] = count[:sum] / (count[:count] * 1.0) if count[:sum] and count[:count] > 0
121
- # output[key_prefix + group_key + "#{@delimiter}rate"] = ((count[:count] * 100.0) / (1.00 * step)).floor / 100.0
122
- # output[key_prefix + group_key + "#{@delimiter}percentage"] = count[:count] * 100.0 / (1.00 * total_count) if total_count > 0
115
+ output[key_prefix + group_key_with + "#{@min_key}#{@min_suffix}"] = count[:min] if count[:min]
116
+ output[key_prefix + group_key_with + "#{@max_key}#{@max_suffix}"] = count[:max] if count[:max]
117
+ output[key_prefix + group_key_with + "#{@avg_key}#{@avg_suffix}"] = count[:sum] / (count[:count] * 1.0) if count[:sum] and count[:count] > 0
118
+ # output[key_prefix + group_key_with + "rate"] = ((count[:count] * 100.0) / (1.00 * step)).floor / 100.0
119
+ # output[key_prefix + group_key_with + "percentage"] = count[:count] * 100.0 / (1.00 * total_count) if total_count > 0
123
120
  end
124
121
 
125
122
  output
@@ -139,7 +136,7 @@ class Fluent::GroupCounterOutput < Fluent::Output
139
136
 
140
137
  output = {}
141
138
  counts.keys.each do |tag|
142
- generate_fields(counts[tag], output, stripped_tag(tag) + '_')
139
+ generate_fields(counts[tag], output, stripped_tag(tag) + @delimiter)
143
140
  end
144
141
  output
145
142
  end
@@ -237,9 +234,11 @@ class Fluent::GroupCounterOutput < Fluent::Output
237
234
  if @group_by_expression
238
235
  tags = tag.split('.')
239
236
  group_key = expand_placeholder(@group_by_expression, record, tag, tags, Time.at(time))
240
- else # @group_by_keys
237
+ elsif @group_by_keys
241
238
  values = @group_by_keys.map {|key| record[key] || 'undef'}
242
239
  group_key = values.join(@delimiter)
240
+ else
241
+ return ""
243
242
  end
244
243
  group_key = group_key.to_s.force_encoding('ASCII-8BIT')
245
244
 
@@ -22,13 +22,6 @@ describe Fluent::GroupCounterOutput do
22
22
  let(:driver) { Fluent::Test::OutputTestDriver.new(Fluent::GroupCounterOutput, tag).configure(config) }
23
23
 
24
24
  describe 'test configure' do
25
- describe 'bad configuration' do
26
- context 'test empty configuration' do
27
- let(:config) { %[] }
28
- it { expect { driver }.to raise_error(Fluent::ConfigError) }
29
- end
30
- end
31
-
32
25
  describe 'good configuration' do
33
26
  subject { driver.instance }
34
27
 
@@ -84,7 +77,7 @@ describe Fluent::GroupCounterOutput do
84
77
  Hash[*(expected.map {|key, val| next ["test_#{key}", val] }.flatten)]
85
78
  end
86
79
 
87
- context 'default' do
80
+ context 'typical' do
88
81
  let(:config) { CONFIG }
89
82
  before do
90
83
  Fluent::Engine.stub(:now).and_return(time)
@@ -221,6 +214,33 @@ describe Fluent::GroupCounterOutput do
221
214
  it { emit }
222
215
  end
223
216
 
217
+ context 'no group_by' do
218
+ let(:config) do
219
+ %[
220
+ tag_prefix count
221
+ output_per_tag true
222
+
223
+ count_suffix count
224
+ max_key reqtime
225
+ min_key reqtime
226
+ avg_key reqtime
227
+ ]
228
+ end
229
+ let(:expected) do
230
+ {
231
+ "count"=>4,
232
+ "reqtime_min"=>0.0,
233
+ "reqtime_max"=>3.003,
234
+ "reqtime_avg"=>1.5015,
235
+ }
236
+ end
237
+ before do
238
+ Fluent::Engine.stub(:now).and_return(time)
239
+ Fluent::Engine.should_receive(:emit).with("count.#{tag}", time, expected)
240
+ end
241
+ it { emit }
242
+ end
243
+
224
244
  context 'tag' do
225
245
  context 'not effective if output_per_tag true' do
226
246
  let(:config) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-groupcounter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryosuke IWANAGA