fluent-plugin-elapsed-time 0.0.5 → 0.0.6

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: b6b4411b3f7e6a8ed0dea0d37972d8df8cb2a295
4
- data.tar.gz: 7f5453e0b6170779a246def7c9dec3f62c124eae
3
+ metadata.gz: 54e022a4e92b2c000e6d9384593349387312799e
4
+ data.tar.gz: 9de570e3b5f04b862d62765830f91e062b8bd975
5
5
  SHA512:
6
- metadata.gz: e966c603341c1737cc66c20aebea264d2d70d3695e7c92ff3d246b9f3538ff7cfb8101eface9eb8dd2adbdb92446db052150ad80601239050bd4963883343b7a
7
- data.tar.gz: c4b491e6f0c50878618074be99b4c187cc79608766a9f23857f4e3194cf9f5a22897b14198a7994ac65ff1a6e9de86933a9ba421609c230a1f692a078eda4d19
6
+ metadata.gz: 13b7bc08bd9c9194602d27a39b36e0d95f2653dd21ea12123381f903bdefc1563964c0f0bc21e0f05fb834cfc9742e931dc2f15c81bf61928509a0ecb3efd667
7
+ data.tar.gz: a1a4e2e466396d87f2a481972e721f7c226338a195e85cbd0198fea317bd11c6b596950e7ca2b78e14c5a76b05b5b779b259baf95e3bb74e64ace5c0ca029c56
@@ -1,6 +1,6 @@
1
1
  rvm:
2
- - 1.9.2
3
2
  - 1.9.3
4
3
  - 2.0.0
4
+ - 2.1.*
5
5
  gemfile:
6
6
  - Gemfile
@@ -1,3 +1,9 @@
1
+ ## 0.0.6 (2014/09/22)
2
+
3
+ Changes:
4
+
5
+ * Change fluentd dependency from '~>' to '>='
6
+
1
7
  ## 0.0.5 (2014/02/04)
2
8
 
3
9
  Enhancement:
data/README.md CHANGED
@@ -10,13 +10,43 @@ Use RubyGems:
10
10
 
11
11
  gem install fluent-plugin-elapsed-time
12
12
 
13
+ ## Illustration
14
+
15
+ This illustration draws how fluent-plugin-elapsed-time measures elapsed times.
16
+
17
+ ```
18
+ +–––––––––––––+ +––––––––––––––+ +––––––––––––––+ +–––––––––––––––+
19
+ | Input | | ElapsedTime | | Output | | Output |
20
+ +––––––+––––––+ +––––––+–––––––+ +––––––+–––––––+ +–––––––+–––––––+
21
+ #on_message | | | |
22
+ +––––––––––––––––––> | |
23
+ | #emit | start = Time.now | |
24
+ | +––––––––––––––––––> |
25
+ | | #emit +–––––––––––––––––––>
26
+ | | | #emit |
27
+ | | <– – – – – – – – – +
28
+ | <– – – – – – – – – + |
29
+ | | elapsed = Time.now - start |
30
+ <– – – – – - – – – + | |
31
+ | | | |
32
+ + + + +
33
+ ```
34
+
13
35
  ## Configuration
14
36
 
15
37
  Example:
16
38
 
17
- Following example measures the max and average time taken to process [fluent-plugin-grep](https://github.com/sonots/fluent-plugin-grep) => [fluent-plugin-parser](https://github.com/tagomoris/fluent-plugin-parser) => out_stdout chain in messages. Please notice that this plugin measures the total processing time until match chain finishes.
39
+ Following example measures the max and average time taken to process [fluent-plugin-grep](https://github.com/sonots/fluent-plugin-grep) => out_stdout chain in messages. Please notice that this plugin measures the total processing time until match chain finishes.
18
40
 
19
41
  ```apache
42
+ <match greped.**>
43
+ type stdout
44
+ </match>
45
+
46
+ <match elapsed>
47
+ type stdout
48
+ </match>
49
+
20
50
  <match **>
21
51
  type elapsed_time
22
52
  tag elapsed
@@ -28,22 +58,6 @@ Following example measures the max and average time taken to process [fluent-plu
28
58
  add_tag_prefix greped
29
59
  </store>
30
60
  </match>
31
-
32
- <match greped.**>
33
- type parse
34
- format ltsv
35
- key_name message
36
- remove_prefix greped
37
- add_prefix parsed
38
- </match>
39
-
40
- <match parsed.**>
41
- type stdout
42
- </match>
43
-
44
- <match elapsed>
45
- type stdout
46
- </match>
47
61
  ```
48
62
 
49
63
  Output will be like
@@ -101,6 +115,14 @@ where `max` and `avg` are the maximum and average elapsed times, and `num` is th
101
115
  # after @interval later
102
116
  elapsed: {"max":0,"avg":0,"num"=>0}
103
117
 
118
+ ## Relatives
119
+
120
+ * [fluent-plugin-measure_time](https://github.com/sonots/fluent-plugin-measure_time)
121
+
122
+ * This plugin make possible to measure the elapsed time of not only output plugins but also input plugins.
123
+ * Also, this plugin has a flexibility to measure arbitrary methods of plugins.
124
+ * But, this does not have flexibility of output messages such as `add_tag_prefix`, `aggregate` options because of its limitaion of internal mechanism.
125
+
104
126
  ## ChangeLog
105
127
 
106
128
  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.5"
6
+ gem.version = "0.0.6"
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"
@@ -17,9 +17,10 @@ Gem::Specification.new do |gem|
17
17
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  gem.require_paths = ['lib']
19
19
 
20
- gem.add_dependency "fluentd", "~> 0.10.17"
20
+ gem.add_dependency "fluentd", ">= 0.10.17"
21
21
  gem.add_development_dependency "rake"
22
22
  gem.add_development_dependency "rspec"
23
+ gem.add_development_dependency "rspec-its"
23
24
  gem.add_development_dependency "pry"
24
25
  gem.add_development_dependency "pry-nav"
25
26
  end
@@ -63,57 +63,41 @@ module Fluent
63
63
  raise ConfigError, "out_elapsed_time: aggregate allows `tag` or `all`"
64
64
  end
65
65
 
66
- @tag_slice_proc =
67
- if @remove_tag_slice
68
- lindex, rindex = @remove_tag_slice.split('..', 2)
69
- if lindex.nil? or rindex.nil? or lindex !~ /^-?\d+$/ or rindex !~ /^-?\d+$/
70
- raise Fluent::ConfigError, "out_elapsed_time: remove_tag_slice must be formatted like [num]..[num]"
71
- end
72
- l, r = lindex.to_i, rindex.to_i
73
- Proc.new {|tag| (tags = tag.split('.')[l..r]).nil? ? "" : tags.join('.') }
74
- else
75
- Proc.new {|tag| tag }
76
- end
77
-
78
- @tag_prefix = "#{@add_tag_prefix}." if @add_tag_prefix
79
- @tag_prefix_match = "#{@remove_tag_prefix}." if @remove_tag_prefix
80
- @tag_proc =
81
- if @tag_prefix and @tag_prefix_match
82
- Proc.new {|tag| "#{@tag_prefix}#{lstrip(@tag_slice_proc.call(tag), @tag_prefix_match)}" }
83
- elsif @tag_prefix_match
84
- Proc.new {|tag| lstrip(@tag_slice_proc.call(tag), @tag_prefix_match) }
85
- elsif @tag_prefix
86
- Proc.new {|tag| "#{@tag_prefix}#{@tag_slice_proc.call(tag)}" }
87
- elsif @tag
88
- Proc.new {|tag| @tag }
89
- else
90
- Proc.new {|tag| @tag_slice_proc.call(tag) }
91
- end
66
+ @tag_proc = tag_proc
92
67
 
93
68
  @emit_proc =
94
69
  if @each == :message
95
- chain = NullOutputChain.instance
96
- Proc.new {|tag, es|
97
- start = Time.now
98
- es.each do |time, record|
99
- @outputs.each {|output| output.emit(tag, OneEventStream.new(time, record), chain) }
100
- finish = Time.now
101
- emit_tag = @tag_proc.call(tag)
102
- elapsed(emit_tag) << (finish - start).to_f
103
- start = finish
104
- end
105
- }
70
+ self.method(:emit_message)
106
71
  else
107
- chain = NullOutputChain.instance
108
- Proc.new {|tag, es|
109
- t = Time.now
110
- @outputs.each {|output| output.emit(tag, es, chain) }
111
- emit_tag = @tag_proc.call(tag)
112
- elapsed(emit_tag) << (Time.now - t).to_f
113
- }
72
+ self.method(:emit_es)
114
73
  end
115
74
  end
116
75
 
76
+ def emit(tag, es, chain)
77
+ @emit_proc.call(tag, es)
78
+ chain.next
79
+ end
80
+
81
+ def emit_message(tag, es)
82
+ chain = NullOutputChain.instance
83
+ start = Time.now
84
+ es.each do |time, record|
85
+ @outputs.each {|output| output.emit(tag, OneEventStream.new(time, record), chain) }
86
+ finish = Time.now
87
+ emit_tag = @tag_proc.call(tag)
88
+ elapsed(emit_tag) << (finish - start).to_f
89
+ start = finish
90
+ end
91
+ end
92
+
93
+ def emit_es(tag, es)
94
+ chain = NullOutputChain.instance
95
+ t = Time.now
96
+ @outputs.each {|output| output.emit(tag, es, chain) }
97
+ emit_tag = @tag_proc.call(tag)
98
+ elapsed(emit_tag) << (Time.now - t).to_f
99
+ end
100
+
117
101
  def initial_elapsed(prev_elapsed = nil)
118
102
  return {} if !@zero_emit or prev_elapsed.nil?
119
103
  elapsed = {}
@@ -162,13 +146,39 @@ module Fluent
162
146
  messages.each {|tag, message| Engine.emit(tag, Engine.now, message) }
163
147
  end
164
148
 
165
- def emit(tag, es, chain)
166
- @emit_proc.call(tag, es)
167
- chain.next
168
- end
149
+ private
150
+
151
+ def tag_proc
152
+ tag_slice_proc =
153
+ if @remove_tag_slice
154
+ lindex, rindex = @remove_tag_slice.split('..', 2)
155
+ if lindex.nil? or rindex.nil? or lindex !~ /^-?\d+$/ or rindex !~ /^-?\d+$/
156
+ raise Fluent::ConfigError, "out_elapsed_time: remove_tag_slice must be formatted like [num]..[num]"
157
+ end
158
+ l, r = lindex.to_i, rindex.to_i
159
+ Proc.new {|tag| (tags = tag.split('.')[l..r]).nil? ? "" : tags.join('.') }
160
+ else
161
+ Proc.new {|tag| tag }
162
+ end
169
163
 
170
- def lstrip(string, substring)
171
- string.index(substring) == 0 ? string[substring.size..-1] : string
164
+ rstrip = Proc.new {|str, substr| str.chomp(substr) }
165
+ lstrip = Proc.new {|str, substr| str.start_with?(substr) ? str[substr.size..-1] : str }
166
+ tag_prefix = "#{rstrip.call(@add_tag_prefix, '.')}." if @add_tag_prefix
167
+ tag_suffix = ".#{lstrip.call(@add_tag_suffix, '.')}" if @add_tag_suffix
168
+ tag_prefix_match = "#{rstrip.call(@remove_tag_prefix, '.')}." if @remove_tag_prefix
169
+ tag_suffix_match = ".#{lstrip.call(@remove_tag_suffix, '.')}" if @remove_tag_suffix
170
+ tag_fixed = @tag if @tag
171
+ if tag_prefix_match and tag_suffix_match
172
+ Proc.new {|tag| "#{tag_prefix}#{rstrip.call(lstrip.call(tag_slice_proc.call(tag), tag_prefix_match), tag_suffix_match)}#{tag_suffix}" }
173
+ elsif tag_prefix_match
174
+ Proc.new {|tag| "#{tag_prefix}#{lstrip.call(tag_slice_proc.call(tag), tag_prefix_match)}#{tag_suffix}" }
175
+ elsif tag_suffix_match
176
+ Proc.new {|tag| "#{tag_prefix}#{rstrip.call(tag_slice_proc.call(tag), tag_suffix_match)}#{tag_suffix}" }
177
+ elsif tag_prefix || @remove_tag_slice || tag_suffix
178
+ Proc.new {|tag| "#{tag_prefix}#{tag_slice_proc.call(tag)}#{tag_suffix}" }
179
+ else
180
+ Proc.new {|tag| tag_fixed }
181
+ end
172
182
  end
173
183
  end
174
184
  end
@@ -6,6 +6,7 @@ Bundler.require(:default, :test)
6
6
 
7
7
  require 'fluent/test'
8
8
  require 'rspec'
9
+ require 'rspec/its'
9
10
  require 'pry'
10
11
 
11
12
  $TESTING=true
metadata CHANGED
@@ -1,83 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-elapsed-time
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
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-02-04 00:00:00.000000000 Z
11
+ date: 2014-09-21 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.10.17
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.10.17
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
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - '>='
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  description: Fluentd plugin to measure elapsed time to process messages
@@ -86,9 +100,9 @@ executables: []
86
100
  extensions: []
87
101
  extra_rdoc_files: []
88
102
  files:
89
- - .gitignore
90
- - .rspec
91
- - .travis.yml
103
+ - ".gitignore"
104
+ - ".rspec"
105
+ - ".travis.yml"
92
106
  - CHANGELOG.md
93
107
  - Gemfile
94
108
  - LICENSE
@@ -108,17 +122,17 @@ require_paths:
108
122
  - lib
109
123
  required_ruby_version: !ruby/object:Gem::Requirement
110
124
  requirements:
111
- - - '>='
125
+ - - ">="
112
126
  - !ruby/object:Gem::Version
113
127
  version: '0'
114
128
  required_rubygems_version: !ruby/object:Gem::Requirement
115
129
  requirements:
116
- - - '>='
130
+ - - ">="
117
131
  - !ruby/object:Gem::Version
118
132
  version: '0'
119
133
  requirements: []
120
134
  rubyforge_project:
121
- rubygems_version: 2.0.3
135
+ rubygems_version: 2.2.2
122
136
  signing_key:
123
137
  specification_version: 4
124
138
  summary: Fluentd plugin to measure elapsed time to process messages