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 +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile.v0.12 +5 -0
- data/fluent-plugin-reemit.gemspec +1 -1
- data/lib/fluent/plugin/out_reemit.rb +92 -38
- data/spec/out_reemit_spec.rb +9 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92a5d08ac9438d11190b6bfd139a5bbb12cc501f
|
4
|
+
data.tar.gz: 44a90ef06dbf130eac54648ea03d8ca2e9c9e83f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d92f99ad94d1d5c8b3a14b460054908e73cce1a409abb0b76943b6bad656204cae444f7900390e9f70e2aed154cb44cb6a3d259e03c7e837df8cb9e96b451860
|
7
|
+
data.tar.gz: 0d032e86c8f337b3280fdd4933eda7ccabbb87181196627c971da9807f22d5ab6daf85c7700da107f67ad67f1a113290cba5eb03f371c981b4926312325a3c10
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.v0.12
ADDED
@@ -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
|
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
|
10
|
+
def configure(conf)
|
11
11
|
super
|
12
|
-
@match_cache = {}
|
13
12
|
end
|
14
13
|
|
15
|
-
def
|
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
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
65
|
-
|
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
|
data/spec/out_reemit_spec.rb
CHANGED
@@ -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
|
-
|
11
|
-
|
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.
|
24
|
+
expect(reemit.included?(output)).to be_truthy
|
23
25
|
end
|
24
26
|
|
25
|
-
it 'should not
|
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.
|
43
|
+
expect(reemit.included?(output)).to be_falsy
|
42
44
|
end
|
43
45
|
|
44
|
-
it 'should
|
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.
|
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
|
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-
|
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
|