fluent-plugin-datacalculator 0.0.4 → 0.0.5

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/Rakefile CHANGED
@@ -7,12 +7,5 @@ Rake::TestTask.new(:test) do |test|
7
7
  test.verbose = true
8
8
  end
9
9
 
10
- desc "fomulas test"
11
- Rake::TestTask.new(:fomulas) do |test|
12
- test.libs << 'lib' << 'test'
13
- test.pattern = 'test/**/test_out_datacalculator_fomulas.rb'
14
- test.verbose = true
15
- end
16
-
17
10
  task :default => :test
18
11
 
@@ -2,21 +2,6 @@
2
2
  type forward
3
3
  </source>
4
4
 
5
-
6
-
7
- <match payment.install>
8
- type datacalculator
9
- tag result.install
10
- count_interval 5s
11
- aggregate keys area_id, mission_id
12
- formulas sum = amount * price, cnt = 1, total = amount
13
- finalizer name = "area_" + cnt.to_s
14
- <unmatched>
15
- type file
16
- path unmatched
17
- </unmatched>
18
- </match>
19
-
20
5
  <match payment.quest>
21
6
  type datacalculator
22
7
  tag result.quest
@@ -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.4"
6
+ s.version = "0.0.5"
7
7
  s.authors = ["Muddy Dixon"]
8
8
  s.email = ["muddydixon@gmail.com"]
9
9
  s.homepage = "https://github.com/muddydixon/fluent-plugin-datacalculator"
@@ -24,15 +24,27 @@ class Fluent::DataCalculatorOutput < Fluent::Output
24
24
  if @count_interval
25
25
  @tick = @count_interval.to_i
26
26
  else
27
- @tick = case @unit
28
- when 'minute' then 60
29
- when 'hour' then 3600
30
- when 'day' then 86400
31
- else
32
- raise RuntimeError, "@unit must be one of minute/hour/day"
33
- end
27
+ if @unit.index('sec') == 0
28
+ @tick = 1
29
+ elsif @unit.index('sec') != nil
30
+ @tick = @unit[0, @unit.index('sec')].to_i
31
+ elsif @unit.index('minute') == 0
32
+ @tick = 60
33
+ elsif @unit.index('minute') != nil
34
+ @tick = @unit[0, @unit.index('minute')].to_i * 60
35
+ elsif @unit.index('hour') == 0
36
+ @tick = 3600
37
+ elsif @unit.index('hour') != nil
38
+ @tick = @unit[0, @unit.index('hour')].to_i * 3600
39
+ elsif @unit.index('day') == 0
40
+ @tick = 86400
41
+ elsif @unit.index('day') != nil
42
+ @tick = @unit[0, @unit.index('day')].to_i * 86400
43
+ else
44
+ raise RuntimeError, "@unit must be one of Xsec[onds]/Xminute[s]/Xhour[s]/Xday[s]"
45
+ end
34
46
  end
35
-
47
+
36
48
 
37
49
  conf.elements.each do |element|
38
50
  element.keys.each do |k|
@@ -70,12 +82,8 @@ class Fluent::DataCalculatorOutput < Fluent::Output
70
82
  def createFunc (cnt, str)
71
83
  str.strip!
72
84
  left, right = str.split(/\s*=\s*/, 2)
73
-
74
- rights = right.gsub(/([^\\]|^)\".+[^\\]\"/, '')
75
- rights = rights.scan(/[a-zA-Z][\w\d_\.\$\:\@]*/).uniq.select{|x| not x.match(/^[A-Z]/)}
76
- rights = rights.map do|var|
77
- var.sub(/[\.:].+$/, '')
78
- end
85
+ # Fluent moduleだけはOK
86
+ rights = right.scan(/[a-zA-Z][\w\d_\.\$\:\@]*/).uniq.select{|x| x.index('Fluent') != 0}
79
87
 
80
88
  begin
81
89
  f = eval('lambda {|'+rights.join(',')+'| '+right + '}')
@@ -96,13 +104,9 @@ class Fluent::DataCalculatorOutput < Fluent::Output
96
104
  if tag != nil and tag != 'all'
97
105
  arg = tag + '_' + arg
98
106
  end
99
- _argv.push obj[arg]
107
+ _argv.push obj[arg].to_f
100
108
  }
101
- begin
102
- formula.call(*_argv)
103
- rescue ArgumentError
104
- raise Fluent::RuntimeError, "argument error " + _argv + " are adapted to "+ formula
105
- end
109
+ formula.call(*_argv)
106
110
  end
107
111
 
108
112
  @_formulas = []
@@ -167,7 +171,7 @@ class Fluent::DataCalculatorOutput < Fluent::Output
167
171
  if @aggregate == :all
168
172
  tag = 'all'
169
173
  end
170
-
174
+
171
175
  @mutex.synchronize {
172
176
  @counts[tag] ||= [0] * @_formulas.length
173
177
  counts.each_with_index do |count, i|
@@ -208,7 +212,7 @@ class Fluent::DataCalculatorOutput < Fluent::Output
208
212
  name = @_formulas[i][1]
209
213
  output[name] = count
210
214
  end
211
-
215
+
212
216
  @aggregate_keys.each_with_index do |key, i|
213
217
  output[@aggregate_keys[i]] = pat_val[i]
214
218
  end
@@ -216,10 +220,10 @@ class Fluent::DataCalculatorOutput < Fluent::Output
216
220
  if @_finalizer
217
221
  output[@_finalizer[1]] = execFunc('all', output, @_finalizer[2], @_finalizer[3])
218
222
  end
219
-
223
+
220
224
  outputs.push(output)
221
225
  end
222
-
226
+
223
227
  return outputs
224
228
  end
225
229
 
@@ -253,7 +257,7 @@ class Fluent::DataCalculatorOutput < Fluent::Output
253
257
  # for internal, or tests only
254
258
  @watcher = Thread.new(&method(:watch))
255
259
  end
256
-
260
+
257
261
  def watch
258
262
  # instance variable, and public accessable, for test
259
263
  @last_checked = Fluent::Engine.now
@@ -277,7 +281,7 @@ class Fluent::DataCalculatorOutput < Fluent::Output
277
281
  end
278
282
 
279
283
  def emit (tag, es, chain)
280
-
284
+
281
285
  if @aggregate == 'keys'
282
286
  emit_aggregate_keys(tag, es, chain)
283
287
  else
@@ -314,13 +318,12 @@ class Fluent::DataCalculatorOutput < Fluent::Output
314
318
 
315
319
  def emit_single_tag (tag, es, chain)
316
320
  c = [0] * @_formulas.length
317
-
321
+
318
322
  es.each do |time,record|
319
323
  matched = false
320
324
  if @_formulas.length > 0
321
325
  @_formulas.each do |index, outkey, inkeys, formula|
322
326
  next unless formula and checkArgs(record, inkeys)
323
-
324
327
  c[index] += execFunc(nil, record, inkeys, formula)
325
328
  matched = true
326
329
  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.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-29 00:00:00.000000000 Z
12
+ date: 2013-07-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &2164769940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
24
+ version_requirements: *2164769940
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: fluentd
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &2164769420 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ! '>='
@@ -37,12 +32,7 @@ dependencies:
37
32
  version: '0'
38
33
  type: :runtime
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
35
+ version_requirements: *2164769420
46
36
  description: Output filter plugin to calculate messages that matches specified conditions
47
37
  email:
48
38
  - muddydixon@gmail.com
@@ -61,7 +51,6 @@ files:
61
51
  - lib/fluent/plugin/out_datacalculator.rb
62
52
  - test/helper.rb
63
53
  - test/plugin/test_out_datacalculator.rb
64
- - test/plugin/test_out_datacalculator_fomulas.rb
65
54
  homepage: https://github.com/muddydixon/fluent-plugin-datacalculator
66
55
  licenses: []
67
56
  post_install_message:
@@ -82,11 +71,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
71
  version: '0'
83
72
  requirements: []
84
73
  rubyforge_project: fluent-plugin-datacalculator
85
- rubygems_version: 1.8.21
74
+ rubygems_version: 1.8.11
86
75
  signing_key:
87
76
  specification_version: 3
88
77
  summary: Output filter plugin to calculate messages that matches specified conditions
89
78
  test_files:
90
79
  - test/helper.rb
91
80
  - test/plugin/test_out_datacalculator.rb
92
- - test/plugin/test_out_datacalculator_fomulas.rb
@@ -1,79 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'helper'
3
-
4
- class DataCalculatorOutputTest < Test::Unit::TestCase
5
- def setup
6
- Fluent::Test.setup
7
- end
8
-
9
- CONFIG = %[
10
- unit minute
11
- aggregate tag
12
- input_tag_remove_prefix test
13
- formulas sum = amount * price, amounts = amount, record = 1
14
- finalizer ave = amounts > 0 ? 1.0 * sum / amounts : 0
15
- ]
16
-
17
- def create_driver(conf = CONFIG, tag='test.input')
18
- Fluent::Test::OutputTestDriver.new(Fluent::DataCalculatorOutput, tag).configure(conf)
19
- end
20
-
21
- def test_create_formula
22
-
23
- # case: common case
24
- d = create_driver %[
25
- aggregate all
26
- formulas sum = amount * price, cnt = amount
27
- ]
28
- assert_equal 0, d.instance._formulas[0][0]
29
- assert_equal 'sum', d.instance._formulas[0][1]
30
- assert_equal ['amount', 'price'], d.instance._formulas[0][2]
31
- assert_equal 1, d.instance._formulas[1][0]
32
- assert_equal 'cnt', d.instance._formulas[1][1]
33
- assert_equal ['amount'], d.instance._formulas[1][2]
34
-
35
- assert_equal 200, d.instance._formulas[0][3].call(10, 20)
36
- assert_equal 20, d.instance._formulas[1][3].call(20)
37
- assert_raise(ArgumentError){
38
- d.instance._formulas[0][3].call(10)
39
- }
40
-
41
- # case: use Class
42
- d = create_driver %[
43
- aggregate all
44
- formulas time = Fluent::Engine.now
45
- ]
46
- assert_equal 0, d.instance._formulas[0][0]
47
- assert_equal 'time', d.instance._formulas[0][1]
48
- assert_equal [], d.instance._formulas[0][2]
49
- assert_equal Time.now.to_i, d.instance._formulas[0][3].call()
50
-
51
- # case: use instance.method
52
- d = create_driver %[
53
- aggregate all
54
- formulas sum = amount.to_i * price, cnt = amount
55
- ]
56
- assert_equal 0, d.instance._formulas[0][0]
57
- assert_equal 'sum', d.instance._formulas[0][1]
58
- assert_equal ['amount', 'price'], d.instance._formulas[0][2]
59
- assert_equal 1, d.instance._formulas[1][0]
60
- assert_equal 'cnt', d.instance._formulas[1][1]
61
- assert_equal ['amount'], d.instance._formulas[1][2]
62
-
63
- assert_equal 200, d.instance._formulas[0][3].call("10", 20)
64
- assert_equal 20, d.instance._formulas[1][3].call(20)
65
- assert_raise(ArgumentError){
66
- d.instance._formulas[0][3].call(10)
67
- }
68
-
69
- # case: use string
70
- d = create_driver %[
71
- aggregate all
72
- formulas cnt = 1
73
- finalizer name = "muddy" + "dixon" + cnt.to_s
74
- ]
75
- assert_equal 0, d.instance._finalizer[0]
76
- assert_equal ['cnt'], d.instance._finalizer[2]
77
- assert_equal "muddydixon20", d.instance._finalizer[3].call(20)
78
- end
79
- end