fluent-plugin-elapsed-time 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d14cf6319e26776194fbb0919e67088cd7ea95b4
4
- data.tar.gz: 3ddedf3e28e320fafcff40ceab676373afcbaa57
3
+ metadata.gz: 6c0f9adda6567da79749a6fc034bcb0487c9e141
4
+ data.tar.gz: ecb930003b14f489d71ef6855cf2156e28c9a53f
5
5
  SHA512:
6
- metadata.gz: a2cdc21c833167dfdbcb966eb94985dc368f55887bda1b19a28711b400fdfe3a840b06bf654688f1337b8baa9f74fb8bff5c960797c7365232a5e30a3afead4d
7
- data.tar.gz: 851810c1aa907d6be79c9f54fb7cd1b41747006553979f363659b51cbf8b17162b039e700cc0f2af574a186ec71c1a49b202a2e4f4a99772e3e409d76dcc5d3c
6
+ metadata.gz: e7b6c7c34fce1d88eaafed9d96e8b14b81752e36946dffe081043313a25781b88b642addca6f1ea71e9183bf02b67ac02e4cf65e438372d4b242e35dce66d743
7
+ data.tar.gz: d697f84cf3dc25e83eb35851bea61186ddb458909f3d466e9bef96938cab494cb30293d21ce4e2f594dfb62012a5670d249211c2d2f16ea7929bff8b7ec5c888
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.0.4 (2014/01/30)
2
+
3
+ Enhancement:
4
+
5
+ * Add `zero_emit` option
6
+
1
7
  ## 0.0.3 (2014/01/30)
2
8
 
3
9
  Enhancement:
data/README.md CHANGED
@@ -93,6 +93,14 @@ where `max` and `avg` are the maximum and average elapsed times, and `num` is th
93
93
  `all` measures `max` and `avg` for all input messages.
94
94
  `tag` measures `max` and `avg` for each tag *modified* by `add_tag_prefix`, `remove_tag_prefix`, or `remove_tag_slice`.
95
95
 
96
+ * zero_emit *bool*
97
+
98
+ Emit 0 on the next interval. This is useful for some software which requires resetting data such as [GrowthForecast](http://kazeburo.github.io/GrowthForecast).
99
+
100
+ elapsed: {"max":1.013,"avg":0.123,"num"=>0}
101
+ # after @interval later
102
+ elapsed: {"max":0,"avg":0,"num"=>0}
103
+
96
104
  ## ChangeLog
97
105
 
98
106
  See [CHANGELOG.md](CHANGELOG.md) for details.
@@ -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-elapsed-time"
6
- gem.version = "0.0.3"
6
+ gem.version = "0.0.4"
7
7
  gem.authors = ["Naotoshi Seo"]
8
8
  gem.email = "sonots@gmail.com"
9
9
  gem.homepage = "https://github.com/sonots/fluent-plugin-elapsed-time"
@@ -18,6 +18,7 @@ module Fluent
18
18
  raise ConfigError, "out_elapsed_time: each should be 'es' or 'message'"
19
19
  end
20
20
  end
21
+ config_param :zero_emit, :bool, :default => false
21
22
 
22
23
  def initialize
23
24
  super
@@ -28,7 +29,7 @@ module Fluent
28
29
  # for test
29
30
  attr_reader :outputs
30
31
 
31
- def elapsed(tag = :all)
32
+ def elapsed(tag = "elapsed") # default: @tag
32
33
  @elapsed[tag] ||= []
33
34
  end
34
35
 
@@ -84,14 +85,6 @@ module Fluent
84
85
  Proc.new {|tag| @tag_slice_proc.call(tag) }
85
86
  end
86
87
 
87
- @push_elapsed_proc =
88
- case @aggregate
89
- when 'all'
90
- Proc.new {|tag, elapsed_time| elapsed(:all) << elapsed_time }
91
- when 'tag'
92
- Proc.new {|tag, elapsed_time| elapsed(tag) << elapsed_time }
93
- end
94
-
95
88
  @emit_proc =
96
89
  if @each == :message
97
90
  chain = NullOutputChain.instance
@@ -100,8 +93,8 @@ module Fluent
100
93
  es.each do |time, record|
101
94
  @outputs.each {|output| output.emit(tag, OneEventStream.new(time, record), chain) }
102
95
  finish = Time.now
103
- elapsed = (finish - start).to_f
104
- @push_elapsed_proc.call(@tag_proc.call(tag), elapsed)
96
+ emit_tag = @tag_proc.call(tag)
97
+ elapsed(emit_tag) << (finish - start).to_f
105
98
  start = finish
106
99
  end
107
100
  }
@@ -110,12 +103,22 @@ module Fluent
110
103
  Proc.new {|tag, es|
111
104
  t = Time.now
112
105
  @outputs.each {|output| output.emit(tag, es, chain) }
113
- elapsed = (Time.now - t).to_f
114
- @push_elapsed_proc.call(@tag_proc.call(tag), elapsed)
106
+ emit_tag = @tag_proc.call(tag)
107
+ elapsed(emit_tag) << (Time.now - t).to_f
115
108
  }
116
109
  end
117
110
  end
118
111
 
112
+ def initial_elapsed(prev_elapsed = nil)
113
+ return {} if !@zero_emit or prev_elapsed.nil?
114
+ elapsed = {}
115
+ prev_elapsed.keys.each do |tag|
116
+ next if prev_elapsed[tag].empty? # Prohibit to emit anymore
117
+ elapsed[tag] = []
118
+ end
119
+ elapsed
120
+ end
121
+
119
122
  def start
120
123
  @outputs.each {|o|
121
124
  o.start
@@ -143,15 +146,15 @@ module Fluent
143
146
  end
144
147
 
145
148
  def flush_emit
146
- elapseds, @elapsed = @elapsed, {}
147
- elapseds.each do |tag, elapsed|
148
- unless elapsed.empty?
149
- max = elapsed.max
150
- num = elapsed.size
151
- avg = elapsed.map(&:to_f).inject(:+) / num.to_f
152
- Engine.emit(tag, Engine.now, {"max" => max, "avg" => avg, "num" => num})
153
- end
149
+ flushed_elapsed, @elapsed = @elapsed, initial_elapsed(@elapsed)
150
+ messages = {}
151
+ flushed_elapsed.each do |tag, elapsed|
152
+ num = elapsed.size
153
+ max = num == 0 ? 0 : elapsed.max
154
+ avg = num == 0 ? 0 : elapsed.map(&:to_f).inject(:+) / num.to_f
155
+ messages[tag] = {"max" => max, "avg" => avg, "num" => num}
154
156
  end
157
+ messages.each {|tag, message| Engine.emit(tag, Engine.now, message) }
155
158
  end
156
159
 
157
160
  def emit(tag, es, chain)
@@ -17,9 +17,6 @@ end
17
17
  describe Fluent::ElapsedTimeOutput do
18
18
  before { Fluent::Test.setup }
19
19
  CONFIG = %[
20
- tag tag
21
- interval 120
22
- each message
23
20
  <store>
24
21
  type stdout
25
22
  </store>
@@ -46,7 +43,7 @@ describe Fluent::ElapsedTimeOutput do
46
43
  end
47
44
 
48
45
  context "check config" do
49
- let(:config) { CONFIG }
46
+ let(:config) { CONFIG + %[tag tag\ninterval 120\neach message]}
50
47
  its(:tag) { should == 'tag' }
51
48
  its(:interval) { should == 120 }
52
49
  its(:each) { should == :message }
@@ -121,5 +118,29 @@ describe Fluent::ElapsedTimeOutput do
121
118
  driver.instance.elapsed("elapsed.#{expected_tag}").size.should == 4
122
119
  }
123
120
  end
121
+
122
+ context 'zero_emit true' do
123
+ let(:config) { CONFIG + %[zero_emit true]}
124
+ before do
125
+ Fluent::Engine.stub(:now).and_return(time)
126
+ end
127
+ it {
128
+ driver.run { messages.each {|message| driver.emit({'message' => message}, time) } }
129
+ driver.instance.flush_emit["elapsed"]["num"].should == 4
130
+ driver.instance.flush_emit["elapsed"].should == {"max" => 0, "avg" => 0, "num" => 0}
131
+ }
132
+ end
133
+
134
+ context 'zero_emit false' do
135
+ let(:config) { CONFIG }
136
+ before do
137
+ Fluent::Engine.stub(:now).and_return(time)
138
+ end
139
+ it {
140
+ driver.run { messages.each {|message| driver.emit({'message' => message}, time) } }
141
+ driver.instance.flush_emit["elapsed"]["num"].should == 4
142
+ driver.instance.flush_emit.should == {}
143
+ }
144
+ end
124
145
  end
125
146
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-elapsed-time
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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-01-29 00:00:00.000000000 Z
11
+ date: 2014-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd