fluentd 0.14.4-x86-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,73 @@
|
|
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 'serverengine'
|
18
|
+
require 'fluent/log'
|
19
|
+
|
20
|
+
module Fluent
|
21
|
+
module Test
|
22
|
+
class DummyLogDevice
|
23
|
+
attr_reader :logs
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@logs = []
|
27
|
+
end
|
28
|
+
|
29
|
+
def reset
|
30
|
+
@logs = []
|
31
|
+
end
|
32
|
+
|
33
|
+
def tty?
|
34
|
+
false
|
35
|
+
end
|
36
|
+
|
37
|
+
def puts(*args)
|
38
|
+
args.each{ |arg| write(arg + "\n") }
|
39
|
+
end
|
40
|
+
|
41
|
+
def write(message)
|
42
|
+
@logs.push message
|
43
|
+
end
|
44
|
+
|
45
|
+
def flush
|
46
|
+
true
|
47
|
+
end
|
48
|
+
|
49
|
+
def close
|
50
|
+
true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class TestLogger < Fluent::PluginLogger
|
55
|
+
def initialize
|
56
|
+
@logdev = DummyLogDevice.new
|
57
|
+
dl_opts = {}
|
58
|
+
dl_opts[:log_level] = ServerEngine::DaemonLogger::INFO
|
59
|
+
logger = ServerEngine::DaemonLogger.new(@logdev, dl_opts)
|
60
|
+
log = Fluent::Log.new(logger)
|
61
|
+
super(log)
|
62
|
+
end
|
63
|
+
|
64
|
+
def reset
|
65
|
+
@logdev.reset
|
66
|
+
end
|
67
|
+
|
68
|
+
def logs
|
69
|
+
@logdev.logs
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,156 @@
|
|
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/engine'
|
18
|
+
require 'fluent/event'
|
19
|
+
require 'fluent/test/input_test'
|
20
|
+
|
21
|
+
module Fluent
|
22
|
+
module Test
|
23
|
+
class TestOutputChain
|
24
|
+
def initialize
|
25
|
+
@called = 0
|
26
|
+
end
|
27
|
+
|
28
|
+
def next
|
29
|
+
@called += 1
|
30
|
+
end
|
31
|
+
|
32
|
+
attr_reader :called
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
class OutputTestDriver < InputTestDriver
|
37
|
+
def initialize(klass, tag='test', &block)
|
38
|
+
super(klass, &block)
|
39
|
+
@tag = tag
|
40
|
+
end
|
41
|
+
|
42
|
+
attr_accessor :tag
|
43
|
+
|
44
|
+
def emit(record, time=Engine.now)
|
45
|
+
es = OneEventStream.new(time, record)
|
46
|
+
@instance.emit_events(@tag, es)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
class BufferedOutputTestDriver < InputTestDriver
|
52
|
+
def initialize(klass, tag='test', &block)
|
53
|
+
super(klass, &block)
|
54
|
+
@entries = []
|
55
|
+
@expected_buffer = nil
|
56
|
+
@tag = tag
|
57
|
+
|
58
|
+
def @instance.buffer
|
59
|
+
@buffer
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
attr_accessor :tag
|
64
|
+
|
65
|
+
def emit(record, time=Engine.now)
|
66
|
+
@entries << [time, record]
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
def expect_format(str)
|
71
|
+
(@expected_buffer ||= '') << str
|
72
|
+
end
|
73
|
+
|
74
|
+
def run(num_waits = 10, &block)
|
75
|
+
result = nil
|
76
|
+
super(num_waits) {
|
77
|
+
block.call if block
|
78
|
+
|
79
|
+
es = ArrayEventStream.new(@entries)
|
80
|
+
buffer = @instance.format_stream(@tag, es)
|
81
|
+
|
82
|
+
if @expected_buffer
|
83
|
+
assert_equal(@expected_buffer, buffer)
|
84
|
+
end
|
85
|
+
|
86
|
+
chunk = if @instance.instance_eval{ @chunk_key_tag }
|
87
|
+
@instance.buffer.generate_chunk(@instance.metadata(@tag, nil, nil)).staged!
|
88
|
+
else
|
89
|
+
@instance.buffer.generate_chunk(@instance.metadata(nil, nil, nil)).staged!
|
90
|
+
end
|
91
|
+
chunk.concat(buffer, es.size)
|
92
|
+
|
93
|
+
begin
|
94
|
+
result = @instance.write(chunk)
|
95
|
+
ensure
|
96
|
+
chunk.purge
|
97
|
+
end
|
98
|
+
}
|
99
|
+
result
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class TimeSlicedOutputTestDriver < InputTestDriver
|
104
|
+
def initialize(klass, tag='test', &block)
|
105
|
+
super(klass, &block)
|
106
|
+
@entries = []
|
107
|
+
@expected_buffer = nil
|
108
|
+
@tag = tag
|
109
|
+
end
|
110
|
+
|
111
|
+
attr_accessor :tag
|
112
|
+
|
113
|
+
def emit(record, time=Engine.now)
|
114
|
+
@entries << [time, record]
|
115
|
+
self
|
116
|
+
end
|
117
|
+
|
118
|
+
def expect_format(str)
|
119
|
+
(@expected_buffer ||= '') << str
|
120
|
+
end
|
121
|
+
|
122
|
+
def run(&block)
|
123
|
+
result = []
|
124
|
+
super {
|
125
|
+
block.call if block
|
126
|
+
|
127
|
+
buffer = ''
|
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
|
137
|
+
|
138
|
+
if @expected_buffer
|
139
|
+
assert_equal(@expected_buffer, buffer)
|
140
|
+
end
|
141
|
+
|
142
|
+
lines.keys.each do |meta|
|
143
|
+
chunk = @instance.buffer.generate_chunk(meta).staged!
|
144
|
+
chunk.append(lines[meta])
|
145
|
+
begin
|
146
|
+
result.push(@instance.write(chunk))
|
147
|
+
ensure
|
148
|
+
chunk.purge
|
149
|
+
end
|
150
|
+
end
|
151
|
+
}
|
152
|
+
result
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,70 @@
|
|
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/parser'
|
18
|
+
require 'fluent/config'
|
19
|
+
|
20
|
+
module Fluent
|
21
|
+
module Test
|
22
|
+
class ParserTestDriver
|
23
|
+
def initialize(klass_or_str, format=nil, conf={}, &block)
|
24
|
+
if klass_or_str.is_a?(Class)
|
25
|
+
if block
|
26
|
+
# Create new class for test w/ overwritten methods
|
27
|
+
# klass.dup is worse because its ancestors does NOT include original class name
|
28
|
+
klass_name = klass_or_str.name
|
29
|
+
klass_or_str = Class.new(klass_or_str)
|
30
|
+
klass_or_str.define_singleton_method("name") { klass_name }
|
31
|
+
klass_or_str.module_eval(&block)
|
32
|
+
end
|
33
|
+
case klass_or_str.instance_method(:initialize).arity
|
34
|
+
when 0
|
35
|
+
@instance = klass_or_str.new
|
36
|
+
when -2
|
37
|
+
# for RegexpParser
|
38
|
+
@instance = klass_or_str.new(format, conf)
|
39
|
+
end
|
40
|
+
elsif klass_or_str.is_a?(String)
|
41
|
+
@instance = Fluent::Plugin.new_parser(klass_or_str)
|
42
|
+
else
|
43
|
+
@instance = klass_or_str
|
44
|
+
end
|
45
|
+
@config = Config.new
|
46
|
+
end
|
47
|
+
|
48
|
+
attr_reader :instance, :config
|
49
|
+
|
50
|
+
def configure(conf)
|
51
|
+
case conf
|
52
|
+
when Fluent::Config::Element
|
53
|
+
@config = conf
|
54
|
+
when String
|
55
|
+
@config = Config.parse(conf, 'fluent.conf')
|
56
|
+
when Hash
|
57
|
+
@config = Config::Element.new('ROOT', '', conf, [])
|
58
|
+
else
|
59
|
+
raise "Unknown type... #{conf}"
|
60
|
+
end
|
61
|
+
@instance.configure(@config)
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
def parse(text, &block)
|
66
|
+
@instance.parse(text, &block)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/fluent/time.rb
ADDED
@@ -0,0 +1,175 @@
|
|
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
|
+
require 'fluent/timezone'
|
20
|
+
|
21
|
+
module Fluent
|
22
|
+
class EventTime
|
23
|
+
TYPE = 0
|
24
|
+
|
25
|
+
def initialize(sec, nsec = 0)
|
26
|
+
@sec = sec
|
27
|
+
@nsec = nsec
|
28
|
+
end
|
29
|
+
|
30
|
+
def ==(other)
|
31
|
+
if other.is_a?(Fluent::EventTime)
|
32
|
+
@sec == other.sec
|
33
|
+
else
|
34
|
+
@sec == other
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def sec
|
39
|
+
@sec
|
40
|
+
end
|
41
|
+
|
42
|
+
def nsec
|
43
|
+
@nsec
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_int
|
47
|
+
@sec
|
48
|
+
end
|
49
|
+
|
50
|
+
# for Time.at
|
51
|
+
def to_r
|
52
|
+
Rational(@sec * 1_000_000_000 + @nsec, 1_000_000_000)
|
53
|
+
end
|
54
|
+
|
55
|
+
# for > and others
|
56
|
+
def coerce(other)
|
57
|
+
[other, @sec]
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_s
|
61
|
+
@sec.to_s
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_json(*args)
|
65
|
+
@sec.to_s
|
66
|
+
end
|
67
|
+
|
68
|
+
def to_msgpack(io = nil)
|
69
|
+
@sec.to_msgpack(io)
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_msgpack_ext
|
73
|
+
[@sec, @nsec].pack('NN')
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.from_msgpack_ext(data)
|
77
|
+
new(*data.unpack('NN'))
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.from_time(time)
|
81
|
+
Fluent::EventTime.new(time.to_i, time.nsec)
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.eq?(a, b)
|
85
|
+
if a.is_a?(Fluent::EventTime) && b.is_a?(Fluent::EventTime)
|
86
|
+
a.sec == b.sec && a.nsec == b.nsec
|
87
|
+
else
|
88
|
+
a == b
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.now
|
93
|
+
from_time(Time.now)
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.parse(*args)
|
97
|
+
from_time(Time.parse(*args))
|
98
|
+
end
|
99
|
+
|
100
|
+
## TODO: For performance, implement +, -, and so on
|
101
|
+
def method_missing(name, *args, &block)
|
102
|
+
@sec.send(name, *args, &block)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class TimeFormatter
|
107
|
+
def initialize(format, localtime, timezone = nil)
|
108
|
+
@tc1 = 0
|
109
|
+
@tc1_str = nil
|
110
|
+
@tc2 = 0
|
111
|
+
@tc2_str = nil
|
112
|
+
|
113
|
+
if format && format =~ /(^|[^%])(%%)*%L|(^|[^%])(%%)*%\d*N/
|
114
|
+
define_singleton_method(:format, method(:format_with_subsec))
|
115
|
+
define_singleton_method(:call, method(:format_with_subsec))
|
116
|
+
else
|
117
|
+
define_singleton_method(:format, method(:format_without_subsec))
|
118
|
+
define_singleton_method(:call, method(:format_with_subsec))
|
119
|
+
end
|
120
|
+
|
121
|
+
formatter = Fluent::Timezone.formatter(timezone, format)
|
122
|
+
@format_nocache = case
|
123
|
+
when formatter then formatter
|
124
|
+
when format && localtime then ->(time){ Time.at(time).strftime(format) }
|
125
|
+
when format then ->(time){ Time.at(time).utc.strftime(format) }
|
126
|
+
when localtime then ->(time){ Time.at(time).iso8601 }
|
127
|
+
else ->(time){ Time.at(time).utc.iso8601 }
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def format_without_subsec(time)
|
132
|
+
if @tc1 == time
|
133
|
+
return @tc1_str
|
134
|
+
elsif @tc2 == time
|
135
|
+
return @tc2_str
|
136
|
+
else
|
137
|
+
str = format_nocache(time)
|
138
|
+
if @tc1 < @tc2
|
139
|
+
@tc1 = time
|
140
|
+
@tc1_str = str
|
141
|
+
else
|
142
|
+
@tc2 = time
|
143
|
+
@tc2_str = str
|
144
|
+
end
|
145
|
+
return str
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def format_with_subsec(time)
|
150
|
+
if Fluent::EventTime.eq?(@tc1, time)
|
151
|
+
return @tc1_str
|
152
|
+
elsif Fluent::EventTime.eq?(@tc2, time)
|
153
|
+
return @tc2_str
|
154
|
+
else
|
155
|
+
str = format_nocache(time)
|
156
|
+
if @tc1 < @tc2
|
157
|
+
@tc1 = time
|
158
|
+
@tc1_str = str
|
159
|
+
else
|
160
|
+
@tc2 = time
|
161
|
+
@tc2_str = str
|
162
|
+
end
|
163
|
+
return str
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
## Dynamically defined in #initialize
|
168
|
+
# def format(time)
|
169
|
+
# end
|
170
|
+
|
171
|
+
def format_nocache(time)
|
172
|
+
@format_nocache.call(time)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|