fluent-plugin-reemit 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84d14647bf82812c2048c86f59520de45e76f94e
4
- data.tar.gz: 43bd565f6221c20c685a54f2465eea6a12d39dec
3
+ metadata.gz: 92a5d08ac9438d11190b6bfd139a5bbb12cc501f
4
+ data.tar.gz: 44a90ef06dbf130eac54648ea03d8ca2e9c9e83f
5
5
  SHA512:
6
- metadata.gz: 647d70fc30ff282b66c2a940781ab33874d8bd6ad481f98b57cd7bfeca86be0000123a08898bb9d3abbe85ed95adebdef79a24c50ccfc9e588354c92515614aa
7
- data.tar.gz: cbf229dcf1719638e907c50847e05d6ae850b234d7449a95ac197160572de41e3d3390b8ecb53a586940b10382e451d5c5a06e2b4f3d1681f6525bf989252242
6
+ metadata.gz: d92f99ad94d1d5c8b3a14b460054908e73cce1a409abb0b76943b6bad656204cae444f7900390e9f70e2aed154cb44cb6a3d259e03c7e837df8cb9e96b451860
7
+ data.tar.gz: 0d032e86c8f337b3280fdd4933eda7ccabbb87181196627c971da9807f22d5ab6daf85c7700da107f67ad67f1a113290cba5eb03f371c981b4926312325a3c10
@@ -4,3 +4,4 @@ rvm:
4
4
  - 2.0.0
5
5
  gemfile:
6
6
  - Gemfile
7
+ - Gemfile.v0.12
@@ -1,3 +1,9 @@
1
+ ## 0.1.0 (2014/11/26)
2
+
3
+ Changes:
4
+
5
+ * Support fluentd v0.12.pre
6
+
1
7
  ## 0.0.5 (2014/09/22)
2
8
 
3
9
  Changes:
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+ gem 'fluent-plugin-flowcounter' # for examples
5
+ gem 'fluentd', git: 'git@github.com:fluent/fluentd'
@@ -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-reemit"
6
- gem.version = "0.0.5"
6
+ gem.version = "0.1.0"
7
7
  gem.authors = ["Naotoshi Seo"]
8
8
  gem.email = "sonots@gmail.com"
9
9
  gem.homepage = "https://github.com/sonots/fluent-plugin-reemit"
@@ -7,64 +7,118 @@ module Fluent
7
7
  define_method("log") { $log }
8
8
  end
9
9
 
10
- def initialize
10
+ def configure(conf)
11
11
  super
12
- @match_cache = {}
13
12
  end
14
13
 
15
- def configure(conf)
14
+ def start
16
15
  super
16
+ @router =
17
+ if Engine.instance_variable_get(:@event_router)
18
+ V12EventRouter.new(self)
19
+ else
20
+ V10Engine.new(self)
21
+ end
17
22
  end
18
23
 
19
24
  def emit(tag, es, chain)
20
- engine_emit(tag, es)
25
+ @router.emit_stream(tag, es)
21
26
  chain.next
22
27
  rescue => e
23
28
  log.warn "reemit: #{e.class} #{e.message} #{e.backtrace.first}"
24
29
  end
25
30
 
26
- # My Engine.emit
27
- def engine_emit(tag, es)
28
- target = @match_cache[tag]
29
- unless target
30
- target = engine_match(tag) || Fluent::EngineClass::NoMatchMatch.new
31
- @match_cache[tag] = target
31
+ def included?(collector)
32
+ return false if collector.nil?
33
+ if collector == self
34
+ true
35
+ elsif collector.respond_to?(:outputs) # MultiOutput
36
+ collector.outputs.each do |o|
37
+ return true if self.included?(o)
38
+ end
39
+ false
40
+ else
41
+ false
32
42
  end
33
- target.emit(tag, es)
34
43
  end
35
44
 
36
- # My Engine.match
37
- def engine_match(tag)
38
- # @matches.find {|m| m.match(tag) } # original Engine.match
39
- Engine.matches.find {|m| match_without_self(m, tag) }
40
- end
45
+ class V12EventRouter
46
+ def initialize(reemit)
47
+ @reemit = reemit
48
+ @event_router = Engine.instance_variable_get(:@event_router)
49
+ @chain = @event_router.instance_variable_get(:@chain)
50
+ @emit_error_handler = @event_router.instance_variable_get(:@emit_error_handler)
51
+ @match_rules = @event_router.instance_variable_get(:@match_rules)
52
+ @default_collector = @event_router.instance_variable_get(:@default_collector)
53
+ # @match_cache = @event_router.instance_variable_get(:@match_cache)
54
+ @match_cache = EventRouter::MatchCache.new # need to use a different cache
55
+ end
41
56
 
42
- # <match foo.bar>
43
- # type reemit
44
- # </match>
45
- #
46
- # and
47
- #
48
- # <match foo.bar>
49
- # type copy
50
- # <store>
51
- # type reemit
52
- # </store>
53
- # </match>
54
- def match_without_self(m, tag)
55
- return false if contain_self?(m.output)
56
- m.match(tag)
57
+ # same
58
+ def emit_stream(tag, es)
59
+ match(tag).emit(tag, es, @chain)
60
+ rescue => e
61
+ @emit_error_handler.handle_emits_error(tag, es, e)
62
+ end
63
+
64
+ # same
65
+ def match(tag)
66
+ collector = @match_cache.get(tag) {
67
+ c = find(tag) || @default_collector
68
+ }
69
+ collector
70
+ end
71
+
72
+ def find(tag)
73
+ pipeline = nil
74
+ @match_rules.each_with_index { |rule, i|
75
+ # if rule.match?(tag) # this is the original
76
+ if rule.match?(tag) and !@reemit.included?(rule.collector)
77
+ if rule.collector.is_a?(Filter)
78
+ pipeline ||= Pipeline.new
79
+ pipeline.add_filter(rule.collector)
80
+ else
81
+ if pipeline
82
+ pipeline.set_output(rule.collector)
83
+ else
84
+ # Use Output directly when filter is not matched
85
+ pipeline = rule.collector
86
+ end
87
+ return pipeline
88
+ end
89
+ end
90
+ }
91
+
92
+ if pipeline
93
+ # filter is matched but no match
94
+ pipeline.set_output(@default_collector)
95
+ pipeline
96
+ else
97
+ nil
98
+ end
99
+ end
57
100
  end
58
101
 
59
- def contain_self?(output)
60
- if output.kind_of?(MultiOutput)
61
- output.outputs.each do |o|
62
- return true if contain_self?(o)
102
+ class V10Engine
103
+ def initialize(reemit)
104
+ @reemit = reemit
105
+ @matches = Engine.matches
106
+ @match_cache = {}
107
+ end
108
+
109
+ def emit_stream(tag, es)
110
+ target = @match_cache[tag]
111
+ unless target
112
+ target = match(tag) || Fluent::EngineClass::NoMatchMatch.new
113
+ @match_cache[tag] = target
63
114
  end
64
- else
65
- return true if output == self
115
+ target.emit(tag, es)
116
+ end
117
+
118
+ def match(tag)
119
+ # @matches.find {|m| m.match(tag) } # this is the original
120
+ @matches.find {|m| m.match(tag) and !@reemit.included?(m.output) }
66
121
  end
67
- false
68
122
  end
69
123
  end
70
124
  end
@@ -7,8 +7,10 @@ describe Fluent::ReemitOutput do
7
7
  Fluent::Test::OutputTestDriver.new(Fluent::CopyOutput, tag).configure(config)
8
8
  end
9
9
 
10
- describe '#contain_self?' do
11
- it 'should contain self' do
10
+ # THIS TEST IS ABSOLUTELY NOT ENOUGH. INSTEAD, RUN
11
+ # bundle exec fluentd -c examples/reemit.conf
12
+ describe '#included?' do
13
+ it 'should be included' do
12
14
  config = %[
13
15
  <store>
14
16
  type reemit
@@ -19,10 +21,10 @@ describe Fluent::ReemitOutput do
19
21
  ]
20
22
  output = create_driver(config).instance
21
23
  reemit = output.outputs.first
22
- reemit.contain_self?(output).should be_truthy
24
+ expect(reemit.included?(output)).to be_truthy
23
25
  end
24
26
 
25
- it 'should not contain self' do
27
+ it 'should not be included' do
26
28
  reemit_config = %[
27
29
  <store>
28
30
  type reemit
@@ -38,10 +40,10 @@ describe Fluent::ReemitOutput do
38
40
  ]
39
41
  reemit = create_driver(reemit_config).instance.outputs.first
40
42
  output = create_driver(noreemit_config).instance
41
- reemit.contain_self?(output).should be_falsy
43
+ expect(reemit.included?(output)).to be_falsy
42
44
  end
43
45
 
44
- it 'should contain self in deep' do
46
+ it 'should be included in deep' do
45
47
  config = %[
46
48
  <store>
47
49
  type stdout
@@ -58,7 +60,7 @@ describe Fluent::ReemitOutput do
58
60
  ]
59
61
  output = create_driver(config).instance
60
62
  reemit = output.outputs[1].outputs[1]
61
- reemit.contain_self?(output).should be_truthy
63
+ expect(reemit.included?(output)).to be_truthy
62
64
  end
63
65
  end
64
66
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-reemit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
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-09-21 00:00:00.000000000 Z
11
+ date: 2014-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -91,6 +91,7 @@ files:
91
91
  - ".travis.yml"
92
92
  - CHANGELOG.md
93
93
  - Gemfile
94
+ - Gemfile.v0.12
94
95
  - LICENSE
95
96
  - README.md
96
97
  - Rakefile