fluentd 1.20.0-aarch64-mingw-ucrt
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.
- checksums.yaml +7 -0
- data/.rubocop.yml +116 -0
- data/ADOPTERS.md +5 -0
- data/AGENTS.md +46 -0
- data/AUTHORS +2 -0
- data/CHANGELOG.md +3324 -0
- data/CONTRIBUTING.md +45 -0
- data/GOVERNANCE.md +55 -0
- data/GithubWorkflow.md +78 -0
- data/LICENSE +202 -0
- data/MAINTAINERS.md +19 -0
- data/README.md +73 -0
- data/Rakefile +89 -0
- data/SECURITY.md +47 -0
- data/bin/fluent-binlog-reader +7 -0
- data/bin/fluent-ca-generate +6 -0
- data/bin/fluent-cap-ctl +7 -0
- data/bin/fluent-cat +5 -0
- data/bin/fluent-ctl +7 -0
- data/bin/fluent-debug +5 -0
- data/bin/fluent-gem +9 -0
- data/bin/fluent-plugin-config-format +5 -0
- data/bin/fluent-plugin-generate +5 -0
- data/bin/fluentd +15 -0
- data/code-of-conduct.md +3 -0
- data/docs/SECURITY_AUDIT.pdf +0 -0
- data/example/copy_roundrobin.conf +39 -0
- data/example/counter.conf +18 -0
- data/example/filter_stdout.conf +22 -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 +16 -0
- data/example/in_out_forward.conf +17 -0
- data/example/in_sample_blocks.conf +17 -0
- data/example/in_sample_with_compression.conf +23 -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_sd.conf +17 -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/sd.yaml +8 -0
- data/example/secondary_file.conf +42 -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/example/worker_section.conf +36 -0
- data/fluent.conf +139 -0
- data/lib/fluent/agent.rb +168 -0
- data/lib/fluent/capability.rb +87 -0
- data/lib/fluent/clock.rb +66 -0
- data/lib/fluent/command/binlog_reader.rb +244 -0
- data/lib/fluent/command/bundler_injection.rb +45 -0
- data/lib/fluent/command/ca_generate.rb +184 -0
- data/lib/fluent/command/cap_ctl.rb +174 -0
- data/lib/fluent/command/cat.rb +365 -0
- data/lib/fluent/command/ctl.rb +180 -0
- data/lib/fluent/command/debug.rb +103 -0
- data/lib/fluent/command/fluentd.rb +385 -0
- data/lib/fluent/command/plugin_config_formatter.rb +308 -0
- data/lib/fluent/command/plugin_generator.rb +365 -0
- data/lib/fluent/compat/call_super_mixin.rb +76 -0
- data/lib/fluent/compat/detach_process_mixin.rb +33 -0
- data/lib/fluent/compat/exec_util.rb +144 -0
- data/lib/fluent/compat/file_util.rb +54 -0
- data/lib/fluent/compat/filter.rb +68 -0
- data/lib/fluent/compat/formatter.rb +117 -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 +49 -0
- data/lib/fluent/compat/output.rb +721 -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/basic_parser.rb +122 -0
- data/lib/fluent/config/configure_proxy.rb +424 -0
- data/lib/fluent/config/dsl.rb +152 -0
- data/lib/fluent/config/element.rb +265 -0
- data/lib/fluent/config/error.rb +44 -0
- data/lib/fluent/config/literal_parser.rb +305 -0
- data/lib/fluent/config/parser.rb +119 -0
- data/lib/fluent/config/section.rb +272 -0
- data/lib/fluent/config/types.rb +257 -0
- data/lib/fluent/config/v1_parser.rb +200 -0
- data/lib/fluent/config/yaml_parser/fluent_value.rb +47 -0
- data/lib/fluent/config/yaml_parser/loader.rb +124 -0
- data/lib/fluent/config/yaml_parser/parser.rb +179 -0
- data/lib/fluent/config/yaml_parser/section_builder.rb +107 -0
- data/lib/fluent/config/yaml_parser.rb +56 -0
- data/lib/fluent/config.rb +89 -0
- data/lib/fluent/configurable.rb +202 -0
- data/lib/fluent/counter/base_socket.rb +44 -0
- data/lib/fluent/counter/client.rb +297 -0
- data/lib/fluent/counter/error.rb +86 -0
- data/lib/fluent/counter/mutex_hash.rb +163 -0
- data/lib/fluent/counter/server.rb +273 -0
- data/lib/fluent/counter/store.rb +205 -0
- data/lib/fluent/counter/validator.rb +145 -0
- data/lib/fluent/counter.rb +23 -0
- data/lib/fluent/daemon.rb +14 -0
- data/lib/fluent/daemonizer.rb +88 -0
- data/lib/fluent/engine.rb +269 -0
- data/lib/fluent/env.rb +45 -0
- data/lib/fluent/error.rb +37 -0
- data/lib/fluent/event.rb +369 -0
- data/lib/fluent/event_router.rb +315 -0
- data/lib/fluent/ext_monitor_require.rb +28 -0
- data/lib/fluent/file_wrapper.rb +137 -0
- data/lib/fluent/filter.rb +21 -0
- data/lib/fluent/fluent_log_event_router.rb +139 -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 +33 -0
- data/lib/fluent/log/console_adapter.rb +66 -0
- data/lib/fluent/log.rb +775 -0
- data/lib/fluent/match.rb +187 -0
- data/lib/fluent/mixin.rb +31 -0
- data/lib/fluent/msgpack_factory.rb +111 -0
- data/lib/fluent/oj_options.rb +61 -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/bare_output.rb +88 -0
- data/lib/fluent/plugin/base.rb +219 -0
- data/lib/fluent/plugin/buf_file.rb +256 -0
- data/lib/fluent/plugin/buf_file_single.rb +272 -0
- data/lib/fluent/plugin/buf_memory.rb +34 -0
- data/lib/fluent/plugin/buffer/chunk.rb +313 -0
- data/lib/fluent/plugin/buffer/file_chunk.rb +432 -0
- data/lib/fluent/plugin/buffer/file_single_chunk.rb +325 -0
- data/lib/fluent/plugin/buffer/memory_chunk.rb +91 -0
- data/lib/fluent/plugin/buffer.rb +1063 -0
- data/lib/fluent/plugin/compressable.rb +87 -0
- data/lib/fluent/plugin/exec_util.rb +22 -0
- data/lib/fluent/plugin/extractor.rb +132 -0
- data/lib/fluent/plugin/file_util.rb +22 -0
- data/lib/fluent/plugin/filter.rb +119 -0
- data/lib/fluent/plugin/filter_grep.rb +189 -0
- data/lib/fluent/plugin/filter_parser.rb +124 -0
- data/lib/fluent/plugin/filter_record_transformer.rb +325 -0
- data/lib/fluent/plugin/filter_stdout.rb +53 -0
- data/lib/fluent/plugin/formatter.rb +75 -0
- data/lib/fluent/plugin/formatter_csv.rb +92 -0
- data/lib/fluent/plugin/formatter_hash.rb +35 -0
- data/lib/fluent/plugin/formatter_json.rb +62 -0
- data/lib/fluent/plugin/formatter_ltsv.rb +44 -0
- data/lib/fluent/plugin/formatter_msgpack.rb +33 -0
- data/lib/fluent/plugin/formatter_out_file.rb +55 -0
- data/lib/fluent/plugin/formatter_single_value.rb +36 -0
- data/lib/fluent/plugin/formatter_stdout.rb +76 -0
- data/lib/fluent/plugin/formatter_tsv.rb +40 -0
- data/lib/fluent/plugin/in_debug_agent.rb +71 -0
- data/lib/fluent/plugin/in_dummy.rb +18 -0
- data/lib/fluent/plugin/in_exec.rb +124 -0
- data/lib/fluent/plugin/in_forward.rb +489 -0
- data/lib/fluent/plugin/in_gc_stat.rb +72 -0
- data/lib/fluent/plugin/in_http.rb +737 -0
- data/lib/fluent/plugin/in_monitor_agent.rb +406 -0
- data/lib/fluent/plugin/in_object_space.rb +93 -0
- data/lib/fluent/plugin/in_sample.rb +148 -0
- data/lib/fluent/plugin/in_syslog.rb +346 -0
- data/lib/fluent/plugin/in_tail/compatibility.rb +111 -0
- data/lib/fluent/plugin/in_tail/dir_watcher.rb +713 -0
- data/lib/fluent/plugin/in_tail/group_watch.rb +204 -0
- data/lib/fluent/plugin/in_tail/io_handler.rb +391 -0
- data/lib/fluent/plugin/in_tail/line_feeder.rb +230 -0
- data/lib/fluent/plugin/in_tail/position_file.rb +269 -0
- data/lib/fluent/plugin/in_tail/stat_watcher.rb +52 -0
- data/lib/fluent/plugin/in_tail/tail_watcher.rb +276 -0
- data/lib/fluent/plugin/in_tail/worker_pool.rb +298 -0
- data/lib/fluent/plugin/in_tail.rb +917 -0
- data/lib/fluent/plugin/in_tcp.rb +230 -0
- data/lib/fluent/plugin/in_udp.rb +101 -0
- data/lib/fluent/plugin/in_unix.rb +197 -0
- data/lib/fluent/plugin/input.rb +71 -0
- data/lib/fluent/plugin/metrics.rb +119 -0
- data/lib/fluent/plugin/metrics_local.rb +96 -0
- data/lib/fluent/plugin/multi_output.rb +179 -0
- data/lib/fluent/plugin/out_buffer.rb +40 -0
- data/lib/fluent/plugin/out_copy.rb +120 -0
- data/lib/fluent/plugin/out_exec.rb +105 -0
- data/lib/fluent/plugin/out_exec_filter.rb +319 -0
- data/lib/fluent/plugin/out_file.rb +371 -0
- data/lib/fluent/plugin/out_forward/ack_handler.rb +176 -0
- data/lib/fluent/plugin/out_forward/connection_manager.rb +131 -0
- data/lib/fluent/plugin/out_forward/error.rb +28 -0
- data/lib/fluent/plugin/out_forward/failure_detector.rb +84 -0
- data/lib/fluent/plugin/out_forward/handshake_protocol.rb +125 -0
- data/lib/fluent/plugin/out_forward/load_balancer.rb +114 -0
- data/lib/fluent/plugin/out_forward/socket_cache.rb +177 -0
- data/lib/fluent/plugin/out_forward.rb +865 -0
- data/lib/fluent/plugin/out_http.rb +419 -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 +148 -0
- data/lib/fluent/plugin/out_stdout.rb +81 -0
- data/lib/fluent/plugin/out_stream.rb +130 -0
- data/lib/fluent/plugin/output.rb +1688 -0
- data/lib/fluent/plugin/owned_by_mixin.rb +41 -0
- data/lib/fluent/plugin/parser.rb +274 -0
- data/lib/fluent/plugin/parser_apache.rb +28 -0
- data/lib/fluent/plugin/parser_apache2.rb +88 -0
- data/lib/fluent/plugin/parser_apache_error.rb +26 -0
- data/lib/fluent/plugin/parser_csv.rb +124 -0
- data/lib/fluent/plugin/parser_json.rb +118 -0
- data/lib/fluent/plugin/parser_ltsv.rb +49 -0
- data/lib/fluent/plugin/parser_msgpack.rb +72 -0
- data/lib/fluent/plugin/parser_multiline.rb +152 -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 +68 -0
- data/lib/fluent/plugin/parser_syslog.rb +543 -0
- data/lib/fluent/plugin/parser_tsv.rb +47 -0
- data/lib/fluent/plugin/sd_file.rb +157 -0
- data/lib/fluent/plugin/sd_srv.rb +135 -0
- data/lib/fluent/plugin/sd_static.rb +58 -0
- data/lib/fluent/plugin/service_discovery.rb +65 -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 +166 -0
- data/lib/fluent/plugin/string_util.rb +22 -0
- data/lib/fluent/plugin.rb +206 -0
- data/lib/fluent/plugin_helper/cert_option.rb +199 -0
- data/lib/fluent/plugin_helper/child_process.rb +369 -0
- data/lib/fluent/plugin_helper/compat_parameters.rb +343 -0
- data/lib/fluent/plugin_helper/counter.rb +51 -0
- data/lib/fluent/plugin_helper/event_emitter.rb +112 -0
- data/lib/fluent/plugin_helper/event_loop.rb +170 -0
- data/lib/fluent/plugin_helper/extract.rb +104 -0
- data/lib/fluent/plugin_helper/formatter.rb +147 -0
- data/lib/fluent/plugin_helper/http_server/app.rb +81 -0
- data/lib/fluent/plugin_helper/http_server/methods.rb +35 -0
- data/lib/fluent/plugin_helper/http_server/request.rb +53 -0
- data/lib/fluent/plugin_helper/http_server/router.rb +54 -0
- data/lib/fluent/plugin_helper/http_server/server.rb +116 -0
- data/lib/fluent/plugin_helper/http_server/ssl_context_builder.rb +41 -0
- data/lib/fluent/plugin_helper/http_server.rb +129 -0
- data/lib/fluent/plugin_helper/inject.rb +154 -0
- data/lib/fluent/plugin_helper/metrics.rb +136 -0
- data/lib/fluent/plugin_helper/parser.rb +147 -0
- data/lib/fluent/plugin_helper/record_accessor.rb +207 -0
- data/lib/fluent/plugin_helper/retry_state.rb +219 -0
- data/lib/fluent/plugin_helper/server.rb +840 -0
- data/lib/fluent/plugin_helper/service_discovery/manager.rb +146 -0
- data/lib/fluent/plugin_helper/service_discovery/round_robin_balancer.rb +43 -0
- data/lib/fluent/plugin_helper/service_discovery.rb +125 -0
- data/lib/fluent/plugin_helper/socket.rb +288 -0
- data/lib/fluent/plugin_helper/socket_option.rb +98 -0
- data/lib/fluent/plugin_helper/storage.rb +349 -0
- data/lib/fluent/plugin_helper/thread.rb +180 -0
- data/lib/fluent/plugin_helper/timer.rb +92 -0
- data/lib/fluent/plugin_helper.rb +75 -0
- data/lib/fluent/plugin_id.rb +93 -0
- data/lib/fluent/process.rb +22 -0
- data/lib/fluent/registry.rb +117 -0
- data/lib/fluent/root_agent.rb +468 -0
- data/lib/fluent/rpc.rb +95 -0
- data/lib/fluent/source_only_buffer_agent.rb +102 -0
- data/lib/fluent/static_config_analysis.rb +195 -0
- data/lib/fluent/supervisor.rb +1347 -0
- data/lib/fluent/system_config.rb +213 -0
- data/lib/fluent/test/base.rb +83 -0
- data/lib/fluent/test/driver/base.rb +231 -0
- data/lib/fluent/test/driver/base_owned.rb +83 -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 +61 -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/storage.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 +138 -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 +44 -0
- data/lib/fluent/test.rb +61 -0
- data/lib/fluent/time.rb +513 -0
- data/lib/fluent/timezone.rb +171 -0
- data/lib/fluent/tls.rb +105 -0
- data/lib/fluent/unique_id.rb +39 -0
- data/lib/fluent/variable_store.rb +40 -0
- data/lib/fluent/version.rb +21 -0
- data/lib/fluent/win32api.rb +38 -0
- data/lib/fluent/winsvc.rb +130 -0
- data/templates/new_gem/.gitignore +8 -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 +28 -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/lib/fluent/plugin/storage.rb.erb +40 -0
- data/templates/new_gem/test/helper.rb.erb +7 -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/new_gem/test/plugin/test_storage.rb.erb +18 -0
- data/templates/plugin_config_formatter/param.md-compact.erb +25 -0
- data/templates/plugin_config_formatter/param.md-table.erb +10 -0
- data/templates/plugin_config_formatter/param.md.erb +34 -0
- data/templates/plugin_config_formatter/section.md.erb +12 -0
- metadata +996 -0
|
@@ -0,0 +1,315 @@
|
|
|
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 'fluent/match'
|
|
18
|
+
require 'fluent/event'
|
|
19
|
+
require 'fluent/filter'
|
|
20
|
+
require 'fluent/msgpack_factory'
|
|
21
|
+
|
|
22
|
+
module Fluent
|
|
23
|
+
#
|
|
24
|
+
# EventRouter is responsible to route events to a collector.
|
|
25
|
+
#
|
|
26
|
+
# It has a list of MatchPattern and Collector pairs:
|
|
27
|
+
#
|
|
28
|
+
# +----------------+ +-----------------+
|
|
29
|
+
# | MatchPattern | | Collector |
|
|
30
|
+
# +----------------+ +-----------------+
|
|
31
|
+
# | access.** ---------> type forward |
|
|
32
|
+
# | logs.** ---------> type copy |
|
|
33
|
+
# | archive.** ---------> type s3 |
|
|
34
|
+
# +----------------+ +-----------------+
|
|
35
|
+
#
|
|
36
|
+
# EventRouter does:
|
|
37
|
+
#
|
|
38
|
+
# 1) receive an event at `#emit` methods
|
|
39
|
+
# 2) match the event's tag with the MatchPatterns
|
|
40
|
+
# 3) forward the event to the corresponding Collector
|
|
41
|
+
#
|
|
42
|
+
# Collector is either of Output, Filter or other EventRouter.
|
|
43
|
+
#
|
|
44
|
+
class EventRouter
|
|
45
|
+
def initialize(default_collector, emit_error_handler)
|
|
46
|
+
@match_rules = []
|
|
47
|
+
@match_cache = MatchCache.new
|
|
48
|
+
@default_collector = default_collector
|
|
49
|
+
@emit_error_handler = emit_error_handler
|
|
50
|
+
@metric_callbacks = {}
|
|
51
|
+
@caller_plugin_id = nil
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
attr_accessor :default_collector
|
|
55
|
+
attr_accessor :emit_error_handler
|
|
56
|
+
|
|
57
|
+
class Rule
|
|
58
|
+
def initialize(pattern, collector)
|
|
59
|
+
patterns = pattern.split(/\s+/).map { |str| MatchPattern.create(str) }
|
|
60
|
+
@pattern = if patterns.length == 1
|
|
61
|
+
patterns[0]
|
|
62
|
+
else
|
|
63
|
+
OrMatchPattern.new(patterns)
|
|
64
|
+
end
|
|
65
|
+
@pattern_str = pattern
|
|
66
|
+
@collector = collector
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def match?(tag)
|
|
70
|
+
@pattern.match(tag)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
attr_reader :collector
|
|
74
|
+
attr_reader :pattern_str
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def suppress_missing_match!
|
|
78
|
+
if @default_collector.respond_to?(:suppress_missing_match!)
|
|
79
|
+
@default_collector.suppress_missing_match!
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# called by Agent to add new match pattern and collector
|
|
84
|
+
def add_rule(pattern, collector)
|
|
85
|
+
@match_rules << Rule.new(pattern, collector)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def add_metric_callbacks(caller_plugin_id, callback)
|
|
89
|
+
@metric_callbacks[caller_plugin_id] = callback
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def caller_plugin_id=(caller_plugin_id)
|
|
93
|
+
@caller_plugin_id = caller_plugin_id
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def find_callback
|
|
97
|
+
if @caller_plugin_id
|
|
98
|
+
@metric_callbacks[@caller_plugin_id]
|
|
99
|
+
else
|
|
100
|
+
nil
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def emit(tag, time, record)
|
|
105
|
+
unless record.nil?
|
|
106
|
+
emit_stream(tag, OneEventStream.new(time, record))
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def emit_array(tag, array)
|
|
111
|
+
emit_stream(tag, ArrayEventStream.new(array))
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def emit_stream(tag, es)
|
|
115
|
+
match(tag).emit_events(tag, es)
|
|
116
|
+
if callback = find_callback
|
|
117
|
+
callback.call(es)
|
|
118
|
+
end
|
|
119
|
+
rescue Pipeline::OutputError => e
|
|
120
|
+
@emit_error_handler.handle_emits_error(tag, e.processed_es, e.internal_error)
|
|
121
|
+
rescue => e
|
|
122
|
+
@emit_error_handler.handle_emits_error(tag, es, e)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def emit_error_event(tag, time, record, error)
|
|
126
|
+
@emit_error_handler.emit_error_event(tag, time, record, error)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def match?(tag)
|
|
130
|
+
!!find(tag)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def match(tag)
|
|
134
|
+
collector = @match_cache.get(tag) {
|
|
135
|
+
find(tag) || @default_collector
|
|
136
|
+
}
|
|
137
|
+
collector
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
class MatchCache
|
|
141
|
+
MATCH_CACHE_SIZE = 1024
|
|
142
|
+
|
|
143
|
+
def initialize
|
|
144
|
+
super
|
|
145
|
+
@map = {}
|
|
146
|
+
@keys = []
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def get(key)
|
|
150
|
+
if collector = @map[key]
|
|
151
|
+
return collector
|
|
152
|
+
end
|
|
153
|
+
collector = @map[key] = yield
|
|
154
|
+
if @keys.size >= MATCH_CACHE_SIZE
|
|
155
|
+
# expire the oldest key
|
|
156
|
+
@map.delete @keys.shift
|
|
157
|
+
end
|
|
158
|
+
@keys << key
|
|
159
|
+
collector
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
private
|
|
164
|
+
|
|
165
|
+
class Pipeline
|
|
166
|
+
|
|
167
|
+
class OutputError < StandardError
|
|
168
|
+
attr_reader :internal_error
|
|
169
|
+
attr_reader :processed_es
|
|
170
|
+
|
|
171
|
+
def initialize(internal_error, processed_es)
|
|
172
|
+
@internal_error = internal_error
|
|
173
|
+
@processed_es = processed_es
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def initialize
|
|
178
|
+
@filters = []
|
|
179
|
+
@output = nil
|
|
180
|
+
@optimizer = FilterOptimizer.new
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def add_filter(filter)
|
|
184
|
+
@filters << filter
|
|
185
|
+
@optimizer.filters = @filters
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def set_output(output)
|
|
189
|
+
@output = output
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def emit_events(tag, es)
|
|
193
|
+
processed = @optimizer.filter_stream(tag, es)
|
|
194
|
+
|
|
195
|
+
begin
|
|
196
|
+
@output.emit_events(tag, processed)
|
|
197
|
+
rescue => e
|
|
198
|
+
raise OutputError.new(e, processed)
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
class FilterOptimizer
|
|
203
|
+
def initialize(filters = [])
|
|
204
|
+
@filters = filters
|
|
205
|
+
@optimizable = nil
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def filters=(filters)
|
|
209
|
+
@filters = filters
|
|
210
|
+
reset_optimization
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def filter_stream(tag, es)
|
|
214
|
+
if optimizable?
|
|
215
|
+
optimized_filter_stream(tag, es)
|
|
216
|
+
else
|
|
217
|
+
@filters.reduce(es) { |acc, filter|
|
|
218
|
+
filtered_es = filter.filter_stream(tag, acc)
|
|
219
|
+
filter.measure_metrics(filtered_es)
|
|
220
|
+
filtered_es
|
|
221
|
+
}
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
private
|
|
226
|
+
|
|
227
|
+
def optimized_filter_stream(tag, es)
|
|
228
|
+
new_es = MultiEventStream.new
|
|
229
|
+
es.each(unpacker: Fluent::MessagePackFactory.thread_local_msgpack_unpacker) do |time, record|
|
|
230
|
+
filtered_record = record
|
|
231
|
+
filtered_time = time
|
|
232
|
+
|
|
233
|
+
catch :break_loop do
|
|
234
|
+
@filters.each do |filter|
|
|
235
|
+
if filter.has_filter_with_time
|
|
236
|
+
begin
|
|
237
|
+
filtered_time, filtered_record = filter.filter_with_time(tag, filtered_time, filtered_record)
|
|
238
|
+
throw :break_loop unless filtered_record && filtered_time
|
|
239
|
+
filter.measure_metrics(OneEventStream.new(time, record))
|
|
240
|
+
rescue => e
|
|
241
|
+
filter.router.emit_error_event(tag, filtered_time, filtered_record, e)
|
|
242
|
+
end
|
|
243
|
+
else
|
|
244
|
+
begin
|
|
245
|
+
filtered_record = filter.filter(tag, filtered_time, filtered_record)
|
|
246
|
+
throw :break_loop unless filtered_record
|
|
247
|
+
filter.measure_metrics(OneEventStream.new(time, record))
|
|
248
|
+
rescue => e
|
|
249
|
+
filter.router.emit_error_event(tag, filtered_time, filtered_record, e)
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
new_es.add(filtered_time, filtered_record)
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
new_es
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
def optimizable?
|
|
261
|
+
return @optimizable unless @optimizable.nil?
|
|
262
|
+
fs_filters = filters_having_filter_stream
|
|
263
|
+
@optimizable = if fs_filters.empty?
|
|
264
|
+
true
|
|
265
|
+
else
|
|
266
|
+
# skip log message when filter is only 1, because its performance is same as non optimized chain.
|
|
267
|
+
if @filters.size > 1 && fs_filters.size >= 1
|
|
268
|
+
$log.info "disable filter chain optimization because #{fs_filters.map(&:class)} uses `#filter_stream` method."
|
|
269
|
+
end
|
|
270
|
+
false
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
def filters_having_filter_stream
|
|
275
|
+
@filters_having_filter_stream ||= @filters.select do |filter|
|
|
276
|
+
filter.class.instance_methods(false).include?(:filter_stream)
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
def reset_optimization
|
|
281
|
+
@optimizable = nil
|
|
282
|
+
@filters_having_filter_stream = nil
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def find(tag)
|
|
288
|
+
pipeline = nil
|
|
289
|
+
@match_rules.each do |rule|
|
|
290
|
+
if rule.match?(tag)
|
|
291
|
+
if rule.collector.is_a?(Plugin::Filter)
|
|
292
|
+
pipeline ||= Pipeline.new
|
|
293
|
+
pipeline.add_filter(rule.collector)
|
|
294
|
+
else
|
|
295
|
+
if pipeline
|
|
296
|
+
pipeline.set_output(rule.collector)
|
|
297
|
+
else
|
|
298
|
+
# Use Output directly when filter is not matched
|
|
299
|
+
pipeline = rule.collector
|
|
300
|
+
end
|
|
301
|
+
return pipeline
|
|
302
|
+
end
|
|
303
|
+
end
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
if pipeline
|
|
307
|
+
# filter is matched but no match
|
|
308
|
+
pipeline.set_output(@default_collector)
|
|
309
|
+
pipeline
|
|
310
|
+
else
|
|
311
|
+
nil
|
|
312
|
+
end
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
# To avoid duplicated requirements, extract this logic as file.
|
|
18
|
+
|
|
19
|
+
if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('2.7.0')
|
|
20
|
+
require 'monitor'
|
|
21
|
+
else
|
|
22
|
+
begin
|
|
23
|
+
# monitor_ext is bundled since ruby 2.7.0
|
|
24
|
+
require 'ext_monitor'
|
|
25
|
+
rescue LoadError => _
|
|
26
|
+
require 'monitor'
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,137 @@
|
|
|
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
|
+
unless Fluent.windows?
|
|
18
|
+
Fluent::FileWrapper = File
|
|
19
|
+
else
|
|
20
|
+
require 'fluent/win32api'
|
|
21
|
+
|
|
22
|
+
module Fluent
|
|
23
|
+
module FileWrapper
|
|
24
|
+
def self.open(path, mode='r')
|
|
25
|
+
io = WindowsFile.new(path, mode).io
|
|
26
|
+
if block_given?
|
|
27
|
+
v = yield io
|
|
28
|
+
io.close
|
|
29
|
+
v
|
|
30
|
+
else
|
|
31
|
+
io
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.stat(path)
|
|
36
|
+
f = WindowsFile.new(path)
|
|
37
|
+
s = f.stat
|
|
38
|
+
f.close
|
|
39
|
+
s
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class WindowsFile
|
|
44
|
+
include File::Constants
|
|
45
|
+
|
|
46
|
+
attr_reader :io
|
|
47
|
+
|
|
48
|
+
INVALID_HANDLE_VALUE = -1
|
|
49
|
+
|
|
50
|
+
def initialize(path, mode_enc='r')
|
|
51
|
+
@path = path
|
|
52
|
+
mode, enc = mode_enc.split(":", 2)
|
|
53
|
+
@io = File.open(path, mode2flags(mode))
|
|
54
|
+
@io.set_encoding(enc) if enc
|
|
55
|
+
@file_handle = Win32API._get_osfhandle(@io.to_i)
|
|
56
|
+
@io.instance_variable_set(:@file_index, self.ino)
|
|
57
|
+
def @io.ino
|
|
58
|
+
@file_index
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def close
|
|
63
|
+
@io.close
|
|
64
|
+
@file_handle = INVALID_HANDLE_VALUE
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# To keep backward compatibility, we continue to use GetFileInformationByHandle()
|
|
68
|
+
# to get file id.
|
|
69
|
+
# Note that Ruby's File.stat uses GetFileInformationByHandleEx() with FileIdInfo
|
|
70
|
+
# and returned value is different with above one, former one is 64 bit while
|
|
71
|
+
# later one is 128bit.
|
|
72
|
+
def ino
|
|
73
|
+
by_handle_file_information = '\0'*(4+8+8+8+4+4+4+4+4+4) #72bytes
|
|
74
|
+
|
|
75
|
+
unless Win32API.GetFileInformationByHandle(@file_handle, by_handle_file_information)
|
|
76
|
+
return 0
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
by_handle_file_information.unpack("I11Q1")[11] # fileindex
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def stat
|
|
83
|
+
raise Errno::ENOENT if delete_pending
|
|
84
|
+
s = File.stat(@path)
|
|
85
|
+
s.instance_variable_set :@ino, self.ino
|
|
86
|
+
def s.ino; @ino; end
|
|
87
|
+
s
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
private
|
|
91
|
+
|
|
92
|
+
def mode2flags(mode)
|
|
93
|
+
# Always inject File::Constants::SHARE_DELETE
|
|
94
|
+
# https://github.com/fluent/fluentd/pull/3585#issuecomment-1101502617
|
|
95
|
+
# To enable SHARE_DELETE, BINARY is also required.
|
|
96
|
+
# https://bugs.ruby-lang.org/issues/11218
|
|
97
|
+
# https://github.com/ruby/ruby/blob/d6684f063bc53e3cab025bd39526eca3b480b5e7/win32/win32.c#L6332-L6345
|
|
98
|
+
flags = BINARY | SHARE_DELETE
|
|
99
|
+
case mode.delete("b")
|
|
100
|
+
when "r"
|
|
101
|
+
flags |= RDONLY
|
|
102
|
+
when "r+"
|
|
103
|
+
flags |= RDWR
|
|
104
|
+
when "w"
|
|
105
|
+
flags |= WRONLY | CREAT | TRUNC
|
|
106
|
+
when "w+"
|
|
107
|
+
flags |= RDWR | CREAT | TRUNC
|
|
108
|
+
when "a"
|
|
109
|
+
flags |= WRONLY | CREAT | APPEND
|
|
110
|
+
when "a+"
|
|
111
|
+
flags |= RDWR | CREAT | APPEND
|
|
112
|
+
else
|
|
113
|
+
raise Errno::EINVAL.new("Unsupported mode by Fluent::FileWrapper: #{mode}")
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# DeletePending is a Windows-specific file state that roughly means
|
|
118
|
+
# "this file is queued for deletion, so close any open handlers"
|
|
119
|
+
#
|
|
120
|
+
# This flag can be retrieved via GetFileInformationByHandleEx().
|
|
121
|
+
#
|
|
122
|
+
# https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getfileinformationbyhandleex
|
|
123
|
+
#
|
|
124
|
+
def delete_pending
|
|
125
|
+
file_standard_info = 0x01
|
|
126
|
+
bufsize = 1024
|
|
127
|
+
buf = '\0' * bufsize
|
|
128
|
+
|
|
129
|
+
unless Win32API.GetFileInformationByHandleEx(@file_handle, file_standard_info, buf, bufsize)
|
|
130
|
+
return false
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
return buf.unpack("QQICC")[3] != 0
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
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 'fluent/compat/filter'
|
|
18
|
+
|
|
19
|
+
module Fluent
|
|
20
|
+
Filter = Fluent::Compat::Filter
|
|
21
|
+
end
|
|
@@ -0,0 +1,139 @@
|
|
|
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 'fluent/log'
|
|
18
|
+
|
|
19
|
+
module Fluent
|
|
20
|
+
# DO NOT write any logic here
|
|
21
|
+
class NullFluentLogEventRouter
|
|
22
|
+
def start; end
|
|
23
|
+
|
|
24
|
+
def stop; end
|
|
25
|
+
|
|
26
|
+
def graceful_stop; end
|
|
27
|
+
|
|
28
|
+
def emit_event(_event); end
|
|
29
|
+
|
|
30
|
+
def emittable?
|
|
31
|
+
self.class != NullFluentLogEventRouter
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# This class is for handling fluentd's inner log
|
|
36
|
+
# e.g. <label @FLUNT_LOG> section and <match fluent.**> section
|
|
37
|
+
class FluentLogEventRouter < NullFluentLogEventRouter
|
|
38
|
+
# @param root_agent [Fluent::RootAgent]
|
|
39
|
+
def self.build(root_agent)
|
|
40
|
+
log_event_router = nil
|
|
41
|
+
|
|
42
|
+
begin
|
|
43
|
+
log_event_agent = root_agent.find_label(Fluent::Log::LOG_EVENT_LABEL)
|
|
44
|
+
log_event_router = log_event_agent.event_router
|
|
45
|
+
|
|
46
|
+
# suppress mismatched tags only for <label @FLUENT_LOG> label.
|
|
47
|
+
# it's not suppressed in default event router for non-log-event events
|
|
48
|
+
log_event_router.suppress_missing_match!
|
|
49
|
+
|
|
50
|
+
unmatched_tags = Fluent::Log.event_tags.select { |t| !log_event_router.match?(t) }
|
|
51
|
+
unless unmatched_tags.empty?
|
|
52
|
+
$log.warn "match for some tags of log events are not defined in @FLUENT_LOG label (to be ignored)", tags: unmatched_tags
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
rescue ArgumentError # ArgumentError "#{label_name} label not found"
|
|
56
|
+
# use default event router if <label @FLUENT_LOG> is missing in configuration
|
|
57
|
+
root_log_event_router = root_agent.event_router
|
|
58
|
+
event_tags = Fluent::Log.event_tags
|
|
59
|
+
if event_tags.any? { |t| root_log_event_router.match?(t) }
|
|
60
|
+
log_event_router = root_log_event_router
|
|
61
|
+
|
|
62
|
+
unmatched_tags = event_tags.select { |t| !log_event_router.match?(t) }
|
|
63
|
+
if unmatched_tags.empty?
|
|
64
|
+
$log.warn "define <match fluent.**> to capture fluentd logs in top level is deprecated. Use <label @FLUENT_LOG> instead"
|
|
65
|
+
else
|
|
66
|
+
matched_sections = (event_tags - unmatched_tags).map { |tag| "<match #{tag}>" }.join(', ')
|
|
67
|
+
$log.warn "define #{matched_sections} to capture fluentd logs in top level is deprecated. Use <label @FLUENT_LOG> instead"
|
|
68
|
+
$log.warn "match for some tags of log events are not defined in top level (to be ignored)", tags: unmatched_tags
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
if log_event_router
|
|
74
|
+
FluentLogEventRouter.new(log_event_router)
|
|
75
|
+
else
|
|
76
|
+
$log.debug('No fluent logger for internal event')
|
|
77
|
+
NullFluentLogEventRouter.new
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
STOP = :stop
|
|
82
|
+
GRACEFUL_STOP = :graceful_stop
|
|
83
|
+
|
|
84
|
+
# @param event_router [Fluent::EventRouter]
|
|
85
|
+
def initialize(event_router)
|
|
86
|
+
@event_router = event_router
|
|
87
|
+
@thread = nil
|
|
88
|
+
@graceful_stop = false
|
|
89
|
+
@event_queue = Queue.new
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def start
|
|
93
|
+
@thread = Thread.new do
|
|
94
|
+
$log.disable_events(Thread.current)
|
|
95
|
+
|
|
96
|
+
loop do
|
|
97
|
+
event = @event_queue.pop
|
|
98
|
+
|
|
99
|
+
case event
|
|
100
|
+
when GRACEFUL_STOP
|
|
101
|
+
@graceful_stop = true
|
|
102
|
+
when STOP
|
|
103
|
+
break
|
|
104
|
+
else
|
|
105
|
+
begin
|
|
106
|
+
tag, time, record = event
|
|
107
|
+
@event_router.emit(tag, time, record)
|
|
108
|
+
rescue => e
|
|
109
|
+
# This $log.error doesn't emit log events, because of `$log.disable_events(Thread.current)` above
|
|
110
|
+
$log.error "failed to emit fluentd's log event", tag: tag, event: record, error: e
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
if @graceful_stop && @event_queue.empty?
|
|
115
|
+
break
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
@thread.abort_on_exception = true
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def stop
|
|
124
|
+
@event_queue.push(STOP)
|
|
125
|
+
# there is no problem calling Thread#join multiple times.
|
|
126
|
+
@thread && @thread.join
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def graceful_stop
|
|
130
|
+
# to make sure to emit all log events into router, before shutting down
|
|
131
|
+
@event_queue.push(GRACEFUL_STOP)
|
|
132
|
+
@thread && @thread.join
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def emit_event(event)
|
|
136
|
+
@event_queue.push(event)
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
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 'fluent/compat/formatter'
|
|
18
|
+
|
|
19
|
+
module Fluent
|
|
20
|
+
Formatter = Fluent::Compat::Formatter
|
|
21
|
+
TextFormatter = Fluent::Compat::TextFormatter
|
|
22
|
+
# deprecate_constant is ruby 2.3 feature
|
|
23
|
+
end
|
data/lib/fluent/input.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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 'fluent/compat/input'
|
|
18
|
+
|
|
19
|
+
module Fluent
|
|
20
|
+
Input = Fluent::Compat::Input
|
|
21
|
+
end
|