fluentd 0.12.43 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fluentd might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +6 -0
- data/.gitignore +2 -0
- data/.travis.yml +33 -21
- data/CONTRIBUTING.md +1 -0
- data/ChangeLog +1239 -0
- data/README.md +0 -25
- data/Rakefile +2 -1
- data/Vagrantfile +17 -0
- data/appveyor.yml +35 -0
- data/example/filter_stdout.conf +5 -5
- data/example/in_forward.conf +2 -2
- data/example/in_http.conf +2 -2
- data/example/in_out_forward.conf +17 -0
- data/example/in_syslog.conf +2 -2
- data/example/in_tail.conf +2 -2
- data/example/in_tcp.conf +2 -2
- data/example/in_udp.conf +2 -2
- data/example/out_copy.conf +4 -4
- data/example/out_file.conf +2 -2
- data/example/out_forward.conf +2 -2
- data/example/out_forward_buf_file.conf +23 -0
- data/example/v0_12_filter.conf +8 -8
- data/fluent.conf +29 -0
- data/fluentd.gemspec +18 -11
- data/lib/fluent/agent.rb +60 -58
- data/lib/fluent/command/cat.rb +1 -1
- data/lib/fluent/command/debug.rb +7 -5
- data/lib/fluent/command/fluentd.rb +97 -2
- data/lib/fluent/compat/call_super_mixin.rb +67 -0
- data/lib/fluent/compat/filter.rb +50 -0
- data/lib/fluent/compat/formatter.rb +109 -0
- data/lib/fluent/compat/input.rb +50 -0
- data/lib/fluent/compat/output.rb +617 -0
- data/lib/fluent/compat/output_chain.rb +60 -0
- data/lib/fluent/compat/parser.rb +163 -0
- data/lib/fluent/compat/propagate_default.rb +62 -0
- data/lib/fluent/config.rb +23 -20
- data/lib/fluent/config/configure_proxy.rb +119 -70
- data/lib/fluent/config/dsl.rb +5 -18
- data/lib/fluent/config/element.rb +72 -8
- data/lib/fluent/config/error.rb +0 -3
- data/lib/fluent/config/literal_parser.rb +0 -2
- data/lib/fluent/config/parser.rb +4 -4
- data/lib/fluent/config/section.rb +39 -28
- data/lib/fluent/config/types.rb +2 -13
- data/lib/fluent/config/v1_parser.rb +1 -3
- data/lib/fluent/configurable.rb +48 -16
- data/lib/fluent/daemon.rb +15 -0
- data/lib/fluent/engine.rb +26 -52
- data/lib/fluent/env.rb +6 -4
- data/lib/fluent/event.rb +58 -11
- data/lib/fluent/event_router.rb +5 -5
- data/lib/fluent/filter.rb +2 -50
- data/lib/fluent/formatter.rb +4 -293
- data/lib/fluent/input.rb +2 -32
- data/lib/fluent/label.rb +2 -2
- data/lib/fluent/load.rb +3 -2
- data/lib/fluent/log.rb +107 -38
- data/lib/fluent/match.rb +0 -36
- data/lib/fluent/mixin.rb +117 -7
- data/lib/fluent/msgpack_factory.rb +62 -0
- data/lib/fluent/output.rb +7 -612
- data/lib/fluent/output_chain.rb +23 -0
- data/lib/fluent/parser.rb +4 -800
- data/lib/fluent/plugin.rb +100 -121
- data/lib/fluent/plugin/bare_output.rb +63 -0
- data/lib/fluent/plugin/base.rb +121 -0
- data/lib/fluent/plugin/buf_file.rb +101 -182
- data/lib/fluent/plugin/buf_memory.rb +9 -92
- data/lib/fluent/plugin/buffer.rb +473 -0
- data/lib/fluent/plugin/buffer/chunk.rb +135 -0
- data/lib/fluent/plugin/buffer/file_chunk.rb +339 -0
- data/lib/fluent/plugin/buffer/memory_chunk.rb +100 -0
- data/lib/fluent/plugin/exec_util.rb +80 -75
- data/lib/fluent/plugin/file_util.rb +33 -28
- data/lib/fluent/plugin/file_wrapper.rb +120 -0
- data/lib/fluent/plugin/filter.rb +51 -0
- data/lib/fluent/plugin/filter_grep.rb +13 -40
- data/lib/fluent/plugin/filter_record_transformer.rb +22 -18
- data/lib/fluent/plugin/formatter.rb +93 -0
- data/lib/fluent/plugin/formatter_csv.rb +48 -0
- data/lib/fluent/plugin/formatter_hash.rb +32 -0
- data/lib/fluent/plugin/formatter_json.rb +47 -0
- data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
- data/lib/fluent/plugin/formatter_msgpack.rb +32 -0
- data/lib/fluent/plugin/formatter_out_file.rb +45 -0
- data/lib/fluent/plugin/formatter_single_value.rb +34 -0
- data/lib/fluent/plugin/formatter_stdout.rb +39 -0
- data/lib/fluent/plugin/in_debug_agent.rb +4 -0
- data/lib/fluent/plugin/in_dummy.rb +22 -18
- data/lib/fluent/plugin/in_exec.rb +18 -8
- data/lib/fluent/plugin/in_forward.rb +36 -79
- data/lib/fluent/plugin/in_gc_stat.rb +4 -0
- data/lib/fluent/plugin/in_http.rb +21 -18
- data/lib/fluent/plugin/in_monitor_agent.rb +15 -48
- data/lib/fluent/plugin/in_object_space.rb +6 -1
- data/lib/fluent/plugin/in_stream.rb +7 -3
- data/lib/fluent/plugin/in_syslog.rb +46 -95
- data/lib/fluent/plugin/in_tail.rb +58 -640
- data/lib/fluent/plugin/in_tcp.rb +8 -1
- data/lib/fluent/plugin/in_udp.rb +8 -18
- data/lib/fluent/plugin/input.rb +33 -0
- data/lib/fluent/plugin/multi_output.rb +95 -0
- data/lib/fluent/plugin/out_buffered_null.rb +59 -0
- data/lib/fluent/plugin/out_copy.rb +11 -7
- data/lib/fluent/plugin/out_exec.rb +15 -11
- data/lib/fluent/plugin/out_exec_filter.rb +18 -10
- data/lib/fluent/plugin/out_file.rb +34 -5
- data/lib/fluent/plugin/out_forward.rb +25 -19
- data/lib/fluent/plugin/out_null.rb +0 -14
- data/lib/fluent/plugin/out_roundrobin.rb +11 -7
- data/lib/fluent/plugin/out_stdout.rb +5 -7
- data/lib/fluent/plugin/out_stream.rb +3 -1
- data/lib/fluent/plugin/output.rb +979 -0
- data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
- data/lib/fluent/plugin/parser.rb +244 -0
- data/lib/fluent/plugin/parser_apache.rb +24 -0
- data/lib/fluent/plugin/parser_apache2.rb +84 -0
- data/lib/fluent/plugin/parser_apache_error.rb +21 -0
- data/lib/fluent/plugin/parser_csv.rb +31 -0
- data/lib/fluent/plugin/parser_json.rb +79 -0
- data/lib/fluent/plugin/parser_ltsv.rb +50 -0
- data/lib/fluent/plugin/parser_multiline.rb +102 -0
- data/lib/fluent/plugin/parser_nginx.rb +24 -0
- data/lib/fluent/plugin/parser_none.rb +36 -0
- data/lib/fluent/plugin/parser_syslog.rb +82 -0
- data/lib/fluent/plugin/parser_tsv.rb +37 -0
- data/lib/fluent/plugin/socket_util.rb +119 -117
- data/lib/fluent/plugin/storage.rb +84 -0
- data/lib/fluent/plugin/storage_local.rb +116 -0
- data/lib/fluent/plugin/string_util.rb +16 -13
- data/lib/fluent/plugin_helper.rb +39 -0
- data/lib/fluent/plugin_helper/child_process.rb +298 -0
- data/lib/fluent/plugin_helper/compat_parameters.rb +99 -0
- data/lib/fluent/plugin_helper/event_emitter.rb +80 -0
- data/lib/fluent/plugin_helper/event_loop.rb +118 -0
- data/lib/fluent/plugin_helper/retry_state.rb +177 -0
- data/lib/fluent/plugin_helper/storage.rb +308 -0
- data/lib/fluent/plugin_helper/thread.rb +147 -0
- data/lib/fluent/plugin_helper/timer.rb +85 -0
- data/lib/fluent/plugin_id.rb +63 -0
- data/lib/fluent/process.rb +21 -30
- data/lib/fluent/registry.rb +21 -9
- data/lib/fluent/root_agent.rb +115 -40
- data/lib/fluent/supervisor.rb +330 -320
- data/lib/fluent/system_config.rb +42 -18
- data/lib/fluent/test.rb +6 -1
- data/lib/fluent/test/base.rb +23 -3
- data/lib/fluent/test/driver/base.rb +247 -0
- data/lib/fluent/test/driver/event_feeder.rb +98 -0
- data/lib/fluent/test/driver/filter.rb +35 -0
- data/lib/fluent/test/driver/input.rb +31 -0
- data/lib/fluent/test/driver/output.rb +78 -0
- data/lib/fluent/test/driver/test_event_router.rb +45 -0
- data/lib/fluent/test/filter_test.rb +0 -1
- data/lib/fluent/test/formatter_test.rb +2 -1
- data/lib/fluent/test/input_test.rb +23 -17
- data/lib/fluent/test/output_test.rb +28 -39
- data/lib/fluent/test/parser_test.rb +1 -1
- data/lib/fluent/time.rb +104 -1
- data/lib/fluent/{status.rb → unique_id.rb} +15 -24
- data/lib/fluent/version.rb +1 -1
- data/lib/fluent/winsvc.rb +72 -0
- data/test/compat/test_calls_super.rb +164 -0
- data/test/config/test_config_parser.rb +83 -0
- data/test/config/test_configurable.rb +547 -274
- data/test/config/test_configure_proxy.rb +146 -29
- data/test/config/test_dsl.rb +3 -181
- data/test/config/test_element.rb +274 -0
- data/test/config/test_literal_parser.rb +1 -1
- data/test/config/test_section.rb +79 -7
- data/test/config/test_system_config.rb +21 -0
- data/test/config/test_types.rb +3 -26
- data/test/helper.rb +78 -8
- data/test/plugin/test_bare_output.rb +118 -0
- data/test/plugin/test_base.rb +75 -0
- data/test/plugin/test_buf_file.rb +420 -521
- data/test/plugin/test_buf_memory.rb +32 -194
- data/test/plugin/test_buffer.rb +981 -0
- data/test/plugin/test_buffer_chunk.rb +110 -0
- data/test/plugin/test_buffer_file_chunk.rb +770 -0
- data/test/plugin/test_buffer_memory_chunk.rb +265 -0
- data/test/plugin/test_filter.rb +255 -0
- data/test/plugin/test_filter_grep.rb +2 -73
- data/test/plugin/test_filter_record_transformer.rb +24 -68
- data/test/plugin/test_filter_stdout.rb +6 -6
- data/test/plugin/test_in_debug_agent.rb +2 -0
- data/test/plugin/test_in_dummy.rb +11 -17
- data/test/plugin/test_in_exec.rb +6 -25
- data/test/plugin/test_in_forward.rb +112 -151
- data/test/plugin/test_in_gc_stat.rb +2 -0
- data/test/plugin/test_in_http.rb +106 -157
- data/test/plugin/test_in_object_space.rb +21 -5
- data/test/plugin/test_in_stream.rb +14 -13
- data/test/plugin/test_in_syslog.rb +30 -275
- data/test/plugin/test_in_tail.rb +95 -282
- data/test/plugin/test_in_tcp.rb +14 -0
- data/test/plugin/test_in_udp.rb +21 -67
- data/test/plugin/test_input.rb +122 -0
- data/test/plugin/test_multi_output.rb +180 -0
- data/test/plugin/test_out_buffered_null.rb +79 -0
- data/test/plugin/test_out_copy.rb +15 -2
- data/test/plugin/test_out_exec.rb +75 -25
- data/test/plugin/test_out_exec_filter.rb +74 -8
- data/test/plugin/test_out_file.rb +61 -7
- data/test/plugin/test_out_forward.rb +92 -15
- data/test/plugin/test_out_roundrobin.rb +1 -0
- data/test/plugin/test_out_stdout.rb +22 -13
- data/test/plugin/test_out_stream.rb +18 -0
- data/test/plugin/test_output.rb +515 -0
- data/test/plugin/test_output_as_buffered.rb +1540 -0
- data/test/plugin/test_output_as_buffered_overflow.rb +247 -0
- data/test/plugin/test_output_as_buffered_retries.rb +808 -0
- data/test/plugin/test_output_as_buffered_secondary.rb +776 -0
- data/test/plugin/test_output_as_standard.rb +362 -0
- data/test/plugin/test_owned_by.rb +35 -0
- data/test/plugin/test_storage.rb +167 -0
- data/test/plugin/test_storage_local.rb +8 -0
- data/test/plugin_helper/test_child_process.rb +599 -0
- data/test/plugin_helper/test_compat_parameters.rb +175 -0
- data/test/plugin_helper/test_event_emitter.rb +51 -0
- data/test/plugin_helper/test_event_loop.rb +52 -0
- data/test/plugin_helper/test_retry_state.rb +399 -0
- data/test/plugin_helper/test_storage.rb +411 -0
- data/test/plugin_helper/test_thread.rb +164 -0
- data/test/plugin_helper/test_timer.rb +100 -0
- data/test/scripts/exec_script.rb +0 -6
- data/test/scripts/fluent/plugin/out_test.rb +3 -0
- data/test/test_config.rb +13 -4
- data/test/test_event.rb +24 -13
- data/test/test_event_router.rb +8 -7
- data/test/test_event_time.rb +187 -0
- data/test/test_formatter.rb +13 -51
- data/test/test_input.rb +1 -1
- data/test/test_log.rb +239 -16
- data/test/test_mixin.rb +1 -1
- data/test/test_output.rb +53 -66
- data/test/test_parser.rb +105 -323
- data/test/test_plugin_helper.rb +81 -0
- data/test/test_root_agent.rb +4 -52
- data/test/test_supervisor.rb +272 -0
- data/test/test_unique_id.rb +47 -0
- metadata +181 -55
- data/CHANGELOG.md +0 -710
- data/lib/fluent/buffer.rb +0 -365
- data/lib/fluent/plugin/filter_parser.rb +0 -107
- data/lib/fluent/plugin/in_status.rb +0 -76
- data/lib/fluent/test/helpers.rb +0 -86
- data/test/plugin/data/log/foo/bar2 +0 -0
- data/test/plugin/test_filter_parser.rb +0 -744
- data/test/plugin/test_in_status.rb +0 -38
- data/test/test_buffer.rb +0 -624
@@ -0,0 +1,81 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require 'fluent/plugin_helper'
|
3
|
+
require 'fluent/plugin/base'
|
4
|
+
|
5
|
+
class ConfigTest < Test::Unit::TestCase
|
6
|
+
module FluentTest; end
|
7
|
+
|
8
|
+
sub_test_case 'Fluent::Plugin::Base.helpers method works as shortcut to include helper modules' do
|
9
|
+
class FluentTest::PluginTest1 < Fluent::Plugin::TestBase
|
10
|
+
helpers :event_emitter
|
11
|
+
end
|
12
|
+
class FluentTest::PluginTest2 < Fluent::Plugin::TestBase
|
13
|
+
helpers :thread
|
14
|
+
end
|
15
|
+
class FluentTest::PluginTest3 < Fluent::Plugin::TestBase
|
16
|
+
helpers :event_loop
|
17
|
+
end
|
18
|
+
class FluentTest::PluginTest4 < Fluent::Plugin::TestBase
|
19
|
+
helpers :timer
|
20
|
+
end
|
21
|
+
class FluentTest::PluginTest5 < Fluent::Plugin::TestBase
|
22
|
+
helpers :child_process
|
23
|
+
end
|
24
|
+
class FluentTest::PluginTest6 < Fluent::Plugin::TestBase
|
25
|
+
helpers :retry_state
|
26
|
+
end
|
27
|
+
class FluentTest::PluginTest0 < Fluent::Plugin::TestBase
|
28
|
+
helpers :event_emitter, :thread, :event_loop, :timer, :child_process, :retry_state
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'plugin can include helper event_emitter' do
|
32
|
+
assert FluentTest::PluginTest1.include?(Fluent::PluginHelper::EventEmitter)
|
33
|
+
p1 = FluentTest::PluginTest1.new
|
34
|
+
assert p1.respond_to?(:has_router?)
|
35
|
+
assert p1.has_router?
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'plugin can include helper thread' do
|
39
|
+
assert FluentTest::PluginTest2.include?(Fluent::PluginHelper::Thread)
|
40
|
+
p2 = FluentTest::PluginTest2.new
|
41
|
+
assert p2.respond_to?(:thread_current_running?)
|
42
|
+
assert p2.respond_to?(:thread_create)
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'plugin can include helper event_loop' do
|
46
|
+
assert FluentTest::PluginTest3.include?(Fluent::PluginHelper::EventLoop)
|
47
|
+
p3 = FluentTest::PluginTest3.new
|
48
|
+
assert p3.respond_to?(:event_loop_attach)
|
49
|
+
assert p3.respond_to?(:event_loop_running?)
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'plugin can include helper timer' do
|
53
|
+
assert FluentTest::PluginTest4.include?(Fluent::PluginHelper::Timer)
|
54
|
+
p4 = FluentTest::PluginTest4.new
|
55
|
+
assert p4.respond_to?(:timer_execute)
|
56
|
+
end
|
57
|
+
|
58
|
+
test 'plugin can include helper child_process' do
|
59
|
+
assert FluentTest::PluginTest5.include?(Fluent::PluginHelper::ChildProcess)
|
60
|
+
p5 = FluentTest::PluginTest5.new
|
61
|
+
assert p5.respond_to?(:child_process_execute)
|
62
|
+
end
|
63
|
+
|
64
|
+
test 'plugin can 2 or more helpers at once' do
|
65
|
+
assert FluentTest::PluginTest0.include?(Fluent::PluginHelper::EventEmitter)
|
66
|
+
assert FluentTest::PluginTest0.include?(Fluent::PluginHelper::Thread)
|
67
|
+
assert FluentTest::PluginTest0.include?(Fluent::PluginHelper::EventLoop)
|
68
|
+
assert FluentTest::PluginTest0.include?(Fluent::PluginHelper::Timer)
|
69
|
+
assert FluentTest::PluginTest0.include?(Fluent::PluginHelper::ChildProcess)
|
70
|
+
|
71
|
+
p0 = FluentTest::PluginTest0.new
|
72
|
+
assert p0.respond_to?(:child_process_execute)
|
73
|
+
assert p0.respond_to?(:timer_execute)
|
74
|
+
assert p0.respond_to?(:event_loop_attach)
|
75
|
+
assert p0.respond_to?(:event_loop_running?)
|
76
|
+
assert p0.respond_to?(:thread_current_running?)
|
77
|
+
assert p0.respond_to?(:thread_create)
|
78
|
+
assert p0.respond_to?(:has_router?)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/test/test_root_agent.rb
CHANGED
@@ -8,7 +8,7 @@ class RootAgentTest < ::Test::Unit::TestCase
|
|
8
8
|
include FluentTest
|
9
9
|
|
10
10
|
def test_initialize
|
11
|
-
ra = RootAgent.new
|
11
|
+
ra = RootAgent.new(log: $log)
|
12
12
|
assert_equal 0, ra.instance_variable_get(:@suppress_emit_error_log_interval)
|
13
13
|
assert_nil ra.instance_variable_get(:@next_emit_error_log_time)
|
14
14
|
end
|
@@ -19,7 +19,7 @@ class RootAgentTest < ::Test::Unit::TestCase
|
|
19
19
|
)
|
20
20
|
def test_initialize_with_opt(data)
|
21
21
|
opt, expected = data
|
22
|
-
ra = RootAgent.new(SystemConfig.new(opt))
|
22
|
+
ra = RootAgent.new(log: $log, system_config: SystemConfig.new(opt))
|
23
23
|
expected.each { |k, v|
|
24
24
|
assert_equal v, ra.instance_variable_get(k)
|
25
25
|
}
|
@@ -27,7 +27,7 @@ class RootAgentTest < ::Test::Unit::TestCase
|
|
27
27
|
|
28
28
|
sub_test_case 'configure' do
|
29
29
|
setup do
|
30
|
-
@ra = RootAgent.new
|
30
|
+
@ra = RootAgent.new(log: $log)
|
31
31
|
stub(Engine).root_agent { @ra }
|
32
32
|
end
|
33
33
|
|
@@ -43,55 +43,10 @@ class RootAgentTest < ::Test::Unit::TestCase
|
|
43
43
|
assert_empty ra.labels
|
44
44
|
assert_empty ra.outputs
|
45
45
|
assert_empty ra.filters
|
46
|
-
[:@started_inputs, :@started_outputs, :@started_filters].each { |k|
|
47
|
-
assert_empty ra.instance_variable_get(k)
|
48
|
-
}
|
49
46
|
assert_nil ra.context
|
50
47
|
assert_nil ra.error_collector
|
51
48
|
end
|
52
49
|
|
53
|
-
test 'raises configuration error for missing type of source' do
|
54
|
-
conf = <<-EOC
|
55
|
-
<source>
|
56
|
-
</source>
|
57
|
-
EOC
|
58
|
-
errmsg = "Missing '@type' parameter on <source> directive"
|
59
|
-
assert_raise Fluent::ConfigError.new(errmsg) do
|
60
|
-
configure_ra(conf)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
test 'raises configuration error for missing type of match' do
|
65
|
-
conf = <<-EOC
|
66
|
-
<source>
|
67
|
-
@type test_in
|
68
|
-
</source>
|
69
|
-
<match *.**>
|
70
|
-
</match>
|
71
|
-
EOC
|
72
|
-
errmsg = "Missing '@type' parameter on <match> directive"
|
73
|
-
assert_raise Fluent::ConfigError.new(errmsg) do
|
74
|
-
configure_ra(conf)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
test 'raises configuration error for missing type of filter' do
|
79
|
-
conf = <<-EOC
|
80
|
-
<source>
|
81
|
-
@type test_in
|
82
|
-
</source>
|
83
|
-
<filter *.**>
|
84
|
-
</filter>
|
85
|
-
<match *.**>
|
86
|
-
@type test_out
|
87
|
-
</match>
|
88
|
-
EOC
|
89
|
-
errmsg = "Missing '@type' parameter on <filter> directive"
|
90
|
-
assert_raise Fluent::ConfigError.new(errmsg) do
|
91
|
-
configure_ra(conf)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
50
|
test 'with plugins' do
|
96
51
|
# check @type and type in one configuration
|
97
52
|
conf = <<-EOC
|
@@ -124,9 +79,6 @@ EOC
|
|
124
79
|
assert_kind_of FluentTestInput, ra.inputs.first
|
125
80
|
assert_kind_of RelabelOutput, ra.outputs.first
|
126
81
|
assert_kind_of FluentTestFilter, ra.filters.first
|
127
|
-
[:@started_inputs, :@started_outputs, :@started_filters].each { |k|
|
128
|
-
assert_empty ra.instance_variable_get(k)
|
129
|
-
}
|
130
82
|
assert ra.error_collector
|
131
83
|
|
132
84
|
%W(@test @ERROR).each { |label_symbol|
|
@@ -146,7 +98,7 @@ EOC
|
|
146
98
|
|
147
99
|
sub_test_case 'start/shutdown' do
|
148
100
|
setup do
|
149
|
-
@ra = RootAgent.new
|
101
|
+
@ra = RootAgent.new(log: $log)
|
150
102
|
@ra.configure(Config.parse(<<-EOC, "(test)", "(test_dir)", true))
|
151
103
|
<source>
|
152
104
|
@type test_in
|
@@ -0,0 +1,272 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require 'fluent/event_router'
|
3
|
+
require 'fluent/system_config'
|
4
|
+
require 'fluent/supervisor'
|
5
|
+
require_relative 'test_plugin_classes'
|
6
|
+
|
7
|
+
require 'net/http'
|
8
|
+
require 'uri'
|
9
|
+
require 'fileutils'
|
10
|
+
|
11
|
+
class SupervisorTest < ::Test::Unit::TestCase
|
12
|
+
include Fluent
|
13
|
+
include FluentTest
|
14
|
+
include ServerModule
|
15
|
+
include WorkerModule
|
16
|
+
|
17
|
+
TMP_DIR = File.dirname(__FILE__) + "/tmp/config#{ENV['TEST_ENV_NUMBER']}"
|
18
|
+
|
19
|
+
def setup
|
20
|
+
FileUtils.mkdir_p('test/tmp/supervisor')
|
21
|
+
end
|
22
|
+
|
23
|
+
def write_config(path, data)
|
24
|
+
FileUtils.mkdir_p(File.dirname(path))
|
25
|
+
File.open(path, "w") {|f| f.write data }
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_initialize
|
29
|
+
opts = Fluent::Supervisor.default_options
|
30
|
+
sv = Fluent::Supervisor.new(opts)
|
31
|
+
opts.each { |k, v|
|
32
|
+
assert_equal v, sv.instance_variable_get("@#{k}")
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_read_config
|
37
|
+
create_info_dummy_logger
|
38
|
+
|
39
|
+
tmp_dir = "#{TMP_DIR}/dir/test_read_config.conf"
|
40
|
+
conf_str = %[
|
41
|
+
<source>
|
42
|
+
@type forward
|
43
|
+
@id forward_input
|
44
|
+
</source>
|
45
|
+
<match debug.**>
|
46
|
+
@type stdout
|
47
|
+
@id stdout_output
|
48
|
+
</match>
|
49
|
+
]
|
50
|
+
write_config tmp_dir, conf_str
|
51
|
+
opts = Fluent::Supervisor.default_options
|
52
|
+
sv = Fluent::Supervisor.new(opts)
|
53
|
+
|
54
|
+
use_v1_config = {}
|
55
|
+
use_v1_config['use_v1_config'] = true
|
56
|
+
|
57
|
+
sv.instance_variable_set(:@config_path, tmp_dir)
|
58
|
+
sv.instance_variable_set(:@use_v1_config, use_v1_config)
|
59
|
+
sv.send(:read_config)
|
60
|
+
|
61
|
+
conf = sv.instance_variable_get(:@conf)
|
62
|
+
|
63
|
+
elem = conf.elements.find { |e| e.name == 'source' }
|
64
|
+
assert_equal elem['@type'], "forward"
|
65
|
+
assert_equal elem['@id'], "forward_input"
|
66
|
+
|
67
|
+
elem = conf.elements.find { |e| e.name == 'match' }
|
68
|
+
assert_equal elem.arg, "debug.**"
|
69
|
+
assert_equal elem['@type'], "stdout"
|
70
|
+
assert_equal elem['@id'], "stdout_output"
|
71
|
+
|
72
|
+
$log.out.reset
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_system_config
|
76
|
+
opts = Fluent::Supervisor.default_options
|
77
|
+
sv = Fluent::Supervisor.new(opts)
|
78
|
+
conf_data = <<-EOC
|
79
|
+
<system>
|
80
|
+
rpc_endpoint 127.0.0.1:24445
|
81
|
+
suppress_repeated_stacktrace true
|
82
|
+
suppress_config_dump true
|
83
|
+
without_source true
|
84
|
+
enable_get_dump true
|
85
|
+
process_name "process_name"
|
86
|
+
log_level info
|
87
|
+
</system>
|
88
|
+
EOC
|
89
|
+
conf = Fluent::Config.parse(conf_data, "(test)", "(test_dir)", true)
|
90
|
+
sv.instance_variable_set(:@conf, conf)
|
91
|
+
sv.send(:set_system_config)
|
92
|
+
sys_conf = sv.instance_variable_get(:@system_config)
|
93
|
+
|
94
|
+
assert_equal sys_conf.rpc_endpoint, '127.0.0.1:24445'
|
95
|
+
assert_equal sys_conf.suppress_repeated_stacktrace, true
|
96
|
+
assert_equal sys_conf.suppress_config_dump, true
|
97
|
+
assert_equal sys_conf.without_source, true
|
98
|
+
assert_equal sys_conf.enable_get_dump, true
|
99
|
+
assert_equal sys_conf.process_name, "process_name"
|
100
|
+
assert_equal sys_conf.log_level, 2
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_main_process_signal_handlers
|
104
|
+
create_info_dummy_logger
|
105
|
+
|
106
|
+
unless Fluent.windows?
|
107
|
+
opts = Fluent::Supervisor.default_options
|
108
|
+
sv = Fluent::Supervisor.new(opts)
|
109
|
+
sv.send(:install_main_process_signal_handlers)
|
110
|
+
|
111
|
+
begin
|
112
|
+
Process.kill :USR1, $$
|
113
|
+
rescue
|
114
|
+
end
|
115
|
+
|
116
|
+
sleep 1
|
117
|
+
|
118
|
+
info_msg = '[info]: force flushing buffered events' + "\n"
|
119
|
+
assert{ $log.out.logs.first.end_with?(info_msg) }
|
120
|
+
end
|
121
|
+
|
122
|
+
$log.out.reset
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_supervisor_signal_handler
|
126
|
+
create_debug_dummy_logger
|
127
|
+
|
128
|
+
unless Fluent.windows?
|
129
|
+
|
130
|
+
install_supervisor_signal_handlers
|
131
|
+
begin
|
132
|
+
Process.kill :USR1, $$
|
133
|
+
rescue
|
134
|
+
end
|
135
|
+
|
136
|
+
sleep 1
|
137
|
+
|
138
|
+
debug_msg = '[debug]: fluentd supervisor process get SIGUSR1' + "\n"
|
139
|
+
assert{ $log.out.logs.first.end_with?(debug_msg) }
|
140
|
+
end
|
141
|
+
|
142
|
+
$log.out.reset
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_rpc_server
|
146
|
+
create_info_dummy_logger
|
147
|
+
|
148
|
+
unless Fluent.windows?
|
149
|
+
opts = Fluent::Supervisor.default_options
|
150
|
+
sv = Fluent::Supervisor.new(opts)
|
151
|
+
conf_data = <<-EOC
|
152
|
+
<system>
|
153
|
+
rpc_endpoint 0.0.0.0:24447
|
154
|
+
</system>
|
155
|
+
EOC
|
156
|
+
conf = Fluent::Config.parse(conf_data, "(test)", "(test_dir)", true)
|
157
|
+
sv.instance_variable_set(:@conf, conf)
|
158
|
+
sv.send(:set_system_config)
|
159
|
+
sys_conf = sv.instance_variable_get(:@system_config)
|
160
|
+
@rpc_endpoint = sys_conf.rpc_endpoint
|
161
|
+
@enable_get_dump = sys_conf.enable_get_dump
|
162
|
+
|
163
|
+
run_rpc_server
|
164
|
+
|
165
|
+
sv.send(:install_main_process_signal_handlers)
|
166
|
+
Net::HTTP.get URI.parse('http://0.0.0.0:24447/api/plugins.flushBuffers')
|
167
|
+
info_msg = '[info]: force flushing buffered events' + "\n"
|
168
|
+
|
169
|
+
stop_rpc_server
|
170
|
+
|
171
|
+
# In TravisCI with OSX(Xcode), it seems that can't use rpc server.
|
172
|
+
# This test will be passed in such environment.
|
173
|
+
pend unless $log.out.logs.first
|
174
|
+
|
175
|
+
assert{ $log.out.logs.first.end_with?(info_msg) }
|
176
|
+
end
|
177
|
+
|
178
|
+
$log.out.reset
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_load_config
|
182
|
+
tmp_dir = "#{TMP_DIR}/dir/test_load_config.conf"
|
183
|
+
conf_info_str = %[
|
184
|
+
<system>
|
185
|
+
log_level info
|
186
|
+
</system>
|
187
|
+
]
|
188
|
+
conf_debug_str = %[
|
189
|
+
<system>
|
190
|
+
log_level debug
|
191
|
+
</system>
|
192
|
+
]
|
193
|
+
write_config tmp_dir, conf_info_str
|
194
|
+
|
195
|
+
params = {}
|
196
|
+
params['use_v1_config'] = true
|
197
|
+
params['log_path'] = 'test/tmp/supervisor/log'
|
198
|
+
params['suppress_repeated_stacktrace'] = true
|
199
|
+
params['log_level'] = Fluent::Log::LEVEL_INFO
|
200
|
+
load_config_proc = Proc.new { Fluent::Supervisor.load_config(tmp_dir, params) }
|
201
|
+
|
202
|
+
# first call
|
203
|
+
se_config = load_config_proc.call
|
204
|
+
assert_equal se_config[:log_level], Fluent::Log::LEVEL_INFO
|
205
|
+
assert_equal se_config[:suppress_repeated_stacktrace], true
|
206
|
+
assert_equal se_config[:worker_type], 'spawn'
|
207
|
+
assert_equal se_config[:workers], 1
|
208
|
+
assert_equal se_config[:log_stdin], false
|
209
|
+
assert_equal se_config[:log_stdout], false
|
210
|
+
assert_equal se_config[:log_stderr], false
|
211
|
+
assert_equal se_config[:enable_heartbeat], true
|
212
|
+
assert_equal se_config[:auto_heartbeat], false
|
213
|
+
|
214
|
+
# second call immediately(reuse config)
|
215
|
+
se_config = load_config_proc.call
|
216
|
+
pre_config_mtime = se_config[:windows_daemon_cmdline][5]['pre_config_mtime']
|
217
|
+
pre_loadtime = se_config[:windows_daemon_cmdline][5]['pre_loadtime']
|
218
|
+
assert_nil pre_config_mtime
|
219
|
+
assert_nil pre_loadtime
|
220
|
+
|
221
|
+
sleep 5
|
222
|
+
|
223
|
+
# third call after 5 seconds(don't reuse config)
|
224
|
+
se_config = load_config_proc.call
|
225
|
+
pre_config_mtime = se_config[:windows_daemon_cmdline][5]['pre_config_mtime']
|
226
|
+
pre_loadtime = se_config[:windows_daemon_cmdline][5]['pre_loadtime']
|
227
|
+
assert_not_nil pre_config_mtime
|
228
|
+
assert_not_nil pre_loadtime
|
229
|
+
|
230
|
+
# forth call immediately(reuse config)
|
231
|
+
se_config = load_config_proc.call
|
232
|
+
# test that pre_config_mtime and pre_loadtime are not changed from previous one because reused pre_config
|
233
|
+
assert_equal se_config[:windows_daemon_cmdline][5]['pre_config_mtime'], pre_config_mtime
|
234
|
+
assert_equal se_config[:windows_daemon_cmdline][5]['pre_loadtime'], pre_loadtime
|
235
|
+
|
236
|
+
write_config tmp_dir, conf_debug_str
|
237
|
+
|
238
|
+
# fifth call after changed conf file(don't reuse config)
|
239
|
+
se_config = load_config_proc.call
|
240
|
+
assert_equal se_config[:log_level], Fluent::Log::LEVEL_DEBUG
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_logger
|
244
|
+
opts = Fluent::Supervisor.default_options
|
245
|
+
sv = Fluent::Supervisor.new(opts)
|
246
|
+
log = sv.instance_variable_get(:@log)
|
247
|
+
log.init
|
248
|
+
logger = $log.instance_variable_get(:@logger)
|
249
|
+
|
250
|
+
assert_equal $log.level, Fluent::Log::LEVEL_INFO
|
251
|
+
|
252
|
+
# test that DamonLogger#level= overwrites Fluent.log#level
|
253
|
+
logger.level = 'debug'
|
254
|
+
assert_equal $log.level, Fluent::Log::LEVEL_DEBUG
|
255
|
+
end
|
256
|
+
|
257
|
+
def create_debug_dummy_logger
|
258
|
+
dl_opts = {}
|
259
|
+
dl_opts[:log_level] = ServerEngine::DaemonLogger::DEBUG
|
260
|
+
logdev = Fluent::Test::DummyLogDevice.new
|
261
|
+
logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
|
262
|
+
$log = Fluent::Log.new(logger)
|
263
|
+
end
|
264
|
+
|
265
|
+
def create_info_dummy_logger
|
266
|
+
dl_opts = {}
|
267
|
+
dl_opts[:log_level] = ServerEngine::DaemonLogger::INFO
|
268
|
+
logdev = Fluent::Test::DummyLogDevice.new
|
269
|
+
logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
|
270
|
+
$log = Fluent::Log.new(logger)
|
271
|
+
end
|
272
|
+
end
|