fluentd-hubspot 0.14.14.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.github/ISSUE_TEMPLATE.md +6 -0
- data/.gitignore +28 -0
- data/.travis.yml +51 -0
- data/AUTHORS +2 -0
- data/CONTRIBUTING.md +42 -0
- data/COPYING +14 -0
- data/ChangeLog +593 -0
- data/Gemfile +9 -0
- data/README.md +76 -0
- data/Rakefile +74 -0
- data/Vagrantfile +17 -0
- data/appveyor.yml +43 -0
- data/bin/fluent-binlog-reader +7 -0
- data/bin/fluent-debug +5 -0
- data/bin/fluent-plugin-config-format +5 -0
- data/bin/fluent-plugin-generate +5 -0
- data/code-of-conduct.md +3 -0
- data/example/copy_roundrobin.conf +39 -0
- data/example/filter_stdout.conf +22 -0
- data/example/in_dummy_blocks.conf +17 -0
- data/example/in_dummy_with_compression.conf +23 -0
- data/example/in_forward.conf +14 -0
- data/example/in_forward_client.conf +37 -0
- data/example/in_forward_shared_key.conf +15 -0
- data/example/in_forward_tls.conf +14 -0
- data/example/in_forward_users.conf +24 -0
- data/example/in_forward_workers.conf +21 -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/logevents.conf +25 -0
- data/example/multi_filters.conf +61 -0
- data/example/out_copy.conf +20 -0
- data/example/out_exec_filter.conf +42 -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/out_forward_client.conf +109 -0
- data/example/out_forward_heartbeat_none.conf +16 -0
- data/example/out_forward_shared_key.conf +36 -0
- data/example/out_forward_tls.conf +18 -0
- data/example/out_forward_users.conf +65 -0
- data/example/out_null.conf +36 -0
- data/example/secondary_file.conf +41 -0
- data/example/suppress_config_dump.conf +7 -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 +163 -0
- data/lib/fluent/clock.rb +62 -0
- data/lib/fluent/command/binlog_reader.rb +234 -0
- data/lib/fluent/command/bundler_injection.rb +45 -0
- data/lib/fluent/command/cat.rb +330 -0
- data/lib/fluent/command/debug.rb +102 -0
- data/lib/fluent/command/fluentd.rb +301 -0
- data/lib/fluent/command/plugin_config_formatter.rb +258 -0
- data/lib/fluent/command/plugin_generator.rb +301 -0
- data/lib/fluent/compat/call_super_mixin.rb +67 -0
- data/lib/fluent/compat/detach_process_mixin.rb +25 -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 +59 -0
- data/lib/fluent/compat/output.rb +728 -0
- data/lib/fluent/compat/output_chain.rb +60 -0
- data/lib/fluent/compat/parser.rb +310 -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 +418 -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 +223 -0
- data/lib/fluent/config/types.rb +136 -0
- data/lib/fluent/config/v1_parser.rb +190 -0
- data/lib/fluent/configurable.rb +200 -0
- data/lib/fluent/daemon.rb +15 -0
- data/lib/fluent/engine.rb +266 -0
- data/lib/fluent/env.rb +28 -0
- data/lib/fluent/error.rb +30 -0
- data/lib/fluent/event.rb +334 -0
- data/lib/fluent/event_router.rb +269 -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 +46 -0
- data/lib/fluent/load.rb +35 -0
- data/lib/fluent/log.rb +546 -0
- data/lib/fluent/match.rb +178 -0
- data/lib/fluent/mixin.rb +31 -0
- data/lib/fluent/msgpack_factory.rb +62 -0
- data/lib/fluent/output.rb +29 -0
- data/lib/fluent/output_chain.rb +23 -0
- data/lib/fluent/parser.rb +23 -0
- data/lib/fluent/plugin.rb +183 -0
- data/lib/fluent/plugin/bare_output.rb +63 -0
- data/lib/fluent/plugin/base.rb +165 -0
- data/lib/fluent/plugin/buf_file.rb +184 -0
- data/lib/fluent/plugin/buf_memory.rb +34 -0
- data/lib/fluent/plugin/buffer.rb +617 -0
- data/lib/fluent/plugin/buffer/chunk.rb +221 -0
- data/lib/fluent/plugin/buffer/file_chunk.rb +364 -0
- data/lib/fluent/plugin/buffer/memory_chunk.rb +90 -0
- data/lib/fluent/plugin/compressable.rb +92 -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_parser.rb +119 -0
- data/lib/fluent/plugin/filter_record_transformer.rb +322 -0
- data/lib/fluent/plugin/filter_stdout.rb +53 -0
- data/lib/fluent/plugin/formatter.rb +50 -0
- data/lib/fluent/plugin/formatter_csv.rb +52 -0
- data/lib/fluent/plugin/formatter_hash.rb +33 -0
- data/lib/fluent/plugin/formatter_json.rb +55 -0
- data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
- data/lib/fluent/plugin/formatter_msgpack.rb +33 -0
- data/lib/fluent/plugin/formatter_out_file.rb +51 -0
- data/lib/fluent/plugin/formatter_single_value.rb +34 -0
- data/lib/fluent/plugin/formatter_stdout.rb +75 -0
- data/lib/fluent/plugin/formatter_tsv.rb +34 -0
- data/lib/fluent/plugin/in_debug_agent.rb +64 -0
- data/lib/fluent/plugin/in_dummy.rb +139 -0
- data/lib/fluent/plugin/in_exec.rb +108 -0
- data/lib/fluent/plugin/in_forward.rb +455 -0
- data/lib/fluent/plugin/in_gc_stat.rb +56 -0
- data/lib/fluent/plugin/in_http.rb +433 -0
- data/lib/fluent/plugin/in_monitor_agent.rb +448 -0
- data/lib/fluent/plugin/in_object_space.rb +93 -0
- data/lib/fluent/plugin/in_syslog.rb +209 -0
- data/lib/fluent/plugin/in_tail.rb +905 -0
- data/lib/fluent/plugin/in_tcp.rb +85 -0
- data/lib/fluent/plugin/in_udp.rb +81 -0
- data/lib/fluent/plugin/in_unix.rb +201 -0
- data/lib/fluent/plugin/input.rb +37 -0
- data/lib/fluent/plugin/multi_output.rb +157 -0
- data/lib/fluent/plugin/out_copy.rb +46 -0
- data/lib/fluent/plugin/out_exec.rb +105 -0
- data/lib/fluent/plugin/out_exec_filter.rb +317 -0
- data/lib/fluent/plugin/out_file.rb +302 -0
- data/lib/fluent/plugin/out_forward.rb +912 -0
- data/lib/fluent/plugin/out_null.rb +74 -0
- data/lib/fluent/plugin/out_relabel.rb +32 -0
- data/lib/fluent/plugin/out_roundrobin.rb +84 -0
- data/lib/fluent/plugin/out_secondary_file.rb +133 -0
- data/lib/fluent/plugin/out_stdout.rb +75 -0
- data/lib/fluent/plugin/out_stream.rb +130 -0
- data/lib/fluent/plugin/output.rb +1291 -0
- data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
- data/lib/fluent/plugin/parser.rb +191 -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 +39 -0
- data/lib/fluent/plugin/parser_json.rb +81 -0
- data/lib/fluent/plugin/parser_ltsv.rb +42 -0
- data/lib/fluent/plugin/parser_msgpack.rb +50 -0
- data/lib/fluent/plugin/parser_multiline.rb +105 -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 +63 -0
- data/lib/fluent/plugin/parser_syslog.rb +121 -0
- data/lib/fluent/plugin/parser_tsv.rb +42 -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 +159 -0
- data/lib/fluent/plugin/string_util.rb +22 -0
- data/lib/fluent/plugin_helper.rb +70 -0
- data/lib/fluent/plugin_helper/cert_option.rb +159 -0
- data/lib/fluent/plugin_helper/child_process.rb +364 -0
- data/lib/fluent/plugin_helper/compat_parameters.rb +331 -0
- data/lib/fluent/plugin_helper/event_emitter.rb +93 -0
- data/lib/fluent/plugin_helper/event_loop.rb +161 -0
- data/lib/fluent/plugin_helper/extract.rb +104 -0
- data/lib/fluent/plugin_helper/formatter.rb +147 -0
- data/lib/fluent/plugin_helper/inject.rb +151 -0
- data/lib/fluent/plugin_helper/parser.rb +147 -0
- data/lib/fluent/plugin_helper/retry_state.rb +201 -0
- data/lib/fluent/plugin_helper/server.rb +738 -0
- data/lib/fluent/plugin_helper/socket.rb +241 -0
- data/lib/fluent/plugin_helper/socket_option.rb +69 -0
- data/lib/fluent/plugin_helper/storage.rb +349 -0
- data/lib/fluent/plugin_helper/thread.rb +179 -0
- data/lib/fluent/plugin_helper/timer.rb +91 -0
- data/lib/fluent/plugin_id.rb +80 -0
- data/lib/fluent/process.rb +22 -0
- data/lib/fluent/registry.rb +116 -0
- data/lib/fluent/root_agent.rb +323 -0
- data/lib/fluent/rpc.rb +94 -0
- data/lib/fluent/supervisor.rb +741 -0
- data/lib/fluent/system_config.rb +159 -0
- data/lib/fluent/test.rb +58 -0
- data/lib/fluent/test/base.rb +78 -0
- data/lib/fluent/test/driver/base.rb +224 -0
- data/lib/fluent/test/driver/base_owned.rb +70 -0
- data/lib/fluent/test/driver/base_owner.rb +135 -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 +53 -0
- data/lib/fluent/test/driver/output.rb +102 -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 +134 -0
- data/lib/fluent/test/input_test.rb +174 -0
- data/lib/fluent/test/log.rb +79 -0
- data/lib/fluent/test/output_test.rb +156 -0
- data/lib/fluent/test/parser_test.rb +70 -0
- data/lib/fluent/test/startup_shutdown.rb +46 -0
- data/lib/fluent/time.rb +412 -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/templates/new_gem/Gemfile +3 -0
- data/templates/new_gem/README.md.erb +43 -0
- data/templates/new_gem/Rakefile +13 -0
- data/templates/new_gem/fluent-plugin.gemspec.erb +27 -0
- data/templates/new_gem/lib/fluent/plugin/filter.rb.erb +14 -0
- data/templates/new_gem/lib/fluent/plugin/formatter.rb.erb +14 -0
- data/templates/new_gem/lib/fluent/plugin/input.rb.erb +11 -0
- data/templates/new_gem/lib/fluent/plugin/output.rb.erb +11 -0
- data/templates/new_gem/lib/fluent/plugin/parser.rb.erb +15 -0
- data/templates/new_gem/test/helper.rb.erb +8 -0
- data/templates/new_gem/test/plugin/test_filter.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_formatter.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_input.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_output.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_parser.rb.erb +18 -0
- data/templates/plugin_config_formatter/param.md-compact.erb +25 -0
- data/templates/plugin_config_formatter/param.md.erb +34 -0
- data/templates/plugin_config_formatter/section.md.erb +12 -0
- data/test/command/test_binlog_reader.rb +346 -0
- data/test/command/test_fluentd.rb +618 -0
- data/test/command/test_plugin_config_formatter.rb +275 -0
- data/test/command/test_plugin_generator.rb +66 -0
- data/test/compat/test_calls_super.rb +166 -0
- data/test/compat/test_parser.rb +92 -0
- data/test/config/assertions.rb +42 -0
- data/test/config/test_config_parser.rb +513 -0
- data/test/config/test_configurable.rb +1587 -0
- data/test/config/test_configure_proxy.rb +566 -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 +168 -0
- data/test/config/test_types.rb +191 -0
- data/test/helper.rb +153 -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/foo/bar2 +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 +115 -0
- data/test/plugin/test_buf_file.rb +843 -0
- data/test/plugin/test_buf_memory.rb +42 -0
- data/test/plugin/test_buffer.rb +1220 -0
- data/test/plugin/test_buffer_chunk.rb +198 -0
- data/test/plugin/test_buffer_file_chunk.rb +844 -0
- data/test/plugin/test_buffer_memory_chunk.rb +338 -0
- data/test/plugin/test_compressable.rb +84 -0
- data/test/plugin/test_file_util.rb +96 -0
- data/test/plugin/test_filter.rb +357 -0
- data/test/plugin/test_filter_grep.rb +119 -0
- data/test/plugin/test_filter_parser.rb +700 -0
- data/test/plugin/test_filter_record_transformer.rb +556 -0
- data/test/plugin/test_filter_stdout.rb +202 -0
- data/test/plugin/test_formatter_csv.rb +111 -0
- data/test/plugin/test_formatter_hash.rb +35 -0
- data/test/plugin/test_formatter_json.rb +51 -0
- data/test/plugin/test_formatter_ltsv.rb +59 -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 +192 -0
- data/test/plugin/test_in_exec.rb +245 -0
- data/test/plugin/test_in_forward.rb +1120 -0
- data/test/plugin/test_in_gc_stat.rb +39 -0
- data/test/plugin/test_in_http.rb +588 -0
- data/test/plugin/test_in_monitor_agent.rb +516 -0
- data/test/plugin/test_in_object_space.rb +64 -0
- data/test/plugin/test_in_syslog.rb +271 -0
- data/test/plugin/test_in_tail.rb +1216 -0
- data/test/plugin/test_in_tcp.rb +118 -0
- data/test/plugin/test_in_udp.rb +152 -0
- data/test/plugin/test_in_unix.rb +126 -0
- data/test/plugin/test_input.rb +126 -0
- data/test/plugin/test_multi_output.rb +180 -0
- data/test/plugin/test_out_copy.rb +160 -0
- data/test/plugin/test_out_exec.rb +310 -0
- data/test/plugin/test_out_exec_filter.rb +613 -0
- data/test/plugin/test_out_file.rb +873 -0
- data/test/plugin/test_out_forward.rb +685 -0
- data/test/plugin/test_out_null.rb +105 -0
- data/test/plugin/test_out_relabel.rb +28 -0
- data/test/plugin/test_out_roundrobin.rb +146 -0
- data/test/plugin/test_out_secondary_file.rb +442 -0
- data/test/plugin/test_out_stdout.rb +170 -0
- data/test/plugin/test_out_stream.rb +93 -0
- data/test/plugin/test_output.rb +870 -0
- data/test/plugin/test_output_as_buffered.rb +1932 -0
- data/test/plugin/test_output_as_buffered_compress.rb +165 -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 +877 -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.rb +359 -0
- data/test/plugin/test_parser_apache.rb +42 -0
- data/test/plugin/test_parser_apache2.rb +46 -0
- data/test/plugin/test_parser_apache_error.rb +45 -0
- data/test/plugin/test_parser_csv.rb +103 -0
- data/test/plugin/test_parser_json.rb +114 -0
- data/test/plugin/test_parser_labeled_tsv.rb +128 -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 +52 -0
- data/test/plugin/test_parser_regexp.rb +281 -0
- data/test/plugin/test_parser_syslog.rb +242 -0
- data/test/plugin/test_parser_tsv.rb +122 -0
- data/test/plugin/test_storage.rb +167 -0
- data/test/plugin/test_storage_local.rb +335 -0
- data/test/plugin/test_string_util.rb +26 -0
- data/test/plugin_helper/test_child_process.rb +794 -0
- data/test/plugin_helper/test_compat_parameters.rb +331 -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_extract.rb +194 -0
- data/test/plugin_helper/test_formatter.rb +255 -0
- data/test/plugin_helper/test_inject.rb +519 -0
- data/test/plugin_helper/test_parser.rb +264 -0
- data/test/plugin_helper/test_retry_state.rb +422 -0
- data/test/plugin_helper/test_server.rb +1677 -0
- data/test/plugin_helper/test_storage.rb +542 -0
- data/test/plugin_helper/test_thread.rb +164 -0
- data/test/plugin_helper/test_timer.rb +132 -0
- data/test/scripts/exec_script.rb +32 -0
- data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +7 -0
- data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +7 -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_clock.rb +164 -0
- data/test/test_config.rb +179 -0
- data/test/test_configdsl.rb +148 -0
- data/test/test_event.rb +515 -0
- data/test/test_event_router.rb +331 -0
- data/test/test_event_time.rb +186 -0
- data/test/test_filter.rb +121 -0
- data/test/test_formatter.rb +312 -0
- data/test/test_input.rb +31 -0
- data/test/test_log.rb +828 -0
- data/test/test_match.rb +137 -0
- data/test/test_mixin.rb +351 -0
- data/test/test_output.rb +273 -0
- data/test/test_plugin.rb +251 -0
- data/test/test_plugin_classes.rb +253 -0
- data/test/test_plugin_helper.rb +81 -0
- data/test/test_plugin_id.rb +101 -0
- data/test/test_process.rb +14 -0
- data/test/test_root_agent.rb +611 -0
- data/test/test_supervisor.rb +373 -0
- data/test/test_test_drivers.rb +135 -0
- data/test/test_time_formatter.rb +282 -0
- data/test/test_time_parser.rb +211 -0
- data/test/test_unique_id.rb +47 -0
- metadata +898 -0
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/plugin/bare_output'
|
3
|
+
require 'fluent/event'
|
4
|
+
|
5
|
+
module FluentPluginBareOutputTest
|
6
|
+
class DummyPlugin < Fluent::Plugin::BareOutput
|
7
|
+
attr_reader :store
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
@store = []
|
11
|
+
end
|
12
|
+
def process(tag, es)
|
13
|
+
es.each do |time, record|
|
14
|
+
@store << [tag, time, record]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class BareOutputTest < Test::Unit::TestCase
|
21
|
+
setup do
|
22
|
+
Fluent::Test.setup
|
23
|
+
@p = FluentPluginBareOutputTest::DummyPlugin.new
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'has healthy lifecycle' do
|
27
|
+
assert !@p.configured?
|
28
|
+
@p.configure(config_element())
|
29
|
+
assert @p.configured?
|
30
|
+
|
31
|
+
assert !@p.started?
|
32
|
+
@p.start
|
33
|
+
assert @p.start
|
34
|
+
|
35
|
+
assert !@p.stopped?
|
36
|
+
@p.stop
|
37
|
+
assert @p.stopped?
|
38
|
+
|
39
|
+
assert !@p.before_shutdown?
|
40
|
+
@p.before_shutdown
|
41
|
+
assert @p.before_shutdown?
|
42
|
+
|
43
|
+
assert !@p.shutdown?
|
44
|
+
@p.shutdown
|
45
|
+
assert @p.shutdown?
|
46
|
+
|
47
|
+
assert !@p.after_shutdown?
|
48
|
+
@p.after_shutdown
|
49
|
+
assert @p.after_shutdown?
|
50
|
+
|
51
|
+
assert !@p.closed?
|
52
|
+
@p.close
|
53
|
+
assert @p.closed?
|
54
|
+
|
55
|
+
assert !@p.terminated?
|
56
|
+
@p.terminate
|
57
|
+
assert @p.terminated?
|
58
|
+
end
|
59
|
+
|
60
|
+
test 'has plugin_id automatically generated' do
|
61
|
+
assert @p.respond_to?(:plugin_id_configured?)
|
62
|
+
assert @p.respond_to?(:plugin_id)
|
63
|
+
|
64
|
+
@p.configure(config_element())
|
65
|
+
|
66
|
+
assert !@p.plugin_id_configured?
|
67
|
+
assert @p.plugin_id
|
68
|
+
assert{ @p.plugin_id != 'mytest' }
|
69
|
+
end
|
70
|
+
|
71
|
+
test 'has plugin_id manually configured' do
|
72
|
+
@p.configure(config_element('ROOT', '', {'@id' => 'mytest'}))
|
73
|
+
assert @p.plugin_id_configured?
|
74
|
+
assert_equal 'mytest', @p.plugin_id
|
75
|
+
end
|
76
|
+
|
77
|
+
test 'has plugin logger' do
|
78
|
+
assert @p.respond_to?(:log)
|
79
|
+
assert @p.log
|
80
|
+
|
81
|
+
# default logger
|
82
|
+
original_logger = @p.log
|
83
|
+
|
84
|
+
@p.configure(config_element('ROOT', '', {'@log_level' => 'debug'}))
|
85
|
+
|
86
|
+
assert{ @p.log.object_id != original_logger.object_id }
|
87
|
+
assert_equal Fluent::Log::LEVEL_DEBUG, @p.log.level
|
88
|
+
end
|
89
|
+
|
90
|
+
test 'can load plugin helpers' do
|
91
|
+
assert_nothing_raised do
|
92
|
+
class FluentPluginBareOutputTest::DummyPlugin2 < Fluent::Plugin::BareOutput
|
93
|
+
helpers :storage
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
test 'can get input event stream to write' do
|
99
|
+
@p.configure(config_element('ROOT'))
|
100
|
+
@p.start
|
101
|
+
|
102
|
+
es1 = Fluent::OneEventStream.new(event_time('2016-05-21 18:37:31 +0900'), {'k1' => 'v1'})
|
103
|
+
es2 = Fluent::ArrayEventStream.new([
|
104
|
+
[event_time('2016-05-21 18:38:33 +0900'), {'k2' => 'v2'}],
|
105
|
+
[event_time('2016-05-21 18:39:10 +0900'), {'k3' => 'v3'}],
|
106
|
+
])
|
107
|
+
@p.emit_events('mytest1', es1)
|
108
|
+
@p.emit_events('mytest2', es2)
|
109
|
+
|
110
|
+
all_events = [
|
111
|
+
['mytest1', event_time('2016-05-21 18:37:31 +0900'), {'k1' => 'v1'}],
|
112
|
+
['mytest2', event_time('2016-05-21 18:38:33 +0900'), {'k2' => 'v2'}],
|
113
|
+
['mytest2', event_time('2016-05-21 18:39:10 +0900'), {'k3' => 'v3'}],
|
114
|
+
]
|
115
|
+
|
116
|
+
assert_equal all_events, @p.store
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/plugin/base'
|
3
|
+
|
4
|
+
module FluentPluginBaseTest
|
5
|
+
class DummyPlugin < Fluent::Plugin::Base
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class BaseTest < Test::Unit::TestCase
|
10
|
+
setup do
|
11
|
+
@p = FluentPluginBaseTest::DummyPlugin.new
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'has methods for phases of plugin life cycle, and methods to know "super"s were correctly called or not' do
|
15
|
+
assert !@p.configured?
|
16
|
+
@p.configure(config_element())
|
17
|
+
assert @p.configured?
|
18
|
+
|
19
|
+
assert !@p.started?
|
20
|
+
@p.start
|
21
|
+
assert @p.start
|
22
|
+
|
23
|
+
assert !@p.stopped?
|
24
|
+
@p.stop
|
25
|
+
assert @p.stopped?
|
26
|
+
|
27
|
+
assert !@p.before_shutdown?
|
28
|
+
@p.before_shutdown
|
29
|
+
assert @p.before_shutdown?
|
30
|
+
|
31
|
+
assert !@p.shutdown?
|
32
|
+
@p.shutdown
|
33
|
+
assert @p.shutdown?
|
34
|
+
|
35
|
+
assert !@p.after_shutdown?
|
36
|
+
@p.after_shutdown
|
37
|
+
assert @p.after_shutdown?
|
38
|
+
|
39
|
+
assert !@p.closed?
|
40
|
+
@p.close
|
41
|
+
assert @p.closed?
|
42
|
+
|
43
|
+
assert !@p.terminated?
|
44
|
+
@p.terminate
|
45
|
+
assert @p.terminated?
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'can access system config' do
|
49
|
+
assert @p.system_config
|
50
|
+
|
51
|
+
@p.system_config_override({'process_name' => 'mytest'})
|
52
|
+
assert_equal 'mytest', @p.system_config.process_name
|
53
|
+
end
|
54
|
+
|
55
|
+
test 'does not have router in default' do
|
56
|
+
assert !@p.has_router?
|
57
|
+
end
|
58
|
+
|
59
|
+
sub_test_case '#fluentd_worker_id' do
|
60
|
+
test 'returns 0 in default' do
|
61
|
+
assert_equal 0, @p.fluentd_worker_id
|
62
|
+
end
|
63
|
+
|
64
|
+
test 'returns the value specified via SERVERENGINE_WORKER_ID env variable' do
|
65
|
+
pre_value = ENV['SERVERENGINE_WORKER_ID']
|
66
|
+
begin
|
67
|
+
ENV['SERVERENGINE_WORKER_ID'] = 7.to_s
|
68
|
+
assert_equal 7, @p.fluentd_worker_id
|
69
|
+
ensure
|
70
|
+
ENV['SERVERENGINE_WORKER_ID'] = pre_value
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
test 'does not have root dir in default' do
|
76
|
+
assert_nil @p.plugin_root_dir
|
77
|
+
end
|
78
|
+
|
79
|
+
test 'is configurable by config_param and config_section' do
|
80
|
+
assert_nothing_raised do
|
81
|
+
class FluentPluginBaseTest::DummyPlugin2 < Fluent::Plugin::TestBase
|
82
|
+
config_param :myparam1, :string
|
83
|
+
config_section :mysection, multi: false do
|
84
|
+
config_param :myparam2, :integer
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
p2 = FluentPluginBaseTest::DummyPlugin2.new
|
89
|
+
assert_nothing_raised do
|
90
|
+
p2.configure(config_element('ROOT', '', {'myparam1' => 'myvalue1'}, [config_element('mysection', '', {'myparam2' => 99})]))
|
91
|
+
end
|
92
|
+
assert_equal 'myvalue1', p2.myparam1
|
93
|
+
assert_equal 99, p2.mysection.myparam2
|
94
|
+
end
|
95
|
+
|
96
|
+
test 'plugins are available with multi worker configuration in default' do
|
97
|
+
assert @p.multi_workers_ready?
|
98
|
+
end
|
99
|
+
|
100
|
+
test 'provides #string_safe_encoding to scrub invalid sequence string with info logging' do
|
101
|
+
logger = Fluent::Test::TestLogger.new
|
102
|
+
m = Module.new do
|
103
|
+
define_method(:log) do
|
104
|
+
logger
|
105
|
+
end
|
106
|
+
end
|
107
|
+
@p.extend m
|
108
|
+
assert_equal [], logger.logs
|
109
|
+
|
110
|
+
ret = @p.string_safe_encoding("abc\xff.\x01f"){|s| s.split(/\./) }
|
111
|
+
assert_equal ['abc?', "\u0001f"], ret
|
112
|
+
assert_equal 1, logger.logs.size
|
113
|
+
assert{ logger.logs.first.include?("invalid byte sequence is replaced in ") }
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,843 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/plugin/buf_file'
|
3
|
+
require 'fluent/plugin/output'
|
4
|
+
require 'fluent/unique_id'
|
5
|
+
require 'fluent/system_config'
|
6
|
+
require 'fluent/env'
|
7
|
+
|
8
|
+
require 'msgpack'
|
9
|
+
|
10
|
+
module FluentPluginFileBufferTest
|
11
|
+
class DummyOutputPlugin < Fluent::Plugin::Output
|
12
|
+
Fluent::Plugin.register_output('buffer_file_test_output', self)
|
13
|
+
config_section :buffer do
|
14
|
+
config_set_default :@type, 'file'
|
15
|
+
end
|
16
|
+
def multi_workers_ready?
|
17
|
+
true
|
18
|
+
end
|
19
|
+
def write(chunk)
|
20
|
+
# drop
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class FileBufferTest < Test::Unit::TestCase
|
26
|
+
def metadata(timekey: nil, tag: nil, variables: nil)
|
27
|
+
Fluent::Plugin::Buffer::Metadata.new(timekey, tag, variables)
|
28
|
+
end
|
29
|
+
|
30
|
+
def write_metadata(path, chunk_id, metadata, size, ctime, mtime)
|
31
|
+
metadata = {
|
32
|
+
timekey: metadata.timekey, tag: metadata.tag, variables: metadata.variables,
|
33
|
+
id: chunk_id,
|
34
|
+
s: size,
|
35
|
+
c: ctime,
|
36
|
+
m: mtime,
|
37
|
+
}
|
38
|
+
File.open(path, 'wb') do |f|
|
39
|
+
f.write metadata.to_msgpack
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
sub_test_case 'non configured buffer plugin instance' do
|
44
|
+
setup do
|
45
|
+
Fluent::Test.setup
|
46
|
+
|
47
|
+
@dir = File.expand_path('../../tmp/buffer_file_dir', __FILE__)
|
48
|
+
FileUtils.rm_rf @dir
|
49
|
+
FileUtils.mkdir_p @dir
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'path should include * normally' do
|
53
|
+
d = FluentPluginFileBufferTest::DummyOutputPlugin.new
|
54
|
+
p = Fluent::Plugin::FileBuffer.new
|
55
|
+
p.owner = d
|
56
|
+
p.configure(config_element('buffer', '', {'path' => File.join(@dir, 'buffer.*.file')}))
|
57
|
+
assert_equal File.join(@dir, 'buffer.*.file'), p.path
|
58
|
+
end
|
59
|
+
|
60
|
+
test 'existing directory will be used with additional default file name' do
|
61
|
+
d = FluentPluginFileBufferTest::DummyOutputPlugin.new
|
62
|
+
p = Fluent::Plugin::FileBuffer.new
|
63
|
+
p.owner = d
|
64
|
+
p.configure(config_element('buffer', '', {'path' => @dir}))
|
65
|
+
assert_equal File.join(@dir, 'buffer.*.log'), p.path
|
66
|
+
end
|
67
|
+
|
68
|
+
test 'unexisting path without * handled as directory' do
|
69
|
+
d = FluentPluginFileBufferTest::DummyOutputPlugin.new
|
70
|
+
p = Fluent::Plugin::FileBuffer.new
|
71
|
+
p.owner = d
|
72
|
+
p.configure(config_element('buffer', '', {'path' => File.join(@dir, 'buffer')}))
|
73
|
+
assert_equal File.join(@dir, 'buffer', 'buffer.*.log'), p.path
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
sub_test_case 'buffer configurations and workers' do
|
78
|
+
setup do
|
79
|
+
@bufdir = File.expand_path('../../tmp/buffer_file', __FILE__)
|
80
|
+
FileUtils.rm_rf @bufdir
|
81
|
+
Fluent::Test.setup
|
82
|
+
|
83
|
+
@d = FluentPluginFileBufferTest::DummyOutputPlugin.new
|
84
|
+
@p = Fluent::Plugin::FileBuffer.new
|
85
|
+
@p.owner = @d
|
86
|
+
end
|
87
|
+
|
88
|
+
test 'raise error if configured path is of existing file' do
|
89
|
+
@bufpath = File.join(@bufdir, 'buf')
|
90
|
+
FileUtils.mkdir_p @bufdir
|
91
|
+
File.open(@bufpath, 'w'){|f| } # create and close the file
|
92
|
+
assert File.exist?(@bufpath)
|
93
|
+
assert File.file?(@bufpath)
|
94
|
+
|
95
|
+
buf_conf = config_element('buffer', '', {'path' => @bufpath})
|
96
|
+
assert_raise Fluent::ConfigError.new("Plugin 'file' does not support multi workers configuration (Fluent::Plugin::FileBuffer)") do
|
97
|
+
Fluent::SystemConfig.overwrite_system_config('workers' => 4) do
|
98
|
+
@d.configure(config_element('ROOT', '', {'@id' => 'dummy_output_with_buf'}, [buf_conf]))
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
test 'raise error if fluentd is configured to use file path pattern and multi workers' do
|
104
|
+
@bufpath = File.join(@bufdir, 'testbuf.*.log')
|
105
|
+
buf_conf = config_element('buffer', '', {'path' => @bufpath})
|
106
|
+
assert_raise Fluent::ConfigError.new("Plugin 'file' does not support multi workers configuration (Fluent::Plugin::FileBuffer)") do
|
107
|
+
Fluent::SystemConfig.overwrite_system_config('workers' => 4) do
|
108
|
+
@d.configure(config_element('ROOT', '', {'@id' => 'dummy_output_with_buf'}, [buf_conf]))
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
test 'enables multi worker configuration with unexisting directory path' do
|
114
|
+
assert_false File.exist?(@bufdir)
|
115
|
+
buf_conf = config_element('buffer', '', {'path' => @bufdir})
|
116
|
+
assert_nothing_raised do
|
117
|
+
Fluent::SystemConfig.overwrite_system_config('root_dir' => @bufdir, 'workers' => 4) do
|
118
|
+
@d.configure(config_element('ROOT', '', {}, [buf_conf]))
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
test 'enables multi worker configuration with existing directory path' do
|
124
|
+
FileUtils.mkdir_p @bufdir
|
125
|
+
buf_conf = config_element('buffer', '', {'path' => @bufdir})
|
126
|
+
assert_nothing_raised do
|
127
|
+
Fluent::SystemConfig.overwrite_system_config('root_dir' => @bufdir, 'workers' => 4) do
|
128
|
+
@d.configure(config_element('ROOT', '', {}, [buf_conf]))
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
test 'enables multi worker configuration with root dir' do
|
134
|
+
buf_conf = config_element('buffer', '')
|
135
|
+
assert_nothing_raised do
|
136
|
+
Fluent::SystemConfig.overwrite_system_config('root_dir' => @bufdir, 'workers' => 4) do
|
137
|
+
@d.configure(config_element('ROOT', '', {'@id' => 'dummy_output_with_buf'}, [buf_conf]))
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
sub_test_case 'buffer plugin configured only with path' do
|
144
|
+
setup do
|
145
|
+
@bufdir = File.expand_path('../../tmp/buffer_file', __FILE__)
|
146
|
+
@bufpath = File.join(@bufdir, 'testbuf.*.log')
|
147
|
+
FileUtils.rm_r @bufdir if File.exist?(@bufdir)
|
148
|
+
|
149
|
+
Fluent::Test.setup
|
150
|
+
@d = FluentPluginFileBufferTest::DummyOutputPlugin.new
|
151
|
+
@p = Fluent::Plugin::FileBuffer.new
|
152
|
+
@p.owner = @d
|
153
|
+
@p.configure(config_element('buffer', '', {'path' => @bufpath}))
|
154
|
+
@p.start
|
155
|
+
end
|
156
|
+
|
157
|
+
teardown do
|
158
|
+
if @p
|
159
|
+
@p.stop unless @p.stopped?
|
160
|
+
@p.before_shutdown unless @p.before_shutdown?
|
161
|
+
@p.shutdown unless @p.shutdown?
|
162
|
+
@p.after_shutdown unless @p.after_shutdown?
|
163
|
+
@p.close unless @p.closed?
|
164
|
+
@p.terminate unless @p.terminated?
|
165
|
+
end
|
166
|
+
if @bufdir
|
167
|
+
Dir.glob(File.join(@bufdir, '*')).each do |path|
|
168
|
+
next if ['.', '..'].include?(File.basename(path))
|
169
|
+
File.delete(path)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
test 'this is persistent plugin' do
|
175
|
+
assert @p.persistent?
|
176
|
+
end
|
177
|
+
|
178
|
+
test '#start creates directory for buffer chunks' do
|
179
|
+
plugin = Fluent::Plugin::FileBuffer.new
|
180
|
+
plugin.owner = @d
|
181
|
+
rand_num = rand(0..100)
|
182
|
+
bufpath = File.join(File.expand_path("../../tmp/buffer_file_#{rand_num}", __FILE__), 'testbuf.*.log')
|
183
|
+
bufdir = File.dirname(bufpath)
|
184
|
+
|
185
|
+
FileUtils.rm_r bufdir if File.exist?(bufdir)
|
186
|
+
assert !File.exist?(bufdir)
|
187
|
+
|
188
|
+
plugin.configure(config_element('buffer', '', {'path' => bufpath}))
|
189
|
+
assert !File.exist?(bufdir)
|
190
|
+
|
191
|
+
plugin.start
|
192
|
+
assert File.exist?(bufdir)
|
193
|
+
assert{ File.stat(bufdir).mode.to_s(8).end_with?('755') }
|
194
|
+
|
195
|
+
plugin.stop; plugin.before_shutdown; plugin.shutdown; plugin.after_shutdown; plugin.close; plugin.terminate
|
196
|
+
FileUtils.rm_r bufdir
|
197
|
+
end
|
198
|
+
|
199
|
+
test '#start creates directory for buffer chunks with specified permission' do
|
200
|
+
omit "NTFS doesn't support UNIX like permissions" if Fluent.windows?
|
201
|
+
|
202
|
+
plugin = Fluent::Plugin::FileBuffer.new
|
203
|
+
plugin.owner = @d
|
204
|
+
rand_num = rand(0..100)
|
205
|
+
bufpath = File.join(File.expand_path("../../tmp/buffer_file_#{rand_num}", __FILE__), 'testbuf.*.log')
|
206
|
+
bufdir = File.dirname(bufpath)
|
207
|
+
|
208
|
+
FileUtils.rm_r bufdir if File.exist?(bufdir)
|
209
|
+
assert !File.exist?(bufdir)
|
210
|
+
|
211
|
+
plugin.configure(config_element('buffer', '', {'path' => bufpath, 'dir_permission' => '0700'}))
|
212
|
+
assert !File.exist?(bufdir)
|
213
|
+
|
214
|
+
plugin.start
|
215
|
+
assert File.exist?(bufdir)
|
216
|
+
assert{ File.stat(bufdir).mode.to_s(8).end_with?('700') }
|
217
|
+
|
218
|
+
plugin.stop; plugin.before_shutdown; plugin.shutdown; plugin.after_shutdown; plugin.close; plugin.terminate
|
219
|
+
FileUtils.rm_r bufdir
|
220
|
+
end
|
221
|
+
|
222
|
+
test '#start creates directory for buffer chunks with specified permission via system config' do
|
223
|
+
omit "NTFS doesn't support UNIX like permissions" if Fluent.windows?
|
224
|
+
|
225
|
+
sysconf = {'dir_permission' => '700'}
|
226
|
+
Fluent::SystemConfig.overwrite_system_config(sysconf) do
|
227
|
+
plugin = Fluent::Plugin::FileBuffer.new
|
228
|
+
plugin.owner = @d
|
229
|
+
rand_num = rand(0..100)
|
230
|
+
bufpath = File.join(File.expand_path("../../tmp/buffer_file_#{rand_num}", __FILE__), 'testbuf.*.log')
|
231
|
+
bufdir = File.dirname(bufpath)
|
232
|
+
|
233
|
+
FileUtils.rm_r bufdir if File.exist?(bufdir)
|
234
|
+
assert !File.exist?(bufdir)
|
235
|
+
|
236
|
+
plugin.configure(config_element('buffer', '', {'path' => bufpath}))
|
237
|
+
assert !File.exist?(bufdir)
|
238
|
+
|
239
|
+
plugin.start
|
240
|
+
assert File.exist?(bufdir)
|
241
|
+
assert{ File.stat(bufdir).mode.to_s(8).end_with?('700') }
|
242
|
+
|
243
|
+
plugin.stop; plugin.before_shutdown; plugin.shutdown; plugin.after_shutdown; plugin.close; plugin.terminate
|
244
|
+
FileUtils.rm_r bufdir
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
test '#generate_chunk generates blank file chunk on path from unique_id of metadata' do
|
249
|
+
m1 = metadata()
|
250
|
+
c1 = @p.generate_chunk(m1)
|
251
|
+
assert c1.is_a? Fluent::Plugin::Buffer::FileChunk
|
252
|
+
assert_equal m1, c1.metadata
|
253
|
+
assert c1.empty?
|
254
|
+
assert_equal :unstaged, c1.state
|
255
|
+
assert_equal Fluent::Plugin::Buffer::FileChunk::FILE_PERMISSION, c1.permission
|
256
|
+
assert_equal @bufpath.gsub('.*.', ".b#{Fluent::UniqueId.hex(c1.unique_id)}."), c1.path
|
257
|
+
assert{ File.stat(c1.path).mode.to_s(8).end_with?('644') }
|
258
|
+
|
259
|
+
m2 = metadata(timekey: event_time('2016-04-17 11:15:00 -0700').to_i)
|
260
|
+
c2 = @p.generate_chunk(m2)
|
261
|
+
assert c2.is_a? Fluent::Plugin::Buffer::FileChunk
|
262
|
+
assert_equal m2, c2.metadata
|
263
|
+
assert c2.empty?
|
264
|
+
assert_equal :unstaged, c2.state
|
265
|
+
assert_equal Fluent::Plugin::Buffer::FileChunk::FILE_PERMISSION, c2.permission
|
266
|
+
assert_equal @bufpath.gsub('.*.', ".b#{Fluent::UniqueId.hex(c2.unique_id)}."), c2.path
|
267
|
+
assert{ File.stat(c2.path).mode.to_s(8).end_with?('644') }
|
268
|
+
|
269
|
+
c1.purge
|
270
|
+
c2.purge
|
271
|
+
end
|
272
|
+
|
273
|
+
test '#generate_chunk generates blank file chunk with specified permission' do
|
274
|
+
omit "NTFS doesn't support UNIX like permissions" if Fluent.windows?
|
275
|
+
|
276
|
+
plugin = Fluent::Plugin::FileBuffer.new
|
277
|
+
plugin.owner = @d
|
278
|
+
rand_num = rand(0..100)
|
279
|
+
bufpath = File.join(File.expand_path("../../tmp/buffer_file_#{rand_num}", __FILE__), 'testbuf.*.log')
|
280
|
+
bufdir = File.dirname(bufpath)
|
281
|
+
|
282
|
+
FileUtils.rm_r bufdir if File.exist?(bufdir)
|
283
|
+
assert !File.exist?(bufdir)
|
284
|
+
|
285
|
+
plugin.configure(config_element('buffer', '', {'path' => bufpath, 'file_permission' => '0600'}))
|
286
|
+
assert !File.exist?(bufdir)
|
287
|
+
plugin.start
|
288
|
+
|
289
|
+
m = metadata()
|
290
|
+
c = plugin.generate_chunk(m)
|
291
|
+
assert c.is_a? Fluent::Plugin::Buffer::FileChunk
|
292
|
+
assert_equal m, c.metadata
|
293
|
+
assert c.empty?
|
294
|
+
assert_equal :unstaged, c.state
|
295
|
+
assert_equal 0600, c.permission
|
296
|
+
assert_equal bufpath.gsub('.*.', ".b#{Fluent::UniqueId.hex(c.unique_id)}."), c.path
|
297
|
+
assert{ File.stat(c.path).mode.to_s(8).end_with?('600') }
|
298
|
+
|
299
|
+
c.purge
|
300
|
+
|
301
|
+
plugin.stop; plugin.before_shutdown; plugin.shutdown; plugin.after_shutdown; plugin.close; plugin.terminate
|
302
|
+
FileUtils.rm_r bufdir
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
sub_test_case 'configured with system root directory and plugin @id' do
|
307
|
+
setup do
|
308
|
+
@root_dir = File.expand_path('../../tmp/buffer_file_root', __FILE__)
|
309
|
+
FileUtils.rm_rf @root_dir
|
310
|
+
|
311
|
+
Fluent::Test.setup
|
312
|
+
@d = FluentPluginFileBufferTest::DummyOutputPlugin.new
|
313
|
+
@p = Fluent::Plugin::FileBuffer.new
|
314
|
+
@p.owner = @d
|
315
|
+
Fluent::SystemConfig.overwrite_system_config('root_dir' => @root_dir) do
|
316
|
+
@d.configure(config_element('ROOT', '', {'@id' => 'dummy_output_with_buf'}))
|
317
|
+
@p.configure(config_element('buffer', ''))
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
teardown do
|
322
|
+
if @p
|
323
|
+
@p.stop unless @p.stopped?
|
324
|
+
@p.before_shutdown unless @p.before_shutdown?
|
325
|
+
@p.shutdown unless @p.shutdown?
|
326
|
+
@p.after_shutdown unless @p.after_shutdown?
|
327
|
+
@p.close unless @p.closed?
|
328
|
+
@p.terminate unless @p.terminated?
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
test '#start creates directory for buffer chunks' do
|
333
|
+
expected_buffer_path = File.join(@root_dir, 'worker0', 'dummy_output_with_buf', 'buffer', 'buffer.*.log')
|
334
|
+
expected_buffer_dir = File.dirname(expected_buffer_path)
|
335
|
+
assert_equal expected_buffer_path, @p.path
|
336
|
+
assert_false Dir.exist?(expected_buffer_dir)
|
337
|
+
|
338
|
+
@p.start
|
339
|
+
|
340
|
+
assert Dir.exist?(expected_buffer_dir)
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
sub_test_case 'there are no existing file chunks' do
|
345
|
+
setup do
|
346
|
+
@bufdir = File.expand_path('../../tmp/buffer_file', __FILE__)
|
347
|
+
@bufpath = File.join(@bufdir, 'testbuf.*.log')
|
348
|
+
FileUtils.rm_r @bufdir if File.exist?(@bufdir)
|
349
|
+
|
350
|
+
Fluent::Test.setup
|
351
|
+
@d = FluentPluginFileBufferTest::DummyOutputPlugin.new
|
352
|
+
@p = Fluent::Plugin::FileBuffer.new
|
353
|
+
@p.owner = @d
|
354
|
+
@p.configure(config_element('buffer', '', {'path' => @bufpath}))
|
355
|
+
@p.start
|
356
|
+
end
|
357
|
+
teardown do
|
358
|
+
if @p
|
359
|
+
@p.stop unless @p.stopped?
|
360
|
+
@p.before_shutdown unless @p.before_shutdown?
|
361
|
+
@p.shutdown unless @p.shutdown?
|
362
|
+
@p.after_shutdown unless @p.after_shutdown?
|
363
|
+
@p.close unless @p.closed?
|
364
|
+
@p.terminate unless @p.terminated?
|
365
|
+
end
|
366
|
+
if @bufdir
|
367
|
+
Dir.glob(File.join(@bufdir, '*')).each do |path|
|
368
|
+
next if ['.', '..'].include?(File.basename(path))
|
369
|
+
File.delete(path)
|
370
|
+
end
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
test '#resume returns empty buffer state' do
|
375
|
+
ary = @p.resume
|
376
|
+
assert_equal({}, ary[0])
|
377
|
+
assert_equal([], ary[1])
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
sub_test_case 'there are some existing file chunks' do
|
382
|
+
setup do
|
383
|
+
@bufdir = File.expand_path('../../tmp/buffer_file', __FILE__)
|
384
|
+
FileUtils.mkdir_p @bufdir unless File.exist?(@bufdir)
|
385
|
+
|
386
|
+
@c1id = Fluent::UniqueId.generate
|
387
|
+
p1 = File.join(@bufdir, "etest.q#{Fluent::UniqueId.hex(@c1id)}.log")
|
388
|
+
File.open(p1, 'wb') do |f|
|
389
|
+
f.write ["t1.test", event_time('2016-04-17 13:58:15 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
390
|
+
f.write ["t2.test", event_time('2016-04-17 13:58:17 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
391
|
+
f.write ["t3.test", event_time('2016-04-17 13:58:21 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
392
|
+
f.write ["t4.test", event_time('2016-04-17 13:58:22 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
393
|
+
end
|
394
|
+
write_metadata(
|
395
|
+
p1 + '.meta', @c1id, metadata(timekey: event_time('2016-04-17 13:58:00 -0700').to_i),
|
396
|
+
4, event_time('2016-04-17 13:58:00 -0700').to_i, event_time('2016-04-17 13:58:22 -0700').to_i
|
397
|
+
)
|
398
|
+
|
399
|
+
@c2id = Fluent::UniqueId.generate
|
400
|
+
p2 = File.join(@bufdir, "etest.q#{Fluent::UniqueId.hex(@c2id)}.log")
|
401
|
+
File.open(p2, 'wb') do |f|
|
402
|
+
f.write ["t1.test", event_time('2016-04-17 13:59:15 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
403
|
+
f.write ["t2.test", event_time('2016-04-17 13:59:17 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
404
|
+
f.write ["t3.test", event_time('2016-04-17 13:59:21 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
405
|
+
end
|
406
|
+
write_metadata(
|
407
|
+
p2 + '.meta', @c2id, metadata(timekey: event_time('2016-04-17 13:59:00 -0700').to_i),
|
408
|
+
3, event_time('2016-04-17 13:59:00 -0700').to_i, event_time('2016-04-17 13:59:23 -0700').to_i
|
409
|
+
)
|
410
|
+
|
411
|
+
@c3id = Fluent::UniqueId.generate
|
412
|
+
p3 = File.join(@bufdir, "etest.b#{Fluent::UniqueId.hex(@c3id)}.log")
|
413
|
+
File.open(p3, 'wb') do |f|
|
414
|
+
f.write ["t1.test", event_time('2016-04-17 14:00:15 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
415
|
+
f.write ["t2.test", event_time('2016-04-17 14:00:17 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
416
|
+
f.write ["t3.test", event_time('2016-04-17 14:00:21 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
417
|
+
f.write ["t4.test", event_time('2016-04-17 14:00:28 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
418
|
+
end
|
419
|
+
write_metadata(
|
420
|
+
p3 + '.meta', @c3id, metadata(timekey: event_time('2016-04-17 14:00:00 -0700').to_i),
|
421
|
+
4, event_time('2016-04-17 14:00:00 -0700').to_i, event_time('2016-04-17 14:00:28 -0700').to_i
|
422
|
+
)
|
423
|
+
|
424
|
+
@c4id = Fluent::UniqueId.generate
|
425
|
+
p4 = File.join(@bufdir, "etest.b#{Fluent::UniqueId.hex(@c4id)}.log")
|
426
|
+
File.open(p4, 'wb') do |f|
|
427
|
+
f.write ["t1.test", event_time('2016-04-17 14:01:15 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
428
|
+
f.write ["t2.test", event_time('2016-04-17 14:01:17 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
429
|
+
f.write ["t3.test", event_time('2016-04-17 14:01:21 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
430
|
+
end
|
431
|
+
write_metadata(
|
432
|
+
p4 + '.meta', @c4id, metadata(timekey: event_time('2016-04-17 14:01:00 -0700').to_i),
|
433
|
+
3, event_time('2016-04-17 14:01:00 -0700').to_i, event_time('2016-04-17 14:01:25 -0700').to_i
|
434
|
+
)
|
435
|
+
|
436
|
+
@bufpath = File.join(@bufdir, 'etest.*.log')
|
437
|
+
|
438
|
+
Fluent::Test.setup
|
439
|
+
@d = FluentPluginFileBufferTest::DummyOutputPlugin.new
|
440
|
+
@p = Fluent::Plugin::FileBuffer.new
|
441
|
+
@p.owner = @d
|
442
|
+
@p.configure(config_element('buffer', '', {'path' => @bufpath}))
|
443
|
+
@p.start
|
444
|
+
end
|
445
|
+
|
446
|
+
teardown do
|
447
|
+
if @p
|
448
|
+
@p.stop unless @p.stopped?
|
449
|
+
@p.before_shutdown unless @p.before_shutdown?
|
450
|
+
@p.shutdown unless @p.shutdown?
|
451
|
+
@p.after_shutdown unless @p.after_shutdown?
|
452
|
+
@p.close unless @p.closed?
|
453
|
+
@p.terminate unless @p.terminated?
|
454
|
+
end
|
455
|
+
if @bufdir
|
456
|
+
Dir.glob(File.join(@bufdir, '*')).each do |path|
|
457
|
+
next if ['.', '..'].include?(File.basename(path))
|
458
|
+
File.delete(path)
|
459
|
+
end
|
460
|
+
end
|
461
|
+
end
|
462
|
+
|
463
|
+
test '#resume returns staged/queued chunks with metadata' do
|
464
|
+
assert_equal 2, @p.stage.size
|
465
|
+
assert_equal 2, @p.queue.size
|
466
|
+
|
467
|
+
stage = @p.stage
|
468
|
+
|
469
|
+
m3 = metadata(timekey: event_time('2016-04-17 14:00:00 -0700').to_i)
|
470
|
+
assert_equal @c3id, stage[m3].unique_id
|
471
|
+
assert_equal 4, stage[m3].size
|
472
|
+
assert_equal :staged, stage[m3].state
|
473
|
+
|
474
|
+
m4 = metadata(timekey: event_time('2016-04-17 14:01:00 -0700').to_i)
|
475
|
+
assert_equal @c4id, stage[m4].unique_id
|
476
|
+
assert_equal 3, stage[m4].size
|
477
|
+
assert_equal :staged, stage[m4].state
|
478
|
+
end
|
479
|
+
|
480
|
+
test '#resume returns queued chunks ordered by last modified time (FIFO)' do
|
481
|
+
assert_equal 2, @p.stage.size
|
482
|
+
assert_equal 2, @p.queue.size
|
483
|
+
|
484
|
+
queue = @p.queue
|
485
|
+
|
486
|
+
assert{ queue[0].modified_at < queue[1].modified_at }
|
487
|
+
|
488
|
+
assert_equal @c1id, queue[0].unique_id
|
489
|
+
assert_equal :queued, queue[0].state
|
490
|
+
assert_equal event_time('2016-04-17 13:58:00 -0700').to_i, queue[0].metadata.timekey
|
491
|
+
assert_nil queue[0].metadata.tag
|
492
|
+
assert_nil queue[0].metadata.variables
|
493
|
+
assert_equal Time.parse('2016-04-17 13:58:00 -0700').localtime, queue[0].created_at
|
494
|
+
assert_equal Time.parse('2016-04-17 13:58:22 -0700').localtime, queue[0].modified_at
|
495
|
+
assert_equal 4, queue[0].size
|
496
|
+
|
497
|
+
assert_equal @c2id, queue[1].unique_id
|
498
|
+
assert_equal :queued, queue[1].state
|
499
|
+
assert_equal event_time('2016-04-17 13:59:00 -0700').to_i, queue[1].metadata.timekey
|
500
|
+
assert_nil queue[1].metadata.tag
|
501
|
+
assert_nil queue[1].metadata.variables
|
502
|
+
assert_equal Time.parse('2016-04-17 13:59:00 -0700').localtime, queue[1].created_at
|
503
|
+
assert_equal Time.parse('2016-04-17 13:59:23 -0700').localtime, queue[1].modified_at
|
504
|
+
assert_equal 3, queue[1].size
|
505
|
+
end
|
506
|
+
end
|
507
|
+
|
508
|
+
sub_test_case 'there are some existing file chunks, both in specified path and per-worker directory under specified path, configured as multi workers' do
|
509
|
+
setup do
|
510
|
+
@bufdir = File.expand_path('../../tmp/buffer_file/path', __FILE__)
|
511
|
+
@worker0_dir = File.join(@bufdir, "worker0")
|
512
|
+
@worker1_dir = File.join(@bufdir, "worker1")
|
513
|
+
FileUtils.rm_rf @bufdir
|
514
|
+
FileUtils.mkdir_p @worker0_dir
|
515
|
+
FileUtils.mkdir_p @worker1_dir
|
516
|
+
|
517
|
+
@bufdir_chunk_1 = Fluent::UniqueId.generate
|
518
|
+
bc1 = File.join(@bufdir, "buffer.q#{Fluent::UniqueId.hex(@bufdir_chunk_1)}.log")
|
519
|
+
File.open(bc1, 'wb') do |f|
|
520
|
+
f.write ["t1.test", event_time('2016-04-17 13:58:15 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
521
|
+
f.write ["t2.test", event_time('2016-04-17 13:58:17 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
522
|
+
f.write ["t3.test", event_time('2016-04-17 13:58:21 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
523
|
+
f.write ["t4.test", event_time('2016-04-17 13:58:22 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
524
|
+
end
|
525
|
+
write_metadata(
|
526
|
+
bc1 + '.meta', @bufdir_chunk_1, metadata(timekey: event_time('2016-04-17 13:58:00 -0700').to_i),
|
527
|
+
4, event_time('2016-04-17 13:58:00 -0700').to_i, event_time('2016-04-17 13:58:22 -0700').to_i
|
528
|
+
)
|
529
|
+
|
530
|
+
@bufdir_chunk_2 = Fluent::UniqueId.generate
|
531
|
+
bc2 = File.join(@bufdir, "buffer.q#{Fluent::UniqueId.hex(@bufdir_chunk_2)}.log")
|
532
|
+
File.open(bc2, 'wb') do |f|
|
533
|
+
f.write ["t1.test", event_time('2016-04-17 13:58:15 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
534
|
+
f.write ["t2.test", event_time('2016-04-17 13:58:17 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
535
|
+
f.write ["t3.test", event_time('2016-04-17 13:58:21 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
536
|
+
f.write ["t4.test", event_time('2016-04-17 13:58:22 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
537
|
+
end
|
538
|
+
write_metadata(
|
539
|
+
bc2 + '.meta', @bufdir_chunk_2, metadata(timekey: event_time('2016-04-17 13:58:00 -0700').to_i),
|
540
|
+
4, event_time('2016-04-17 13:58:00 -0700').to_i, event_time('2016-04-17 13:58:22 -0700').to_i
|
541
|
+
)
|
542
|
+
|
543
|
+
@worker_dir_chunk_1 = Fluent::UniqueId.generate
|
544
|
+
wc0_1 = File.join(@worker0_dir, "buffer.q#{Fluent::UniqueId.hex(@worker_dir_chunk_1)}.log")
|
545
|
+
wc1_1 = File.join(@worker1_dir, "buffer.q#{Fluent::UniqueId.hex(@worker_dir_chunk_1)}.log")
|
546
|
+
[wc0_1, wc1_1].each do |chunk_path|
|
547
|
+
File.open(chunk_path, 'wb') do |f|
|
548
|
+
f.write ["t1.test", event_time('2016-04-17 13:59:15 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
549
|
+
f.write ["t2.test", event_time('2016-04-17 13:59:17 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
550
|
+
f.write ["t3.test", event_time('2016-04-17 13:59:21 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
551
|
+
end
|
552
|
+
write_metadata(
|
553
|
+
chunk_path + '.meta', @worker_dir_chunk_1, metadata(timekey: event_time('2016-04-17 13:59:00 -0700').to_i),
|
554
|
+
3, event_time('2016-04-17 13:59:00 -0700').to_i, event_time('2016-04-17 13:59:23 -0700').to_i
|
555
|
+
)
|
556
|
+
end
|
557
|
+
|
558
|
+
@worker_dir_chunk_2 = Fluent::UniqueId.generate
|
559
|
+
wc0_2 = File.join(@worker0_dir, "buffer.b#{Fluent::UniqueId.hex(@worker_dir_chunk_2)}.log")
|
560
|
+
wc1_2 = File.join(@worker1_dir, "buffer.b#{Fluent::UniqueId.hex(@worker_dir_chunk_2)}.log")
|
561
|
+
[wc0_2, wc1_2].each do |chunk_path|
|
562
|
+
File.open(chunk_path, 'wb') do |f|
|
563
|
+
f.write ["t1.test", event_time('2016-04-17 14:00:15 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
564
|
+
f.write ["t2.test", event_time('2016-04-17 14:00:17 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
565
|
+
f.write ["t3.test", event_time('2016-04-17 14:00:21 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
566
|
+
f.write ["t4.test", event_time('2016-04-17 14:00:28 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
567
|
+
end
|
568
|
+
write_metadata(
|
569
|
+
chunk_path + '.meta', @worker_dir_chunk_2, metadata(timekey: event_time('2016-04-17 14:00:00 -0700').to_i),
|
570
|
+
4, event_time('2016-04-17 14:00:00 -0700').to_i, event_time('2016-04-17 14:00:28 -0700').to_i
|
571
|
+
)
|
572
|
+
end
|
573
|
+
|
574
|
+
@worker_dir_chunk_3 = Fluent::UniqueId.generate
|
575
|
+
wc0_3 = File.join(@worker0_dir, "buffer.b#{Fluent::UniqueId.hex(@worker_dir_chunk_3)}.log")
|
576
|
+
wc1_3 = File.join(@worker1_dir, "buffer.b#{Fluent::UniqueId.hex(@worker_dir_chunk_3)}.log")
|
577
|
+
[wc0_3, wc1_3].each do |chunk_path|
|
578
|
+
File.open(chunk_path, 'wb') do |f|
|
579
|
+
f.write ["t1.test", event_time('2016-04-17 14:01:15 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
580
|
+
f.write ["t2.test", event_time('2016-04-17 14:01:17 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
581
|
+
f.write ["t3.test", event_time('2016-04-17 14:01:21 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
582
|
+
end
|
583
|
+
write_metadata(
|
584
|
+
chunk_path + '.meta', @worker_dir_chunk_3, metadata(timekey: event_time('2016-04-17 14:01:00 -0700').to_i),
|
585
|
+
3, event_time('2016-04-17 14:01:00 -0700').to_i, event_time('2016-04-17 14:01:25 -0700').to_i
|
586
|
+
)
|
587
|
+
end
|
588
|
+
|
589
|
+
Fluent::Test.setup
|
590
|
+
end
|
591
|
+
|
592
|
+
teardown do
|
593
|
+
if @p
|
594
|
+
@p.stop unless @p.stopped?
|
595
|
+
@p.before_shutdown unless @p.before_shutdown?
|
596
|
+
@p.shutdown unless @p.shutdown?
|
597
|
+
@p.after_shutdown unless @p.after_shutdown?
|
598
|
+
@p.close unless @p.closed?
|
599
|
+
@p.terminate unless @p.terminated?
|
600
|
+
end
|
601
|
+
end
|
602
|
+
|
603
|
+
test 'worker(id=0) #resume returns staged/queued chunks with metadata, not only in worker dir, including the directory specified by path' do
|
604
|
+
ENV['SERVERENGINE_WORKER_ID'] = '0'
|
605
|
+
|
606
|
+
buf_conf = config_element('buffer', '', {'path' => @bufdir})
|
607
|
+
@d = FluentPluginFileBufferTest::DummyOutputPlugin.new
|
608
|
+
with_worker_config(workers: 2, worker_id: 0) do
|
609
|
+
@d.configure(config_element('output', '', {}, [buf_conf]))
|
610
|
+
end
|
611
|
+
|
612
|
+
@d.start
|
613
|
+
@p = @d.buffer
|
614
|
+
|
615
|
+
assert_equal 2, @p.stage.size
|
616
|
+
assert_equal 3, @p.queue.size
|
617
|
+
|
618
|
+
stage = @p.stage
|
619
|
+
|
620
|
+
m1 = metadata(timekey: event_time('2016-04-17 14:00:00 -0700').to_i)
|
621
|
+
assert_equal @worker_dir_chunk_2, stage[m1].unique_id
|
622
|
+
assert_equal 4, stage[m1].size
|
623
|
+
assert_equal :staged, stage[m1].state
|
624
|
+
|
625
|
+
m2 = metadata(timekey: event_time('2016-04-17 14:01:00 -0700').to_i)
|
626
|
+
assert_equal @worker_dir_chunk_3, stage[m2].unique_id
|
627
|
+
assert_equal 3, stage[m2].size
|
628
|
+
assert_equal :staged, stage[m2].state
|
629
|
+
|
630
|
+
queue = @p.queue
|
631
|
+
|
632
|
+
assert_equal [@bufdir_chunk_1, @bufdir_chunk_2, @worker_dir_chunk_1].sort, queue.map(&:unique_id).sort
|
633
|
+
assert_equal [3, 4, 4], queue.map(&:size).sort
|
634
|
+
assert_equal [:queued, :queued, :queued], queue.map(&:state)
|
635
|
+
end
|
636
|
+
|
637
|
+
test 'worker(id=1) #resume returns staged/queued chunks with metadata, only in worker dir' do
|
638
|
+
buf_conf = config_element('buffer', '', {'path' => @bufdir})
|
639
|
+
@d = FluentPluginFileBufferTest::DummyOutputPlugin.new
|
640
|
+
with_worker_config(workers: 2, worker_id: 1) do
|
641
|
+
@d.configure(config_element('output', '', {}, [buf_conf]))
|
642
|
+
end
|
643
|
+
|
644
|
+
@d.start
|
645
|
+
@p = @d.buffer
|
646
|
+
|
647
|
+
assert_equal 2, @p.stage.size
|
648
|
+
assert_equal 1, @p.queue.size
|
649
|
+
|
650
|
+
stage = @p.stage
|
651
|
+
|
652
|
+
m1 = metadata(timekey: event_time('2016-04-17 14:00:00 -0700').to_i)
|
653
|
+
assert_equal @worker_dir_chunk_2, stage[m1].unique_id
|
654
|
+
assert_equal 4, stage[m1].size
|
655
|
+
assert_equal :staged, stage[m1].state
|
656
|
+
|
657
|
+
m2 = metadata(timekey: event_time('2016-04-17 14:01:00 -0700').to_i)
|
658
|
+
assert_equal @worker_dir_chunk_3, stage[m2].unique_id
|
659
|
+
assert_equal 3, stage[m2].size
|
660
|
+
assert_equal :staged, stage[m2].state
|
661
|
+
|
662
|
+
queue = @p.queue
|
663
|
+
|
664
|
+
assert_equal @worker_dir_chunk_1, queue[0].unique_id
|
665
|
+
assert_equal 3, queue[0].size
|
666
|
+
assert_equal :queued, queue[0].state
|
667
|
+
end
|
668
|
+
end
|
669
|
+
|
670
|
+
sub_test_case 'there are some existing file chunks without metadata file' do
|
671
|
+
setup do
|
672
|
+
@bufdir = File.expand_path('../../tmp/buffer_file', __FILE__)
|
673
|
+
|
674
|
+
@c1id = Fluent::UniqueId.generate
|
675
|
+
p1 = File.join(@bufdir, "etest.201604171358.q#{Fluent::UniqueId.hex(@c1id)}.log")
|
676
|
+
File.open(p1, 'wb') do |f|
|
677
|
+
f.write ["t1.test", event_time('2016-04-17 13:58:15 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
678
|
+
f.write ["t2.test", event_time('2016-04-17 13:58:17 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
679
|
+
f.write ["t3.test", event_time('2016-04-17 13:58:21 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
680
|
+
f.write ["t4.test", event_time('2016-04-17 13:58:22 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
681
|
+
end
|
682
|
+
FileUtils.touch(p1, mtime: Time.parse('2016-04-17 13:58:28 -0700'))
|
683
|
+
|
684
|
+
@c2id = Fluent::UniqueId.generate
|
685
|
+
p2 = File.join(@bufdir, "etest.201604171359.q#{Fluent::UniqueId.hex(@c2id)}.log")
|
686
|
+
File.open(p2, 'wb') do |f|
|
687
|
+
f.write ["t1.test", event_time('2016-04-17 13:59:15 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
688
|
+
f.write ["t2.test", event_time('2016-04-17 13:59:17 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
689
|
+
f.write ["t3.test", event_time('2016-04-17 13:59:21 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
690
|
+
end
|
691
|
+
FileUtils.touch(p2, mtime: Time.parse('2016-04-17 13:59:30 -0700'))
|
692
|
+
|
693
|
+
@c3id = Fluent::UniqueId.generate
|
694
|
+
p3 = File.join(@bufdir, "etest.201604171400.b#{Fluent::UniqueId.hex(@c3id)}.log")
|
695
|
+
File.open(p3, 'wb') do |f|
|
696
|
+
f.write ["t1.test", event_time('2016-04-17 14:00:15 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
697
|
+
f.write ["t2.test", event_time('2016-04-17 14:00:17 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
698
|
+
f.write ["t3.test", event_time('2016-04-17 14:00:21 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
699
|
+
f.write ["t4.test", event_time('2016-04-17 14:00:28 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
700
|
+
end
|
701
|
+
FileUtils.touch(p3, mtime: Time.parse('2016-04-17 14:00:29 -0700'))
|
702
|
+
|
703
|
+
@c4id = Fluent::UniqueId.generate
|
704
|
+
p4 = File.join(@bufdir, "etest.201604171401.b#{Fluent::UniqueId.hex(@c4id)}.log")
|
705
|
+
File.open(p4, 'wb') do |f|
|
706
|
+
f.write ["t1.test", event_time('2016-04-17 14:01:15 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
707
|
+
f.write ["t2.test", event_time('2016-04-17 14:01:17 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
708
|
+
f.write ["t3.test", event_time('2016-04-17 14:01:21 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
709
|
+
end
|
710
|
+
FileUtils.touch(p4, mtime: Time.parse('2016-04-17 14:01:22 -0700'))
|
711
|
+
|
712
|
+
@bufpath = File.join(@bufdir, 'etest.*.log')
|
713
|
+
|
714
|
+
Fluent::Test.setup
|
715
|
+
@d = FluentPluginFileBufferTest::DummyOutputPlugin.new
|
716
|
+
@p = Fluent::Plugin::FileBuffer.new
|
717
|
+
@p.owner = @d
|
718
|
+
@p.configure(config_element('buffer', '', {'path' => @bufpath}))
|
719
|
+
@p.start
|
720
|
+
end
|
721
|
+
|
722
|
+
teardown do
|
723
|
+
if @p
|
724
|
+
@p.stop unless @p.stopped?
|
725
|
+
@p.before_shutdown unless @p.before_shutdown?
|
726
|
+
@p.shutdown unless @p.shutdown?
|
727
|
+
@p.after_shutdown unless @p.after_shutdown?
|
728
|
+
@p.close unless @p.closed?
|
729
|
+
@p.terminate unless @p.terminated?
|
730
|
+
end
|
731
|
+
if @bufdir
|
732
|
+
Dir.glob(File.join(@bufdir, '*')).each do |path|
|
733
|
+
next if ['.', '..'].include?(File.basename(path))
|
734
|
+
File.delete(path)
|
735
|
+
end
|
736
|
+
end
|
737
|
+
end
|
738
|
+
|
739
|
+
test '#resume returns queued chunks for files without metadata' do
|
740
|
+
assert_equal 0, @p.stage.size
|
741
|
+
assert_equal 4, @p.queue.size
|
742
|
+
|
743
|
+
queue = @p.queue
|
744
|
+
|
745
|
+
m = metadata()
|
746
|
+
|
747
|
+
assert_equal @c1id, queue[0].unique_id
|
748
|
+
assert_equal m, queue[0].metadata
|
749
|
+
assert_equal 0, queue[0].size
|
750
|
+
assert_equal :queued, queue[0].state
|
751
|
+
assert_equal Time.parse('2016-04-17 13:58:28 -0700'), queue[0].modified_at
|
752
|
+
|
753
|
+
assert_equal @c2id, queue[1].unique_id
|
754
|
+
assert_equal m, queue[1].metadata
|
755
|
+
assert_equal 0, queue[1].size
|
756
|
+
assert_equal :queued, queue[1].state
|
757
|
+
assert_equal Time.parse('2016-04-17 13:59:30 -0700'), queue[1].modified_at
|
758
|
+
|
759
|
+
assert_equal @c3id, queue[2].unique_id
|
760
|
+
assert_equal m, queue[2].metadata
|
761
|
+
assert_equal 0, queue[2].size
|
762
|
+
assert_equal :queued, queue[2].state
|
763
|
+
assert_equal Time.parse('2016-04-17 14:00:29 -0700'), queue[2].modified_at
|
764
|
+
|
765
|
+
assert_equal @c4id, queue[3].unique_id
|
766
|
+
assert_equal m, queue[3].metadata
|
767
|
+
assert_equal 0, queue[3].size
|
768
|
+
assert_equal :queued, queue[3].state
|
769
|
+
assert_equal Time.parse('2016-04-17 14:01:22 -0700'), queue[3].modified_at
|
770
|
+
end
|
771
|
+
end
|
772
|
+
|
773
|
+
sub_test_case 'there are some non-buffer chunk files, with a path without buffer chunk ids' do
|
774
|
+
setup do
|
775
|
+
@bufdir = File.expand_path('../../tmp/buffer_file', __FILE__)
|
776
|
+
|
777
|
+
FileUtils.rm_rf @bufdir
|
778
|
+
FileUtils.mkdir_p @bufdir
|
779
|
+
|
780
|
+
@c1id = Fluent::UniqueId.generate
|
781
|
+
p1 = File.join(@bufdir, "etest.201604171358.q#{Fluent::UniqueId.hex(@c1id)}.log")
|
782
|
+
File.open(p1, 'wb') do |f|
|
783
|
+
f.write ["t1.test", event_time('2016-04-17 13:58:15 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
784
|
+
f.write ["t2.test", event_time('2016-04-17 13:58:17 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
785
|
+
f.write ["t3.test", event_time('2016-04-17 13:58:21 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
786
|
+
f.write ["t4.test", event_time('2016-04-17 13:58:22 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
787
|
+
end
|
788
|
+
FileUtils.touch(p1, mtime: Time.parse('2016-04-17 13:58:28 -0700'))
|
789
|
+
|
790
|
+
@not_chunk = File.join(@bufdir, 'etest.20160416.log')
|
791
|
+
File.open(@not_chunk, 'wb') do |f|
|
792
|
+
f.write ["t1.test", event_time('2016-04-16 23:58:15 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
793
|
+
f.write ["t2.test", event_time('2016-04-16 23:58:17 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
794
|
+
f.write ["t3.test", event_time('2016-04-16 23:58:21 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
795
|
+
f.write ["t4.test", event_time('2016-04-16 23:58:22 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
796
|
+
end
|
797
|
+
FileUtils.touch(@not_chunk, mtime: Time.parse('2016-04-17 00:00:00 -0700'))
|
798
|
+
|
799
|
+
@bufpath = File.join(@bufdir, 'etest.*.log')
|
800
|
+
|
801
|
+
Fluent::Test.setup
|
802
|
+
@d = FluentPluginFileBufferTest::DummyOutputPlugin.new
|
803
|
+
@p = Fluent::Plugin::FileBuffer.new
|
804
|
+
@p.owner = @d
|
805
|
+
@p.configure(config_element('buffer', '', {'path' => @bufpath}))
|
806
|
+
@p.start
|
807
|
+
end
|
808
|
+
|
809
|
+
teardown do
|
810
|
+
if @p
|
811
|
+
@p.stop unless @p.stopped?
|
812
|
+
@p.before_shutdown unless @p.before_shutdown?
|
813
|
+
@p.shutdown unless @p.shutdown?
|
814
|
+
@p.after_shutdown unless @p.after_shutdown?
|
815
|
+
@p.close unless @p.closed?
|
816
|
+
@p.terminate unless @p.terminated?
|
817
|
+
end
|
818
|
+
if @bufdir
|
819
|
+
Dir.glob(File.join(@bufdir, '*')).each do |path|
|
820
|
+
next if ['.', '..'].include?(File.basename(path))
|
821
|
+
File.delete(path)
|
822
|
+
end
|
823
|
+
end
|
824
|
+
end
|
825
|
+
|
826
|
+
test '#resume returns queued chunks for files without metadata, while ignoring non-chunk looking files' do
|
827
|
+
assert_equal 0, @p.stage.size
|
828
|
+
assert_equal 1, @p.queue.size
|
829
|
+
|
830
|
+
queue = @p.queue
|
831
|
+
|
832
|
+
m = metadata()
|
833
|
+
|
834
|
+
assert_equal @c1id, queue[0].unique_id
|
835
|
+
assert_equal m, queue[0].metadata
|
836
|
+
assert_equal 0, queue[0].size
|
837
|
+
assert_equal :queued, queue[0].state
|
838
|
+
assert_equal Time.parse('2016-04-17 13:58:28 -0700'), queue[0].modified_at
|
839
|
+
|
840
|
+
assert File.exist?(@not_chunk)
|
841
|
+
end
|
842
|
+
end
|
843
|
+
end
|