fluent-plugin-calc 0.1.2 → 0.2.0

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: 0f8d625101f66b98091f034d26d6bdb61332f507
4
- data.tar.gz: 5e65dc06ab15e2ff39d19cdc287fd71532a4a6d4
3
+ metadata.gz: 30c8943cbad7b43b318067d0708773cce1e1adff
4
+ data.tar.gz: 74e0cdf6eaf70a24efae255962333c499bc72fcb
5
5
  SHA512:
6
- metadata.gz: c9f94407643311294a2d6014dfbbaae0682e787cfa057934025a3f23531a35d9fd2665ca279cd875bc9dca3e18c17f5ba617d5dc2ce43b2cdf45f28cb1679ad3
7
- data.tar.gz: e3fd1ab151b4cee10922e6b553a88f931ec0d4ab70a052c4f92d111f7dbcb6cf97e37c5373150d79f91bb5e75aa4a5b78542aaf5dea5853f14d564e9cc668e44
6
+ metadata.gz: 82ed5239999ff5306267c125bbbfb2e46ac5bcefd9ace0e55dede3145dc809f6c747590a48e49b5d1e794f2bd64835a545ddec273e0597d3dde02bee71b03e65
7
+ data.tar.gz: f0ea97358cc2b5695a96a101a3851fca6a6cb5758f7953b3d9668f14bfdbc938a5129801412e79b80b913e18270e6058bb9f9c46f2f9c4495fa2c9976a9ce9c7
@@ -1,3 +1,9 @@
1
+ ## 0.2.0 (2013/12/12)
2
+
3
+ Enhancement:
4
+
5
+ - Add `remove_tag_prefix` option
6
+
1
7
  ## 0.1.2 (2013/10/10)
2
8
 
3
9
  Enhancement:
data/README.md CHANGED
@@ -82,7 +82,11 @@ then output bocomes as belows:
82
82
 
83
83
  - add_tag_prefix
84
84
 
85
- Add tag prefix for output message.
85
+ Add tag prefix for output message. Default: 'calc'
86
+
87
+ - remove_tag_prefix
88
+
89
+ Remove tag prefix for output message.
86
90
 
87
91
  - aggragate
88
92
 
@@ -3,11 +3,11 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fluent-plugin-calc"
6
- s.version = "0.1.2"
7
- s.authors = ["Naotoshi SEO"]
6
+ s.version = "0.2.0"
7
+ s.authors = ["Naotoshi Seo"]
8
8
  s.email = ["sonots@gmail.com"]
9
9
  s.homepage = "https://github.com/sonots/fluent-plugin-calc"
10
- s.summary = "fluentd plugin to calcucate numbers in messages"
10
+ s.summary = "Fluentd plugin to calcucate statistics in messages"
11
11
  s.description = s.summary
12
12
 
13
13
  s.rubyforge_project = "fluent-plugin-calc"
@@ -21,7 +21,8 @@ class Fluent::CalcOutput < Fluent::Output
21
21
  config_param :avg_suffix, :string, :default => ""
22
22
  config_param :interval, :time, :default => 5
23
23
  config_param :tag, :string, :default => nil
24
- config_param :add_tag_prefix, :string, :default => 'calc'
24
+ config_param :add_tag_prefix, :string, :default => nil
25
+ config_param :remove_tag_prefix, :string, :default => nil
25
26
  config_param :aggregate, :string, :default => 'tag'
26
27
  config_param :store_file, :string, :default => nil
27
28
  config_param :zero_emit, :bool, :default => false
@@ -53,6 +54,25 @@ class Fluent::CalcOutput < Fluent::Output
53
54
  raise Fluent::ConfigError, "tag must be specified for aggregate all" if @tag.nil?
54
55
  end
55
56
 
57
+ if @tag.nil? and @add_tag_prefix.nil? and @remove_tag_prefix.nil?
58
+ @add_tag_prefix = 'calc' # not ConfigError for lower version compatibility
59
+ end
60
+
61
+ @tag_prefix = "#{@add_tag_prefix}." if @add_tag_prefix
62
+ @tag_prefix_match = "#{@remove_tag_prefix}." if @remove_tag_prefix
63
+ @tag_proc =
64
+ if @tag
65
+ Proc.new {|tag| @tag }
66
+ elsif @tag_prefix and @tag_prefix_match
67
+ Proc.new {|tag| "#{@tag_prefix}#{lstrip(tag, @tag_prefix_match)}" }
68
+ elsif @tag_prefix_match
69
+ Proc.new {|tag| lstrip(tag, @tag_prefix_match) }
70
+ elsif @tag_prefix
71
+ Proc.new {|tag| "#{@tag_prefix}#{tag}" }
72
+ else
73
+ Proc.new {|tag| tag }
74
+ end
75
+
56
76
  @matches = {}
57
77
  @mutex = Mutex.new
58
78
  end
@@ -177,8 +197,8 @@ class Fluent::CalcOutput < Fluent::Output
177
197
  flushed_matches.keys.each do |tag|
178
198
  matches = flushed_matches[tag]
179
199
  output = generate_output(matches)
180
- tag = @tag ? @tag : "#{@add_tag_prefix}.#{tag}"
181
- Fluent::Engine.emit(tag, time, output) if output
200
+ emit_tag = @tag_proc.call(tag)
201
+ Fluent::Engine.emit(emit_tag, time, output) if output
182
202
  end
183
203
  end
184
204
 
@@ -283,4 +303,10 @@ class Fluent::CalcOutput < Fluent::Output
283
303
  end
284
304
  end
285
305
 
306
+ private
307
+
308
+ def lstrip(string, substring)
309
+ string.index(substring) == 0 ? string[substring.size..-1] : string
310
+ end
311
+
286
312
  end
@@ -199,6 +199,22 @@ describe Fluent::CalcOutput do
199
199
  it { emit }
200
200
  end
201
201
 
202
+ context 'remove_tag_prefix' do
203
+ let(:config) do
204
+ CONFIG + %[
205
+ remove_tag_prefix foo
206
+ sum _count$
207
+ ]
208
+ end
209
+ before do
210
+ Fluent::Engine.stub(:now).and_return(time)
211
+ Fluent::Engine.should_receive(:emit).with("bar", time, {
212
+ "4xx_count"=>6,"5xx_count"=>6
213
+ })
214
+ end
215
+ it { emit }
216
+ end
217
+
202
218
  context 'aggregate' do
203
219
  let(:emit) do
204
220
  driver.run { messages.each {|message| driver.emit_with_tag(message, time, 'foo.bar') } }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-calc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Naotoshi SEO
7
+ - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-10 00:00:00.000000000 Z
11
+ date: 2013-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: fluentd plugin to calcucate numbers in messages
83
+ description: Fluentd plugin to calcucate statistics in messages
84
84
  email:
85
85
  - sonots@gmail.com
86
86
  executables: []
@@ -120,11 +120,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project: fluent-plugin-calc
123
- rubygems_version: 2.0.2
123
+ rubygems_version: 2.0.3
124
124
  signing_key:
125
125
  specification_version: 4
126
- summary: fluentd plugin to calcucate numbers in messages
126
+ summary: Fluentd plugin to calcucate statistics in messages
127
127
  test_files:
128
128
  - spec/out_calc_spec.rb
129
129
  - spec/spec_helper.rb
130
- has_rdoc: