fluentd-hubspot 0.14.14.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.github/ISSUE_TEMPLATE.md +6 -0
- data/.gitignore +28 -0
- data/.travis.yml +51 -0
- data/AUTHORS +2 -0
- data/CONTRIBUTING.md +42 -0
- data/COPYING +14 -0
- data/ChangeLog +593 -0
- data/Gemfile +9 -0
- data/README.md +76 -0
- data/Rakefile +74 -0
- data/Vagrantfile +17 -0
- data/appveyor.yml +43 -0
- data/bin/fluent-binlog-reader +7 -0
- data/bin/fluent-debug +5 -0
- data/bin/fluent-plugin-config-format +5 -0
- data/bin/fluent-plugin-generate +5 -0
- data/code-of-conduct.md +3 -0
- data/example/copy_roundrobin.conf +39 -0
- data/example/filter_stdout.conf +22 -0
- data/example/in_dummy_blocks.conf +17 -0
- data/example/in_dummy_with_compression.conf +23 -0
- data/example/in_forward.conf +14 -0
- data/example/in_forward_client.conf +37 -0
- data/example/in_forward_shared_key.conf +15 -0
- data/example/in_forward_tls.conf +14 -0
- data/example/in_forward_users.conf +24 -0
- data/example/in_forward_workers.conf +21 -0
- data/example/in_http.conf +14 -0
- data/example/in_out_forward.conf +17 -0
- data/example/in_syslog.conf +15 -0
- data/example/in_tail.conf +14 -0
- data/example/in_tcp.conf +13 -0
- data/example/in_udp.conf +13 -0
- data/example/logevents.conf +25 -0
- data/example/multi_filters.conf +61 -0
- data/example/out_copy.conf +20 -0
- data/example/out_exec_filter.conf +42 -0
- data/example/out_file.conf +13 -0
- data/example/out_forward.conf +35 -0
- data/example/out_forward_buf_file.conf +23 -0
- data/example/out_forward_client.conf +109 -0
- data/example/out_forward_heartbeat_none.conf +16 -0
- data/example/out_forward_shared_key.conf +36 -0
- data/example/out_forward_tls.conf +18 -0
- data/example/out_forward_users.conf +65 -0
- data/example/out_null.conf +36 -0
- data/example/secondary_file.conf +41 -0
- data/example/suppress_config_dump.conf +7 -0
- data/example/v0_12_filter.conf +78 -0
- data/example/v1_literal_example.conf +36 -0
- data/fluent.conf +139 -0
- data/fluentd.gemspec +51 -0
- data/lib/fluent/agent.rb +163 -0
- data/lib/fluent/clock.rb +62 -0
- data/lib/fluent/command/binlog_reader.rb +234 -0
- data/lib/fluent/command/bundler_injection.rb +45 -0
- data/lib/fluent/command/cat.rb +330 -0
- data/lib/fluent/command/debug.rb +102 -0
- data/lib/fluent/command/fluentd.rb +301 -0
- data/lib/fluent/command/plugin_config_formatter.rb +258 -0
- data/lib/fluent/command/plugin_generator.rb +301 -0
- data/lib/fluent/compat/call_super_mixin.rb +67 -0
- data/lib/fluent/compat/detach_process_mixin.rb +25 -0
- data/lib/fluent/compat/exec_util.rb +129 -0
- data/lib/fluent/compat/file_util.rb +54 -0
- data/lib/fluent/compat/filter.rb +68 -0
- data/lib/fluent/compat/formatter.rb +111 -0
- data/lib/fluent/compat/formatter_utils.rb +85 -0
- data/lib/fluent/compat/handle_tag_and_time_mixin.rb +62 -0
- data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
- data/lib/fluent/compat/input.rb +59 -0
- data/lib/fluent/compat/output.rb +728 -0
- data/lib/fluent/compat/output_chain.rb +60 -0
- data/lib/fluent/compat/parser.rb +310 -0
- data/lib/fluent/compat/parser_utils.rb +40 -0
- data/lib/fluent/compat/propagate_default.rb +62 -0
- data/lib/fluent/compat/record_filter_mixin.rb +34 -0
- data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
- data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
- data/lib/fluent/compat/socket_util.rb +165 -0
- data/lib/fluent/compat/string_util.rb +34 -0
- data/lib/fluent/compat/structured_format_mixin.rb +26 -0
- data/lib/fluent/compat/type_converter.rb +90 -0
- data/lib/fluent/config.rb +56 -0
- data/lib/fluent/config/basic_parser.rb +123 -0
- data/lib/fluent/config/configure_proxy.rb +418 -0
- data/lib/fluent/config/dsl.rb +149 -0
- data/lib/fluent/config/element.rb +218 -0
- data/lib/fluent/config/error.rb +26 -0
- data/lib/fluent/config/literal_parser.rb +251 -0
- data/lib/fluent/config/parser.rb +107 -0
- data/lib/fluent/config/section.rb +223 -0
- data/lib/fluent/config/types.rb +136 -0
- data/lib/fluent/config/v1_parser.rb +190 -0
- data/lib/fluent/configurable.rb +200 -0
- data/lib/fluent/daemon.rb +15 -0
- data/lib/fluent/engine.rb +266 -0
- data/lib/fluent/env.rb +28 -0
- data/lib/fluent/error.rb +30 -0
- data/lib/fluent/event.rb +334 -0
- data/lib/fluent/event_router.rb +269 -0
- data/lib/fluent/filter.rb +21 -0
- data/lib/fluent/formatter.rb +23 -0
- data/lib/fluent/input.rb +21 -0
- data/lib/fluent/label.rb +46 -0
- data/lib/fluent/load.rb +35 -0
- data/lib/fluent/log.rb +546 -0
- data/lib/fluent/match.rb +178 -0
- data/lib/fluent/mixin.rb +31 -0
- data/lib/fluent/msgpack_factory.rb +62 -0
- data/lib/fluent/output.rb +29 -0
- data/lib/fluent/output_chain.rb +23 -0
- data/lib/fluent/parser.rb +23 -0
- data/lib/fluent/plugin.rb +183 -0
- data/lib/fluent/plugin/bare_output.rb +63 -0
- data/lib/fluent/plugin/base.rb +165 -0
- data/lib/fluent/plugin/buf_file.rb +184 -0
- data/lib/fluent/plugin/buf_memory.rb +34 -0
- data/lib/fluent/plugin/buffer.rb +617 -0
- data/lib/fluent/plugin/buffer/chunk.rb +221 -0
- data/lib/fluent/plugin/buffer/file_chunk.rb +364 -0
- data/lib/fluent/plugin/buffer/memory_chunk.rb +90 -0
- data/lib/fluent/plugin/compressable.rb +92 -0
- data/lib/fluent/plugin/exec_util.rb +22 -0
- data/lib/fluent/plugin/file_util.rb +22 -0
- data/lib/fluent/plugin/file_wrapper.rb +120 -0
- data/lib/fluent/plugin/filter.rb +93 -0
- data/lib/fluent/plugin/filter_grep.rb +75 -0
- data/lib/fluent/plugin/filter_parser.rb +119 -0
- data/lib/fluent/plugin/filter_record_transformer.rb +322 -0
- data/lib/fluent/plugin/filter_stdout.rb +53 -0
- data/lib/fluent/plugin/formatter.rb +50 -0
- data/lib/fluent/plugin/formatter_csv.rb +52 -0
- data/lib/fluent/plugin/formatter_hash.rb +33 -0
- data/lib/fluent/plugin/formatter_json.rb +55 -0
- data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
- data/lib/fluent/plugin/formatter_msgpack.rb +33 -0
- data/lib/fluent/plugin/formatter_out_file.rb +51 -0
- data/lib/fluent/plugin/formatter_single_value.rb +34 -0
- data/lib/fluent/plugin/formatter_stdout.rb +75 -0
- data/lib/fluent/plugin/formatter_tsv.rb +34 -0
- data/lib/fluent/plugin/in_debug_agent.rb +64 -0
- data/lib/fluent/plugin/in_dummy.rb +139 -0
- data/lib/fluent/plugin/in_exec.rb +108 -0
- data/lib/fluent/plugin/in_forward.rb +455 -0
- data/lib/fluent/plugin/in_gc_stat.rb +56 -0
- data/lib/fluent/plugin/in_http.rb +433 -0
- data/lib/fluent/plugin/in_monitor_agent.rb +448 -0
- data/lib/fluent/plugin/in_object_space.rb +93 -0
- data/lib/fluent/plugin/in_syslog.rb +209 -0
- data/lib/fluent/plugin/in_tail.rb +905 -0
- data/lib/fluent/plugin/in_tcp.rb +85 -0
- data/lib/fluent/plugin/in_udp.rb +81 -0
- data/lib/fluent/plugin/in_unix.rb +201 -0
- data/lib/fluent/plugin/input.rb +37 -0
- data/lib/fluent/plugin/multi_output.rb +157 -0
- data/lib/fluent/plugin/out_copy.rb +46 -0
- data/lib/fluent/plugin/out_exec.rb +105 -0
- data/lib/fluent/plugin/out_exec_filter.rb +317 -0
- data/lib/fluent/plugin/out_file.rb +302 -0
- data/lib/fluent/plugin/out_forward.rb +912 -0
- data/lib/fluent/plugin/out_null.rb +74 -0
- data/lib/fluent/plugin/out_relabel.rb +32 -0
- data/lib/fluent/plugin/out_roundrobin.rb +84 -0
- data/lib/fluent/plugin/out_secondary_file.rb +133 -0
- data/lib/fluent/plugin/out_stdout.rb +75 -0
- data/lib/fluent/plugin/out_stream.rb +130 -0
- data/lib/fluent/plugin/output.rb +1291 -0
- data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
- data/lib/fluent/plugin/parser.rb +191 -0
- data/lib/fluent/plugin/parser_apache.rb +28 -0
- data/lib/fluent/plugin/parser_apache2.rb +84 -0
- data/lib/fluent/plugin/parser_apache_error.rb +26 -0
- data/lib/fluent/plugin/parser_csv.rb +39 -0
- data/lib/fluent/plugin/parser_json.rb +81 -0
- data/lib/fluent/plugin/parser_ltsv.rb +42 -0
- data/lib/fluent/plugin/parser_msgpack.rb +50 -0
- data/lib/fluent/plugin/parser_multiline.rb +105 -0
- data/lib/fluent/plugin/parser_nginx.rb +28 -0
- data/lib/fluent/plugin/parser_none.rb +36 -0
- data/lib/fluent/plugin/parser_regexp.rb +63 -0
- data/lib/fluent/plugin/parser_syslog.rb +121 -0
- data/lib/fluent/plugin/parser_tsv.rb +42 -0
- data/lib/fluent/plugin/socket_util.rb +22 -0
- data/lib/fluent/plugin/storage.rb +84 -0
- data/lib/fluent/plugin/storage_local.rb +159 -0
- data/lib/fluent/plugin/string_util.rb +22 -0
- data/lib/fluent/plugin_helper.rb +70 -0
- data/lib/fluent/plugin_helper/cert_option.rb +159 -0
- data/lib/fluent/plugin_helper/child_process.rb +364 -0
- data/lib/fluent/plugin_helper/compat_parameters.rb +331 -0
- data/lib/fluent/plugin_helper/event_emitter.rb +93 -0
- data/lib/fluent/plugin_helper/event_loop.rb +161 -0
- data/lib/fluent/plugin_helper/extract.rb +104 -0
- data/lib/fluent/plugin_helper/formatter.rb +147 -0
- data/lib/fluent/plugin_helper/inject.rb +151 -0
- data/lib/fluent/plugin_helper/parser.rb +147 -0
- data/lib/fluent/plugin_helper/retry_state.rb +201 -0
- data/lib/fluent/plugin_helper/server.rb +738 -0
- data/lib/fluent/plugin_helper/socket.rb +241 -0
- data/lib/fluent/plugin_helper/socket_option.rb +69 -0
- data/lib/fluent/plugin_helper/storage.rb +349 -0
- data/lib/fluent/plugin_helper/thread.rb +179 -0
- data/lib/fluent/plugin_helper/timer.rb +91 -0
- data/lib/fluent/plugin_id.rb +80 -0
- data/lib/fluent/process.rb +22 -0
- data/lib/fluent/registry.rb +116 -0
- data/lib/fluent/root_agent.rb +323 -0
- data/lib/fluent/rpc.rb +94 -0
- data/lib/fluent/supervisor.rb +741 -0
- data/lib/fluent/system_config.rb +159 -0
- data/lib/fluent/test.rb +58 -0
- data/lib/fluent/test/base.rb +78 -0
- data/lib/fluent/test/driver/base.rb +224 -0
- data/lib/fluent/test/driver/base_owned.rb +70 -0
- data/lib/fluent/test/driver/base_owner.rb +135 -0
- data/lib/fluent/test/driver/event_feeder.rb +98 -0
- data/lib/fluent/test/driver/filter.rb +57 -0
- data/lib/fluent/test/driver/formatter.rb +30 -0
- data/lib/fluent/test/driver/input.rb +31 -0
- data/lib/fluent/test/driver/multi_output.rb +53 -0
- data/lib/fluent/test/driver/output.rb +102 -0
- data/lib/fluent/test/driver/parser.rb +30 -0
- data/lib/fluent/test/driver/test_event_router.rb +45 -0
- data/lib/fluent/test/filter_test.rb +77 -0
- data/lib/fluent/test/formatter_test.rb +65 -0
- data/lib/fluent/test/helpers.rb +134 -0
- data/lib/fluent/test/input_test.rb +174 -0
- data/lib/fluent/test/log.rb +79 -0
- data/lib/fluent/test/output_test.rb +156 -0
- data/lib/fluent/test/parser_test.rb +70 -0
- data/lib/fluent/test/startup_shutdown.rb +46 -0
- data/lib/fluent/time.rb +412 -0
- data/lib/fluent/timezone.rb +133 -0
- data/lib/fluent/unique_id.rb +39 -0
- data/lib/fluent/version.rb +21 -0
- data/lib/fluent/winsvc.rb +71 -0
- data/templates/new_gem/Gemfile +3 -0
- data/templates/new_gem/README.md.erb +43 -0
- data/templates/new_gem/Rakefile +13 -0
- data/templates/new_gem/fluent-plugin.gemspec.erb +27 -0
- data/templates/new_gem/lib/fluent/plugin/filter.rb.erb +14 -0
- data/templates/new_gem/lib/fluent/plugin/formatter.rb.erb +14 -0
- data/templates/new_gem/lib/fluent/plugin/input.rb.erb +11 -0
- data/templates/new_gem/lib/fluent/plugin/output.rb.erb +11 -0
- data/templates/new_gem/lib/fluent/plugin/parser.rb.erb +15 -0
- data/templates/new_gem/test/helper.rb.erb +8 -0
- data/templates/new_gem/test/plugin/test_filter.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_formatter.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_input.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_output.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_parser.rb.erb +18 -0
- data/templates/plugin_config_formatter/param.md-compact.erb +25 -0
- data/templates/plugin_config_formatter/param.md.erb +34 -0
- data/templates/plugin_config_formatter/section.md.erb +12 -0
- data/test/command/test_binlog_reader.rb +346 -0
- data/test/command/test_fluentd.rb +618 -0
- data/test/command/test_plugin_config_formatter.rb +275 -0
- data/test/command/test_plugin_generator.rb +66 -0
- data/test/compat/test_calls_super.rb +166 -0
- data/test/compat/test_parser.rb +92 -0
- data/test/config/assertions.rb +42 -0
- data/test/config/test_config_parser.rb +513 -0
- data/test/config/test_configurable.rb +1587 -0
- data/test/config/test_configure_proxy.rb +566 -0
- data/test/config/test_dsl.rb +415 -0
- data/test/config/test_element.rb +403 -0
- data/test/config/test_literal_parser.rb +297 -0
- data/test/config/test_section.rb +184 -0
- data/test/config/test_system_config.rb +168 -0
- data/test/config/test_types.rb +191 -0
- data/test/helper.rb +153 -0
- data/test/plugin/data/2010/01/20100102-030405.log +0 -0
- data/test/plugin/data/2010/01/20100102-030406.log +0 -0
- data/test/plugin/data/2010/01/20100102.log +0 -0
- data/test/plugin/data/log/bar +0 -0
- data/test/plugin/data/log/foo/bar.log +0 -0
- data/test/plugin/data/log/foo/bar2 +0 -0
- data/test/plugin/data/log/test.log +0 -0
- data/test/plugin/test_bare_output.rb +118 -0
- data/test/plugin/test_base.rb +115 -0
- data/test/plugin/test_buf_file.rb +843 -0
- data/test/plugin/test_buf_memory.rb +42 -0
- data/test/plugin/test_buffer.rb +1220 -0
- data/test/plugin/test_buffer_chunk.rb +198 -0
- data/test/plugin/test_buffer_file_chunk.rb +844 -0
- data/test/plugin/test_buffer_memory_chunk.rb +338 -0
- data/test/plugin/test_compressable.rb +84 -0
- data/test/plugin/test_file_util.rb +96 -0
- data/test/plugin/test_filter.rb +357 -0
- data/test/plugin/test_filter_grep.rb +119 -0
- data/test/plugin/test_filter_parser.rb +700 -0
- data/test/plugin/test_filter_record_transformer.rb +556 -0
- data/test/plugin/test_filter_stdout.rb +202 -0
- data/test/plugin/test_formatter_csv.rb +111 -0
- data/test/plugin/test_formatter_hash.rb +35 -0
- data/test/plugin/test_formatter_json.rb +51 -0
- data/test/plugin/test_formatter_ltsv.rb +59 -0
- data/test/plugin/test_formatter_msgpack.rb +28 -0
- data/test/plugin/test_formatter_out_file.rb +95 -0
- data/test/plugin/test_formatter_single_value.rb +38 -0
- data/test/plugin/test_in_debug_agent.rb +28 -0
- data/test/plugin/test_in_dummy.rb +192 -0
- data/test/plugin/test_in_exec.rb +245 -0
- data/test/plugin/test_in_forward.rb +1120 -0
- data/test/plugin/test_in_gc_stat.rb +39 -0
- data/test/plugin/test_in_http.rb +588 -0
- data/test/plugin/test_in_monitor_agent.rb +516 -0
- data/test/plugin/test_in_object_space.rb +64 -0
- data/test/plugin/test_in_syslog.rb +271 -0
- data/test/plugin/test_in_tail.rb +1216 -0
- data/test/plugin/test_in_tcp.rb +118 -0
- data/test/plugin/test_in_udp.rb +152 -0
- data/test/plugin/test_in_unix.rb +126 -0
- data/test/plugin/test_input.rb +126 -0
- data/test/plugin/test_multi_output.rb +180 -0
- data/test/plugin/test_out_copy.rb +160 -0
- data/test/plugin/test_out_exec.rb +310 -0
- data/test/plugin/test_out_exec_filter.rb +613 -0
- data/test/plugin/test_out_file.rb +873 -0
- data/test/plugin/test_out_forward.rb +685 -0
- data/test/plugin/test_out_null.rb +105 -0
- data/test/plugin/test_out_relabel.rb +28 -0
- data/test/plugin/test_out_roundrobin.rb +146 -0
- data/test/plugin/test_out_secondary_file.rb +442 -0
- data/test/plugin/test_out_stdout.rb +170 -0
- data/test/plugin/test_out_stream.rb +93 -0
- data/test/plugin/test_output.rb +870 -0
- data/test/plugin/test_output_as_buffered.rb +1932 -0
- data/test/plugin/test_output_as_buffered_compress.rb +165 -0
- data/test/plugin/test_output_as_buffered_overflow.rb +250 -0
- data/test/plugin/test_output_as_buffered_retries.rb +839 -0
- data/test/plugin/test_output_as_buffered_secondary.rb +877 -0
- data/test/plugin/test_output_as_standard.rb +374 -0
- data/test/plugin/test_owned_by.rb +35 -0
- data/test/plugin/test_parser.rb +359 -0
- data/test/plugin/test_parser_apache.rb +42 -0
- data/test/plugin/test_parser_apache2.rb +46 -0
- data/test/plugin/test_parser_apache_error.rb +45 -0
- data/test/plugin/test_parser_csv.rb +103 -0
- data/test/plugin/test_parser_json.rb +114 -0
- data/test/plugin/test_parser_labeled_tsv.rb +128 -0
- data/test/plugin/test_parser_multiline.rb +100 -0
- data/test/plugin/test_parser_nginx.rb +48 -0
- data/test/plugin/test_parser_none.rb +52 -0
- data/test/plugin/test_parser_regexp.rb +281 -0
- data/test/plugin/test_parser_syslog.rb +242 -0
- data/test/plugin/test_parser_tsv.rb +122 -0
- data/test/plugin/test_storage.rb +167 -0
- data/test/plugin/test_storage_local.rb +335 -0
- data/test/plugin/test_string_util.rb +26 -0
- data/test/plugin_helper/test_child_process.rb +794 -0
- data/test/plugin_helper/test_compat_parameters.rb +331 -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_extract.rb +194 -0
- data/test/plugin_helper/test_formatter.rb +255 -0
- data/test/plugin_helper/test_inject.rb +519 -0
- data/test/plugin_helper/test_parser.rb +264 -0
- data/test/plugin_helper/test_retry_state.rb +422 -0
- data/test/plugin_helper/test_server.rb +1677 -0
- data/test/plugin_helper/test_storage.rb +542 -0
- data/test/plugin_helper/test_thread.rb +164 -0
- data/test/plugin_helper/test_timer.rb +132 -0
- data/test/scripts/exec_script.rb +32 -0
- data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +7 -0
- data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +7 -0
- data/test/scripts/fluent/plugin/formatter_known.rb +8 -0
- data/test/scripts/fluent/plugin/out_test.rb +81 -0
- data/test/scripts/fluent/plugin/out_test2.rb +80 -0
- data/test/scripts/fluent/plugin/parser_known.rb +4 -0
- data/test/test_clock.rb +164 -0
- data/test/test_config.rb +179 -0
- data/test/test_configdsl.rb +148 -0
- data/test/test_event.rb +515 -0
- data/test/test_event_router.rb +331 -0
- data/test/test_event_time.rb +186 -0
- data/test/test_filter.rb +121 -0
- data/test/test_formatter.rb +312 -0
- data/test/test_input.rb +31 -0
- data/test/test_log.rb +828 -0
- data/test/test_match.rb +137 -0
- data/test/test_mixin.rb +351 -0
- data/test/test_output.rb +273 -0
- data/test/test_plugin.rb +251 -0
- data/test/test_plugin_classes.rb +253 -0
- data/test/test_plugin_helper.rb +81 -0
- data/test/test_plugin_id.rb +101 -0
- data/test/test_process.rb +14 -0
- data/test/test_root_agent.rb +611 -0
- data/test/test_supervisor.rb +373 -0
- data/test/test_test_drivers.rb +135 -0
- data/test/test_time_formatter.rb +282 -0
- data/test/test_time_parser.rb +211 -0
- data/test/test_unique_id.rb +47 -0
- metadata +898 -0
@@ -0,0 +1,323 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'delegate'
|
18
|
+
|
19
|
+
require 'fluent/config/error'
|
20
|
+
require 'fluent/agent'
|
21
|
+
require 'fluent/label'
|
22
|
+
require 'fluent/plugin'
|
23
|
+
require 'fluent/system_config'
|
24
|
+
require 'fluent/time'
|
25
|
+
|
26
|
+
module Fluent
|
27
|
+
#
|
28
|
+
# Fluentd forms a tree structure to manage plugins:
|
29
|
+
#
|
30
|
+
# RootAgent
|
31
|
+
# |
|
32
|
+
# +------------+-------------+-------------+
|
33
|
+
# | | | |
|
34
|
+
# <label> <source> <filter> <match>
|
35
|
+
# |
|
36
|
+
# +----+----+
|
37
|
+
# | |
|
38
|
+
# <filter> <match>
|
39
|
+
#
|
40
|
+
# Relation:
|
41
|
+
# * RootAgent has many <label>, <source>, <filter> and <match>
|
42
|
+
# * <label> has many <match> and <filter>
|
43
|
+
#
|
44
|
+
# Next step: `fluentd/agent.rb`
|
45
|
+
# Next step: 'fluentd/label.rb'
|
46
|
+
#
|
47
|
+
class RootAgent < Agent
|
48
|
+
ERROR_LABEL = "@ERROR".freeze # @ERROR is built-in error label
|
49
|
+
|
50
|
+
def initialize(log:, system_config: SystemConfig.new)
|
51
|
+
super(log: log)
|
52
|
+
|
53
|
+
@labels = {}
|
54
|
+
@inputs = []
|
55
|
+
@suppress_emit_error_log_interval = 0
|
56
|
+
@next_emit_error_log_time = nil
|
57
|
+
@without_source = false
|
58
|
+
|
59
|
+
suppress_interval(system_config.emit_error_log_interval) unless system_config.emit_error_log_interval.nil?
|
60
|
+
@without_source = system_config.without_source unless system_config.without_source.nil?
|
61
|
+
end
|
62
|
+
|
63
|
+
attr_reader :inputs
|
64
|
+
attr_reader :labels
|
65
|
+
|
66
|
+
def configure(conf)
|
67
|
+
error_label_config = nil
|
68
|
+
|
69
|
+
# initialize <label> elements before configuring all plugins to avoid 'label not found' in input, filter and output.
|
70
|
+
label_configs = {}
|
71
|
+
conf.elements(name: 'label').each { |e|
|
72
|
+
name = e.arg
|
73
|
+
raise ConfigError, "Missing symbol argument on <label> directive" if name.empty?
|
74
|
+
|
75
|
+
if name == ERROR_LABEL
|
76
|
+
error_label_config = e
|
77
|
+
else
|
78
|
+
add_label(name)
|
79
|
+
label_configs[name] = e
|
80
|
+
end
|
81
|
+
}
|
82
|
+
# Call 'configure' here to avoid 'label not found'
|
83
|
+
label_configs.each { |name, e| @labels[name].configure(e) }
|
84
|
+
setup_error_label(error_label_config) if error_label_config
|
85
|
+
|
86
|
+
super
|
87
|
+
|
88
|
+
# initialize <source> elements
|
89
|
+
if @without_source
|
90
|
+
log.info :worker0, "'--without-source' is applied. Ignore <source> sections"
|
91
|
+
else
|
92
|
+
conf.elements(name: 'source').each { |e|
|
93
|
+
type = e['@type']
|
94
|
+
raise ConfigError, "Missing '@type' parameter on <source> directive" unless type
|
95
|
+
add_source(type, e)
|
96
|
+
}
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def setup_error_label(e)
|
101
|
+
error_label = add_label(ERROR_LABEL)
|
102
|
+
error_label.configure(e)
|
103
|
+
error_label.root_agent = RootAgentProxyWithoutErrorCollector.new(self)
|
104
|
+
@error_collector = error_label.event_router
|
105
|
+
end
|
106
|
+
|
107
|
+
def lifecycle(desc: false, kind_callback: nil)
|
108
|
+
kind_or_label_list = if desc
|
109
|
+
[:output, :filter, @labels.values.reverse, :output_with_router, :input].flatten
|
110
|
+
else
|
111
|
+
[:input, :output_with_router, @labels.values, :filter, :output].flatten
|
112
|
+
end
|
113
|
+
kind_or_label_list.each do |kind|
|
114
|
+
if kind.respond_to?(:lifecycle)
|
115
|
+
label = kind
|
116
|
+
label.lifecycle(desc: desc) do |plugin, display_kind|
|
117
|
+
yield plugin, display_kind
|
118
|
+
end
|
119
|
+
else
|
120
|
+
list = if desc
|
121
|
+
lifecycle_control_list[kind].reverse
|
122
|
+
else
|
123
|
+
lifecycle_control_list[kind]
|
124
|
+
end
|
125
|
+
display_kind = (kind == :output_with_router ? :output : kind)
|
126
|
+
list.each do |instance|
|
127
|
+
yield instance, display_kind
|
128
|
+
end
|
129
|
+
end
|
130
|
+
if kind_callback
|
131
|
+
kind_callback.call
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def start
|
137
|
+
lifecycle(desc: true) do |i| # instance
|
138
|
+
i.start unless i.started?
|
139
|
+
# Input#start sometimes emits lots of evetns with in_tail/`read_from_head true` case
|
140
|
+
# and it causes deadlock for small buffer/queue output. To avoid such problem,
|
141
|
+
# buffer related output threads should be run before `Input#start`.
|
142
|
+
# This is why after_start should be called immediately after start call.
|
143
|
+
# This depends on `desc: true` because calling plugin order of `desc: true` is
|
144
|
+
# Output, Filter, Label, Output with Router, then Input.
|
145
|
+
i.after_start unless i.after_started?
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def flush!
|
150
|
+
log.info "flushing all buffer forcedly"
|
151
|
+
flushing_threads = []
|
152
|
+
lifecycle(desc: true) do |instance|
|
153
|
+
if instance.respond_to?(:force_flush)
|
154
|
+
t = Thread.new do
|
155
|
+
Thread.current.abort_on_exception = true
|
156
|
+
begin
|
157
|
+
instance.force_flush
|
158
|
+
rescue => e
|
159
|
+
log.warn "unexpected error while flushing buffer", plugin: instance.class, plugin_id: instance.plugin_id, error: e
|
160
|
+
log.warn_backtrace
|
161
|
+
end
|
162
|
+
end
|
163
|
+
flushing_threads << t
|
164
|
+
end
|
165
|
+
end
|
166
|
+
flushing_threads.each{|t| t.join }
|
167
|
+
end
|
168
|
+
|
169
|
+
def shutdown # Fluentd's shutdown sequence is stop, before_shutdown, shutdown, after_shutdown, close, terminate for plugins
|
170
|
+
# These method callers does `rescue Exception` to call methods of shutdown sequence as far as possible
|
171
|
+
# if plugin methods does something like infinite recursive call, `exit`, unregistering signal handlers or others.
|
172
|
+
# Plugins should be separated and be in sandbox to protect data in each plugins/buffers.
|
173
|
+
|
174
|
+
lifecycle_safe_sequence = ->(method, checker) {
|
175
|
+
lifecycle do |instance, kind|
|
176
|
+
begin
|
177
|
+
log.debug "calling #{method} on #{kind} plugin", type: Plugin.lookup_type_from_class(instance.class), plugin_id: instance.plugin_id
|
178
|
+
instance.send(method) unless instance.send(checker)
|
179
|
+
rescue Exception => e
|
180
|
+
log.warn "unexpected error while calling #{method} on #{kind} plugin", plugin: instance.class, plugin_id: instance.plugin_id, error: e
|
181
|
+
log.warn_backtrace
|
182
|
+
end
|
183
|
+
end
|
184
|
+
}
|
185
|
+
|
186
|
+
lifecycle_unsafe_sequence = ->(method, checker) {
|
187
|
+
operation = case method
|
188
|
+
when :before_shutdown then "preparing shutdown"
|
189
|
+
when :shutdown then "shutting down"
|
190
|
+
when :close then "closing"
|
191
|
+
else
|
192
|
+
raise "BUG: unknown method name '#{method}'"
|
193
|
+
end
|
194
|
+
operation_threads = []
|
195
|
+
callback = ->(){
|
196
|
+
operation_threads.each{|t| t.join }
|
197
|
+
operation_threads.clear
|
198
|
+
}
|
199
|
+
lifecycle(kind_callback: callback) do |instance, kind|
|
200
|
+
t = Thread.new do
|
201
|
+
Thread.current.abort_on_exception = true
|
202
|
+
begin
|
203
|
+
if method == :shutdown
|
204
|
+
log.info "#{operation} #{kind} plugin", type: Plugin.lookup_type_from_class(instance.class), plugin_id: instance.plugin_id
|
205
|
+
else
|
206
|
+
log.debug "#{operation} #{kind} plugin", type: Plugin.lookup_type_from_class(instance.class), plugin_id: instance.plugin_id
|
207
|
+
end
|
208
|
+
instance.send(method) unless instance.send(checker)
|
209
|
+
rescue Exception => e
|
210
|
+
log.warn "unexpected error while #{operation} on #{kind} plugin", plugin: instance.class, plugin_id: instance.plugin_id, error: e
|
211
|
+
log.warn_backtrace
|
212
|
+
end
|
213
|
+
end
|
214
|
+
operation_threads << t
|
215
|
+
end
|
216
|
+
}
|
217
|
+
|
218
|
+
lifecycle_safe_sequence.call(:stop, :stopped?)
|
219
|
+
|
220
|
+
# before_shutdown does force_flush for output plugins: it should block, so it's unsafe operation
|
221
|
+
lifecycle_unsafe_sequence.call(:before_shutdown, :before_shutdown?)
|
222
|
+
|
223
|
+
lifecycle_unsafe_sequence.call(:shutdown, :shutdown?)
|
224
|
+
|
225
|
+
lifecycle_safe_sequence.call(:after_shutdown, :after_shutdown?)
|
226
|
+
|
227
|
+
lifecycle_unsafe_sequence.call(:close, :closed?)
|
228
|
+
|
229
|
+
lifecycle_safe_sequence.call(:terminate, :terminated?)
|
230
|
+
end
|
231
|
+
|
232
|
+
def suppress_interval(interval_time)
|
233
|
+
@suppress_emit_error_log_interval = interval_time
|
234
|
+
@next_emit_error_log_time = Time.now.to_i
|
235
|
+
end
|
236
|
+
|
237
|
+
def add_source(type, conf)
|
238
|
+
log.info :worker0, "adding source", type: type
|
239
|
+
|
240
|
+
input = Plugin.new_input(type)
|
241
|
+
# <source> emits events to the top-level event router (RootAgent#event_router).
|
242
|
+
# Input#configure overwrites event_router to a label's event_router if it has `@label` parameter.
|
243
|
+
# See also 'fluentd/plugin/input.rb'
|
244
|
+
input.context_router = @event_router
|
245
|
+
input.configure(conf)
|
246
|
+
@inputs << input
|
247
|
+
|
248
|
+
input
|
249
|
+
end
|
250
|
+
|
251
|
+
def add_label(name)
|
252
|
+
label = Label.new(name, log: log)
|
253
|
+
raise ConfigError, "Section <label #{name}> appears twice" if @labels[name]
|
254
|
+
label.root_agent = self
|
255
|
+
@labels[name] = label
|
256
|
+
end
|
257
|
+
|
258
|
+
def find_label(label_name)
|
259
|
+
if label = @labels[label_name]
|
260
|
+
label
|
261
|
+
else
|
262
|
+
raise ArgumentError, "#{label_name} label not found"
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
def emit_error_event(tag, time, record, error)
|
267
|
+
error_info = {error: error, tag: tag, time: time}
|
268
|
+
if @error_collector
|
269
|
+
# A record is not included in the logs because <@ERROR> handles it. This warn is for the notification
|
270
|
+
log.warn "send an error event to @ERROR:", error_info
|
271
|
+
@error_collector.emit(tag, time, record)
|
272
|
+
else
|
273
|
+
error_info[:record] = record
|
274
|
+
log.warn "dump an error event:", error_info
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
def handle_emits_error(tag, es, error)
|
279
|
+
error_info = {error: error, tag: tag}
|
280
|
+
if @error_collector
|
281
|
+
log.warn "send an error event stream to @ERROR:", error_info
|
282
|
+
@error_collector.emit_stream(tag, es)
|
283
|
+
else
|
284
|
+
now = Time.now
|
285
|
+
if @suppress_emit_error_log_interval.zero? || now > @next_emit_error_log_time
|
286
|
+
log.warn "emit transaction failed:", error_info
|
287
|
+
log.warn_backtrace
|
288
|
+
@next_emit_error_log_time = now + @suppress_emit_error_log_interval
|
289
|
+
end
|
290
|
+
raise error
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
# <label @ERROR> element use RootAgent wrapped by # this RootAgentProxyWithoutErrorCollector.
|
295
|
+
# So that those elements don't send cause infinite loop.
|
296
|
+
class RootAgentProxyWithoutErrorCollector < SimpleDelegator
|
297
|
+
def initialize(root_agent)
|
298
|
+
super
|
299
|
+
|
300
|
+
@suppress_emit_error_log_interval = 0
|
301
|
+
@next_emit_error_log_time = nil
|
302
|
+
|
303
|
+
interval_time = root_agent.instance_variable_get(:@suppress_emit_error_log_interval)
|
304
|
+
suppress_interval(interval_time) unless interval_time.zero?
|
305
|
+
end
|
306
|
+
|
307
|
+
def emit_error_event(tag, time, record, error)
|
308
|
+
error_info = {error: error, tag: tag, time: time, record: record}
|
309
|
+
log.warn "dump an error event in @ERROR:", error_info
|
310
|
+
end
|
311
|
+
|
312
|
+
def handle_emits_error(tag, es, e)
|
313
|
+
now = EventTime.now
|
314
|
+
if @suppress_emit_error_log_interval.zero? || now > @next_emit_error_log_time
|
315
|
+
log.warn "emit transaction failed in @ERROR:", error: e, tag: tag
|
316
|
+
log.warn_backtrace
|
317
|
+
@next_emit_error_log_time = now + @suppress_emit_error_log_interval
|
318
|
+
end
|
319
|
+
raise e
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
data/lib/fluent/rpc.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'webrick'
|
18
|
+
|
19
|
+
module Fluent
|
20
|
+
module RPC
|
21
|
+
class Server
|
22
|
+
def initialize(endpoint, log)
|
23
|
+
bind, port = endpoint.split(':')
|
24
|
+
@bind = bind
|
25
|
+
@port = port
|
26
|
+
@log = log
|
27
|
+
|
28
|
+
@server = WEBrick::HTTPServer.new(
|
29
|
+
BindAddress: @bind,
|
30
|
+
Port: @port,
|
31
|
+
Logger: WEBrick::Log.new(STDERR, WEBrick::Log::FATAL),
|
32
|
+
AccessLog: [],
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def mount(path, servlet, *args)
|
37
|
+
@server.mount(path, servlet, *args)
|
38
|
+
@log.debug "register #{path} RPC servlet"
|
39
|
+
end
|
40
|
+
|
41
|
+
def mount_proc(path, &block)
|
42
|
+
@server.mount_proc(path) { |req, res|
|
43
|
+
begin
|
44
|
+
code, header, response = block.call(req, res)
|
45
|
+
rescue => e
|
46
|
+
@log.warn "failed to handle RPC request", path: path, error: e.to_s
|
47
|
+
@log.warn_backtrace e.backtrace
|
48
|
+
|
49
|
+
code = 500
|
50
|
+
body = {
|
51
|
+
'message '=> 'Internal Server Error',
|
52
|
+
'error' => "#{e}",
|
53
|
+
'backtrace'=> e.backtrace,
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
code = 200 if code.nil?
|
58
|
+
header = {'Content-Type' => 'application/json'} if header.nil?
|
59
|
+
body = if response.nil?
|
60
|
+
'{"ok":true}'
|
61
|
+
else
|
62
|
+
response.body['ok'] = code == 200
|
63
|
+
response.body.to_json
|
64
|
+
end
|
65
|
+
|
66
|
+
res.status = code
|
67
|
+
header.each_pair { |k, v|
|
68
|
+
res[k] = v
|
69
|
+
}
|
70
|
+
res.body = body
|
71
|
+
}
|
72
|
+
@log.debug "register #{path} RPC handler"
|
73
|
+
end
|
74
|
+
|
75
|
+
def start
|
76
|
+
@log.debug "listening RPC http server on http://#{@bind}:#{@port}/"
|
77
|
+
@thread = Thread.new {
|
78
|
+
@server.start
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
def shutdown
|
83
|
+
if @server
|
84
|
+
@server.shutdown
|
85
|
+
@server = nil
|
86
|
+
end
|
87
|
+
if @thread
|
88
|
+
@thread.join
|
89
|
+
@thread = nil
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,741 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'fileutils'
|
18
|
+
|
19
|
+
require 'fluent/config'
|
20
|
+
require 'fluent/env'
|
21
|
+
require 'fluent/engine'
|
22
|
+
require 'fluent/error'
|
23
|
+
require 'fluent/log'
|
24
|
+
require 'fluent/plugin'
|
25
|
+
require 'fluent/rpc'
|
26
|
+
require 'fluent/system_config'
|
27
|
+
require 'serverengine'
|
28
|
+
|
29
|
+
if Fluent.windows?
|
30
|
+
require 'windows/library'
|
31
|
+
require 'windows/synchronize'
|
32
|
+
require 'windows/system_info'
|
33
|
+
include Windows::Library
|
34
|
+
include Windows::Synchronize
|
35
|
+
include Windows::SystemInfo
|
36
|
+
require 'win32/ipc'
|
37
|
+
require 'win32/event'
|
38
|
+
end
|
39
|
+
|
40
|
+
module Fluent
|
41
|
+
module ServerModule
|
42
|
+
def before_run
|
43
|
+
@start_time = Time.now
|
44
|
+
|
45
|
+
if config[:rpc_endpoint]
|
46
|
+
@rpc_endpoint = config[:rpc_endpoint]
|
47
|
+
@enable_get_dump = config[:enable_get_dump]
|
48
|
+
run_rpc_server
|
49
|
+
end
|
50
|
+
install_supervisor_signal_handlers
|
51
|
+
|
52
|
+
if config[:signame]
|
53
|
+
@signame = config[:signame]
|
54
|
+
install_windows_event_handler
|
55
|
+
end
|
56
|
+
|
57
|
+
socket_manager_path = ServerEngine::SocketManager::Server.generate_path
|
58
|
+
ServerEngine::SocketManager::Server.open(socket_manager_path)
|
59
|
+
ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = socket_manager_path.to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
def after_run
|
63
|
+
stop_rpc_server if @rpc_endpoint
|
64
|
+
Fluent::Supervisor.cleanup_resources
|
65
|
+
end
|
66
|
+
|
67
|
+
def run_rpc_server
|
68
|
+
@rpc_server = RPC::Server.new(@rpc_endpoint, $log)
|
69
|
+
|
70
|
+
# built-in RPC for signals
|
71
|
+
@rpc_server.mount_proc('/api/processes.interruptWorkers') { |req, res|
|
72
|
+
$log.debug "fluentd RPC got /api/processes.interruptWorkers request"
|
73
|
+
Process.kill :INT, $$
|
74
|
+
nil
|
75
|
+
}
|
76
|
+
@rpc_server.mount_proc('/api/processes.killWorkers') { |req, res|
|
77
|
+
$log.debug "fluentd RPC got /api/processes.killWorkers request"
|
78
|
+
Process.kill :TERM, $$
|
79
|
+
nil
|
80
|
+
}
|
81
|
+
@rpc_server.mount_proc('/api/processes.flushBuffersAndKillWorkers') { |req, res|
|
82
|
+
$log.debug "fluentd RPC got /api/processes.flushBuffersAndKillWorkers request"
|
83
|
+
if Fluent.windows?
|
84
|
+
$log.warn "operation 'flushBuffersAndKillWorkers' is not supported on Windows now."
|
85
|
+
else
|
86
|
+
Process.kill :USR1, $$
|
87
|
+
Process.kill :TERM, $$
|
88
|
+
end
|
89
|
+
nil
|
90
|
+
}
|
91
|
+
@rpc_server.mount_proc('/api/plugins.flushBuffers') { |req, res|
|
92
|
+
$log.debug "fluentd RPC got /api/plugins.flushBuffers request"
|
93
|
+
unless Fluent.windows?
|
94
|
+
Process.kill :USR1, $$
|
95
|
+
end
|
96
|
+
nil
|
97
|
+
}
|
98
|
+
@rpc_server.mount_proc('/api/config.reload') { |req, res|
|
99
|
+
$log.debug "fluentd RPC got /api/config.reload request"
|
100
|
+
if Fluent.windows?
|
101
|
+
# restart worker with auto restarting by killing
|
102
|
+
kill_worker
|
103
|
+
else
|
104
|
+
Process.kill :HUP, $$
|
105
|
+
end
|
106
|
+
nil
|
107
|
+
}
|
108
|
+
@rpc_server.mount_proc('/api/config.dump') { |req, res|
|
109
|
+
$log.debug "fluentd RPC got /api/config.dump request"
|
110
|
+
$log.info "dump in-memory config"
|
111
|
+
supervisor_dump_config_handler
|
112
|
+
nil
|
113
|
+
}
|
114
|
+
|
115
|
+
@rpc_server.mount_proc('/api/config.getDump') { |req, res|
|
116
|
+
$log.debug "fluentd RPC got /api/config.dump request"
|
117
|
+
$log.info "get dump in-memory config via HTTP"
|
118
|
+
res.body = supervisor_get_dump_config_handler
|
119
|
+
[nil, nil, res]
|
120
|
+
} if @enable_get_dump
|
121
|
+
|
122
|
+
@rpc_server.start
|
123
|
+
end
|
124
|
+
|
125
|
+
def stop_rpc_server
|
126
|
+
@rpc_server.shutdown
|
127
|
+
end
|
128
|
+
|
129
|
+
def install_supervisor_signal_handlers
|
130
|
+
trap :HUP do
|
131
|
+
$log.debug "fluentd supervisor process get SIGHUP"
|
132
|
+
supervisor_sighup_handler
|
133
|
+
end unless Fluent.windows?
|
134
|
+
|
135
|
+
trap :USR1 do
|
136
|
+
$log.debug "fluentd supervisor process get SIGUSR1"
|
137
|
+
supervisor_sigusr1_handler
|
138
|
+
end unless Fluent.windows?
|
139
|
+
end
|
140
|
+
|
141
|
+
def install_windows_event_handler
|
142
|
+
Thread.new do
|
143
|
+
ev = Win32::Event.new(@signame)
|
144
|
+
begin
|
145
|
+
ev.reset
|
146
|
+
until WaitForSingleObject(ev.handle, 0) == WAIT_OBJECT_0
|
147
|
+
sleep 1
|
148
|
+
end
|
149
|
+
kill_worker
|
150
|
+
stop(true)
|
151
|
+
ensure
|
152
|
+
ev.close
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def supervisor_sighup_handler
|
158
|
+
kill_worker
|
159
|
+
end
|
160
|
+
|
161
|
+
def supervisor_sigusr1_handler
|
162
|
+
if log = config[:logger_initializer]
|
163
|
+
log.reopen!
|
164
|
+
end
|
165
|
+
|
166
|
+
if pid = config[:worker_pid]
|
167
|
+
Process.kill(:USR1, pid)
|
168
|
+
# don't rescue Erro::ESRSH here (invalid status)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def kill_worker
|
173
|
+
if pid = config[:worker_pid]
|
174
|
+
if Fluent.windows?
|
175
|
+
Process.kill :KILL, pid
|
176
|
+
else
|
177
|
+
Process.kill :TERM, pid
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def supervisor_dump_config_handler
|
183
|
+
$log.info config[:fluentd_conf].to_s
|
184
|
+
end
|
185
|
+
|
186
|
+
def supervisor_get_dump_config_handler
|
187
|
+
{conf: config[:fluentd_conf].to_s}
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
module WorkerModule
|
192
|
+
def spawn(process_manager)
|
193
|
+
main_cmd = config[:main_cmd]
|
194
|
+
env = {
|
195
|
+
'SERVERENGINE_WORKER_ID' => @worker_id.to_i.to_s,
|
196
|
+
}
|
197
|
+
@pm = process_manager.spawn(env, *main_cmd)
|
198
|
+
end
|
199
|
+
|
200
|
+
def after_start
|
201
|
+
config[:worker_pid] = @pm.pid
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
class Supervisor
|
206
|
+
def self.load_config(path, params = {})
|
207
|
+
|
208
|
+
pre_loadtime = 0
|
209
|
+
pre_loadtime = params['pre_loadtime'].to_i if params['pre_loadtime']
|
210
|
+
pre_config_mtime = nil
|
211
|
+
pre_config_mtime = params['pre_config_mtime'] if params['pre_config_mtime']
|
212
|
+
config_mtime = File.mtime(path)
|
213
|
+
|
214
|
+
# reuse previous config if last load time is within 5 seconds and mtime of the config file is not changed
|
215
|
+
if Time.now - Time.at(pre_loadtime) < 5 and config_mtime == pre_config_mtime
|
216
|
+
return params['pre_conf']
|
217
|
+
end
|
218
|
+
|
219
|
+
config_fname = File.basename(path)
|
220
|
+
config_basedir = File.dirname(path)
|
221
|
+
config_data = File.read(path)
|
222
|
+
inline_config = params['inline_config']
|
223
|
+
if inline_config == '-'
|
224
|
+
config_data << "\n" << STDIN.read
|
225
|
+
elsif inline_config
|
226
|
+
config_data << "\n" << inline_config.gsub("\\n","\n")
|
227
|
+
end
|
228
|
+
fluentd_conf = Fluent::Config.parse(config_data, config_fname, config_basedir, params['use_v1_config'])
|
229
|
+
system_config = SystemConfig.create(fluentd_conf)
|
230
|
+
|
231
|
+
# these params must NOT be configured via system config here.
|
232
|
+
# these may be overridden by command line params.
|
233
|
+
workers = params['workers']
|
234
|
+
root_dir = params['root_dir']
|
235
|
+
log_level = params['log_level']
|
236
|
+
suppress_repeated_stacktrace = params['suppress_repeated_stacktrace']
|
237
|
+
|
238
|
+
log_path = params['log_path']
|
239
|
+
chuser = params['chuser']
|
240
|
+
chgroup = params['chgroup']
|
241
|
+
log_rotate_age = params['log_rotate_age']
|
242
|
+
log_rotate_size = params['log_rotate_size']
|
243
|
+
rpc_endpoint = system_config.rpc_endpoint
|
244
|
+
enable_get_dump = system_config.enable_get_dump
|
245
|
+
|
246
|
+
log_opts = {suppress_repeated_stacktrace: suppress_repeated_stacktrace}
|
247
|
+
logger_initializer = Supervisor::LoggerInitializer.new(
|
248
|
+
log_path, log_level, chuser, chgroup, log_opts,
|
249
|
+
log_rotate_age: log_rotate_age,
|
250
|
+
log_rotate_size: log_rotate_size
|
251
|
+
)
|
252
|
+
# this #init sets initialized logger to $log
|
253
|
+
logger_initializer.init(:supervisor, 0)
|
254
|
+
logger = $log
|
255
|
+
|
256
|
+
command_sender = Fluent.windows? ? "pipe" : "signal"
|
257
|
+
|
258
|
+
# ServerEngine's "daemonize" option is boolean, and path of pid file is brought by "pid_path"
|
259
|
+
pid_path = params['daemonize']
|
260
|
+
daemonize = !!params['daemonize']
|
261
|
+
main_cmd = params['main_cmd']
|
262
|
+
signame = params['signame']
|
263
|
+
|
264
|
+
se_config = {
|
265
|
+
worker_type: 'spawn',
|
266
|
+
workers: workers,
|
267
|
+
log_stdin: false,
|
268
|
+
log_stdout: false,
|
269
|
+
log_stderr: false,
|
270
|
+
enable_heartbeat: true,
|
271
|
+
auto_heartbeat: false,
|
272
|
+
unrecoverable_exit_codes: [2],
|
273
|
+
stop_immediately_at_unrecoverable_exit: true,
|
274
|
+
root_dir: root_dir,
|
275
|
+
logger: logger,
|
276
|
+
log: logger.out,
|
277
|
+
log_path: log_path,
|
278
|
+
log_level: log_level,
|
279
|
+
logger_initializer: logger_initializer,
|
280
|
+
chuser: chuser,
|
281
|
+
chgroup: chgroup,
|
282
|
+
chumask: 0,
|
283
|
+
suppress_repeated_stacktrace: suppress_repeated_stacktrace,
|
284
|
+
daemonize: daemonize,
|
285
|
+
rpc_endpoint: rpc_endpoint,
|
286
|
+
enable_get_dump: enable_get_dump,
|
287
|
+
windows_daemon_cmdline: [ServerEngine.ruby_bin_path,
|
288
|
+
File.join(File.dirname(__FILE__), 'daemon.rb'),
|
289
|
+
ServerModule.name,
|
290
|
+
WorkerModule.name,
|
291
|
+
path,
|
292
|
+
JSON.dump(params)],
|
293
|
+
command_sender: command_sender,
|
294
|
+
fluentd_conf: fluentd_conf,
|
295
|
+
main_cmd: main_cmd,
|
296
|
+
signame: signame,
|
297
|
+
}
|
298
|
+
if daemonize
|
299
|
+
se_config[:pid_path] = pid_path
|
300
|
+
end
|
301
|
+
pre_params = params.dup
|
302
|
+
params['pre_loadtime'] = Time.now.to_i
|
303
|
+
params['pre_config_mtime'] = config_mtime
|
304
|
+
params['pre_conf'] = se_config
|
305
|
+
# prevent pre_conf from being too big by reloading many times.
|
306
|
+
pre_params['pre_conf'] = nil
|
307
|
+
params['pre_conf'][:windows_daemon_cmdline][5] = JSON.dump(pre_params)
|
308
|
+
|
309
|
+
return se_config
|
310
|
+
end
|
311
|
+
|
312
|
+
class LoggerInitializer
|
313
|
+
def initialize(path, level, chuser, chgroup, opts, log_rotate_age: nil, log_rotate_size: nil)
|
314
|
+
@path = path
|
315
|
+
@level = level
|
316
|
+
@chuser = chuser
|
317
|
+
@chgroup = chgroup
|
318
|
+
@opts = opts
|
319
|
+
@log_rotate_age = log_rotate_age
|
320
|
+
@log_rotate_size = log_rotate_size
|
321
|
+
end
|
322
|
+
|
323
|
+
def init(process_type, worker_id)
|
324
|
+
@opts[:process_type] = process_type
|
325
|
+
@opts[:worker_id] = worker_id
|
326
|
+
|
327
|
+
if @path && @path != "-"
|
328
|
+
@logdev = if @log_rotate_age || @log_rotate_size
|
329
|
+
Fluent::LogDeviceIO.new(@path, shift_age: @log_rotate_age, shift_size: @log_rotate_size)
|
330
|
+
else
|
331
|
+
File.open(@path, "a")
|
332
|
+
end
|
333
|
+
if @chuser || @chgroup
|
334
|
+
chuid = @chuser ? ServerEngine::Privilege.get_etc_passwd(@chuser).uid : nil
|
335
|
+
chgid = @chgroup ? ServerEngine::Privilege.get_etc_group(@chgroup).gid : nil
|
336
|
+
File.chown(chuid, chgid, @path)
|
337
|
+
end
|
338
|
+
else
|
339
|
+
@logdev = STDOUT
|
340
|
+
end
|
341
|
+
|
342
|
+
dl_opts = {}
|
343
|
+
# subtract 1 to match serverengine daemon logger side logging severity.
|
344
|
+
dl_opts[:log_level] = @level - 1
|
345
|
+
logger = ServerEngine::DaemonLogger.new(@logdev, dl_opts)
|
346
|
+
$log = Fluent::Log.new(logger, @opts)
|
347
|
+
$log.enable_color(false) if @path
|
348
|
+
$log.enable_debug if @level <= Fluent::Log::LEVEL_DEBUG
|
349
|
+
end
|
350
|
+
|
351
|
+
def stdout?
|
352
|
+
@logdev == STDOUT
|
353
|
+
end
|
354
|
+
|
355
|
+
def reopen!
|
356
|
+
if @path && @path != "-"
|
357
|
+
@logdev.reopen(@path, "a")
|
358
|
+
end
|
359
|
+
self
|
360
|
+
end
|
361
|
+
|
362
|
+
def level=(level)
|
363
|
+
@level = level
|
364
|
+
$log.level = level
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
def self.default_options
|
369
|
+
{
|
370
|
+
config_path: Fluent::DEFAULT_CONFIG_PATH,
|
371
|
+
plugin_dirs: [Fluent::DEFAULT_PLUGIN_DIR],
|
372
|
+
log_level: Fluent::Log::LEVEL_INFO,
|
373
|
+
log_path: nil,
|
374
|
+
daemonize: nil,
|
375
|
+
libs: [],
|
376
|
+
setup_path: nil,
|
377
|
+
chuser: nil,
|
378
|
+
chgroup: nil,
|
379
|
+
root_dir: nil,
|
380
|
+
suppress_interval: 0,
|
381
|
+
suppress_repeated_stacktrace: true,
|
382
|
+
without_source: nil,
|
383
|
+
use_v1_config: true,
|
384
|
+
supervise: true,
|
385
|
+
standalone_worker: false,
|
386
|
+
signame: nil,
|
387
|
+
winsvcreg: nil,
|
388
|
+
}
|
389
|
+
end
|
390
|
+
|
391
|
+
def self.cleanup_resources
|
392
|
+
unless Fluent.windows?
|
393
|
+
if ENV.has_key?('SERVERENGINE_SOCKETMANAGER_PATH')
|
394
|
+
FileUtils.rm_f(ENV['SERVERENGINE_SOCKETMANAGER_PATH'])
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
def initialize(opt)
|
400
|
+
@daemonize = opt[:daemonize]
|
401
|
+
@supervise = opt[:supervise]
|
402
|
+
@standalone_worker= opt[:standalone_worker]
|
403
|
+
@config_path = opt[:config_path]
|
404
|
+
@inline_config = opt[:inline_config]
|
405
|
+
@use_v1_config = opt[:use_v1_config]
|
406
|
+
@log_path = opt[:log_path]
|
407
|
+
@dry_run = opt[:dry_run]
|
408
|
+
@show_plugin_config = opt[:show_plugin_config]
|
409
|
+
@libs = opt[:libs]
|
410
|
+
@plugin_dirs = opt[:plugin_dirs]
|
411
|
+
@chgroup = opt[:chgroup]
|
412
|
+
@chuser = opt[:chuser]
|
413
|
+
@rpc_server = nil
|
414
|
+
@process_name = nil
|
415
|
+
|
416
|
+
@workers = opt[:workers]
|
417
|
+
@root_dir = opt[:root_dir]
|
418
|
+
@log_level = opt[:log_level]
|
419
|
+
@log_rotate_age = opt[:log_rotate_age]
|
420
|
+
@log_rotate_size = opt[:log_rotate_size]
|
421
|
+
@suppress_interval = opt[:suppress_interval]
|
422
|
+
@suppress_config_dump = opt[:suppress_config_dump]
|
423
|
+
@log_event_verbose = opt[:log_event_verbose]
|
424
|
+
@without_source = opt[:without_source]
|
425
|
+
@signame = opt[:signame]
|
426
|
+
|
427
|
+
@suppress_repeated_stacktrace = opt[:suppress_repeated_stacktrace]
|
428
|
+
log_opts = {suppress_repeated_stacktrace: @suppress_repeated_stacktrace}
|
429
|
+
@log = LoggerInitializer.new(
|
430
|
+
@log_path, @log_level, @chuser, @chgroup, log_opts,
|
431
|
+
log_rotate_age: @log_rotate_age,
|
432
|
+
log_rotate_size: @log_rotate_size
|
433
|
+
)
|
434
|
+
@finished = false
|
435
|
+
end
|
436
|
+
|
437
|
+
def run_supervisor
|
438
|
+
@log.init(:supervisor, 0)
|
439
|
+
show_plugin_config if @show_plugin_config
|
440
|
+
read_config
|
441
|
+
set_system_config
|
442
|
+
|
443
|
+
if @workers < 1
|
444
|
+
raise Fluent::ConfigError, "invalid number of workers (must be > 0):#{@workers}"
|
445
|
+
end
|
446
|
+
|
447
|
+
if @root_dir
|
448
|
+
if File.exist?(@root_dir)
|
449
|
+
unless Dir.exist?(@root_dir)
|
450
|
+
raise Fluent::InvalidRootDirectory, "non directory entry exists:#{@root_dir}"
|
451
|
+
end
|
452
|
+
else
|
453
|
+
begin
|
454
|
+
FileUtils.mkdir_p(@root_dir)
|
455
|
+
rescue => e
|
456
|
+
raise Fluent::InvalidRootDirectory, "failed to create root directory:#{@root_dir}, #{e.inspect}"
|
457
|
+
end
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
dry_run if @dry_run
|
462
|
+
supervise
|
463
|
+
end
|
464
|
+
|
465
|
+
def options
|
466
|
+
{
|
467
|
+
'config_path' => @config_path,
|
468
|
+
'pid_file' => @daemonize,
|
469
|
+
'plugin_dirs' => @plugin_dirs,
|
470
|
+
'log_path' => @log_path,
|
471
|
+
'root_dir' => @root_dir,
|
472
|
+
}
|
473
|
+
end
|
474
|
+
|
475
|
+
def run_worker
|
476
|
+
begin
|
477
|
+
require 'sigdump/setup'
|
478
|
+
rescue Exception
|
479
|
+
# ignore LoadError and others (related with signals): it may raise these errors in Windows
|
480
|
+
end
|
481
|
+
worker_id = ENV['SERVERENGINE_WORKER_ID'].to_i
|
482
|
+
process_type = case
|
483
|
+
when @standalone_worker then :standalone
|
484
|
+
when worker_id == 0 then :worker0
|
485
|
+
else :workers
|
486
|
+
end
|
487
|
+
@log.init(process_type, worker_id)
|
488
|
+
Process.setproctitle("worker:#{@process_name}") if @process_name
|
489
|
+
|
490
|
+
show_plugin_config if @show_plugin_config
|
491
|
+
read_config
|
492
|
+
set_system_config
|
493
|
+
|
494
|
+
install_main_process_signal_handlers
|
495
|
+
|
496
|
+
# This is the only log messsage for @standalone_worker
|
497
|
+
$log.info "starting fluentd-#{Fluent::VERSION} without supervision", pid: Process.pid if @standalone_worker
|
498
|
+
|
499
|
+
main_process do
|
500
|
+
create_socket_manager if @standalone_worker
|
501
|
+
change_privilege
|
502
|
+
init_engine
|
503
|
+
run_configure
|
504
|
+
run_engine
|
505
|
+
self.class.cleanup_resources if @standalone_worker
|
506
|
+
exit 0
|
507
|
+
end
|
508
|
+
end
|
509
|
+
|
510
|
+
private
|
511
|
+
|
512
|
+
def create_socket_manager
|
513
|
+
socket_manager_path = ServerEngine::SocketManager::Server.generate_path
|
514
|
+
ServerEngine::SocketManager::Server.open(socket_manager_path)
|
515
|
+
ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = socket_manager_path.to_s
|
516
|
+
end
|
517
|
+
|
518
|
+
def dry_run
|
519
|
+
$log.info "starting fluentd-#{Fluent::VERSION} as dry run mode"
|
520
|
+
change_privilege
|
521
|
+
init_engine
|
522
|
+
run_configure
|
523
|
+
exit 0
|
524
|
+
rescue => e
|
525
|
+
$log.error "dry run failed: #{e}"
|
526
|
+
exit 1
|
527
|
+
end
|
528
|
+
|
529
|
+
def show_plugin_config
|
530
|
+
name, type = @show_plugin_config.split(":") # input:tail
|
531
|
+
$log.info "Use fluent-plugin-config-format --format=txt #{name} #{type}"
|
532
|
+
exit 0
|
533
|
+
end
|
534
|
+
|
535
|
+
def supervise
|
536
|
+
Process.setproctitle("supervisor:#{@process_name}") if @process_name
|
537
|
+
$log.info "starting fluentd-#{Fluent::VERSION}", pid: Process.pid
|
538
|
+
|
539
|
+
rubyopt = ENV["RUBYOPT"]
|
540
|
+
fluentd_spawn_cmd = [ServerEngine.ruby_bin_path, "-Eascii-8bit:ascii-8bit"]
|
541
|
+
fluentd_spawn_cmd << rubyopt if rubyopt
|
542
|
+
fluentd_spawn_cmd << $0
|
543
|
+
fluentd_spawn_cmd += $fluentdargv
|
544
|
+
fluentd_spawn_cmd << "--under-supervisor"
|
545
|
+
|
546
|
+
$log.info "spawn command to main: ", cmdline: fluentd_spawn_cmd
|
547
|
+
|
548
|
+
params = {}
|
549
|
+
params['main_cmd'] = fluentd_spawn_cmd
|
550
|
+
params['daemonize'] = @daemonize
|
551
|
+
params['inline_config'] = @inline_config
|
552
|
+
params['log_path'] = @log_path
|
553
|
+
params['log_rotate_age'] = @log_rotate_age
|
554
|
+
params['log_rotate_size'] = @log_rotate_size
|
555
|
+
params['chuser'] = @chuser
|
556
|
+
params['chgroup'] = @chgroup
|
557
|
+
params['use_v1_config'] = @use_v1_config
|
558
|
+
|
559
|
+
# system config parameters
|
560
|
+
params['workers'] = @workers
|
561
|
+
params['root_dir'] = @root_dir
|
562
|
+
params['log_level'] = @log_level
|
563
|
+
params['suppress_repeated_stacktrace'] = @suppress_repeated_stacktrace
|
564
|
+
params['signame'] = @signame
|
565
|
+
|
566
|
+
se = ServerEngine.create(ServerModule, WorkerModule){
|
567
|
+
Fluent::Supervisor.load_config(@config_path, params)
|
568
|
+
}
|
569
|
+
se.run
|
570
|
+
end
|
571
|
+
|
572
|
+
def install_main_process_signal_handlers
|
573
|
+
# Fluentd worker process (worker of ServerEngine) don't use code in serverengine to set signal handlers,
|
574
|
+
# because it does almost nothing.
|
575
|
+
# This method is the only method to set signal handlers in Fluentd worker process.
|
576
|
+
|
577
|
+
# When user use Ctrl + C not SIGINT, SIGINT is sent to all process in same process group.
|
578
|
+
# ServerEngine server process will send SIGTERM to child(spawned) processes by that SIGINT, so
|
579
|
+
# worker process SHOULD NOT do anything with SIGINT, SHOULD just ignore.
|
580
|
+
trap :INT do
|
581
|
+
$log.debug "fluentd main process get SIGINT"
|
582
|
+
|
583
|
+
# When Fluentd is launched without supervisor, worker should handle ctrl-c by itself
|
584
|
+
if @standalone_worker
|
585
|
+
@finished = true
|
586
|
+
$log.debug "getting start to shutdown main process"
|
587
|
+
Fluent::Engine.stop
|
588
|
+
end
|
589
|
+
end
|
590
|
+
|
591
|
+
trap :TERM do
|
592
|
+
$log.debug "fluentd main process get SIGTERM"
|
593
|
+
unless @finished
|
594
|
+
@finished = true
|
595
|
+
$log.debug "getting start to shutdown main process"
|
596
|
+
Fluent::Engine.stop
|
597
|
+
end
|
598
|
+
end
|
599
|
+
|
600
|
+
trap :USR1 do
|
601
|
+
flush_buffer
|
602
|
+
end unless Fluent.windows?
|
603
|
+
|
604
|
+
if Fluent.windows?
|
605
|
+
command_pipe = STDIN.dup
|
606
|
+
STDIN.reopen(File::NULL, "rb")
|
607
|
+
command_pipe.binmode
|
608
|
+
command_pipe.sync = true
|
609
|
+
|
610
|
+
Thread.new do
|
611
|
+
loop do
|
612
|
+
cmd = command_pipe.gets.chomp
|
613
|
+
case cmd
|
614
|
+
when "GRACEFUL_STOP", "IMMEDIATE_STOP"
|
615
|
+
$log.debug "fluentd main process get #{cmd} command"
|
616
|
+
@finished = true
|
617
|
+
$log.debug "getting start to shutdown main process"
|
618
|
+
Fluent::Engine.stop
|
619
|
+
break
|
620
|
+
else
|
621
|
+
$log.warn "fluentd main process get unknown command [#{cmd}]"
|
622
|
+
end
|
623
|
+
end
|
624
|
+
end
|
625
|
+
end
|
626
|
+
end
|
627
|
+
|
628
|
+
def flush_buffer
|
629
|
+
$log.debug "fluentd main process get SIGUSR1"
|
630
|
+
$log.info "force flushing buffered events"
|
631
|
+
@log.reopen!
|
632
|
+
|
633
|
+
# Creating new thread due to mutex can't lock
|
634
|
+
# in main thread during trap context
|
635
|
+
Thread.new {
|
636
|
+
begin
|
637
|
+
Fluent::Engine.flush!
|
638
|
+
$log.debug "flushing thread: flushed"
|
639
|
+
rescue Exception => e
|
640
|
+
$log.warn "flushing thread error: #{e}"
|
641
|
+
end
|
642
|
+
}.run
|
643
|
+
end
|
644
|
+
|
645
|
+
def logging_with_console_output
|
646
|
+
yield $log
|
647
|
+
unless @log.stdout?
|
648
|
+
logger = ServerEngine::DaemonLogger.new(STDOUT)
|
649
|
+
log = Fluent::Log.new(logger)
|
650
|
+
log.level = @log_level
|
651
|
+
console = log.enable_debug
|
652
|
+
yield console
|
653
|
+
end
|
654
|
+
end
|
655
|
+
|
656
|
+
def main_process(&block)
|
657
|
+
Process.setproctitle("worker:#{@process_name}") if @process_name
|
658
|
+
|
659
|
+
unrecoverable_error = false
|
660
|
+
|
661
|
+
begin
|
662
|
+
block.call
|
663
|
+
rescue Fluent::ConfigError => e
|
664
|
+
logging_with_console_output do |log|
|
665
|
+
log.error "config error", file: @config_path, error: e
|
666
|
+
log.debug_backtrace
|
667
|
+
end
|
668
|
+
unrecoverable_error = true
|
669
|
+
rescue Fluent::UnrecoverableError => e
|
670
|
+
logging_with_console_output do |log|
|
671
|
+
log.error e.message, error: e
|
672
|
+
log.error_backtrace
|
673
|
+
end
|
674
|
+
unrecoverable_error = true
|
675
|
+
rescue ScriptError => e # LoadError, NotImplementedError, SyntaxError
|
676
|
+
logging_with_console_output do |log|
|
677
|
+
if e.respond_to?(:path)
|
678
|
+
log.error e.message, path: e.path, error: e
|
679
|
+
else
|
680
|
+
log.error e.message, error: e
|
681
|
+
end
|
682
|
+
log.error_backtrace
|
683
|
+
end
|
684
|
+
unrecoverable_error = true
|
685
|
+
rescue => e
|
686
|
+
logging_with_console_output do |log|
|
687
|
+
log.error "unexpected error", error: e
|
688
|
+
log.error_backtrace
|
689
|
+
end
|
690
|
+
end
|
691
|
+
|
692
|
+
exit!(unrecoverable_error ? 2 : 1)
|
693
|
+
end
|
694
|
+
|
695
|
+
def read_config
|
696
|
+
$log.info :supervisor, "reading config file", path: @config_path
|
697
|
+
@config_fname = File.basename(@config_path)
|
698
|
+
@config_basedir = File.dirname(@config_path)
|
699
|
+
@config_data = File.read(@config_path)
|
700
|
+
if @inline_config == '-'
|
701
|
+
@config_data << "\n" << STDIN.read
|
702
|
+
elsif @inline_config
|
703
|
+
@config_data << "\n" << @inline_config.gsub("\\n","\n")
|
704
|
+
end
|
705
|
+
@conf = Fluent::Config.parse(@config_data, @config_fname, @config_basedir, @use_v1_config)
|
706
|
+
end
|
707
|
+
|
708
|
+
def set_system_config
|
709
|
+
@system_config = SystemConfig.create(@conf) # @conf is set in read_config
|
710
|
+
@system_config.attach(self)
|
711
|
+
@system_config.apply(self)
|
712
|
+
end
|
713
|
+
|
714
|
+
def change_privilege
|
715
|
+
ServerEngine::Privilege.change(@chuser, @chgroup)
|
716
|
+
end
|
717
|
+
|
718
|
+
def init_engine
|
719
|
+
Fluent::Engine.init(@system_config)
|
720
|
+
|
721
|
+
@libs.each {|lib|
|
722
|
+
require lib
|
723
|
+
}
|
724
|
+
|
725
|
+
@plugin_dirs.each {|dir|
|
726
|
+
if Dir.exist?(dir)
|
727
|
+
dir = File.expand_path(dir)
|
728
|
+
Fluent::Engine.add_plugin_dir(dir)
|
729
|
+
end
|
730
|
+
}
|
731
|
+
end
|
732
|
+
|
733
|
+
def run_configure
|
734
|
+
Fluent::Engine.run_configure(@conf)
|
735
|
+
end
|
736
|
+
|
737
|
+
def run_engine
|
738
|
+
Fluent::Engine.run
|
739
|
+
end
|
740
|
+
end
|
741
|
+
end
|