fluent-plugin-suppress 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Changes CHANGED
@@ -1,3 +1,6 @@
1
+ 2014-04-11 v0.0.4
2
+ suppress by tag only mode
3
+
1
4
  2013-06-06 v0.0.3
2
5
  nested key support (by Harukasan <miruca@me.com>)
3
6
 
data/README.rdoc CHANGED
@@ -54,6 +54,13 @@ Input messages will be suppressed by key data.host and data.message.
54
54
  2012-11-22T11:22:33 foo.info {"id":1,"data":{"host":"web01","message":"error!!"}}
55
55
  2012-11-22T11:22:34 foo.info {"id":2,"data":{"host":"web01","message":"error!!"}}
56
56
 
57
+ If attr_keys is not specified, suppressed by tag only.
58
+
59
+ <match foo.**>
60
+ type suppress
61
+ </match>
62
+
63
+
57
64
  == TODO
58
65
 
59
66
  - 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.3"
16
+ gem.version = "0.0.4"
17
17
 
18
18
  gem.add_development_dependency "fluentd"
19
19
  gem.add_runtime_dependency "fluentd"
@@ -9,18 +9,18 @@ module Fluent
9
9
  config_param :num, :integer, :default => 3
10
10
  config_param :interval, :integer, :default => 300
11
11
 
12
+ unless method_defined?(:log)
13
+ define_method("log") { $log }
14
+ end
15
+
12
16
  def configure(conf)
13
17
  super
14
18
 
15
- unless @attr_keys
16
- raise ConfigError, "out_suppress: attr_keys is required."
17
- end
18
-
19
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
 
23
- @keys = @attr_keys.split(/ *, */)
23
+ @keys = @attr_keys ? @attr_keys.split(/ *, */) : nil
24
24
  @slots = {}
25
25
  end
26
26
 
@@ -34,10 +34,14 @@ module Fluent
34
34
 
35
35
  def emit(tag, es, chain)
36
36
  es.each do |time, record|
37
- keys = @keys.map do |key|
38
- key.split(/\./).inject(record) {|r, k| r[k] }
37
+ if @keys
38
+ keys = @keys.map do |key|
39
+ key.split(/\./).inject(record) {|r, k| r[k] }
40
+ end
41
+ key = tag + "\0" + keys.join("\0")
42
+ else
43
+ key = tag
39
44
  end
40
- key = tag + "\0" + keys.join("\0")
41
45
  slot = @slots[key] ||= []
42
46
 
43
47
  # expire old records time
@@ -47,7 +51,7 @@ module Fluent
47
51
  end
48
52
 
49
53
  if slot.length >= @num
50
- $log.debug "suppressed record: #{record.to_json}"
54
+ log.debug "suppressed record: #{record.to_json}"
51
55
  next
52
56
  end
53
57
 
@@ -57,7 +61,7 @@ module Fluent
57
61
  if tag != _tag
58
62
  Engine.emit(_tag, time, record)
59
63
  else
60
- $log.warn "Drop record #{record} tag '#{tag}' was not replaced. Can't emit record, cause infinity looping. Set remove_tag_prefix, remove_tag_suffix, add_tag_prefix or add_tag_suffix correctly."
64
+ log.warn "Drop record #{record} tag '#{tag}' was not replaced. Can't emit record, cause infinity looping. Set remove_tag_prefix, remove_tag_suffix, add_tag_prefix or add_tag_suffix correctly."
61
65
  end
62
66
  end
63
67
 
@@ -19,6 +19,12 @@ class SuppressOutputTest < Test::Unit::TestCase
19
19
  add_tag_prefix sp.
20
20
  ]
21
21
 
22
+ CONFIG_TAG_ONLY = %[
23
+ interval 10
24
+ num 2
25
+ add_tag_prefix sp.
26
+ ]
27
+
22
28
  def create_driver(conf = CONFIG, tag='test.info')
23
29
  Fluent::Test::OutputTestDriver.new(Fluent::SuppressOutput, tag).configure(conf)
24
30
  end
@@ -72,4 +78,28 @@ class SuppressOutputTest < Test::Unit::TestCase
72
78
  assert_equal ["sp.test.info", time + 13, {"id"=>7, "data" => {"host"=>"web01", "message"=>"error!!"}}], emits[4]
73
79
 
74
80
  end
81
+
82
+ def test_emit_tagonly
83
+ d = create_driver(CONFIG_TAG_ONLY)
84
+
85
+ time = Time.parse("2012-11-22 11:22:33 UTC").to_i
86
+ d.run do
87
+ d.emit({"id" => 1, "host" => "web01", "message" => "1 error!!"}, time + 1)
88
+ d.emit({"id" => 2, "host" => "web02", "message" => "2 error!!"}, time + 2)
89
+ d.emit({"id" => 3, "host" => "web03", "message" => "3 error!!"}, time + 3)
90
+ d.emit({"id" => 4, "host" => "web04", "message" => "4 error!!"}, time + 4)
91
+ d.emit({"id" => 5, "host" => "app05", "message" => "5 error!!"}, time + 4)
92
+ d.emit({"id" => 6, "host" => "web06", "message" => "6 error!!"}, time + 12)
93
+ d.emit({"id" => 7, "host" => "web07", "message" => "7 error!!"}, time + 13)
94
+ d.emit({"id" => 8, "host" => "web08", "message" => "8 error!!"}, time + 14)
95
+ end
96
+
97
+ emits = d.emits
98
+ assert_equal 4, emits.length
99
+ assert_equal ["sp.test.info", time + 1, {"id"=>1, "host"=>"web01", "message"=>"1 error!!"}], emits[0]
100
+ assert_equal ["sp.test.info", time + 2, {"id"=>2, "host"=>"web02", "message"=>"2 error!!"}], emits[1]
101
+ assert_equal ["sp.test.info", time + 12, {"id"=>6, "host"=>"web06", "message"=>"6 error!!"}], emits[2]
102
+ assert_equal ["sp.test.info", time + 13, {"id"=>7, "host"=>"web07", "message"=>"7 error!!"}], emits[3]
103
+ end
104
+
75
105
  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.3
4
+ version: 0.0.4
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: 2013-06-06 00:00:00.000000000 Z
12
+ date: 2014-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd