fluent-plugin-datacalculator 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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-datacalculator"
6
- s.version = "0.0.2"
6
+ s.version = "0.0.3"
7
7
  s.authors = ["Muddy Dixon"]
8
8
  s.email = ["muddydixon@gmail.com"]
9
9
  s.homepage = "https://github.com/muddydixon/fluent-plugin-datacalculator"
@@ -5,6 +5,7 @@ class Fluent::DataCalculatorOutput < Fluent::Output
5
5
  config_param :count_interval, :time, :default => nil
6
6
  config_param :unit, :string, :default => 'minute'
7
7
  config_param :aggregate, :string, :default => 'tag'
8
+ config_param :aggregate_delimiter, :string, :default => '_$_'
8
9
  config_param :tag, :string, :default => 'datacalculate'
9
10
  config_param :input_tag_remove_prefix, :string, :default => nil
10
11
  config_param :formulas, :string
@@ -194,7 +195,7 @@ class Fluent::DataCalculatorOutput < Fluent::Output
194
195
 
195
196
  counts.keys.each do |pat|
196
197
  output = {}
197
- pat_val = pat.split('_').map{|x| x.to_i }
198
+ pat_val = pat.split(@aggregate_delimiter).map{|x| x.to_s }
198
199
  counts[pat].each_with_index do |count, i|
199
200
  name = @_formulas[i][1]
200
201
  output[name] = count
@@ -280,7 +281,7 @@ class Fluent::DataCalculatorOutput < Fluent::Output
280
281
  cs = {}
281
282
  es.each do |time, record|
282
283
  matched = false
283
- pat = @aggregate_keys.map{ |key| record[key] }.join('_')
284
+ pat = @aggregate_keys.map{ |key| record[key] }.join(@aggregate_delimiter)
284
285
  cs[pat] = [0] * @_formulas.length unless cs.has_key?(pat)
285
286
 
286
287
  if @_formulas.length > 0
@@ -112,6 +112,7 @@ class DataCalculatorOutputTest < Test::Unit::TestCase
112
112
  d = create_driver
113
113
  r1 = d.instance.generate_output({'test.input' => [240,120,180], 'test.input2' => [600,0,0]}, 60)[0]
114
114
 
115
+
115
116
  assert_equal 240, r1['input_sum']
116
117
  assert_equal 120, r1['input_amounts']
117
118
  assert_equal 180, r1['input_record']
@@ -206,5 +207,37 @@ class DataCalculatorOutputTest < Test::Unit::TestCase
206
207
  assert_equal sums[pat], r['sum']
207
208
  assert_equal counts[pat], r['count']
208
209
  end
210
+
211
+ d4 = create_driver(%[
212
+ unit minute
213
+ aggregate keys area_id, mission_id
214
+ formulas sum = amount * price, count = 1
215
+ <unmatched>
216
+ type stdout
217
+ </unmatched>
218
+ ], 'test.input3')
219
+
220
+ sums = {}
221
+ counts = {}
222
+ d4.run do
223
+ 240.times do
224
+ area_id = 'area_'+rand(5).to_s
225
+ mission_id = 'mission_'+rand(5).to_s
226
+ amount = rand(10)
227
+ price = rand(5) * 100
228
+ pat = [area_id, mission_id].join('_$_')
229
+ d4.emit({'amount' => amount, 'price' => price, 'area_id' => area_id, 'mission_id' => mission_id})
230
+ sums[pat] = 0 unless sums.has_key?(pat)
231
+ counts[pat] = 0 unless counts.has_key?(pat)
232
+ sums[pat] += amount * price
233
+ counts[pat] += 1
234
+ end
235
+ end
236
+ r4 = d4.instance.flush(60)
237
+ r4.each do |r|
238
+ pat = [r['area_id'], r['mission_id']].join('_$_')
239
+ assert_equal sums[pat], r['sum']
240
+ assert_equal counts[pat], r['count']
241
+ end
209
242
  end
210
243
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-datacalculator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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: 2012-05-22 00:00:00.000000000 Z
12
+ date: 2012-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd