fluentd 0.14.4-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fluentd might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.github/ISSUE_TEMPLATE.md +6 -0
- data/.gitignore +26 -0
- data/.travis.yml +45 -0
- data/AUTHORS +2 -0
- data/CONTRIBUTING.md +35 -0
- data/COPYING +14 -0
- data/ChangeLog +276 -0
- data/Gemfile +9 -0
- data/README.md +51 -0
- data/Rakefile +53 -0
- data/Vagrantfile +17 -0
- data/appveyor.yml +41 -0
- data/bin/fluent-debug +5 -0
- data/example/copy_roundrobin.conf +39 -0
- data/example/filter_stdout.conf +22 -0
- data/example/in_forward.conf +11 -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/multi_filters.conf +61 -0
- data/example/out_buffered_null.conf +32 -0
- data/example/out_copy.conf +20 -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/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 +194 -0
- data/lib/fluent/command/bundler_injection.rb +45 -0
- data/lib/fluent/command/cat.rb +319 -0
- data/lib/fluent/command/debug.rb +102 -0
- data/lib/fluent/command/fluentd.rb +273 -0
- data/lib/fluent/compat/call_super_mixin.rb +67 -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 +49 -0
- data/lib/fluent/compat/output.rb +677 -0
- data/lib/fluent/compat/output_chain.rb +60 -0
- data/lib/fluent/compat/parser.rb +180 -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 +366 -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 +212 -0
- data/lib/fluent/config/types.rb +136 -0
- data/lib/fluent/config/v1_parser.rb +190 -0
- data/lib/fluent/configurable.rb +176 -0
- data/lib/fluent/daemon.rb +15 -0
- data/lib/fluent/engine.rb +220 -0
- data/lib/fluent/env.rb +27 -0
- data/lib/fluent/event.rb +287 -0
- data/lib/fluent/event_router.rb +259 -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 +38 -0
- data/lib/fluent/load.rb +36 -0
- data/lib/fluent/log.rb +445 -0
- data/lib/fluent/match.rb +141 -0
- data/lib/fluent/mixin.rb +31 -0
- data/lib/fluent/msgpack_factory.rb +62 -0
- data/lib/fluent/output.rb +26 -0
- data/lib/fluent/output_chain.rb +23 -0
- data/lib/fluent/parser.rb +23 -0
- data/lib/fluent/plugin.rb +161 -0
- data/lib/fluent/plugin/bare_output.rb +63 -0
- data/lib/fluent/plugin/base.rb +130 -0
- data/lib/fluent/plugin/buf_file.rb +154 -0
- data/lib/fluent/plugin/buf_memory.rb +34 -0
- data/lib/fluent/plugin/buffer.rb +603 -0
- data/lib/fluent/plugin/buffer/chunk.rb +160 -0
- data/lib/fluent/plugin/buffer/file_chunk.rb +323 -0
- data/lib/fluent/plugin/buffer/memory_chunk.rb +90 -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_record_transformer.rb +342 -0
- data/lib/fluent/plugin/filter_stdout.rb +53 -0
- data/lib/fluent/plugin/formatter.rb +45 -0
- data/lib/fluent/plugin/formatter_csv.rb +47 -0
- data/lib/fluent/plugin/formatter_hash.rb +29 -0
- data/lib/fluent/plugin/formatter_json.rb +44 -0
- data/lib/fluent/plugin/formatter_ltsv.rb +41 -0
- data/lib/fluent/plugin/formatter_msgpack.rb +29 -0
- data/lib/fluent/plugin/formatter_out_file.rb +78 -0
- data/lib/fluent/plugin/formatter_single_value.rb +34 -0
- data/lib/fluent/plugin/formatter_stdout.rb +74 -0
- data/lib/fluent/plugin/in_debug_agent.rb +64 -0
- data/lib/fluent/plugin/in_dummy.rb +135 -0
- data/lib/fluent/plugin/in_exec.rb +149 -0
- data/lib/fluent/plugin/in_forward.rb +366 -0
- data/lib/fluent/plugin/in_gc_stat.rb +52 -0
- data/lib/fluent/plugin/in_http.rb +422 -0
- data/lib/fluent/plugin/in_monitor_agent.rb +401 -0
- data/lib/fluent/plugin/in_object_space.rb +90 -0
- data/lib/fluent/plugin/in_syslog.rb +204 -0
- data/lib/fluent/plugin/in_tail.rb +838 -0
- data/lib/fluent/plugin/in_tcp.rb +41 -0
- data/lib/fluent/plugin/in_udp.rb +37 -0
- data/lib/fluent/plugin/in_unix.rb +201 -0
- data/lib/fluent/plugin/input.rb +33 -0
- data/lib/fluent/plugin/multi_output.rb +95 -0
- data/lib/fluent/plugin/out_buffered_null.rb +59 -0
- data/lib/fluent/plugin/out_buffered_stdout.rb +70 -0
- data/lib/fluent/plugin/out_copy.rb +42 -0
- data/lib/fluent/plugin/out_exec.rb +114 -0
- data/lib/fluent/plugin/out_exec_filter.rb +393 -0
- data/lib/fluent/plugin/out_file.rb +167 -0
- data/lib/fluent/plugin/out_forward.rb +646 -0
- data/lib/fluent/plugin/out_null.rb +27 -0
- data/lib/fluent/plugin/out_relabel.rb +28 -0
- data/lib/fluent/plugin/out_roundrobin.rb +80 -0
- data/lib/fluent/plugin/out_stdout.rb +48 -0
- data/lib/fluent/plugin/out_stream.rb +130 -0
- data/lib/fluent/plugin/output.rb +1020 -0
- data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
- data/lib/fluent/plugin/parser.rb +175 -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 +33 -0
- data/lib/fluent/plugin/parser_json.rb +79 -0
- data/lib/fluent/plugin/parser_ltsv.rb +50 -0
- data/lib/fluent/plugin/parser_multiline.rb +104 -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 +73 -0
- data/lib/fluent/plugin/parser_syslog.rb +82 -0
- data/lib/fluent/plugin/parser_tsv.rb +37 -0
- data/lib/fluent/plugin/socket_util.rb +22 -0
- data/lib/fluent/plugin/storage.rb +84 -0
- data/lib/fluent/plugin/storage_local.rb +132 -0
- data/lib/fluent/plugin/string_util.rb +22 -0
- data/lib/fluent/plugin_helper.rb +42 -0
- data/lib/fluent/plugin_helper/child_process.rb +298 -0
- data/lib/fluent/plugin_helper/compat_parameters.rb +224 -0
- data/lib/fluent/plugin_helper/event_emitter.rb +80 -0
- data/lib/fluent/plugin_helper/event_loop.rb +118 -0
- data/lib/fluent/plugin_helper/formatter.rb +149 -0
- data/lib/fluent/plugin_helper/inject.rb +125 -0
- data/lib/fluent/plugin_helper/parser.rb +147 -0
- data/lib/fluent/plugin_helper/retry_state.rb +177 -0
- data/lib/fluent/plugin_helper/storage.rb +331 -0
- data/lib/fluent/plugin_helper/thread.rb +147 -0
- data/lib/fluent/plugin_helper/timer.rb +90 -0
- data/lib/fluent/plugin_id.rb +63 -0
- data/lib/fluent/process.rb +504 -0
- data/lib/fluent/registry.rb +99 -0
- data/lib/fluent/root_agent.rb +314 -0
- data/lib/fluent/rpc.rb +94 -0
- data/lib/fluent/supervisor.rb +680 -0
- data/lib/fluent/system_config.rb +122 -0
- data/lib/fluent/test.rb +56 -0
- data/lib/fluent/test/base.rb +85 -0
- data/lib/fluent/test/driver/base.rb +179 -0
- data/lib/fluent/test/driver/base_owned.rb +70 -0
- data/lib/fluent/test/driver/base_owner.rb +125 -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 +52 -0
- data/lib/fluent/test/driver/output.rb +76 -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 +79 -0
- data/lib/fluent/test/input_test.rb +172 -0
- data/lib/fluent/test/log.rb +73 -0
- data/lib/fluent/test/output_test.rb +156 -0
- data/lib/fluent/test/parser_test.rb +70 -0
- data/lib/fluent/time.rb +175 -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/test/compat/test_calls_super.rb +166 -0
- data/test/compat/test_parser.rb +82 -0
- data/test/config/assertions.rb +42 -0
- data/test/config/test_config_parser.rb +507 -0
- data/test/config/test_configurable.rb +1194 -0
- data/test/config/test_configure_proxy.rb +386 -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 +120 -0
- data/test/config/test_types.rb +171 -0
- data/test/helper.rb +119 -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/test.log +0 -0
- data/test/plugin/test_bare_output.rb +118 -0
- data/test/plugin/test_base.rb +75 -0
- data/test/plugin/test_buf_file.rb +571 -0
- data/test/plugin/test_buf_memory.rb +42 -0
- data/test/plugin/test_buffer.rb +1200 -0
- data/test/plugin/test_buffer_chunk.rb +168 -0
- data/test/plugin/test_buffer_file_chunk.rb +771 -0
- data/test/plugin/test_buffer_memory_chunk.rb +265 -0
- data/test/plugin/test_file_util.rb +96 -0
- data/test/plugin/test_filter.rb +353 -0
- data/test/plugin/test_filter_grep.rb +119 -0
- data/test/plugin/test_filter_record_transformer.rb +600 -0
- data/test/plugin/test_filter_stdout.rb +211 -0
- data/test/plugin/test_formatter_csv.rb +94 -0
- data/test/plugin/test_formatter_json.rb +30 -0
- data/test/plugin/test_formatter_ltsv.rb +52 -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 +188 -0
- data/test/plugin/test_in_exec.rb +133 -0
- data/test/plugin/test_in_forward.rb +635 -0
- data/test/plugin/test_in_gc_stat.rb +39 -0
- data/test/plugin/test_in_http.rb +442 -0
- data/test/plugin/test_in_monitor_agent.rb +329 -0
- data/test/plugin/test_in_object_space.rb +64 -0
- data/test/plugin/test_in_syslog.rb +205 -0
- data/test/plugin/test_in_tail.rb +1001 -0
- data/test/plugin/test_in_tcp.rb +102 -0
- data/test/plugin/test_in_udp.rb +121 -0
- data/test/plugin/test_in_unix.rb +126 -0
- data/test/plugin/test_input.rb +122 -0
- data/test/plugin/test_multi_output.rb +180 -0
- data/test/plugin/test_out_buffered_null.rb +79 -0
- data/test/plugin/test_out_buffered_stdout.rb +122 -0
- data/test/plugin/test_out_copy.rb +160 -0
- data/test/plugin/test_out_exec.rb +155 -0
- data/test/plugin/test_out_exec_filter.rb +262 -0
- data/test/plugin/test_out_file.rb +383 -0
- data/test/plugin/test_out_forward.rb +590 -0
- data/test/plugin/test_out_null.rb +29 -0
- data/test/plugin/test_out_relabel.rb +28 -0
- data/test/plugin/test_out_roundrobin.rb +146 -0
- data/test/plugin/test_out_stdout.rb +92 -0
- data/test/plugin/test_out_stream.rb +93 -0
- data/test/plugin/test_output.rb +568 -0
- data/test/plugin/test_output_as_buffered.rb +1604 -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 +817 -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_apache.rb +42 -0
- data/test/plugin/test_parser_apache2.rb +38 -0
- data/test/plugin/test_parser_apache_error.rb +45 -0
- data/test/plugin/test_parser_base.rb +32 -0
- data/test/plugin/test_parser_csv.rb +104 -0
- data/test/plugin/test_parser_json.rb +107 -0
- data/test/plugin/test_parser_labeled_tsv.rb +129 -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 +53 -0
- data/test/plugin/test_parser_regexp.rb +277 -0
- data/test/plugin/test_parser_syslog.rb +66 -0
- data/test/plugin/test_parser_time.rb +46 -0
- data/test/plugin/test_parser_tsv.rb +121 -0
- data/test/plugin/test_storage.rb +167 -0
- data/test/plugin/test_storage_local.rb +8 -0
- data/test/plugin/test_string_util.rb +26 -0
- data/test/plugin_helper/test_child_process.rb +608 -0
- data/test/plugin_helper/test_compat_parameters.rb +242 -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_formatter.rb +252 -0
- data/test/plugin_helper/test_inject.rb +487 -0
- data/test/plugin_helper/test_parser.rb +263 -0
- data/test/plugin_helper/test_retry_state.rb +399 -0
- data/test/plugin_helper/test_storage.rb +521 -0
- data/test/plugin_helper/test_thread.rb +164 -0
- data/test/plugin_helper/test_timer.rb +131 -0
- data/test/scripts/exec_script.rb +32 -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_config.rb +179 -0
- data/test/test_configdsl.rb +148 -0
- data/test/test_event.rb +329 -0
- data/test/test_event_router.rb +331 -0
- data/test/test_event_time.rb +184 -0
- data/test/test_filter.rb +121 -0
- data/test/test_formatter.rb +319 -0
- data/test/test_input.rb +31 -0
- data/test/test_log.rb +572 -0
- data/test/test_match.rb +137 -0
- data/test/test_mixin.rb +351 -0
- data/test/test_output.rb +214 -0
- data/test/test_plugin_classes.rb +136 -0
- data/test/test_plugin_helper.rb +81 -0
- data/test/test_process.rb +48 -0
- data/test/test_root_agent.rb +278 -0
- data/test/test_supervisor.rb +339 -0
- data/test/test_time_formatter.rb +186 -0
- data/test/test_unique_id.rb +47 -0
- metadata +823 -0
@@ -0,0 +1,366 @@
|
|
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
|
+
module Fluent
|
18
|
+
module Config
|
19
|
+
class ConfigureProxy
|
20
|
+
attr_accessor :name, :final, :param_name, :init, :required, :multi, :alias, :configured_in_section
|
21
|
+
attr_accessor :argument, :params, :defaults, :descriptions, :sections
|
22
|
+
# config_param :desc, :string, default: '....'
|
23
|
+
# config_set_default :buffer_type, :memory
|
24
|
+
#
|
25
|
+
# config_section :default, required: true, multi: false do
|
26
|
+
# config_argument :arg, :string
|
27
|
+
# config_param :required, :bool, default: false
|
28
|
+
# config_param :name, :string
|
29
|
+
# config_param :power, :integer
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# config_section :child, param_name: 'children', required: false, multi: true, alias: 'node' do
|
33
|
+
# config_param :name, :string
|
34
|
+
# config_param :power, :integer, default: nil
|
35
|
+
# config_section :item do
|
36
|
+
# config_param :name
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
|
40
|
+
def initialize(name, root: false, param_name: nil, final: nil, init: nil, required: nil, multi: nil, alias: nil, type_lookup:)
|
41
|
+
@name = name.to_sym
|
42
|
+
@final = final
|
43
|
+
|
44
|
+
# For ConfigureProxy of root section, "@name" should be a class name of plugins.
|
45
|
+
# Otherwise (like subsections), "@name" should be a name of section, like "buffer", "store".
|
46
|
+
# For subsections, name will be used as parameter names (unless param_name exists), so overriding proxy's name
|
47
|
+
# should override "@name".
|
48
|
+
@root_section = root
|
49
|
+
|
50
|
+
@param_name = param_name && param_name.to_sym
|
51
|
+
@init = init
|
52
|
+
@required = required
|
53
|
+
@multi = multi
|
54
|
+
@alias = binding.local_variable_get(:alias)
|
55
|
+
@type_lookup = type_lookup
|
56
|
+
|
57
|
+
raise "init and required are exclusive" if @init && @required
|
58
|
+
|
59
|
+
# specify section name for viewpoint of owner(parent) plugin
|
60
|
+
# for buffer plugins: all params are in <buffer> section of owner
|
61
|
+
# others: <storage>, <format> (formatter/parser), ...
|
62
|
+
@configured_in_section = nil
|
63
|
+
|
64
|
+
@argument = nil # nil: ignore argument
|
65
|
+
@params = {}
|
66
|
+
@defaults = {}
|
67
|
+
@descriptions = {}
|
68
|
+
@sections = {}
|
69
|
+
@current_description = nil
|
70
|
+
end
|
71
|
+
|
72
|
+
def variable_name
|
73
|
+
@param_name || @name
|
74
|
+
end
|
75
|
+
|
76
|
+
def root?
|
77
|
+
@root_section
|
78
|
+
end
|
79
|
+
|
80
|
+
def init?
|
81
|
+
@init.nil? ? false : @init
|
82
|
+
end
|
83
|
+
|
84
|
+
def required?
|
85
|
+
@required.nil? ? false : @required
|
86
|
+
end
|
87
|
+
|
88
|
+
def multi?
|
89
|
+
@multi.nil? ? true : @multi
|
90
|
+
end
|
91
|
+
|
92
|
+
def final?
|
93
|
+
!!@final
|
94
|
+
end
|
95
|
+
|
96
|
+
def merge(other) # self is base class, other is subclass
|
97
|
+
return merge_for_finalized(other) if self.final?
|
98
|
+
|
99
|
+
[:param_name, :required, :multi, :alias, :configured_in_section].each do |prohibited_name|
|
100
|
+
if overwrite?(other, prohibited_name)
|
101
|
+
raise ConfigError, "BUG: subclass cannot overwrite base class's config_section: #{prohibited_name}"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
options = {}
|
106
|
+
# param_name affects instance variable name, which is just "internal" of each plugins.
|
107
|
+
# so it must not be changed. base class's name (or param_name) is always used.
|
108
|
+
options[:param_name] = @param_name
|
109
|
+
|
110
|
+
# subclass cannot overwrite base class's definition
|
111
|
+
options[:init] = @init.nil? ? other.init : self.init
|
112
|
+
options[:required] = @required.nil? ? other.required : self.required
|
113
|
+
options[:multi] = @multi.nil? ? other.multi : self.multi
|
114
|
+
options[:alias] = @alias.nil? ? other.alias : self.alias
|
115
|
+
options[:final] = @final || other.final
|
116
|
+
options[:type_lookup] = @type_lookup
|
117
|
+
|
118
|
+
merged = if self.root?
|
119
|
+
options[:root] = true
|
120
|
+
self.class.new(other.name, options)
|
121
|
+
else
|
122
|
+
self.class.new(@name, options)
|
123
|
+
end
|
124
|
+
|
125
|
+
# configured_in MUST be kept
|
126
|
+
merged.configured_in_section = self.configured_in_section
|
127
|
+
|
128
|
+
merged.argument = other.argument || self.argument
|
129
|
+
merged.params = other.params.merge(self.params)
|
130
|
+
merged.defaults = self.defaults.merge(other.defaults)
|
131
|
+
merged.sections = {}
|
132
|
+
(self.sections.keys + other.sections.keys).uniq.each do |section_key|
|
133
|
+
self_section = self.sections[section_key]
|
134
|
+
other_section = other.sections[section_key]
|
135
|
+
merged_section = if self_section && other_section
|
136
|
+
self_section.merge(other_section)
|
137
|
+
elsif self_section || other_section
|
138
|
+
self_section || other_section
|
139
|
+
else
|
140
|
+
raise "BUG: both of self and other section are nil"
|
141
|
+
end
|
142
|
+
merged.sections[section_key] = merged_section
|
143
|
+
end
|
144
|
+
|
145
|
+
merged
|
146
|
+
end
|
147
|
+
|
148
|
+
def merge_for_finalized(other)
|
149
|
+
# list what subclass can do for finalized section
|
150
|
+
# * append params/defaults/sections which are missing in superclass
|
151
|
+
# * change default values of superclass
|
152
|
+
# * overwrite init to make it enable to instantiate section objects with added default values
|
153
|
+
|
154
|
+
if other.final == false && overwrite?(other, :final)
|
155
|
+
raise ConfigError, "BUG: subclass cannot overwrite finalized base class's config_section"
|
156
|
+
end
|
157
|
+
|
158
|
+
[:param_name, :required, :multi, :alias, :configured_in_section].each do |prohibited_name|
|
159
|
+
if overwrite?(other, prohibited_name)
|
160
|
+
raise ConfigError, "BUG: subclass cannot overwrite base class's config_section: #{prohibited_name}"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
options = {}
|
165
|
+
options[:param_name] = @param_name
|
166
|
+
options[:init] = @init || other.init
|
167
|
+
options[:required] = @required.nil? ? other.required : self.required
|
168
|
+
options[:multi] = @multi.nil? ? other.multi : self.multi
|
169
|
+
options[:alias] = @alias.nil? ? other.alias : self.alias
|
170
|
+
options[:final] = true
|
171
|
+
options[:type_lookup] = @type_lookup
|
172
|
+
|
173
|
+
merged = if self.root?
|
174
|
+
options[:root] = true
|
175
|
+
self.class.new(other.name, options)
|
176
|
+
else
|
177
|
+
self.class.new(@name, options)
|
178
|
+
end
|
179
|
+
|
180
|
+
merged.configured_in_section = self.configured_in_section
|
181
|
+
|
182
|
+
merged.argument = self.argument || other.argument
|
183
|
+
merged.params = other.params.merge(self.params)
|
184
|
+
merged.defaults = self.defaults.merge(other.defaults)
|
185
|
+
merged.sections = {}
|
186
|
+
(self.sections.keys + other.sections.keys).uniq.each do |section_key|
|
187
|
+
self_section = self.sections[section_key]
|
188
|
+
other_section = other.sections[section_key]
|
189
|
+
merged_section = if self_section && other_section
|
190
|
+
other_section.merge(self_section)
|
191
|
+
elsif self_section || other_section
|
192
|
+
self_section || other_section
|
193
|
+
else
|
194
|
+
raise "BUG: both of self and other section are nil"
|
195
|
+
end
|
196
|
+
merged.sections[section_key] = merged_section
|
197
|
+
end
|
198
|
+
|
199
|
+
merged
|
200
|
+
end
|
201
|
+
|
202
|
+
def overwrite_defaults(other) # other is owner plugin's corresponding proxy
|
203
|
+
self.defaults = self.defaults.merge(other.defaults)
|
204
|
+
self.sections.keys.each do |section_key|
|
205
|
+
if other.sections.has_key?(section_key)
|
206
|
+
self.sections[section_key].overwrite_defaults(other.sections[section_key])
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def option_value_type!(name, opts, key, klass)
|
212
|
+
if opts.has_key?(key) && !opts[key].is_a?(klass)
|
213
|
+
raise ArgumentError, "#{name}: #{key} must be a #{klass}, but #{opts[key].class}"
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
def parameter_configuration(name, type = nil, **kwargs, &block)
|
218
|
+
name = name.to_sym
|
219
|
+
|
220
|
+
opts = {}
|
221
|
+
opts[:type] = type
|
222
|
+
opts.merge!(kwargs)
|
223
|
+
|
224
|
+
if block && type
|
225
|
+
raise ArgumentError, "#{name}: both of block and type cannot be specified"
|
226
|
+
end
|
227
|
+
|
228
|
+
begin
|
229
|
+
type = :string if type.nil?
|
230
|
+
block ||= @type_lookup.call(type)
|
231
|
+
rescue ConfigError
|
232
|
+
# override error message
|
233
|
+
raise ArgumentError, "#{name}: unknown config_argument type `#{type}'"
|
234
|
+
end
|
235
|
+
|
236
|
+
option_value_type!(name, opts, :desc, String)
|
237
|
+
option_value_type!(name, opts, :alias, Symbol)
|
238
|
+
option_value_type!(name, opts, :deprecated, String)
|
239
|
+
option_value_type!(name, opts, :obsoleted, String)
|
240
|
+
if type == :enum
|
241
|
+
if !opts.has_key?(:list) || !opts[:list].all?{|v| v.is_a?(Symbol) }
|
242
|
+
raise ArgumentError, "#{name}: enum parameter requires :list of Symbols"
|
243
|
+
end
|
244
|
+
end
|
245
|
+
option_value_type!(name, opts, :value_type, Symbol) # hash, array
|
246
|
+
|
247
|
+
if opts.has_key?(:default)
|
248
|
+
config_set_default(name, opts[:default])
|
249
|
+
end
|
250
|
+
|
251
|
+
if opts.has_key?(:desc)
|
252
|
+
config_set_desc(name, opts[:desc])
|
253
|
+
end
|
254
|
+
|
255
|
+
if opts[:deprecated] && opts[:obsoleted]
|
256
|
+
raise ArgumentError, "#{name}: both of deprecated and obsoleted cannot be specified at once"
|
257
|
+
end
|
258
|
+
|
259
|
+
[name, block, opts]
|
260
|
+
end
|
261
|
+
|
262
|
+
def configured_in(section_name)
|
263
|
+
if @configured_in_section
|
264
|
+
raise ArgumentError, "#{self.name}: configured_in called twice"
|
265
|
+
end
|
266
|
+
@configured_in_section = section_name.to_sym
|
267
|
+
end
|
268
|
+
|
269
|
+
def config_argument(name, type = nil, **kwargs, &block)
|
270
|
+
if @argument
|
271
|
+
raise ArgumentError, "#{self.name}: config_argument called twice"
|
272
|
+
end
|
273
|
+
name, block, opts = parameter_configuration(name, type, **kwargs, &block)
|
274
|
+
|
275
|
+
@argument = [name, block, opts]
|
276
|
+
name
|
277
|
+
end
|
278
|
+
|
279
|
+
def config_param(name, type = nil, **kwargs, &block)
|
280
|
+
name, block, opts = parameter_configuration(name, type, **kwargs, &block)
|
281
|
+
|
282
|
+
if @current_description
|
283
|
+
config_set_desc(name, @current_description)
|
284
|
+
@current_description = nil
|
285
|
+
end
|
286
|
+
|
287
|
+
@sections.delete(name)
|
288
|
+
@params[name] = [block, opts]
|
289
|
+
name
|
290
|
+
end
|
291
|
+
|
292
|
+
def config_set_default(name, defval)
|
293
|
+
name = name.to_sym
|
294
|
+
|
295
|
+
if @defaults.has_key?(name)
|
296
|
+
raise ArgumentError, "#{self.name}: default value specified twice for #{name}"
|
297
|
+
end
|
298
|
+
|
299
|
+
@defaults[name] = defval
|
300
|
+
nil
|
301
|
+
end
|
302
|
+
|
303
|
+
def config_set_desc(name, description)
|
304
|
+
name = name.to_sym
|
305
|
+
|
306
|
+
if @descriptions.has_key?(name)
|
307
|
+
raise ArgumentError, "#{self.name}: description specified twice for #{name}"
|
308
|
+
end
|
309
|
+
|
310
|
+
@descriptions[name] = description
|
311
|
+
nil
|
312
|
+
end
|
313
|
+
|
314
|
+
def desc(description)
|
315
|
+
@current_description = description
|
316
|
+
end
|
317
|
+
|
318
|
+
def config_section(name, **kwargs, &block)
|
319
|
+
unless block_given?
|
320
|
+
raise ArgumentError, "#{name}: config_section requires block parameter"
|
321
|
+
end
|
322
|
+
name = name.to_sym
|
323
|
+
|
324
|
+
sub_proxy = ConfigureProxy.new(name, type_lookup: @type_lookup, **kwargs)
|
325
|
+
sub_proxy.instance_exec(&block)
|
326
|
+
|
327
|
+
if sub_proxy.init?
|
328
|
+
if sub_proxy.argument && !sub_proxy.defaults.has_key?(sub_proxy.argument.first)
|
329
|
+
raise ArgumentError, "#{name}: init is specified, but default value of argument is missing"
|
330
|
+
end
|
331
|
+
if sub_proxy.params.keys.any?{|param_name| !sub_proxy.defaults.has_key?(param_name)}
|
332
|
+
raise ArgumentError, "#{name}: init is specified, but there're parameters without default values"
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
@params.delete(name)
|
337
|
+
@sections[name] = sub_proxy
|
338
|
+
|
339
|
+
name
|
340
|
+
end
|
341
|
+
|
342
|
+
def dump(level = 0)
|
343
|
+
dumped_config = ""
|
344
|
+
indent = " " * level
|
345
|
+
@params.each do |name, config|
|
346
|
+
dumped_config << "#{indent}#{name}: #{config[1][:type]}: <#{@defaults[name].inspect}>"
|
347
|
+
dumped_config << " # #{@descriptions[name]}" if @descriptions[name]
|
348
|
+
dumped_config << "\n"
|
349
|
+
end
|
350
|
+
@sections.each do |section_name, sub_proxy|
|
351
|
+
dumped_config << "#{indent}#{section_name}\n#{sub_proxy.dump(level + 1)}"
|
352
|
+
end
|
353
|
+
dumped_config
|
354
|
+
end
|
355
|
+
|
356
|
+
private
|
357
|
+
|
358
|
+
def overwrite?(other, attribute_name)
|
359
|
+
value = instance_variable_get("@#{attribute_name}")
|
360
|
+
other_value = other.__send__(attribute_name)
|
361
|
+
!value.nil? && !other_value.nil? && value != other_value
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
@@ -0,0 +1,149 @@
|
|
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 'json'
|
18
|
+
|
19
|
+
require 'fluent/config'
|
20
|
+
require 'fluent/config/element'
|
21
|
+
|
22
|
+
module Fluent
|
23
|
+
module Config
|
24
|
+
module DSL
|
25
|
+
module Parser
|
26
|
+
def self.read(path)
|
27
|
+
path = File.expand_path(path)
|
28
|
+
data = File.read(path)
|
29
|
+
parse(data, path)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.parse(source, source_path="config.rb")
|
33
|
+
Proxy.new('ROOT', nil).eval(source, source_path).to_config_element
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Proxy
|
38
|
+
def initialize(name, arg, include_basepath = Dir.pwd)
|
39
|
+
@element = Element.new(name, arg, self)
|
40
|
+
@include_basepath = include_basepath
|
41
|
+
end
|
42
|
+
|
43
|
+
def element
|
44
|
+
@element
|
45
|
+
end
|
46
|
+
|
47
|
+
def include_basepath
|
48
|
+
@include_basepath
|
49
|
+
end
|
50
|
+
|
51
|
+
def eval(source, source_path)
|
52
|
+
@element.instance_eval(source, source_path)
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_config_element
|
57
|
+
@element.instance_eval do
|
58
|
+
Config::Element.new(@name, @arg, @attrs, @elements)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_element(name, arg, block)
|
63
|
+
::Kernel.raise ::ArgumentError, "#{name} block must be specified" if block.nil?
|
64
|
+
|
65
|
+
proxy = self.class.new(name.to_s, arg)
|
66
|
+
proxy.element.instance_exec(&block)
|
67
|
+
|
68
|
+
@element.instance_eval do
|
69
|
+
@elements.push(proxy.to_config_element)
|
70
|
+
end
|
71
|
+
|
72
|
+
self
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class Element < BasicObject
|
77
|
+
def initialize(name, arg, proxy)
|
78
|
+
@name = name
|
79
|
+
@arg = arg || ''
|
80
|
+
@attrs = {}
|
81
|
+
@elements = []
|
82
|
+
@proxy = proxy
|
83
|
+
end
|
84
|
+
|
85
|
+
def to_int
|
86
|
+
__id__
|
87
|
+
end
|
88
|
+
|
89
|
+
def method_missing(name, *args, &block)
|
90
|
+
::Kernel.raise ::ArgumentError, "Configuration DSL Syntax Error: only one argument allowed" if args.size > 1
|
91
|
+
value = args.first
|
92
|
+
|
93
|
+
if block
|
94
|
+
proxy = Proxy.new(name.to_s, value)
|
95
|
+
proxy.element.instance_exec(&block)
|
96
|
+
@elements.push(proxy.to_config_element)
|
97
|
+
else
|
98
|
+
@attrs[name.to_s] = if value.is_a?(Array) || value.is_a?(Hash)
|
99
|
+
JSON.dump(value)
|
100
|
+
else
|
101
|
+
value.to_s
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
self
|
106
|
+
end
|
107
|
+
|
108
|
+
def include(*args)
|
109
|
+
::Kernel.raise ::ArgumentError, "#{name} block requires arguments for include path" if args.nil? || args.size != 1
|
110
|
+
if args.first =~ /\.rb$/
|
111
|
+
path = File.expand_path(args.first)
|
112
|
+
data = File.read(path)
|
113
|
+
self.instance_eval(data, path)
|
114
|
+
else
|
115
|
+
ss = StringScanner.new('')
|
116
|
+
Config::V1Parser.new(ss, @proxy.include_basepath, '', nil).eval_include(@attrs, @elements, args.first)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def source(&block)
|
121
|
+
@proxy.add_element('source', nil, block)
|
122
|
+
end
|
123
|
+
|
124
|
+
def match(*args, &block)
|
125
|
+
::Kernel.raise ::ArgumentError, "#{name} block requires arguments for match pattern" if args.nil? || args.size != 1
|
126
|
+
@proxy.add_element('match', args.first, block)
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.const_missing(name)
|
130
|
+
return ::Kernel.const_get(name) if ::Kernel.const_defined?(name)
|
131
|
+
|
132
|
+
if name.to_s =~ /^Fluent::Config::DSL::Element::(.*)$/
|
133
|
+
name = "#{$1}".to_sym
|
134
|
+
return ::Kernel.const_get(name) if ::Kernel.const_defined?(name)
|
135
|
+
end
|
136
|
+
::Kernel.eval("#{name}")
|
137
|
+
end
|
138
|
+
|
139
|
+
def ruby(&block)
|
140
|
+
if block
|
141
|
+
@proxy.instance_exec(&block)
|
142
|
+
else
|
143
|
+
::Kernel
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|