fluent-plugin-suppress 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Changes ADDED
@@ -0,0 +1,6 @@
1
+ 2013-06-06 v0.0.3
2
+ nested key support (by Harukasan <miruca@me.com>)
3
+
4
+ 2012-11-22 v0.0.2
5
+ initial release
6
+
data/README.rdoc CHANGED
@@ -42,6 +42,18 @@ Output messages:
42
42
  2012-11-22T11:22:37 sp.foo.info {"id":5,"host":"app01","message":"error!!"}
43
43
  2012-11-22T11:22:45 sp.foo.info {"id":9,"host":"web01","message":"error!!"}
44
44
 
45
+ attr_keys allows nested key name (eg. foo.bar).
46
+
47
+ <match foo.**>
48
+ type suppress
49
+ attr_keys data.host, data.message
50
+ </match>
51
+
52
+ Input messages will be suppressed by key data.host and data.message.
53
+
54
+ 2012-11-22T11:22:33 foo.info {"id":1,"data":{"host":"web01","message":"error!!"}}
55
+ 2012-11-22T11:22:34 foo.info {"id":2,"data":{"host":"web01","message":"error!!"}}
56
+
45
57
  == TODO
46
58
 
47
59
  - patches welcome!
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
14
  gem.name = "fluent-plugin-suppress"
15
15
  gem.require_paths = ["lib"]
16
- gem.version = "0.0.2"
16
+ gem.version = "0.0.3"
17
17
 
18
18
  gem.add_development_dependency "fluentd"
19
19
  gem.add_runtime_dependency "fluentd"
@@ -1,10 +1,10 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module Fluent
3
3
  class SuppressOutput < Output
4
- Fluent::Plugin.register_output('suppress', self)
5
-
6
4
  include Fluent::HandleTagNameMixin
7
5
 
6
+ Fluent::Plugin.register_output('suppress', self)
7
+
8
8
  config_param :attr_keys, :string, :default => nil
9
9
  config_param :num, :integer, :default => 3
10
10
  config_param :interval, :integer, :default => 300
@@ -16,7 +16,7 @@ module Fluent
16
16
  raise ConfigError, "out_suppress: attr_keys is required."
17
17
  end
18
18
 
19
- if ( !@remove_tag_prefix and !@remove_tag_suffix and !@add_tag_prefix and !@add_tag_suffix )
19
+ if ( !@remove_tag_prefix && !@remove_tag_suffix && !@add_tag_prefix && !@add_tag_suffix )
20
20
  raise ConfigError, "out_suppress: Set remove_tag_prefix, remove_tag_suffix, add_tag_prefix or add_tag_suffix."
21
21
  end
22
22
 
@@ -34,13 +34,15 @@ module Fluent
34
34
 
35
35
  def emit(tag, es, chain)
36
36
  es.each do |time, record|
37
- key = @keys.map{|k| record[k]}.join("\0")
38
- key = tag + "\0" + key
37
+ keys = @keys.map do |key|
38
+ key.split(/\./).inject(record) {|r, k| r[k] }
39
+ end
40
+ key = tag + "\0" + keys.join("\0")
39
41
  slot = @slots[key] ||= []
40
42
 
41
43
  # expire old records time
42
44
  expired = time.to_f - @interval
43
- while slot.first and slot.first <= expired
45
+ while slot.first && (slot.first <= expired)
44
46
  slot.shift
45
47
  end
46
48
 
@@ -12,6 +12,13 @@ class SuppressOutputTest < Test::Unit::TestCase
12
12
  add_tag_prefix sp.
13
13
  ]
14
14
 
15
+ CONFIG_WITH_NESTED_KEY = %[
16
+ interval 10
17
+ num 2
18
+ attr_keys data.host, data.message
19
+ add_tag_prefix sp.
20
+ ]
21
+
15
22
  def create_driver(conf = CONFIG, tag='test.info')
16
23
  Fluent::Test::OutputTestDriver.new(Fluent::SuppressOutput, tag).configure(conf)
17
24
  end
@@ -40,4 +47,29 @@ class SuppressOutputTest < Test::Unit::TestCase
40
47
  assert_equal ["sp.test.info", time + 13, {"id"=>7, "host"=>"web01", "message"=>"error!!"}], emits[4]
41
48
 
42
49
  end
50
+
51
+ def test_emit_wtih_nested_key
52
+ d = create_driver(CONFIG_WITH_NESTED_KEY)
53
+
54
+ time = Time.parse("2012-11-22 11:22:33 UTC").to_i
55
+ d.run do
56
+ d.emit({"id" => 1, "data" => {"host" => "web01", "message" => "error!!"}}, time + 1)
57
+ d.emit({"id" => 2, "data" => {"host" => "web01", "message" => "error!!"}}, time + 2)
58
+ d.emit({"id" => 3, "data" => {"host" => "web01", "message" => "error!!"}}, time + 3)
59
+ d.emit({"id" => 4, "data" => {"host" => "web01", "message" => "error!!"}}, time + 4)
60
+ d.emit({"id" => 5, "data" => {"host" => "app01", "message" => "error!!"}}, time + 4)
61
+ d.emit({"id" => 6, "data" => {"host" => "web01", "message" => "error!!"}}, time + 12)
62
+ d.emit({"id" => 7, "data" => {"host" => "web01", "message" => "error!!"}}, time + 13)
63
+ d.emit({"id" => 8, "data" => {"host" => "web01", "message" => "error!!"}}, time + 14)
64
+ end
65
+
66
+ emits = d.emits
67
+ assert_equal 5, emits.length
68
+ assert_equal ["sp.test.info", time + 1, {"id"=>1, "data" => {"host"=>"web01", "message"=>"error!!"}}], emits[0]
69
+ assert_equal ["sp.test.info", time + 2, {"id"=>2, "data" => {"host"=>"web01", "message"=>"error!!"}}], emits[1]
70
+ assert_equal ["sp.test.info", time + 4, {"id"=>5, "data" => {"host"=>"app01", "message"=>"error!!"}}], emits[2]
71
+ assert_equal ["sp.test.info", time + 12, {"id"=>6, "data" => {"host"=>"web01", "message"=>"error!!"}}], emits[3]
72
+ assert_equal ["sp.test.info", time + 13, {"id"=>7, "data" => {"host"=>"web01", "message"=>"error!!"}}], emits[4]
73
+
74
+ end
43
75
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-suppress
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-11-22 00:00:00.000000000 Z
12
+ date: 2013-06-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd
@@ -51,6 +51,7 @@ extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
53
  - .gitignore
54
+ - Changes
54
55
  - Gemfile
55
56
  - LICENSE
56
57
  - README.rdoc