fluentd 0.12.40 → 0.14.0
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 +4 -4
- data/.github/ISSUE_TEMPLATE.md +6 -0
- data/.gitignore +2 -0
- data/.travis.yml +33 -21
- data/CONTRIBUTING.md +1 -0
- data/ChangeLog +810 -237
- data/README.md +0 -25
- data/Rakefile +2 -1
- data/Vagrantfile +17 -0
- data/appveyor.yml +35 -0
- data/example/filter_stdout.conf +5 -5
- data/example/in_forward.conf +2 -2
- data/example/in_http.conf +2 -2
- data/example/in_out_forward.conf +17 -0
- data/example/in_syslog.conf +2 -2
- data/example/in_tail.conf +2 -2
- data/example/in_tcp.conf +2 -2
- data/example/in_udp.conf +2 -2
- data/example/out_copy.conf +4 -4
- data/example/out_file.conf +2 -2
- data/example/out_forward.conf +2 -2
- data/example/out_forward_buf_file.conf +23 -0
- data/example/v0_12_filter.conf +8 -8
- data/fluent.conf +29 -0
- data/fluentd.gemspec +18 -11
- data/lib/fluent/agent.rb +60 -58
- data/lib/fluent/command/cat.rb +1 -1
- data/lib/fluent/command/debug.rb +7 -5
- data/lib/fluent/command/fluentd.rb +97 -2
- data/lib/fluent/compat/call_super_mixin.rb +67 -0
- data/lib/fluent/compat/filter.rb +50 -0
- data/lib/fluent/compat/formatter.rb +109 -0
- data/lib/fluent/compat/input.rb +50 -0
- data/lib/fluent/compat/output.rb +617 -0
- data/lib/fluent/compat/output_chain.rb +60 -0
- data/lib/fluent/compat/parser.rb +163 -0
- data/lib/fluent/compat/propagate_default.rb +62 -0
- data/lib/fluent/config.rb +23 -20
- data/lib/fluent/config/configure_proxy.rb +119 -70
- data/lib/fluent/config/dsl.rb +5 -18
- data/lib/fluent/config/element.rb +72 -8
- data/lib/fluent/config/error.rb +0 -3
- data/lib/fluent/config/literal_parser.rb +0 -2
- data/lib/fluent/config/parser.rb +4 -4
- data/lib/fluent/config/section.rb +39 -28
- data/lib/fluent/config/types.rb +2 -13
- data/lib/fluent/config/v1_parser.rb +1 -3
- data/lib/fluent/configurable.rb +48 -16
- data/lib/fluent/daemon.rb +15 -0
- data/lib/fluent/engine.rb +26 -52
- data/lib/fluent/env.rb +6 -4
- data/lib/fluent/event.rb +58 -11
- data/lib/fluent/event_router.rb +5 -5
- data/lib/fluent/filter.rb +2 -50
- data/lib/fluent/formatter.rb +4 -293
- data/lib/fluent/input.rb +2 -32
- data/lib/fluent/label.rb +2 -2
- data/lib/fluent/load.rb +3 -2
- data/lib/fluent/log.rb +107 -38
- data/lib/fluent/match.rb +0 -36
- data/lib/fluent/mixin.rb +117 -7
- data/lib/fluent/msgpack_factory.rb +62 -0
- data/lib/fluent/output.rb +7 -612
- data/lib/fluent/output_chain.rb +23 -0
- data/lib/fluent/parser.rb +4 -800
- data/lib/fluent/plugin.rb +100 -121
- data/lib/fluent/plugin/bare_output.rb +63 -0
- data/lib/fluent/plugin/base.rb +121 -0
- data/lib/fluent/plugin/buf_file.rb +101 -182
- data/lib/fluent/plugin/buf_memory.rb +9 -92
- data/lib/fluent/plugin/buffer.rb +473 -0
- data/lib/fluent/plugin/buffer/chunk.rb +135 -0
- data/lib/fluent/plugin/buffer/file_chunk.rb +339 -0
- data/lib/fluent/plugin/buffer/memory_chunk.rb +100 -0
- data/lib/fluent/plugin/exec_util.rb +80 -75
- data/lib/fluent/plugin/file_util.rb +33 -28
- data/lib/fluent/plugin/file_wrapper.rb +120 -0
- data/lib/fluent/plugin/filter.rb +51 -0
- data/lib/fluent/plugin/filter_grep.rb +13 -40
- data/lib/fluent/plugin/filter_record_transformer.rb +22 -18
- data/lib/fluent/plugin/formatter.rb +93 -0
- data/lib/fluent/plugin/formatter_csv.rb +48 -0
- data/lib/fluent/plugin/formatter_hash.rb +32 -0
- data/lib/fluent/plugin/formatter_json.rb +47 -0
- data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
- data/lib/fluent/plugin/formatter_msgpack.rb +32 -0
- data/lib/fluent/plugin/formatter_out_file.rb +45 -0
- data/lib/fluent/plugin/formatter_single_value.rb +34 -0
- data/lib/fluent/plugin/formatter_stdout.rb +39 -0
- data/lib/fluent/plugin/in_debug_agent.rb +4 -0
- data/lib/fluent/plugin/in_dummy.rb +22 -18
- data/lib/fluent/plugin/in_exec.rb +18 -8
- data/lib/fluent/plugin/in_forward.rb +36 -79
- data/lib/fluent/plugin/in_gc_stat.rb +4 -0
- data/lib/fluent/plugin/in_http.rb +21 -18
- data/lib/fluent/plugin/in_monitor_agent.rb +15 -48
- data/lib/fluent/plugin/in_object_space.rb +6 -1
- data/lib/fluent/plugin/in_stream.rb +7 -3
- data/lib/fluent/plugin/in_syslog.rb +46 -95
- data/lib/fluent/plugin/in_tail.rb +51 -595
- data/lib/fluent/plugin/in_tcp.rb +8 -1
- data/lib/fluent/plugin/in_udp.rb +8 -14
- data/lib/fluent/plugin/input.rb +33 -0
- data/lib/fluent/plugin/multi_output.rb +95 -0
- data/lib/fluent/plugin/out_buffered_null.rb +59 -0
- data/lib/fluent/plugin/out_copy.rb +11 -7
- data/lib/fluent/plugin/out_exec.rb +15 -11
- data/lib/fluent/plugin/out_exec_filter.rb +18 -10
- data/lib/fluent/plugin/out_file.rb +34 -5
- data/lib/fluent/plugin/out_forward.rb +19 -9
- data/lib/fluent/plugin/out_null.rb +0 -14
- data/lib/fluent/plugin/out_roundrobin.rb +11 -7
- data/lib/fluent/plugin/out_stdout.rb +5 -7
- data/lib/fluent/plugin/out_stream.rb +3 -1
- data/lib/fluent/plugin/output.rb +979 -0
- data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
- data/lib/fluent/plugin/parser.rb +244 -0
- data/lib/fluent/plugin/parser_apache.rb +24 -0
- data/lib/fluent/plugin/parser_apache2.rb +84 -0
- data/lib/fluent/plugin/parser_apache_error.rb +21 -0
- data/lib/fluent/plugin/parser_csv.rb +31 -0
- data/lib/fluent/plugin/parser_json.rb +79 -0
- data/lib/fluent/plugin/parser_ltsv.rb +50 -0
- data/lib/fluent/plugin/parser_multiline.rb +102 -0
- data/lib/fluent/plugin/parser_nginx.rb +24 -0
- data/lib/fluent/plugin/parser_none.rb +36 -0
- data/lib/fluent/plugin/parser_syslog.rb +82 -0
- data/lib/fluent/plugin/parser_tsv.rb +37 -0
- data/lib/fluent/plugin/socket_util.rb +120 -114
- data/lib/fluent/plugin/storage.rb +84 -0
- data/lib/fluent/plugin/storage_local.rb +116 -0
- data/lib/fluent/plugin/string_util.rb +16 -13
- data/lib/fluent/plugin_helper.rb +39 -0
- data/lib/fluent/plugin_helper/child_process.rb +298 -0
- data/lib/fluent/plugin_helper/compat_parameters.rb +99 -0
- data/lib/fluent/plugin_helper/event_emitter.rb +80 -0
- data/lib/fluent/plugin_helper/event_loop.rb +118 -0
- data/lib/fluent/plugin_helper/retry_state.rb +177 -0
- data/lib/fluent/plugin_helper/storage.rb +308 -0
- data/lib/fluent/plugin_helper/thread.rb +147 -0
- data/lib/fluent/plugin_helper/timer.rb +85 -0
- data/lib/fluent/plugin_id.rb +63 -0
- data/lib/fluent/process.rb +21 -30
- data/lib/fluent/registry.rb +21 -9
- data/lib/fluent/root_agent.rb +115 -40
- data/lib/fluent/supervisor.rb +330 -320
- data/lib/fluent/system_config.rb +42 -18
- data/lib/fluent/test.rb +6 -1
- data/lib/fluent/test/base.rb +23 -3
- data/lib/fluent/test/driver/base.rb +247 -0
- data/lib/fluent/test/driver/event_feeder.rb +98 -0
- data/lib/fluent/test/driver/filter.rb +35 -0
- data/lib/fluent/test/driver/input.rb +31 -0
- data/lib/fluent/test/driver/output.rb +78 -0
- data/lib/fluent/test/driver/test_event_router.rb +45 -0
- data/lib/fluent/test/filter_test.rb +0 -1
- data/lib/fluent/test/formatter_test.rb +2 -1
- data/lib/fluent/test/input_test.rb +23 -17
- data/lib/fluent/test/output_test.rb +28 -39
- data/lib/fluent/test/parser_test.rb +1 -1
- data/lib/fluent/time.rb +104 -1
- data/lib/fluent/{status.rb → unique_id.rb} +15 -24
- data/lib/fluent/version.rb +1 -1
- data/lib/fluent/winsvc.rb +72 -0
- data/test/compat/test_calls_super.rb +164 -0
- data/test/config/test_config_parser.rb +83 -0
- data/test/config/test_configurable.rb +547 -274
- data/test/config/test_configure_proxy.rb +146 -29
- data/test/config/test_dsl.rb +3 -181
- data/test/config/test_element.rb +274 -0
- data/test/config/test_literal_parser.rb +1 -1
- data/test/config/test_section.rb +79 -7
- data/test/config/test_system_config.rb +21 -0
- data/test/config/test_types.rb +3 -26
- data/test/helper.rb +78 -8
- data/test/plugin/test_bare_output.rb +118 -0
- data/test/plugin/test_base.rb +75 -0
- data/test/plugin/test_buf_file.rb +420 -521
- data/test/plugin/test_buf_memory.rb +32 -194
- data/test/plugin/test_buffer.rb +981 -0
- data/test/plugin/test_buffer_chunk.rb +110 -0
- data/test/plugin/test_buffer_file_chunk.rb +770 -0
- data/test/plugin/test_buffer_memory_chunk.rb +265 -0
- data/test/plugin/test_filter.rb +255 -0
- data/test/plugin/test_filter_grep.rb +2 -73
- data/test/plugin/test_filter_record_transformer.rb +24 -68
- data/test/plugin/test_filter_stdout.rb +6 -6
- data/test/plugin/test_in_debug_agent.rb +2 -0
- data/test/plugin/test_in_dummy.rb +11 -17
- data/test/plugin/test_in_exec.rb +6 -25
- data/test/plugin/test_in_forward.rb +112 -151
- data/test/plugin/test_in_gc_stat.rb +2 -0
- data/test/plugin/test_in_http.rb +106 -157
- data/test/plugin/test_in_object_space.rb +21 -5
- data/test/plugin/test_in_stream.rb +14 -13
- data/test/plugin/test_in_syslog.rb +30 -275
- data/test/plugin/test_in_tail.rb +95 -234
- data/test/plugin/test_in_tcp.rb +14 -0
- data/test/plugin/test_in_udp.rb +21 -13
- data/test/plugin/test_input.rb +122 -0
- data/test/plugin/test_multi_output.rb +180 -0
- data/test/plugin/test_out_buffered_null.rb +79 -0
- data/test/plugin/test_out_copy.rb +15 -2
- data/test/plugin/test_out_exec.rb +75 -25
- data/test/plugin/test_out_exec_filter.rb +74 -8
- data/test/plugin/test_out_file.rb +61 -7
- data/test/plugin/test_out_forward.rb +92 -15
- data/test/plugin/test_out_roundrobin.rb +1 -0
- data/test/plugin/test_out_stdout.rb +22 -13
- data/test/plugin/test_out_stream.rb +18 -0
- data/test/plugin/test_output.rb +515 -0
- data/test/plugin/test_output_as_buffered.rb +1540 -0
- data/test/plugin/test_output_as_buffered_overflow.rb +247 -0
- data/test/plugin/test_output_as_buffered_retries.rb +808 -0
- data/test/plugin/test_output_as_buffered_secondary.rb +776 -0
- data/test/plugin/test_output_as_standard.rb +362 -0
- data/test/plugin/test_owned_by.rb +35 -0
- data/test/plugin/test_storage.rb +167 -0
- data/test/plugin/test_storage_local.rb +8 -0
- data/test/plugin_helper/test_child_process.rb +599 -0
- data/test/plugin_helper/test_compat_parameters.rb +175 -0
- data/test/plugin_helper/test_event_emitter.rb +51 -0
- data/test/plugin_helper/test_event_loop.rb +52 -0
- data/test/plugin_helper/test_retry_state.rb +399 -0
- data/test/plugin_helper/test_storage.rb +411 -0
- data/test/plugin_helper/test_thread.rb +164 -0
- data/test/plugin_helper/test_timer.rb +100 -0
- data/test/scripts/exec_script.rb +0 -6
- data/test/scripts/fluent/plugin/out_test.rb +3 -0
- data/test/test_config.rb +13 -4
- data/test/test_event.rb +24 -13
- data/test/test_event_router.rb +8 -7
- data/test/test_event_time.rb +187 -0
- data/test/test_formatter.rb +13 -51
- data/test/test_input.rb +1 -1
- data/test/test_log.rb +239 -16
- data/test/test_mixin.rb +1 -1
- data/test/test_output.rb +53 -66
- data/test/test_parser.rb +105 -323
- data/test/test_plugin_helper.rb +81 -0
- data/test/test_root_agent.rb +4 -52
- data/test/test_supervisor.rb +272 -0
- data/test/test_unique_id.rb +47 -0
- metadata +180 -54
- data/lib/fluent/buffer.rb +0 -365
- data/lib/fluent/plugin/filter_parser.rb +0 -107
- data/lib/fluent/plugin/in_status.rb +0 -76
- data/lib/fluent/test/helpers.rb +0 -86
- data/test/plugin/data/log/foo/bar2 +0 -0
- data/test/plugin/test_filter_parser.rb +0 -744
- data/test/plugin/test_in_status.rb +0 -38
- data/test/test_buffer.rb +0 -624
data/lib/fluent/plugin.rb
CHANGED
|
@@ -14,169 +14,148 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
#
|
|
16
16
|
|
|
17
|
+
require 'fluent/registry'
|
|
17
18
|
require 'fluent/config/error'
|
|
18
19
|
|
|
19
20
|
module Fluent
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
module Plugin
|
|
22
|
+
SEARCH_PATHS = []
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
@filter = {}
|
|
27
|
-
@buffer = {}
|
|
28
|
-
end
|
|
24
|
+
# plugins for fluentd: fluent/plugin/type_NAME.rb
|
|
25
|
+
# plugins for fluentd plugins: fluent/plugin/type/NAME.rb
|
|
26
|
+
# ex: storage, buffer chunk, ...
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
# first class plugins (instantiated by Engine)
|
|
29
|
+
INPUT_REGISTRY = Registry.new(:input, 'fluent/plugin/in_')
|
|
30
|
+
OUTPUT_REGISTRY = Registry.new(:output, 'fluent/plugin/out_')
|
|
31
|
+
FILTER_REGISTRY = Registry.new(:filter, 'fluent/plugin/filter_')
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
# feature plugin: second class plugins (instanciated by Plugins or Helpers)
|
|
34
|
+
BUFFER_REGISTRY = Registry.new(:buffer, 'fluent/plugin/buf_')
|
|
35
|
+
PARSER_REGISTRY = Registry.new(:parser, 'fluent/plugin/parser_')
|
|
36
|
+
FORMATTER_REGISTRY = Registry.new(:formatter, 'fluent/plugin/formatter_')
|
|
37
|
+
STORAGE_REGISTRY = Registry.new(:storage, 'fluent/plugin/storage_')
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
register_impl('filter', @filter, type, klass)
|
|
40
|
-
end
|
|
39
|
+
REGISTRIES = [INPUT_REGISTRY, OUTPUT_REGISTRY, FILTER_REGISTRY, BUFFER_REGISTRY, PARSER_REGISTRY, FORMATTER_REGISTRY, STORAGE_REGISTRY]
|
|
41
40
|
|
|
42
|
-
def
|
|
43
|
-
register_impl('
|
|
41
|
+
def self.register_input(type, klass)
|
|
42
|
+
register_impl('input', INPUT_REGISTRY, type, klass)
|
|
44
43
|
end
|
|
45
44
|
|
|
46
|
-
def
|
|
47
|
-
|
|
45
|
+
def self.register_output(type, klass)
|
|
46
|
+
register_impl('output', OUTPUT_REGISTRY, type, klass)
|
|
48
47
|
end
|
|
49
48
|
|
|
50
|
-
def
|
|
51
|
-
|
|
49
|
+
def self.register_filter(type, klass)
|
|
50
|
+
register_impl('filter', FILTER_REGISTRY, type, klass)
|
|
52
51
|
end
|
|
53
52
|
|
|
54
|
-
def
|
|
55
|
-
|
|
53
|
+
def self.register_buffer(type, klass)
|
|
54
|
+
register_impl('buffer', BUFFER_REGISTRY, type, klass)
|
|
56
55
|
end
|
|
57
56
|
|
|
58
|
-
def
|
|
59
|
-
|
|
57
|
+
def self.register_parser(type, klass_or_proc)
|
|
58
|
+
if klass_or_proc.is_a?(Regexp)
|
|
59
|
+
# This usage is not recommended for new API
|
|
60
|
+
require 'fluent/parser'
|
|
61
|
+
register_impl('parser', PARSER_REGISTRY, type, Proc.new { Fluent::TextParser::RegexpParser.new(klass_or_proc) })
|
|
62
|
+
else
|
|
63
|
+
register_impl('parser', PARSER_REGISTRY, type, klass_or_proc)
|
|
64
|
+
end
|
|
60
65
|
end
|
|
61
66
|
|
|
62
|
-
def
|
|
63
|
-
|
|
67
|
+
def self.register_formatter(type, klass_or_proc)
|
|
68
|
+
if klass_or_proc.respond_to?(:call) && klass_or_proc.arity == 3 # Proc.new { |tag, time, record| }
|
|
69
|
+
# This usage is not recommended for new API
|
|
70
|
+
require 'fluent/formatter'
|
|
71
|
+
register_impl('formatter', FORMATTER_REGISTRY, type, Proc.new { Fluent::TextFormatter::ProcWrappedFormatter.new(klass_or_proc) })
|
|
72
|
+
else
|
|
73
|
+
register_impl('formatter', FORMATTER_REGISTRY, type, klass_or_proc)
|
|
74
|
+
end
|
|
64
75
|
end
|
|
65
76
|
|
|
66
|
-
def
|
|
67
|
-
|
|
77
|
+
def self.register_storage(type, klass)
|
|
78
|
+
register_impl('storage', STORAGE_REGISTRY, type, klass)
|
|
68
79
|
end
|
|
69
80
|
|
|
70
|
-
def
|
|
71
|
-
|
|
72
|
-
|
|
81
|
+
def self.lookup_type_from_class(klass_or_its_name)
|
|
82
|
+
klass = if klass_or_its_name.is_a? Class
|
|
83
|
+
klass_or_its_name
|
|
84
|
+
elsif klass_or_its_name.is_a? String
|
|
85
|
+
eval(klass_or_its_name) # const_get can't handle qualified klass name (ex: A::B)
|
|
86
|
+
else
|
|
87
|
+
raise ArgumentError, "invalid argument type #{klass_or_its_name.class}: #{klass_or_its_name}"
|
|
88
|
+
end
|
|
89
|
+
REGISTRIES.reduce(nil){|a, r| a || r.reverse_lookup(klass) }
|
|
73
90
|
end
|
|
74
91
|
|
|
75
|
-
def
|
|
76
|
-
|
|
77
|
-
|
|
92
|
+
def self.add_plugin_dir(dir)
|
|
93
|
+
REGISTRIES.each do |r|
|
|
94
|
+
r.paths.push(dir)
|
|
95
|
+
end
|
|
96
|
+
nil
|
|
78
97
|
end
|
|
79
98
|
|
|
80
|
-
def
|
|
81
|
-
|
|
82
|
-
load_plugin_dir(dir)
|
|
99
|
+
def self.new_input(type)
|
|
100
|
+
new_impl('input', INPUT_REGISTRY, type)
|
|
83
101
|
end
|
|
84
102
|
|
|
85
|
-
def
|
|
86
|
-
|
|
87
|
-
Dir.entries(dir).sort.each {|fname|
|
|
88
|
-
if fname =~ /\.rb$/
|
|
89
|
-
require File.join(dir, fname)
|
|
90
|
-
end
|
|
91
|
-
}
|
|
92
|
-
nil
|
|
103
|
+
def self.new_output(type)
|
|
104
|
+
new_impl('output', OUTPUT_REGISTRY, type)
|
|
93
105
|
end
|
|
94
106
|
|
|
95
|
-
def
|
|
96
|
-
|
|
107
|
+
def self.new_filter(type)
|
|
108
|
+
new_impl('filter', FILTER_REGISTRY, type)
|
|
97
109
|
end
|
|
98
110
|
|
|
99
|
-
def
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
else
|
|
103
|
-
klass_or_str
|
|
104
|
-
end
|
|
111
|
+
def self.new_buffer(type, parent: nil)
|
|
112
|
+
new_impl('buffer', BUFFER_REGISTRY, type, parent)
|
|
113
|
+
end
|
|
105
114
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
@output.each { |name, plugin|
|
|
110
|
-
return name if plugin == klass
|
|
111
|
-
}
|
|
112
|
-
@filter.each { |name, plugin|
|
|
113
|
-
return name if plugin == klass
|
|
114
|
-
}
|
|
115
|
+
def self.new_parser(type, parent: nil)
|
|
116
|
+
require 'fluent/parser'
|
|
115
117
|
|
|
116
|
-
|
|
118
|
+
if type[0] == '/' && type[-1] == '/'
|
|
119
|
+
# This usage is not recommended for new API... create RegexpParser directly
|
|
120
|
+
require 'fluent/parser'
|
|
121
|
+
Fluent::TextParser.lookup(type)
|
|
122
|
+
else
|
|
123
|
+
new_impl('parser', PARSER_REGISTRY, type, parent)
|
|
124
|
+
end
|
|
117
125
|
end
|
|
118
126
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
map[type] = klass
|
|
122
|
-
$log.trace { "registered #{name} plugin '#{type}'" }
|
|
123
|
-
nil
|
|
127
|
+
def self.new_formatter(type, parent: nil)
|
|
128
|
+
new_impl('formatter', FORMATTER_REGISTRY, type, parent)
|
|
124
129
|
end
|
|
125
130
|
|
|
126
|
-
def
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
end
|
|
130
|
-
try_load_plugin(name, type)
|
|
131
|
-
if klass = map[type]
|
|
132
|
-
return klass.new
|
|
133
|
-
end
|
|
134
|
-
raise ConfigError, "Unknown #{name} plugin '#{type}'. Run 'gem search -rd fluent-plugin' to find plugins"
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
def try_load_plugin(name, type)
|
|
138
|
-
case name
|
|
139
|
-
when 'input'
|
|
140
|
-
path = "fluent/plugin/in_#{type}"
|
|
141
|
-
when 'output'
|
|
142
|
-
path = "fluent/plugin/out_#{type}"
|
|
143
|
-
when 'filter'
|
|
144
|
-
path = "fluent/plugin/filter_#{type}"
|
|
145
|
-
when 'buffer'
|
|
146
|
-
path = "fluent/plugin/buf_#{type}"
|
|
147
|
-
else
|
|
148
|
-
return
|
|
149
|
-
end
|
|
131
|
+
def self.new_storage(type, parent: nil)
|
|
132
|
+
new_impl('storage', STORAGE_REGISTRY, type, parent)
|
|
133
|
+
end
|
|
150
134
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
File.exist?(lpath) ? lpath : nil
|
|
155
|
-
}.compact
|
|
156
|
-
unless files.empty?
|
|
157
|
-
# prefer newer version
|
|
158
|
-
require File.expand_path(files.sort.last)
|
|
159
|
-
return
|
|
135
|
+
def self.register_impl(kind, registry, type, value)
|
|
136
|
+
if !value.is_a?(Class) && !value.respond_to?(:call)
|
|
137
|
+
raise Fluent::ConfigError, "Invalid implementation as #{kind} plugin: '#{type}'. It must be a Class, or callable."
|
|
160
138
|
end
|
|
139
|
+
registry.register(type, value)
|
|
140
|
+
$log.trace "registered #{kind} plugin '#{type}'" if defined?($log)
|
|
141
|
+
nil
|
|
142
|
+
end
|
|
161
143
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
end
|
|
176
|
-
}
|
|
144
|
+
def self.new_impl(kind, registry, type, parent=nil)
|
|
145
|
+
# "'type' not found" is handled by registry
|
|
146
|
+
obj = registry.lookup(type)
|
|
147
|
+
impl = case
|
|
148
|
+
when obj.is_a?(Class)
|
|
149
|
+
obj.new
|
|
150
|
+
when obj.respond_to?(:call) && obj.arity == 0
|
|
151
|
+
obj.call
|
|
152
|
+
else
|
|
153
|
+
raise Fluent::ConfigError, "#{kind} plugin '#{type}' is not a Class nor callable (without arguments)."
|
|
154
|
+
end
|
|
155
|
+
if parent && impl.respond_to?("owner=")
|
|
156
|
+
impl.owner = parent
|
|
177
157
|
end
|
|
158
|
+
impl
|
|
178
159
|
end
|
|
179
160
|
end
|
|
180
|
-
|
|
181
|
-
Plugin = PluginClass.new
|
|
182
161
|
end
|
|
@@ -0,0 +1,63 @@
|
|
|
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/plugin/base'
|
|
18
|
+
|
|
19
|
+
require 'fluent/log'
|
|
20
|
+
require 'fluent/plugin_id'
|
|
21
|
+
require 'fluent/plugin_helper'
|
|
22
|
+
|
|
23
|
+
module Fluent
|
|
24
|
+
module Plugin
|
|
25
|
+
class BareOutput < Base
|
|
26
|
+
# DO NOT USE THIS plugin for normal output plugin. Use Output instead.
|
|
27
|
+
# This output plugin base class is only for meta-output plugins
|
|
28
|
+
# which cannot be implemented on MultiOutput.
|
|
29
|
+
# E.g,: forest, config-expander
|
|
30
|
+
|
|
31
|
+
include PluginId
|
|
32
|
+
include PluginLoggerMixin
|
|
33
|
+
include PluginHelper::Mixin
|
|
34
|
+
|
|
35
|
+
attr_reader :num_errors, :emit_count, :emit_records
|
|
36
|
+
|
|
37
|
+
def process(tag, es)
|
|
38
|
+
raise NotImplementedError, "BUG: output plugins MUST implement this method"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def initialize
|
|
42
|
+
super
|
|
43
|
+
@counters_monitor = Monitor.new
|
|
44
|
+
# TODO: well organized counters
|
|
45
|
+
@num_errors = 0
|
|
46
|
+
@emit_count = 0
|
|
47
|
+
@emit_records = 0
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def emit_sync(tag, es)
|
|
51
|
+
@counters_monitor.synchronize{ @emit_count += 1 }
|
|
52
|
+
begin
|
|
53
|
+
process(tag, es)
|
|
54
|
+
@counters_monitor.synchronize{ @emit_records += es.size }
|
|
55
|
+
rescue
|
|
56
|
+
@counters_monitor.synchronize{ @num_errors += 1 }
|
|
57
|
+
raise
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
alias :emit_events :emit_sync
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
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/plugin'
|
|
18
|
+
require 'fluent/configurable'
|
|
19
|
+
require 'fluent/system_config'
|
|
20
|
+
|
|
21
|
+
module Fluent
|
|
22
|
+
module Plugin
|
|
23
|
+
class Base
|
|
24
|
+
include Configurable
|
|
25
|
+
include SystemConfig::Mixin
|
|
26
|
+
|
|
27
|
+
State = Struct.new(:configure, :start, :stop, :before_shutdown, :shutdown, :after_shutdown, :close, :terminate)
|
|
28
|
+
|
|
29
|
+
def initialize
|
|
30
|
+
super
|
|
31
|
+
@_state = State.new(false, false, false, false, false, false, false, false)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def has_router?
|
|
35
|
+
false
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def configure(conf)
|
|
39
|
+
super
|
|
40
|
+
@_state ||= State.new(false, false, false, false, false, false, false, false)
|
|
41
|
+
@_state.configure = true
|
|
42
|
+
self
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def start
|
|
46
|
+
@_state.start = true
|
|
47
|
+
self
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def stop
|
|
51
|
+
@_state.stop = true
|
|
52
|
+
self
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def before_shutdown
|
|
56
|
+
@_state.before_shutdown = true
|
|
57
|
+
self
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def shutdown
|
|
61
|
+
@_state.shutdown = true
|
|
62
|
+
self
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def after_shutdown
|
|
66
|
+
@_state.after_shutdown = true
|
|
67
|
+
self
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def close
|
|
71
|
+
@_state.close = true
|
|
72
|
+
self
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def terminate
|
|
76
|
+
@_state.terminate = true
|
|
77
|
+
self
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def configured?
|
|
81
|
+
@_state.configure
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def started?
|
|
85
|
+
@_state.start
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def stopped?
|
|
89
|
+
@_state.stop
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def before_shutdown?
|
|
93
|
+
@_state.before_shutdown
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def shutdown?
|
|
97
|
+
@_state.shutdown
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def after_shutdown?
|
|
101
|
+
@_state.after_shutdown
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def closed?
|
|
105
|
+
@_state.close
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def terminated?
|
|
109
|
+
@_state.terminate
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def inspect
|
|
113
|
+
# Plugin instances are sometimes too big to dump because it may have too many thins (buffer,storage, ...)
|
|
114
|
+
# Original commit comment says that:
|
|
115
|
+
# To emulate normal inspect behavior `ruby -e'o=Object.new;p o;p (o.__id__<<1).to_s(16)'`.
|
|
116
|
+
# https://github.com/ruby/ruby/blob/trunk/gc.c#L788
|
|
117
|
+
"#<%s:%014x>" % [self.class.name, '0x%014x' % (__id__ << 1)]
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|