fluentd 0.12.43 → 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 +1239 -0
- 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 +58 -640
- data/lib/fluent/plugin/in_tcp.rb +8 -1
- data/lib/fluent/plugin/in_udp.rb +8 -18
- 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 +25 -19
- 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 +119 -117
- 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 -282
- data/test/plugin/test_in_tcp.rb +14 -0
- data/test/plugin/test_in_udp.rb +21 -67
- 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 +181 -55
- data/CHANGELOG.md +0 -710
- 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,35 @@
|
|
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/test/driver/base'
|
18
|
+
require 'fluent/test/driver/event_feeder'
|
19
|
+
|
20
|
+
require 'fluent/plugin/filter'
|
21
|
+
|
22
|
+
module Fluent
|
23
|
+
module Test
|
24
|
+
module Driver
|
25
|
+
class Filter < Base
|
26
|
+
include EventFeeder
|
27
|
+
|
28
|
+
def initialize(klass, opts: {}, &block)
|
29
|
+
super
|
30
|
+
raise ArgumentError, "plugin is not an instance of Fluent::Plugin::Filter" unless @instance.is_a? Fluent::Plugin::Filter
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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/test/driver/base'
|
18
|
+
require 'fluent/plugin/input'
|
19
|
+
|
20
|
+
module Fluent
|
21
|
+
module Test
|
22
|
+
module Driver
|
23
|
+
class Input < Base
|
24
|
+
def initialize(klass, opts: {}, &block)
|
25
|
+
super
|
26
|
+
raise ArgumentError, "plugin is not an instance of Fluent::Plugin::Input" unless @instance.is_a? Fluent::Plugin::Input
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,78 @@
|
|
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/test/driver/base'
|
18
|
+
require 'fluent/test/driver/event_feeder'
|
19
|
+
|
20
|
+
require 'fluent/plugin/output'
|
21
|
+
|
22
|
+
module Fluent
|
23
|
+
module Test
|
24
|
+
module Driver
|
25
|
+
class Output < Base
|
26
|
+
include EventFeeder
|
27
|
+
|
28
|
+
def initialize(klass, opts: {}, &block)
|
29
|
+
super
|
30
|
+
raise ArgumentError, "plugin is not an instance of Fluent::Plugin::Output" unless @instance.is_a? Fluent::Plugin::Output
|
31
|
+
@instance.in_tests = true
|
32
|
+
@flush_buffer_at_cleanup = nil
|
33
|
+
@format_hook = nil
|
34
|
+
@format_results = []
|
35
|
+
end
|
36
|
+
|
37
|
+
def run(flush: true, **kwargs, &block)
|
38
|
+
@flush_buffer_at_cleanup = flush
|
39
|
+
super(**kwargs, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def run_actual(**kwargs, &block)
|
43
|
+
super(**kwargs, &block)
|
44
|
+
if @flush_buffer_at_cleanup
|
45
|
+
@instance.force_flush
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def formatted
|
50
|
+
@format_results
|
51
|
+
end
|
52
|
+
|
53
|
+
def flush
|
54
|
+
@instance.force_flush
|
55
|
+
end
|
56
|
+
|
57
|
+
def instance_hook_after_started
|
58
|
+
super
|
59
|
+
|
60
|
+
# it's decided after #start whether output plugin instances use @custom_format or not.
|
61
|
+
if @instance.instance_eval{ @custom_format }
|
62
|
+
@format_hook = format_hook = ->(result){ @format_results << result }
|
63
|
+
m = Module.new do
|
64
|
+
define_method(:format) do |tag, time, record|
|
65
|
+
result = super(tag, time, record)
|
66
|
+
format_hook.call(result)
|
67
|
+
result
|
68
|
+
end
|
69
|
+
end
|
70
|
+
@instance.singleton_class.module_eval do
|
71
|
+
prepend m
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
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/event'
|
18
|
+
|
19
|
+
module Fluent
|
20
|
+
module Test
|
21
|
+
module Driver
|
22
|
+
class TestEventRouter
|
23
|
+
def initialize(driver)
|
24
|
+
@driver = driver
|
25
|
+
end
|
26
|
+
|
27
|
+
def emit(tag, time, record)
|
28
|
+
@driver.emit_event_stream(tag, OneEventStream.new(time, record))
|
29
|
+
end
|
30
|
+
|
31
|
+
def emit_array(tag, array)
|
32
|
+
@driver.emit_event_stream(tag, ArrayEventStream.new(array))
|
33
|
+
end
|
34
|
+
|
35
|
+
def emit_stream(tag, es)
|
36
|
+
@driver.emit_event_stream(tag, es)
|
37
|
+
end
|
38
|
+
|
39
|
+
def emit_error_event(tag, time, record, error)
|
40
|
+
@driver.emit_error_event(tag, time, record, error)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -16,6 +16,7 @@
|
|
16
16
|
|
17
17
|
require 'fluent/formatter'
|
18
18
|
require 'fluent/config'
|
19
|
+
require 'fluent/plugin'
|
19
20
|
|
20
21
|
module Fluent
|
21
22
|
module Test
|
@@ -30,7 +31,7 @@ module Fluent
|
|
30
31
|
end
|
31
32
|
@instance = klass_or_str.new
|
32
33
|
elsif klass_or_str.is_a?(String)
|
33
|
-
@instance =
|
34
|
+
@instance = Fluent::Plugin.new_formatter(klass_or_str)
|
34
35
|
else
|
35
36
|
@instance = klass_or_str
|
36
37
|
end
|
@@ -14,29 +14,21 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
#
|
16
16
|
|
17
|
-
require 'fluent/input'
|
18
|
-
require 'fluent/buffer'
|
19
17
|
require 'fluent/engine'
|
20
18
|
require 'fluent/time'
|
21
19
|
require 'fluent/test/base'
|
22
20
|
|
23
21
|
module Fluent
|
24
|
-
class FileBuffer < BasicBuffer
|
25
|
-
def self.clear_buffer_paths
|
26
|
-
@@buffer_paths = {}
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
22
|
module Test
|
31
23
|
class InputTestDriver < TestDriver
|
32
24
|
def initialize(klass, &block)
|
33
|
-
FileBuffer.clear_buffer_paths
|
34
25
|
super(klass, &block)
|
35
26
|
@emit_streams = []
|
36
27
|
@expects = nil
|
37
28
|
# for checking only the number of emitted records during run
|
38
29
|
@expected_emits_length = nil
|
39
30
|
@run_timeout = 5
|
31
|
+
@run_post_conditions = []
|
40
32
|
end
|
41
33
|
|
42
34
|
def expect_emit(tag, time, record)
|
@@ -82,7 +74,6 @@ module Fluent
|
|
82
74
|
|
83
75
|
def register_run_post_condition(&block)
|
84
76
|
if block
|
85
|
-
@run_post_conditions ||= []
|
86
77
|
@run_post_conditions << block
|
87
78
|
end
|
88
79
|
end
|
@@ -108,14 +99,26 @@ module Fluent
|
|
108
99
|
false
|
109
100
|
end
|
110
101
|
|
102
|
+
module EmitStreamWrapper
|
103
|
+
def emit_stream_callee=(method)
|
104
|
+
@emit_stream_callee = method
|
105
|
+
end
|
106
|
+
def emit_stream(tag, es)
|
107
|
+
@emit_stream_callee.call(tag, es)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
111
|
def run(num_waits = 10, &block)
|
112
112
|
m = method(:emit_stream)
|
113
|
-
Engine.
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
113
|
+
(class << Engine; self; end).module_eval do
|
114
|
+
prepend EmitStreamWrapper
|
115
|
+
end
|
116
|
+
Engine.emit_stream_callee = m
|
117
|
+
(class << instance.router; self; end).module_eval do
|
118
|
+
prepend EmitStreamWrapper
|
119
|
+
end
|
120
|
+
instance.router.emit_stream_callee = m
|
121
|
+
|
119
122
|
super(num_waits) {
|
120
123
|
block.call if block
|
121
124
|
|
@@ -146,7 +149,10 @@ module Fluent
|
|
146
149
|
|
147
150
|
tag, events = @emit_streams[j]
|
148
151
|
events.each do |time, record|
|
149
|
-
|
152
|
+
if @expects
|
153
|
+
assert_equal(@expects[i], [tag, time, record])
|
154
|
+
assert_equal_event_time(@expects[i][1], time) if @expects[i][1].is_a?(Fluent::EventTime)
|
155
|
+
end
|
150
156
|
i += 1
|
151
157
|
end
|
152
158
|
j += 1
|
@@ -41,11 +41,9 @@ module Fluent
|
|
41
41
|
|
42
42
|
attr_accessor :tag
|
43
43
|
|
44
|
-
def emit(record, time=
|
45
|
-
es = OneEventStream.new(time
|
46
|
-
|
47
|
-
@instance.emit(@tag, es, chain)
|
48
|
-
assert_equal 1, chain.called
|
44
|
+
def emit(record, time=Engine.now)
|
45
|
+
es = OneEventStream.new(time, record)
|
46
|
+
@instance.emit_events(@tag, es)
|
49
47
|
end
|
50
48
|
end
|
51
49
|
|
@@ -64,8 +62,8 @@ module Fluent
|
|
64
62
|
|
65
63
|
attr_accessor :tag
|
66
64
|
|
67
|
-
def emit(record, time=
|
68
|
-
@entries << [time
|
65
|
+
def emit(record, time=Engine.now)
|
66
|
+
@entries << [time, record]
|
69
67
|
self
|
70
68
|
end
|
71
69
|
|
@@ -85,18 +83,13 @@ module Fluent
|
|
85
83
|
assert_equal(@expected_buffer, buffer)
|
86
84
|
end
|
87
85
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
else
|
96
|
-
key = ''
|
97
|
-
end
|
98
|
-
chunk = @instance.buffer.new_chunk(key)
|
99
|
-
chunk << buffer
|
86
|
+
chunk = if @instance.instance_eval{ @chunk_key_tag }
|
87
|
+
@instance.buffer.generate_chunk(@instance.metadata(@tag, nil, nil))
|
88
|
+
else
|
89
|
+
@instance.buffer.generate_chunk(@instance.metadata(nil, nil, nil))
|
90
|
+
end
|
91
|
+
chunk.concat(buffer, es.size)
|
92
|
+
|
100
93
|
begin
|
101
94
|
result = @instance.write(chunk)
|
102
95
|
ensure
|
@@ -110,18 +103,15 @@ module Fluent
|
|
110
103
|
class TimeSlicedOutputTestDriver < InputTestDriver
|
111
104
|
def initialize(klass, tag='test', &block)
|
112
105
|
super(klass, &block)
|
113
|
-
@entries =
|
106
|
+
@entries = []
|
114
107
|
@expected_buffer = nil
|
115
108
|
@tag = tag
|
116
109
|
end
|
117
110
|
|
118
111
|
attr_accessor :tag
|
119
112
|
|
120
|
-
def emit(record, time=
|
121
|
-
|
122
|
-
key = slicer.call(time.to_i)
|
123
|
-
@entries[key] = [] unless @entries.has_key?(key)
|
124
|
-
@entries[key] << [time.to_i, record]
|
113
|
+
def emit(record, time=Engine.now)
|
114
|
+
@entries << [time, record]
|
125
115
|
self
|
126
116
|
end
|
127
117
|
|
@@ -135,30 +125,29 @@ module Fluent
|
|
135
125
|
block.call if block
|
136
126
|
|
137
127
|
buffer = ''
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
128
|
+
lines = {}
|
129
|
+
# v0.12 TimeSlicedOutput doesn't call #format_stream
|
130
|
+
@entries.each do |time, record|
|
131
|
+
meta = @instance.metadata(@tag, time, record)
|
132
|
+
line = @instance.format(@tag, time, record)
|
133
|
+
buffer << line
|
134
|
+
lines[meta] ||= []
|
135
|
+
lines[meta] << line
|
136
|
+
end
|
143
137
|
|
144
138
|
if @expected_buffer
|
145
139
|
assert_equal(@expected_buffer, buffer)
|
146
140
|
end
|
147
141
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
@buffer.push(key)
|
152
|
-
chunks << @buffer.instance_eval{ @queue.pop }
|
153
|
-
end
|
154
|
-
end
|
155
|
-
chunks.each { |chunk|
|
142
|
+
lines.keys.each do |meta|
|
143
|
+
chunk = @instance.buffer.generate_chunk(meta)
|
144
|
+
chunk.append(lines[meta])
|
156
145
|
begin
|
157
146
|
result.push(@instance.write(chunk))
|
158
147
|
ensure
|
159
148
|
chunk.purge
|
160
149
|
end
|
161
|
-
|
150
|
+
end
|
162
151
|
}
|
163
152
|
result
|
164
153
|
end
|
@@ -36,7 +36,7 @@ module Fluent
|
|
36
36
|
@instance = klass_or_str.new(format, conf)
|
37
37
|
end
|
38
38
|
elsif klass_or_str.is_a?(String)
|
39
|
-
@instance =
|
39
|
+
@instance = Fluent::Plugin.new_parser(klass_or_str)
|
40
40
|
else
|
41
41
|
@instance = klass_or_str
|
42
42
|
end
|
data/lib/fluent/time.rb
CHANGED
@@ -1 +1,104 @@
|
|
1
|
-
#
|
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 'time'
|
18
|
+
require 'msgpack'
|
19
|
+
|
20
|
+
module Fluent
|
21
|
+
class EventTime
|
22
|
+
TYPE = 0
|
23
|
+
|
24
|
+
def initialize(sec, nsec = 0)
|
25
|
+
@sec = sec
|
26
|
+
@nsec = nsec
|
27
|
+
end
|
28
|
+
|
29
|
+
def ==(other)
|
30
|
+
if other.is_a?(Fluent::EventTime)
|
31
|
+
@sec == other.sec
|
32
|
+
else
|
33
|
+
@sec == other
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def sec
|
38
|
+
@sec
|
39
|
+
end
|
40
|
+
|
41
|
+
def nsec
|
42
|
+
@nsec
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_int
|
46
|
+
@sec
|
47
|
+
end
|
48
|
+
|
49
|
+
# for Time.at
|
50
|
+
def to_r
|
51
|
+
Rational(@sec * 1_000_000_000 + @nsec, 1_000_000_000)
|
52
|
+
end
|
53
|
+
|
54
|
+
# for > and others
|
55
|
+
def coerce(other)
|
56
|
+
[other, @sec]
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_s
|
60
|
+
@sec.to_s
|
61
|
+
end
|
62
|
+
|
63
|
+
def to_json(*args)
|
64
|
+
@sec.to_s
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_msgpack(io = nil)
|
68
|
+
@sec.to_msgpack(io)
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_msgpack_ext
|
72
|
+
[@sec, @nsec].pack('NN')
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.from_msgpack_ext(data)
|
76
|
+
new(*data.unpack('NN'))
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.from_time(time)
|
80
|
+
Fluent::EventTime.new(time.to_i, time.nsec)
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.eq?(a, b)
|
84
|
+
if a.is_a?(Fluent::EventTime) && b.is_a?(Fluent::EventTime)
|
85
|
+
a.sec == b.sec && a.nsec == b.nsec
|
86
|
+
else
|
87
|
+
a == b
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.now
|
92
|
+
from_time(Time.now)
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.parse(*args)
|
96
|
+
from_time(Time.parse(*args))
|
97
|
+
end
|
98
|
+
|
99
|
+
## TODO: For performance, implement +, -, and so on
|
100
|
+
def method_missing(name, *args, &block)
|
101
|
+
@sec.send(name, *args, &block)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|