fluentd 0.10.4 → 0.10.5
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.
Potentially problematic release.
This version of fluentd might be problematic. Click here for more details.
- data/ChangeLog +7 -0
- data/VERSION +1 -1
- data/fluent.conf +3 -3
- data/lib/fluent/plugin/in_exec.rb +132 -0
- data/lib/fluent/plugin/in_forward.rb +199 -0
- data/lib/fluent/plugin/in_stream.rb +25 -10
- data/lib/fluent/plugin/out_exec.rb +91 -0
- data/lib/fluent/plugin/out_exec_filter.rb +143 -0
- data/lib/fluent/plugin/out_forward.rb +356 -0
- data/lib/fluent/plugin/out_stream.rb +7 -0
- data/lib/fluent/plugin/out_test.rb +15 -5
- data/lib/fluent/test/input_test.rb +16 -6
- data/lib/fluent/version.rb +1 -1
- data/test/plugin/in_exec.rb +44 -0
- data/test/plugin/in_forward.rb +123 -0
- data/test/plugin/out_exec.rb +69 -0
- data/test/plugin/out_exec_filter.rb +74 -0
- data/test/plugin/out_forward.rb +35 -0
- metadata +29 -17
@@ -18,6 +18,7 @@
|
|
18
18
|
module Fluent
|
19
19
|
|
20
20
|
|
21
|
+
# obsolete
|
21
22
|
class StreamOutput < BufferedOutput
|
22
23
|
def initialize
|
23
24
|
require 'socket'
|
@@ -84,11 +85,14 @@ class StreamOutput < BufferedOutput
|
|
84
85
|
end
|
85
86
|
|
86
87
|
|
88
|
+
# obsolete
|
87
89
|
class TcpOutput < StreamOutput
|
88
90
|
Plugin.register_output('tcp', self)
|
89
91
|
|
90
92
|
def initialize
|
91
93
|
super
|
94
|
+
## TODO
|
95
|
+
#$log.warn "'tcp' output is obsoleted and will be removed. Use 'forward' instead."
|
92
96
|
end
|
93
97
|
|
94
98
|
config_param :port, :integer, :default => DEFAULT_LISTEN_PORT
|
@@ -104,11 +108,14 @@ class TcpOutput < StreamOutput
|
|
104
108
|
end
|
105
109
|
|
106
110
|
|
111
|
+
# obsolete
|
107
112
|
class UnixOutput < StreamOutput
|
108
113
|
Plugin.register_output('unix', self)
|
109
114
|
|
110
115
|
def initialize
|
111
116
|
super
|
117
|
+
## TODO
|
118
|
+
#$log.warn "'unix' output is obsoleted and will be removed."
|
112
119
|
end
|
113
120
|
|
114
121
|
config_param :path, :string
|
@@ -22,15 +22,25 @@ class TestOutput < Output
|
|
22
22
|
Plugin.register_output('test', self)
|
23
23
|
|
24
24
|
def initialize
|
25
|
-
@
|
25
|
+
@emit_streams = []
|
26
26
|
@name = nil
|
27
27
|
end
|
28
28
|
|
29
|
-
attr_reader :
|
29
|
+
attr_reader :emit_streams, :name
|
30
|
+
|
31
|
+
def emits
|
32
|
+
all = []
|
33
|
+
@emit_streams.each {|tag,events|
|
34
|
+
events.each {|time,record|
|
35
|
+
all << [tag, time, record]
|
36
|
+
}
|
37
|
+
}
|
38
|
+
all
|
39
|
+
end
|
30
40
|
|
31
41
|
def events
|
32
42
|
all = []
|
33
|
-
@
|
43
|
+
@emit_streams.each {|tag,events|
|
34
44
|
all.concat events
|
35
45
|
}
|
36
46
|
all
|
@@ -38,7 +48,7 @@ class TestOutput < Output
|
|
38
48
|
|
39
49
|
def records
|
40
50
|
all = []
|
41
|
-
@
|
51
|
+
@emit_streams.each {|tag,events|
|
42
52
|
events.each {|time,record|
|
43
53
|
all << record
|
44
54
|
}
|
@@ -60,7 +70,7 @@ class TestOutput < Output
|
|
60
70
|
|
61
71
|
def emit(tag, es, chain)
|
62
72
|
chain.next
|
63
|
-
@
|
73
|
+
@emit_streams << [tag, es.to_a]
|
64
74
|
end
|
65
75
|
end
|
66
76
|
|
@@ -22,7 +22,7 @@ module Test
|
|
22
22
|
class InputTestDriver < TestDriver
|
23
23
|
def initialize(klass, &block)
|
24
24
|
super(klass, &block)
|
25
|
-
@
|
25
|
+
@emit_streams = []
|
26
26
|
@expects = nil
|
27
27
|
end
|
28
28
|
|
@@ -35,11 +35,21 @@ class InputTestDriver < TestDriver
|
|
35
35
|
@expects ||= []
|
36
36
|
end
|
37
37
|
|
38
|
-
attr_reader :
|
38
|
+
attr_reader :emit_streams
|
39
|
+
|
40
|
+
def emits
|
41
|
+
all = []
|
42
|
+
@emit_streams.each {|tag,events|
|
43
|
+
events.each {|time,record|
|
44
|
+
all << [tag, time, record]
|
45
|
+
}
|
46
|
+
}
|
47
|
+
all
|
48
|
+
end
|
39
49
|
|
40
50
|
def events
|
41
51
|
all = []
|
42
|
-
@
|
52
|
+
@emit_streams.each {|tag,events|
|
43
53
|
all.concat events
|
44
54
|
}
|
45
55
|
all
|
@@ -47,7 +57,7 @@ class InputTestDriver < TestDriver
|
|
47
57
|
|
48
58
|
def records
|
49
59
|
all = []
|
50
|
-
@
|
60
|
+
@emit_streams.each {|tag,events|
|
51
61
|
events.each {|time,record|
|
52
62
|
all << record
|
53
63
|
}
|
@@ -66,7 +76,7 @@ class InputTestDriver < TestDriver
|
|
66
76
|
|
67
77
|
if @expects
|
68
78
|
i = 0
|
69
|
-
@
|
79
|
+
@emit_streams.each {|tag,events|
|
70
80
|
events.each {|time,record|
|
71
81
|
assert_equal(@expects[i], [tag, time, record])
|
72
82
|
i += 1
|
@@ -80,7 +90,7 @@ class InputTestDriver < TestDriver
|
|
80
90
|
|
81
91
|
private
|
82
92
|
def emit_stream(tag, es)
|
83
|
-
@
|
93
|
+
@emit_streams << [tag, es.to_a]
|
84
94
|
end
|
85
95
|
end
|
86
96
|
|
data/lib/fluent/version.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'fluent/test'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
class ExecInputTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Fluent::Test.setup
|
7
|
+
end
|
8
|
+
|
9
|
+
CONFIG = %[
|
10
|
+
command bash -c "echo -e '2011-01-02 13:14:15\ttag1\tok'"
|
11
|
+
keys time,tag,k1
|
12
|
+
time_key time
|
13
|
+
tag_key tag
|
14
|
+
time_format %Y-%m-%d %H:%M:%S
|
15
|
+
run_interval 1s
|
16
|
+
]
|
17
|
+
|
18
|
+
def create_driver(conf=CONFIG)
|
19
|
+
Fluent::Test::InputTestDriver.new(Fluent::ExecInput).configure(conf)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_configure
|
23
|
+
d = create_driver
|
24
|
+
assert_equal ["time","tag","k1"], d.instance.keys
|
25
|
+
assert_equal "tag", d.instance.tag_key
|
26
|
+
assert_equal "time", d.instance.time_key
|
27
|
+
assert_equal "%Y-%m-%d %H:%M:%S", d.instance.time_format
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_emit
|
31
|
+
d = create_driver
|
32
|
+
|
33
|
+
time = Time.parse("2011-01-02 13:14:15").to_i
|
34
|
+
|
35
|
+
d.run do
|
36
|
+
sleep 2
|
37
|
+
end
|
38
|
+
|
39
|
+
emits = d.emits
|
40
|
+
assert_equal true, emits.length > 0
|
41
|
+
assert_equal ["tag1", time, {"k1"=>"ok"}], emits[0]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'fluent/test'
|
2
|
+
|
3
|
+
class ForwardInputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
CONFIG = %[
|
9
|
+
port 13998
|
10
|
+
bind 127.0.0.1
|
11
|
+
]
|
12
|
+
|
13
|
+
def create_driver(conf=CONFIG)
|
14
|
+
Fluent::Test::InputTestDriver.new(Fluent::ForwardInput).configure(conf)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_configure
|
18
|
+
d = create_driver
|
19
|
+
assert_equal 13998, d.instance.port
|
20
|
+
assert_equal '127.0.0.1', d.instance.bind
|
21
|
+
end
|
22
|
+
|
23
|
+
def connect
|
24
|
+
TCPSocket.new('127.0.0.1', 13998)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_time
|
28
|
+
d = create_driver
|
29
|
+
|
30
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
31
|
+
Fluent::Engine.now = time
|
32
|
+
|
33
|
+
d.expect_emit "tag1", time, {"a"=>1}
|
34
|
+
d.expect_emit "tag2", time, {"a"=>2}
|
35
|
+
|
36
|
+
d.run do
|
37
|
+
d.expected_emits.each {|tag,time,record|
|
38
|
+
send_data [tag, 0, record].to_msgpack
|
39
|
+
}
|
40
|
+
sleep 0.5
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_message
|
45
|
+
d = create_driver
|
46
|
+
|
47
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
48
|
+
|
49
|
+
d.expect_emit "tag1", time, {"a"=>1}
|
50
|
+
d.expect_emit "tag2", time, {"a"=>2}
|
51
|
+
|
52
|
+
d.run do
|
53
|
+
d.expected_emits.each {|tag,time,record|
|
54
|
+
send_data [tag, time, record].to_msgpack
|
55
|
+
}
|
56
|
+
sleep 0.5
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_forward
|
61
|
+
d = create_driver
|
62
|
+
|
63
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
64
|
+
|
65
|
+
d.expect_emit "tag1", time, {"a"=>1}
|
66
|
+
d.expect_emit "tag1", time, {"a"=>2}
|
67
|
+
|
68
|
+
d.run do
|
69
|
+
entries = []
|
70
|
+
d.expected_emits.each {|tag,time,record|
|
71
|
+
entries << [time, record]
|
72
|
+
}
|
73
|
+
send_data ["tag1", entries].to_msgpack
|
74
|
+
sleep 0.5
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_packed_forward
|
79
|
+
d = create_driver
|
80
|
+
|
81
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
82
|
+
|
83
|
+
d.expect_emit "tag1", time, {"a"=>1}
|
84
|
+
d.expect_emit "tag1", time, {"a"=>2}
|
85
|
+
|
86
|
+
d.run do
|
87
|
+
entries = ''
|
88
|
+
d.expected_emits.each {|tag,time,record|
|
89
|
+
[time, record].to_msgpack(entries)
|
90
|
+
}
|
91
|
+
send_data ["tag1", entries].to_msgpack
|
92
|
+
sleep 0.5
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_message_json
|
97
|
+
d = create_driver
|
98
|
+
|
99
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
100
|
+
|
101
|
+
d.expect_emit "tag1", time, {"a"=>1}
|
102
|
+
d.expect_emit "tag2", time, {"a"=>2}
|
103
|
+
|
104
|
+
d.run do
|
105
|
+
d.expected_emits.each {|tag,time,record|
|
106
|
+
send_data [tag, time, record].to_json
|
107
|
+
}
|
108
|
+
sleep 0.5
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def send_data(data)
|
113
|
+
io = connect
|
114
|
+
begin
|
115
|
+
io.write data
|
116
|
+
ensure
|
117
|
+
io.close
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# TODO heartbeat
|
122
|
+
end
|
123
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'fluent/test'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class ExecOutputTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Fluent::Test.setup
|
7
|
+
FileUtils.rm_rf(TMP_DIR)
|
8
|
+
FileUtils.mkdir_p(TMP_DIR)
|
9
|
+
end
|
10
|
+
|
11
|
+
TMP_DIR = File.dirname(__FILE__) + "/../tmp"
|
12
|
+
|
13
|
+
CONFIG = %[
|
14
|
+
buffer_path #{TMP_DIR}/buffer
|
15
|
+
command cat >#{TMP_DIR}/out
|
16
|
+
keys time,tag,k1
|
17
|
+
tag_key tag
|
18
|
+
time_key time
|
19
|
+
time_format %Y-%m-%d %H:%M:%S
|
20
|
+
localtime
|
21
|
+
]
|
22
|
+
|
23
|
+
def create_driver(conf = CONFIG)
|
24
|
+
Fluent::Test::BufferedOutputTestDriver.new(Fluent::ExecOutput).configure(conf)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_configure
|
28
|
+
d = create_driver
|
29
|
+
|
30
|
+
assert_equal ["time","tag","k1"], d.instance.keys
|
31
|
+
assert_equal "tag", d.instance.tag_key
|
32
|
+
assert_equal "time", d.instance.time_key
|
33
|
+
assert_equal "%Y-%m-%d %H:%M:%S", d.instance.time_format
|
34
|
+
assert_equal true, d.instance.localtime
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_format
|
38
|
+
d = create_driver
|
39
|
+
|
40
|
+
time = Time.parse("2011-01-02 13:14:15").to_i
|
41
|
+
d.emit({"k1"=>"v1","kx"=>"vx"}, time)
|
42
|
+
d.emit({"k1"=>"v2","kx"=>"vx"}, time)
|
43
|
+
|
44
|
+
d.expect_format %[2011-01-02 13:14:15\ttest\tv1\n]
|
45
|
+
d.expect_format %[2011-01-02 13:14:15\ttest\tv2\n]
|
46
|
+
|
47
|
+
d.run
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_write
|
51
|
+
d = create_driver
|
52
|
+
|
53
|
+
time = Time.parse("2011-01-02 13:14:15").to_i
|
54
|
+
d.emit({"k1"=>"v1","kx"=>"vx"}, time)
|
55
|
+
d.emit({"k1"=>"v2","kx"=>"vx"}, time)
|
56
|
+
|
57
|
+
d.run
|
58
|
+
|
59
|
+
expect_path = "#{TMP_DIR}/out"
|
60
|
+
assert_equal true, File.exist?(expect_path)
|
61
|
+
|
62
|
+
data = File.read(expect_path)
|
63
|
+
expect_data =
|
64
|
+
%[2011-01-02 13:14:15\ttest\tv1\n] +
|
65
|
+
%[2011-01-02 13:14:15\ttest\tv2\n]
|
66
|
+
assert_equal expect_data, data
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'fluent/test'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class ExecFilterOutputTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Fluent::Test.setup
|
7
|
+
end
|
8
|
+
|
9
|
+
CONFIG = %[
|
10
|
+
command cat
|
11
|
+
in_keys time,tag,k1
|
12
|
+
out_keys time,tag,k2
|
13
|
+
tag_key tag
|
14
|
+
time_key time
|
15
|
+
time_format %Y-%m-%d %H:%M:%S
|
16
|
+
localtime
|
17
|
+
]
|
18
|
+
|
19
|
+
def create_driver(conf = CONFIG)
|
20
|
+
Fluent::Test::OutputTestDriver.new(Fluent::ExecFilterOutput).configure(conf)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_configure
|
24
|
+
d = create_driver
|
25
|
+
|
26
|
+
assert_equal ["time","tag","k1"], d.instance.in_keys
|
27
|
+
assert_equal ["time","tag","k2"], d.instance.out_keys
|
28
|
+
assert_equal "tag", d.instance.tag_key
|
29
|
+
assert_equal "time", d.instance.time_key
|
30
|
+
assert_equal "%Y-%m-%d %H:%M:%S", d.instance.time_format
|
31
|
+
assert_equal true, d.instance.localtime
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_emit_1
|
35
|
+
d = create_driver
|
36
|
+
|
37
|
+
time = Time.parse("2011-01-02 13:14:15").to_i
|
38
|
+
|
39
|
+
d.run do
|
40
|
+
d.emit({"k1"=>1}, time)
|
41
|
+
d.emit({"k1"=>2}, time)
|
42
|
+
sleep 0.5
|
43
|
+
end
|
44
|
+
|
45
|
+
emits = d.emits
|
46
|
+
assert_equal 2, emits.length
|
47
|
+
assert_equal ["test", time, {"k2"=>"1"}], emits[0]
|
48
|
+
assert_equal ["test", time, {"k2"=>"2"}], emits[1]
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_emit_2
|
52
|
+
d = create_driver %[
|
53
|
+
command cat
|
54
|
+
in_keys time,k1
|
55
|
+
out_keys time,k2
|
56
|
+
tag xxx
|
57
|
+
time_key time
|
58
|
+
]
|
59
|
+
|
60
|
+
time = Time.parse("2011-01-02 13:14:15").to_i
|
61
|
+
|
62
|
+
d.run do
|
63
|
+
d.emit({"k1"=>1}, time)
|
64
|
+
d.emit({"k1"=>2}, time)
|
65
|
+
sleep 0.5
|
66
|
+
end
|
67
|
+
|
68
|
+
emits = d.emits
|
69
|
+
assert_equal 2, emits.length
|
70
|
+
assert_equal ["xxx", time, {"k2"=>"1"}], emits[0]
|
71
|
+
assert_equal ["xxx", time, {"k2"=>"2"}], emits[1]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|