fluentd 0.12.40 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fluentd might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +6 -0
- data/.gitignore +2 -0
- data/.travis.yml +33 -21
- data/CONTRIBUTING.md +1 -0
- data/ChangeLog +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
@@ -0,0 +1,42 @@
|
|
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/formatter'
|
18
|
+
|
19
|
+
module Fluent
|
20
|
+
module Plugin
|
21
|
+
class LabeledTSVFormatter < Formatter
|
22
|
+
Plugin.register_formatter('ltsv', self)
|
23
|
+
|
24
|
+
# http://ltsv.org/
|
25
|
+
include HandleTagAndTimeMixin
|
26
|
+
|
27
|
+
config_param :delimiter, :string, default: "\t"
|
28
|
+
config_param :label_delimiter, :string, default: ":"
|
29
|
+
|
30
|
+
# TODO: escaping for \t in values
|
31
|
+
def format(tag, time, record)
|
32
|
+
filter_record(tag, time, record)
|
33
|
+
formatted = record.inject('') { |result, pair|
|
34
|
+
result << @delimiter if result.length.nonzero?
|
35
|
+
result << "#{pair.first}#{@label_delimiter}#{pair.last}"
|
36
|
+
}
|
37
|
+
formatted << "\n"
|
38
|
+
formatted
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,32 @@
|
|
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/formatter'
|
18
|
+
|
19
|
+
module Fluent
|
20
|
+
module Plugin
|
21
|
+
class MessagePackFormatter < Formatter
|
22
|
+
Plugin.register_formatter('msgpack', self)
|
23
|
+
|
24
|
+
include HandleTagAndTimeMixin
|
25
|
+
include StructuredFormatMixin
|
26
|
+
|
27
|
+
def format_record(record)
|
28
|
+
record.to_msgpack
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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/formatter'
|
18
|
+
|
19
|
+
module Fluent
|
20
|
+
module Plugin
|
21
|
+
class OutFileFormatter < Formatter
|
22
|
+
Plugin.register_formatter('out_file', self)
|
23
|
+
|
24
|
+
include HandleTagAndTimeMixin
|
25
|
+
|
26
|
+
config_param :output_time, :bool, default: true
|
27
|
+
config_param :output_tag, :bool, default: true
|
28
|
+
config_param :delimiter, default: "\t" do |val|
|
29
|
+
case val
|
30
|
+
when /SPACE/i then ' '
|
31
|
+
when /COMMA/i then ','
|
32
|
+
else "\t"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def format(tag, time, record)
|
37
|
+
filter_record(tag, time, record)
|
38
|
+
header = ''
|
39
|
+
header << "#{@timef.format(time)}#{@delimiter}" if @output_time
|
40
|
+
header << "#{tag}#{@delimiter}" if @output_tag
|
41
|
+
"#{header}#{Yajl.dump(record)}\n"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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/formatter'
|
18
|
+
|
19
|
+
module Fluent
|
20
|
+
module Plugin
|
21
|
+
class SingleValueFormatter < Formatter
|
22
|
+
Plugin.register_formatter('single_value', self)
|
23
|
+
|
24
|
+
config_param :message_key, :string, default: 'message'
|
25
|
+
config_param :add_newline, :bool, default: true
|
26
|
+
|
27
|
+
def format(tag, time, record)
|
28
|
+
text = record[@message_key].to_s.dup
|
29
|
+
text << "\n" if @add_newline
|
30
|
+
text
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,39 @@
|
|
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/formatter'
|
18
|
+
|
19
|
+
module Fluent
|
20
|
+
module Plugin
|
21
|
+
class StdoutFormatter < Formatter
|
22
|
+
Plugin.register_formatter('stdout', self)
|
23
|
+
|
24
|
+
config_param :output_type, :string, default: 'json'
|
25
|
+
|
26
|
+
def configure(conf)
|
27
|
+
super
|
28
|
+
|
29
|
+
@sub_formatter = Plugin.new_formatter(@output_type)
|
30
|
+
@sub_formatter.configure(conf)
|
31
|
+
end
|
32
|
+
|
33
|
+
def format(tag, time, record)
|
34
|
+
header = "#{Time.now.localtime} #{tag}: "
|
35
|
+
"#{header}#{@sub_formatter.format(tag, time, record)}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -42,6 +42,8 @@ module Fluent
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def start
|
45
|
+
super
|
46
|
+
|
45
47
|
if @unix_path
|
46
48
|
require 'drb/unix'
|
47
49
|
uri = "drbunix:#{@unix_path}"
|
@@ -55,6 +57,8 @@ module Fluent
|
|
55
57
|
|
56
58
|
def shutdown
|
57
59
|
@server.stop_service if @server
|
60
|
+
|
61
|
+
super
|
58
62
|
end
|
59
63
|
end
|
60
64
|
end
|
@@ -16,13 +16,15 @@
|
|
16
16
|
|
17
17
|
require 'json'
|
18
18
|
|
19
|
-
require 'fluent/input'
|
19
|
+
require 'fluent/plugin/input'
|
20
20
|
require 'fluent/config/error'
|
21
21
|
|
22
|
-
module Fluent
|
22
|
+
module Fluent::Plugin
|
23
23
|
class DummyInput < Input
|
24
24
|
Fluent::Plugin.register_input('dummy', self)
|
25
25
|
|
26
|
+
helpers :thread, :storage
|
27
|
+
|
26
28
|
BIN_NUM = 10
|
27
29
|
|
28
30
|
desc "The value is the tag assigned to the generated events."
|
@@ -35,11 +37,11 @@ module Fluent
|
|
35
37
|
config_param :dummy, default: [{"message"=>"dummy"}] do |val|
|
36
38
|
begin
|
37
39
|
parsed = JSON.parse(val)
|
38
|
-
rescue JSON::ParserError =>
|
40
|
+
rescue JSON::ParserError => ex
|
39
41
|
# Fluent::ConfigParseError, "got incomplete JSON" will be raised
|
40
42
|
# at literal_parser.rb with --use-v1-config, but I had to
|
41
43
|
# take care at here for the case of --use-v0-config.
|
42
|
-
raise Fluent::ConfigError, "#{
|
44
|
+
raise Fluent::ConfigError, "#{ex.class}: #{ex.message}"
|
43
45
|
end
|
44
46
|
dummy = parsed.is_a?(Array) ? parsed : [parsed]
|
45
47
|
dummy.each_with_index do |e, i|
|
@@ -48,36 +50,39 @@ module Fluent
|
|
48
50
|
dummy
|
49
51
|
end
|
50
52
|
|
51
|
-
def
|
53
|
+
def initialize
|
52
54
|
super
|
55
|
+
@storage = nil
|
56
|
+
end
|
53
57
|
|
54
|
-
|
58
|
+
def configure(conf)
|
59
|
+
super
|
55
60
|
@dummy_index = 0
|
56
61
|
end
|
57
62
|
|
58
63
|
def start
|
59
64
|
super
|
60
|
-
@running = true
|
61
|
-
@thread = Thread.new(&method(:run))
|
62
|
-
end
|
63
65
|
|
64
|
-
|
65
|
-
@
|
66
|
-
|
66
|
+
@storage = storage_create(type: 'local')
|
67
|
+
if @auto_increment_key && !@storage.get(:auto_increment_value)
|
68
|
+
@storage.put(:auto_increment_value, -1)
|
69
|
+
end
|
70
|
+
|
71
|
+
thread_create(:dummy_input, &method(:run))
|
67
72
|
end
|
68
73
|
|
69
74
|
def run
|
70
75
|
batch_num = (@rate / BIN_NUM).to_i
|
71
76
|
residual_num = (@rate % BIN_NUM)
|
72
|
-
while
|
77
|
+
while thread_current_running?
|
73
78
|
current_time = Time.now.to_i
|
74
79
|
BIN_NUM.times do
|
75
|
-
break unless (
|
80
|
+
break unless (thread_current_running? && Time.now.to_i <= current_time)
|
76
81
|
wait(0.1) { emit(batch_num) }
|
77
82
|
end
|
78
|
-
emit(residual_num)
|
83
|
+
emit(residual_num) if thread_current_running?
|
79
84
|
# wait for next second
|
80
|
-
while
|
85
|
+
while thread_current_running? && Time.now.to_i <= current_time
|
81
86
|
sleep 0.01
|
82
87
|
end
|
83
88
|
end
|
@@ -96,8 +101,7 @@ module Fluent
|
|
96
101
|
@dummy_index += 1
|
97
102
|
if @auto_increment_key
|
98
103
|
d = d.dup
|
99
|
-
d[@auto_increment_key] = @
|
100
|
-
@increment_value += 1
|
104
|
+
d[@auto_increment_key] = @storage.update(:auto_increment_value){|v| v + 1 }
|
101
105
|
end
|
102
106
|
d
|
103
107
|
end
|
@@ -14,6 +14,7 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
#
|
16
16
|
|
17
|
+
require 'strptime'
|
17
18
|
require 'yajl'
|
18
19
|
|
19
20
|
require 'fluent/input'
|
@@ -52,9 +53,9 @@ module Fluent
|
|
52
53
|
def configure(conf)
|
53
54
|
super
|
54
55
|
|
55
|
-
if
|
56
|
+
if conf['localtime']
|
56
57
|
@localtime = true
|
57
|
-
elsif
|
58
|
+
elsif conf['utc']
|
58
59
|
@localtime = false
|
59
60
|
end
|
60
61
|
|
@@ -70,9 +71,15 @@ module Fluent
|
|
70
71
|
if @time_key
|
71
72
|
if @time_format
|
72
73
|
f = @time_format
|
73
|
-
@time_parse_proc =
|
74
|
+
@time_parse_proc =
|
75
|
+
begin
|
76
|
+
strptime = Strptime.new(f)
|
77
|
+
Proc.new { |str| Fluent::EventTime.from_time(strptime.exec(str)) }
|
78
|
+
rescue
|
79
|
+
Proc.new {|str| Fluent::EventTime.from_time(Time.strptime(str, f)) }
|
80
|
+
end
|
74
81
|
else
|
75
|
-
@time_parse_proc = Proc.new {|str| str.
|
82
|
+
@time_parse_proc = Proc.new {|str| Fluent::EventTime.from_time(Time.at(str.to_f)) }
|
76
83
|
end
|
77
84
|
end
|
78
85
|
|
@@ -96,6 +103,8 @@ module Fluent
|
|
96
103
|
end
|
97
104
|
|
98
105
|
def start
|
106
|
+
super
|
107
|
+
|
99
108
|
if @run_interval
|
100
109
|
@finished = false
|
101
110
|
@thread = Thread.new(&method(:run_periodic))
|
@@ -127,6 +136,8 @@ module Fluent
|
|
127
136
|
end
|
128
137
|
@thread.join
|
129
138
|
end
|
139
|
+
|
140
|
+
super
|
130
141
|
end
|
131
142
|
|
132
143
|
def run
|
@@ -140,11 +151,10 @@ module Fluent
|
|
140
151
|
io = IO.popen(@command, "r")
|
141
152
|
@parser.call(io)
|
142
153
|
Process.waitpid(io.pid)
|
154
|
+
sleep @run_interval
|
143
155
|
rescue
|
144
|
-
log.error "exec failed to run or shutdown child process", error:
|
156
|
+
log.error "exec failed to run or shutdown child process", error: $!
|
145
157
|
log.warn_backtrace $!.backtrace
|
146
|
-
ensure
|
147
|
-
sleep @run_interval
|
148
158
|
end
|
149
159
|
end
|
150
160
|
end
|
@@ -170,7 +180,7 @@ module Fluent
|
|
170
180
|
|
171
181
|
router.emit(tag, time, record)
|
172
182
|
rescue => e
|
173
|
-
log.error "exec failed to emit", error: e
|
183
|
+
log.error "exec failed to emit", error: e, tag: tag, record: Yajl.dump(record)
|
174
184
|
end
|
175
185
|
end
|
176
186
|
end
|
@@ -25,13 +25,15 @@ module Fluent
|
|
25
25
|
class ForwardInput < Input
|
26
26
|
Plugin.register_input('forward', self)
|
27
27
|
|
28
|
+
LISTEN_PORT = 24224
|
29
|
+
|
28
30
|
def initialize
|
29
31
|
super
|
30
32
|
require 'fluent/plugin/socket_util'
|
31
33
|
end
|
32
34
|
|
33
35
|
desc 'The port to listen to.'
|
34
|
-
config_param :port, :integer, default:
|
36
|
+
config_param :port, :integer, default: LISTEN_PORT
|
35
37
|
desc 'The bind address to listen to.'
|
36
38
|
config_param :bind, :string, default: '0.0.0.0'
|
37
39
|
config_param :backlog, :integer, default: nil
|
@@ -47,34 +49,26 @@ module Fluent
|
|
47
49
|
config_param :chunk_size_limit, :size, default: nil
|
48
50
|
desc 'Skip an event if incoming event is invalid.'
|
49
51
|
config_param :skip_invalid_event, :bool, default: false
|
50
|
-
desc 'Try to resolve hostname from IP addresses or not.'
|
51
|
-
config_param :resolve_hostname, :bool, default: nil
|
52
|
-
desc "The field name of the client's source address."
|
53
|
-
config_param :source_address_key, :string, default: nil
|
54
|
-
desc "The field name of the client's hostname."
|
55
|
-
config_param :source_hostname_key, :string, default: nil
|
56
52
|
|
57
53
|
def configure(conf)
|
58
54
|
super
|
59
|
-
|
60
|
-
if @source_hostname_key
|
61
|
-
if @resolve_hostname.nil?
|
62
|
-
@resolve_hostname = true
|
63
|
-
elsif !@resolve_hostname # user specifies "false" in configure
|
64
|
-
raise Fluent::ConfigError, "resolve_hostname must be true with source_hostname_key"
|
65
|
-
end
|
66
|
-
end
|
67
|
-
@enable_field_injection = @source_address_key || @source_hostname_key
|
68
55
|
end
|
69
56
|
|
70
57
|
def start
|
58
|
+
super
|
59
|
+
|
71
60
|
@loop = Coolio::Loop.new
|
72
61
|
|
73
|
-
|
62
|
+
socket_manager_path = ENV['SERVERENGINE_SOCKETMANAGER_PATH']
|
63
|
+
if Fluent.windows?
|
64
|
+
socket_manager_path = socket_manager_path.to_i
|
65
|
+
end
|
66
|
+
client = ServerEngine::SocketManager::Client.new(socket_manager_path)
|
67
|
+
|
68
|
+
@lsock = listen(client)
|
74
69
|
@loop.attach(@lsock)
|
75
70
|
|
76
|
-
@usock =
|
77
|
-
@usock.bind(@bind, @port)
|
71
|
+
@usock = client.listen_udp(@bind, @port)
|
78
72
|
@usock.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)
|
79
73
|
@hbr = HeartbeatRequestHandler.new(@usock, method(:on_heartbeat_request))
|
80
74
|
@loop.attach(@hbr)
|
@@ -97,11 +91,14 @@ module Fluent
|
|
97
91
|
@usock.close
|
98
92
|
@thread.join
|
99
93
|
@lsock.close
|
94
|
+
|
95
|
+
super
|
100
96
|
end
|
101
97
|
|
102
|
-
def listen
|
98
|
+
def listen(client)
|
103
99
|
log.info "listening fluent socket on #{@bind}:#{@port}"
|
104
|
-
|
100
|
+
sock = client.listen_tcp(@bind, @port)
|
101
|
+
s = Coolio::TCPServer.new(sock, nil, Handler, @linger_timeout, log, method(:on_message))
|
105
102
|
s.listen(@backlog) unless @backlog.nil?
|
106
103
|
s
|
107
104
|
end
|
@@ -119,7 +116,7 @@ module Fluent
|
|
119
116
|
def run
|
120
117
|
@loop.run(@blocking_timeout)
|
121
118
|
rescue => e
|
122
|
-
log.error "unexpected error", error: e
|
119
|
+
log.error "unexpected error", error: e
|
123
120
|
log.error_backtrace
|
124
121
|
end
|
125
122
|
|
@@ -148,7 +145,7 @@ module Fluent
|
|
148
145
|
# 3: object record
|
149
146
|
# 4: object option (optional)
|
150
147
|
# }
|
151
|
-
def on_message(msg, chunk_size,
|
148
|
+
def on_message(msg, chunk_size, source)
|
152
149
|
if msg.nil?
|
153
150
|
# for future TCP heartbeat_request
|
154
151
|
return
|
@@ -156,7 +153,7 @@ module Fluent
|
|
156
153
|
|
157
154
|
# TODO: raise an exception if broken chunk is generated by recoverable situation
|
158
155
|
unless msg.is_a?(Array)
|
159
|
-
log.warn "incoming chunk is broken:", source:
|
156
|
+
log.warn "incoming chunk is broken:", source: source, msg: msg
|
160
157
|
return
|
161
158
|
end
|
162
159
|
|
@@ -164,24 +161,23 @@ module Fluent
|
|
164
161
|
entries = msg[1]
|
165
162
|
|
166
163
|
if @chunk_size_limit && (chunk_size > @chunk_size_limit)
|
167
|
-
log.warn "Input chunk size is larger than 'chunk_size_limit', dropped:", tag: tag, source:
|
164
|
+
log.warn "Input chunk size is larger than 'chunk_size_limit', dropped:", tag: tag, source: source, limit: @chunk_size_limit, size: chunk_size
|
168
165
|
return
|
169
166
|
elsif @chunk_size_warn_limit && (chunk_size > @chunk_size_warn_limit)
|
170
|
-
log.warn "Input chunk size is larger than 'chunk_size_warn_limit':", tag: tag, source:
|
167
|
+
log.warn "Input chunk size is larger than 'chunk_size_warn_limit':", tag: tag, source: source, limit: @chunk_size_warn_limit, size: chunk_size
|
171
168
|
end
|
172
169
|
|
173
170
|
if entries.class == String
|
174
171
|
# PackedForward
|
175
172
|
es = MessagePackEventStream.new(entries)
|
176
|
-
es = check_and_skip_invalid_event(tag, es,
|
177
|
-
es = add_source_host(es, peeraddr) if @enable_field_injection
|
173
|
+
es = check_and_skip_invalid_event(tag, es, source) if @skip_invalid_event
|
178
174
|
router.emit_stream(tag, es)
|
179
175
|
option = msg[2]
|
180
176
|
|
181
177
|
elsif entries.class == Array
|
182
178
|
# Forward
|
183
179
|
es = if @skip_invalid_event
|
184
|
-
check_and_skip_invalid_event(tag, entries,
|
180
|
+
check_and_skip_invalid_event(tag, entries, source)
|
185
181
|
else
|
186
182
|
es = MultiEventStream.new
|
187
183
|
entries.each { |e|
|
@@ -193,7 +189,6 @@ module Fluent
|
|
193
189
|
}
|
194
190
|
es
|
195
191
|
end
|
196
|
-
es = add_source_host(es, peeraddr) if @enable_field_injection
|
197
192
|
router.emit_stream(tag, es)
|
198
193
|
option = msg[2]
|
199
194
|
|
@@ -202,15 +197,11 @@ module Fluent
|
|
202
197
|
time = msg[1]
|
203
198
|
record = msg[2]
|
204
199
|
if @skip_invalid_event && invalid_event?(tag, time, record)
|
205
|
-
log.warn "got invalid event and drop it:", source:
|
200
|
+
log.warn "got invalid event and drop it:", source: source, tag: tag, time: time, record: record
|
206
201
|
return msg[3] # retry never succeeded so return ack and drop incoming event.
|
207
202
|
end
|
208
203
|
return if record.nil?
|
209
|
-
time = Engine.now if time == 0
|
210
|
-
if @enable_field_injection
|
211
|
-
record[@source_hostname_key] = peeraddr[2] if @source_hostname_key
|
212
|
-
record[@source_address_key] = peeraddr[3] if @source_address_key
|
213
|
-
end
|
204
|
+
time = Engine.now if time.to_i == 0
|
214
205
|
router.emit(tag, time, record)
|
215
206
|
option = msg[3]
|
216
207
|
end
|
@@ -220,14 +211,14 @@ module Fluent
|
|
220
211
|
end
|
221
212
|
|
222
213
|
def invalid_event?(tag, time, record)
|
223
|
-
!(time.is_a?(Integer) && record.is_a?(Hash) && tag.is_a?(String))
|
214
|
+
!((time.is_a?(Integer) || time.is_a?(::Fluent::EventTime)) && record.is_a?(Hash) && tag.is_a?(String))
|
224
215
|
end
|
225
216
|
|
226
|
-
def check_and_skip_invalid_event(tag, es,
|
217
|
+
def check_and_skip_invalid_event(tag, es, source)
|
227
218
|
new_es = MultiEventStream.new
|
228
219
|
es.each { |time, record|
|
229
220
|
if invalid_event?(tag, time, record)
|
230
|
-
log.warn "skip invalid event:", source:
|
221
|
+
log.warn "skip invalid event:", source: source, tag: tag, time: time, record: record
|
231
222
|
next
|
232
223
|
end
|
233
224
|
new_es.add(time, record)
|
@@ -235,50 +226,16 @@ module Fluent
|
|
235
226
|
new_es
|
236
227
|
end
|
237
228
|
|
238
|
-
def add_source_host(es, peeraddr)
|
239
|
-
new_es = MultiEventStream.new
|
240
|
-
if @source_address_key && @source_hostname_key
|
241
|
-
address = peeraddr[3]
|
242
|
-
hostname = peeraddr[2]
|
243
|
-
es.each { |time, record|
|
244
|
-
record[@source_address_key] = address
|
245
|
-
record[@source_hostname_key] = hostname
|
246
|
-
new_es.add(time, record)
|
247
|
-
}
|
248
|
-
elsif @source_address_key
|
249
|
-
address = peeraddr[3]
|
250
|
-
es.each { |time, record|
|
251
|
-
record[@source_address_key] = address
|
252
|
-
new_es.add(time, record)
|
253
|
-
}
|
254
|
-
elsif @source_hostname_key
|
255
|
-
hostname = peeraddr[2]
|
256
|
-
es.each { |time, record|
|
257
|
-
record[@source_hostname_key] = hostname
|
258
|
-
new_es.add(time, record)
|
259
|
-
}
|
260
|
-
else
|
261
|
-
raise "BUG: don't call this method in this case"
|
262
|
-
end
|
263
|
-
new_es
|
264
|
-
end
|
265
|
-
|
266
|
-
def source_message(peeraddr)
|
267
|
-
_, port, host, addr = peeraddr
|
268
|
-
"host: #{host}, addr: #{addr}, port: #{port}"
|
269
|
-
end
|
270
|
-
|
271
229
|
class Handler < Coolio::Socket
|
272
230
|
PEERADDR_FAILED = ["?", "?", "name resolusion failed", "?"]
|
273
231
|
|
274
|
-
def initialize(io, linger_timeout, log,
|
232
|
+
def initialize(io, linger_timeout, log, on_message)
|
275
233
|
super(io)
|
276
234
|
|
277
|
-
@peeraddr = nil
|
278
235
|
if io.is_a?(TCPSocket) # for unix domain socket support in the future
|
279
|
-
io.
|
236
|
+
_proto, port, host, addr = ( io.peeraddr rescue PEERADDR_FAILED )
|
237
|
+
@source = "host: #{host}, addr: #{addr}, port: #{port}"
|
280
238
|
|
281
|
-
@peeraddr = (io.peeraddr rescue PEERADDR_FAILED)
|
282
239
|
opt = [1, linger_timeout].pack('I!I!') # { int l_onoff; int l_linger; }
|
283
240
|
io.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, opt)
|
284
241
|
end
|
@@ -289,7 +246,7 @@ module Fluent
|
|
289
246
|
@log.trace {
|
290
247
|
begin
|
291
248
|
remote_port, remote_addr = *Socket.unpack_sockaddr_in(@_io.getpeername)
|
292
|
-
rescue
|
249
|
+
rescue
|
293
250
|
remote_port = nil
|
294
251
|
remote_addr = nil
|
295
252
|
end
|
@@ -307,7 +264,7 @@ module Fluent
|
|
307
264
|
@serializer = :to_json.to_proc
|
308
265
|
@y = Yajl::Parser.new
|
309
266
|
@y.on_parse_complete = lambda { |obj|
|
310
|
-
option = @on_message.call(obj, @chunk_counter, @
|
267
|
+
option = @on_message.call(obj, @chunk_counter, @source)
|
311
268
|
respond option if option
|
312
269
|
@chunk_counter = 0
|
313
270
|
}
|
@@ -335,7 +292,7 @@ module Fluent
|
|
335
292
|
def on_read_msgpack(data)
|
336
293
|
@chunk_counter += data.bytesize
|
337
294
|
@u.feed_each(data) do |obj|
|
338
|
-
option = @on_message.call(obj, @chunk_counter, @
|
295
|
+
option = @on_message.call(obj, @chunk_counter, @source)
|
339
296
|
respond option if option
|
340
297
|
@chunk_counter = 0
|
341
298
|
end
|