fluentd 0.12.40 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
- data/.github/ISSUE_TEMPLATE.md +17 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +13 -0
- data/.gitignore +5 -0
- data/.gitlab/cicd-template.yaml +10 -0
- data/.gitlab-ci.yml +147 -0
- data/.travis.yml +56 -20
- data/ADOPTERS.md +5 -0
- data/CHANGELOG.md +1369 -0
- data/CONTRIBUTING.md +16 -5
- data/GOVERNANCE.md +55 -0
- data/Gemfile +5 -0
- data/GithubWorkflow.md +78 -0
- data/LICENSE +202 -0
- data/MAINTAINERS.md +7 -0
- data/README.md +23 -11
- data/Rakefile +48 -2
- data/Vagrantfile +17 -0
- data/appveyor.yml +37 -0
- data/bin/fluent-binlog-reader +7 -0
- data/bin/fluent-ca-generate +6 -0
- data/bin/fluent-plugin-config-format +5 -0
- data/bin/fluent-plugin-generate +5 -0
- data/bin/fluentd +3 -0
- data/code-of-conduct.md +3 -0
- data/example/copy_roundrobin.conf +39 -0
- data/example/counter.conf +18 -0
- data/example/in_dummy_blocks.conf +17 -0
- data/example/in_dummy_with_compression.conf +23 -0
- data/example/in_forward.conf +7 -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 +3 -1
- data/example/in_out_forward.conf +17 -0
- data/example/logevents.conf +25 -0
- data/example/multi_filters.conf +61 -0
- data/example/out_exec_filter.conf +42 -0
- data/example/out_forward.conf +13 -13
- 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 +42 -0
- data/example/suppress_config_dump.conf +7 -0
- data/example/worker_section.conf +36 -0
- data/fluent.conf +29 -0
- data/fluentd.gemspec +21 -11
- data/lib/fluent/agent.rb +67 -90
- data/lib/fluent/clock.rb +62 -0
- data/lib/fluent/command/binlog_reader.rb +244 -0
- data/lib/fluent/command/ca_generate.rb +181 -0
- data/lib/fluent/command/cat.rb +42 -18
- data/lib/fluent/command/debug.rb +12 -10
- data/lib/fluent/command/fluentd.rb +153 -5
- data/lib/fluent/command/plugin_config_formatter.rb +292 -0
- data/lib/fluent/command/plugin_generator.rb +324 -0
- data/lib/fluent/compat/call_super_mixin.rb +67 -0
- data/lib/fluent/compat/detach_process_mixin.rb +33 -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 +718 -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/configure_proxy.rb +210 -62
- data/lib/fluent/config/dsl.rb +12 -5
- data/lib/fluent/config/element.rb +107 -9
- data/lib/fluent/config/literal_parser.rb +9 -3
- data/lib/fluent/config/parser.rb +4 -4
- data/lib/fluent/config/section.rb +51 -14
- data/lib/fluent/config/types.rb +28 -13
- data/lib/fluent/config/v1_parser.rb +3 -5
- data/lib/fluent/config.rb +23 -20
- data/lib/fluent/configurable.rb +79 -21
- data/lib/fluent/counter/base_socket.rb +46 -0
- data/lib/fluent/counter/client.rb +297 -0
- data/lib/fluent/counter/error.rb +86 -0
- data/lib/fluent/counter/mutex_hash.rb +163 -0
- data/lib/fluent/counter/server.rb +273 -0
- data/lib/fluent/counter/store.rb +205 -0
- data/lib/fluent/counter/validator.rb +145 -0
- data/lib/fluent/counter.rb +23 -0
- data/lib/fluent/daemon.rb +15 -0
- data/lib/fluent/engine.rb +102 -65
- data/lib/fluent/env.rb +7 -3
- data/lib/fluent/error.rb +30 -0
- data/lib/fluent/event.rb +197 -21
- data/lib/fluent/event_router.rb +93 -10
- data/lib/fluent/filter.rb +2 -50
- data/lib/fluent/formatter.rb +4 -293
- data/lib/fluent/input.rb +2 -32
- data/lib/fluent/label.rb +10 -2
- data/lib/fluent/load.rb +3 -3
- data/lib/fluent/log.rb +348 -81
- data/lib/fluent/match.rb +37 -36
- data/lib/fluent/mixin.rb +12 -176
- data/lib/fluent/msgpack_factory.rb +62 -0
- data/lib/fluent/output.rb +10 -612
- data/lib/fluent/output_chain.rb +23 -0
- data/lib/fluent/parser.rb +4 -800
- data/lib/fluent/plugin/bare_output.rb +63 -0
- data/lib/fluent/plugin/base.rb +192 -0
- data/lib/fluent/plugin/buf_file.rb +128 -174
- data/lib/fluent/plugin/buf_memory.rb +9 -92
- data/lib/fluent/plugin/buffer/chunk.rb +221 -0
- data/lib/fluent/plugin/buffer/file_chunk.rb +383 -0
- data/lib/fluent/plugin/buffer/memory_chunk.rb +90 -0
- data/lib/fluent/plugin/buffer.rb +779 -0
- data/lib/fluent/plugin/compressable.rb +92 -0
- data/lib/fluent/plugin/exec_util.rb +3 -108
- data/lib/fluent/plugin/file_util.rb +4 -34
- data/lib/fluent/plugin/file_wrapper.rb +120 -0
- data/lib/fluent/plugin/filter.rb +93 -0
- data/lib/fluent/plugin/filter_grep.rb +117 -34
- data/lib/fluent/plugin/filter_parser.rb +85 -62
- data/lib/fluent/plugin/filter_record_transformer.rb +27 -39
- data/lib/fluent/plugin/filter_stdout.rb +15 -12
- 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 +76 -0
- data/lib/fluent/plugin/formatter_tsv.rb +38 -0
- data/lib/fluent/plugin/in_debug_agent.rb +17 -6
- data/lib/fluent/plugin/in_dummy.rb +47 -20
- data/lib/fluent/plugin/in_exec.rb +55 -123
- data/lib/fluent/plugin/in_forward.rb +299 -216
- data/lib/fluent/plugin/in_gc_stat.rb +14 -36
- data/lib/fluent/plugin/in_http.rb +204 -91
- data/lib/fluent/plugin/in_monitor_agent.rb +186 -258
- data/lib/fluent/plugin/in_object_space.rb +13 -41
- data/lib/fluent/plugin/in_syslog.rb +112 -134
- data/lib/fluent/plugin/in_tail.rb +408 -745
- data/lib/fluent/plugin/in_tcp.rb +66 -9
- data/lib/fluent/plugin/in_udp.rb +60 -11
- data/lib/fluent/plugin/{in_stream.rb → in_unix.rb} +8 -4
- data/lib/fluent/plugin/input.rb +37 -0
- data/lib/fluent/plugin/multi_output.rb +158 -0
- data/lib/fluent/plugin/out_copy.rb +23 -35
- data/lib/fluent/plugin/out_exec.rb +67 -70
- data/lib/fluent/plugin/out_exec_filter.rb +204 -271
- data/lib/fluent/plugin/out_file.rb +267 -73
- data/lib/fluent/plugin/out_forward.rb +854 -325
- data/lib/fluent/plugin/out_null.rb +42 -9
- data/lib/fluent/plugin/out_relabel.rb +9 -5
- data/lib/fluent/plugin/out_roundrobin.rb +18 -37
- data/lib/fluent/plugin/out_secondary_file.rb +133 -0
- data/lib/fluent/plugin/out_stdout.rb +43 -10
- data/lib/fluent/plugin/out_stream.rb +7 -2
- data/lib/fluent/plugin/output.rb +1498 -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 +88 -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 +94 -0
- data/lib/fluent/plugin/parser_ltsv.rb +49 -0
- data/lib/fluent/plugin/parser_msgpack.rb +50 -0
- data/lib/fluent/plugin/parser_multiline.rb +106 -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 +68 -0
- data/lib/fluent/plugin/parser_syslog.rb +142 -0
- data/lib/fluent/plugin/parser_tsv.rb +42 -0
- data/lib/fluent/plugin/socket_util.rb +3 -143
- data/lib/fluent/plugin/storage.rb +84 -0
- data/lib/fluent/plugin/storage_local.rb +164 -0
- data/lib/fluent/plugin/string_util.rb +3 -15
- data/lib/fluent/plugin.rb +122 -121
- data/lib/fluent/plugin_helper/cert_option.rb +178 -0
- data/lib/fluent/plugin_helper/child_process.rb +364 -0
- data/lib/fluent/plugin_helper/compat_parameters.rb +333 -0
- data/lib/fluent/plugin_helper/counter.rb +51 -0
- data/lib/fluent/plugin_helper/event_emitter.rb +93 -0
- data/lib/fluent/plugin_helper/event_loop.rb +170 -0
- data/lib/fluent/plugin_helper/extract.rb +104 -0
- data/lib/fluent/plugin_helper/formatter.rb +147 -0
- data/lib/fluent/plugin_helper/http_server/app.rb +79 -0
- data/lib/fluent/plugin_helper/http_server/compat/server.rb +81 -0
- data/lib/fluent/plugin_helper/http_server/compat/webrick_handler.rb +58 -0
- data/lib/fluent/plugin_helper/http_server/methods.rb +35 -0
- data/lib/fluent/plugin_helper/http_server/request.rb +42 -0
- data/lib/fluent/plugin_helper/http_server/router.rb +54 -0
- data/lib/fluent/plugin_helper/http_server/server.rb +87 -0
- data/lib/fluent/plugin_helper/http_server.rb +76 -0
- data/lib/fluent/plugin_helper/inject.rb +151 -0
- data/lib/fluent/plugin_helper/parser.rb +147 -0
- data/lib/fluent/plugin_helper/record_accessor.rb +210 -0
- data/lib/fluent/plugin_helper/retry_state.rb +205 -0
- data/lib/fluent/plugin_helper/server.rb +807 -0
- data/lib/fluent/plugin_helper/socket.rb +250 -0
- data/lib/fluent/plugin_helper/socket_option.rb +80 -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 +92 -0
- data/lib/fluent/plugin_helper.rb +73 -0
- data/lib/fluent/plugin_id.rb +80 -0
- data/lib/fluent/process.rb +3 -489
- data/lib/fluent/registry.rb +52 -10
- data/lib/fluent/root_agent.rb +204 -42
- data/lib/fluent/supervisor.rb +597 -359
- data/lib/fluent/system_config.rb +131 -42
- data/lib/fluent/test/base.rb +6 -54
- 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 +0 -1
- data/lib/fluent/test/formatter_test.rb +4 -1
- data/lib/fluent/test/helpers.rb +58 -10
- data/lib/fluent/test/input_test.rb +27 -19
- data/lib/fluent/test/log.rb +79 -0
- data/lib/fluent/test/output_test.rb +28 -39
- data/lib/fluent/test/parser_test.rb +3 -1
- data/lib/fluent/test/startup_shutdown.rb +46 -0
- data/lib/fluent/test.rb +33 -1
- data/lib/fluent/time.rb +450 -1
- data/lib/fluent/timezone.rb +27 -3
- data/lib/fluent/{status.rb → unique_id.rb} +15 -24
- data/lib/fluent/version.rb +1 -1
- data/lib/fluent/winsvc.rb +85 -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_ca_generate.rb +70 -0
- data/test/command/test_fluentd.rb +901 -0
- data/test/command/test_plugin_config_formatter.rb +276 -0
- data/test/command/test_plugin_generator.rb +92 -0
- data/test/compat/test_calls_super.rb +166 -0
- data/test/compat/test_parser.rb +92 -0
- data/test/config/test_config_parser.rb +126 -2
- data/test/config/test_configurable.rb +946 -187
- data/test/config/test_configure_proxy.rb +424 -74
- data/test/config/test_dsl.rb +11 -11
- data/test/config/test_element.rb +500 -0
- data/test/config/test_literal_parser.rb +8 -0
- data/test/config/test_plugin_configuration.rb +56 -0
- data/test/config/test_section.rb +79 -7
- data/test/config/test_system_config.rb +122 -35
- data/test/config/test_types.rb +38 -0
- data/test/counter/test_client.rb +559 -0
- data/test/counter/test_error.rb +44 -0
- data/test/counter/test_mutex_hash.rb +179 -0
- data/test/counter/test_server.rb +589 -0
- data/test/counter/test_store.rb +258 -0
- data/test/counter/test_validator.rb +137 -0
- data/test/helper.rb +89 -6
- data/test/helpers/fuzzy_assert.rb +89 -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 +823 -460
- data/test/plugin/test_buf_memory.rb +32 -194
- data/test/plugin/test_buffer.rb +1233 -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_filter.rb +357 -0
- data/test/plugin/test_filter_grep.rb +540 -29
- data/test/plugin/test_filter_parser.rb +439 -452
- data/test/plugin/test_filter_record_transformer.rb +123 -166
- data/test/plugin/test_filter_stdout.rb +160 -72
- 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 +62 -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_formatter_tsv.rb +68 -0
- data/test/plugin/test_in_debug_agent.rb +24 -1
- data/test/plugin/test_in_dummy.rb +111 -18
- data/test/plugin/test_in_exec.rb +200 -113
- data/test/plugin/test_in_forward.rb +990 -387
- data/test/plugin/test_in_gc_stat.rb +10 -8
- data/test/plugin/test_in_http.rb +600 -224
- data/test/plugin/test_in_monitor_agent.rb +690 -0
- data/test/plugin/test_in_object_space.rb +24 -8
- data/test/plugin/test_in_syslog.rb +154 -215
- data/test/plugin/test_in_tail.rb +1006 -707
- data/test/plugin/test_in_tcp.rb +125 -48
- data/test/plugin/test_in_udp.rb +204 -63
- data/test/plugin/{test_in_stream.rb → test_in_unix.rb} +14 -13
- data/test/plugin/test_input.rb +126 -0
- data/test/plugin/test_metadata.rb +89 -0
- data/test/plugin/test_multi_output.rb +180 -0
- data/test/plugin/test_out_copy.rb +117 -112
- data/test/plugin/test_out_exec.rb +258 -53
- data/test/plugin/test_out_exec_filter.rb +538 -115
- data/test/plugin/test_out_file.rb +865 -178
- data/test/plugin/test_out_forward.rb +998 -210
- 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 +36 -29
- data/test/plugin/test_out_secondary_file.rb +458 -0
- data/test/plugin/test_out_stdout.rb +135 -37
- data/test/plugin/test_out_stream.rb +18 -0
- data/test/plugin/test_output.rb +984 -0
- data/test/plugin/test_output_as_buffered.rb +2021 -0
- data/test/plugin/test_output_as_buffered_backup.rb +312 -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 +911 -0
- data/test/plugin/test_output_as_buffered_secondary.rb +874 -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 +47 -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 +138 -0
- data/test/plugin/test_parser_labeled_tsv.rb +145 -0
- data/test/plugin/test_parser_multiline.rb +100 -0
- data/test/plugin/test_parser_nginx.rb +88 -0
- data/test/plugin/test_parser_none.rb +52 -0
- data/test/plugin/test_parser_regexp.rb +289 -0
- data/test/plugin/test_parser_syslog.rb +441 -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_helper/data/cert/cert-key.pem +27 -0
- data/test/plugin_helper/data/cert/cert-with-no-newline.pem +19 -0
- data/test/plugin_helper/data/cert/cert.pem +19 -0
- data/test/plugin_helper/http_server/test_app.rb +65 -0
- data/test/plugin_helper/http_server/test_route.rb +32 -0
- data/test/plugin_helper/test_cert_option.rb +16 -0
- data/test/plugin_helper/test_child_process.rb +794 -0
- data/test/plugin_helper/test_compat_parameters.rb +353 -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_http_server_helper.rb +205 -0
- data/test/plugin_helper/test_inject.rb +519 -0
- data/test/plugin_helper/test_parser.rb +264 -0
- data/test/plugin_helper/test_record_accessor.rb +197 -0
- data/test/plugin_helper/test_retry_state.rb +442 -0
- data/test/plugin_helper/test_server.rb +1714 -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 +0 -6
- 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/out_test.rb +23 -15
- data/test/scripts/fluent/plugin/out_test2.rb +80 -0
- data/test/test_clock.rb +164 -0
- data/test/test_config.rb +16 -7
- data/test/test_configdsl.rb +2 -2
- data/test/test_event.rb +360 -13
- data/test/test_event_router.rb +108 -11
- data/test/test_event_time.rb +199 -0
- data/test/test_filter.rb +48 -6
- data/test/test_formatter.rb +11 -391
- data/test/test_input.rb +1 -1
- data/test/test_log.rb +591 -31
- data/test/test_mixin.rb +1 -1
- data/test/test_output.rb +121 -185
- data/test/test_plugin.rb +251 -0
- data/test/test_plugin_classes.rb +177 -10
- data/test/test_plugin_helper.rb +81 -0
- data/test/test_plugin_id.rb +101 -0
- data/test/test_process.rb +8 -42
- data/test/test_root_agent.rb +766 -21
- data/test/test_supervisor.rb +481 -0
- data/test/test_test_drivers.rb +135 -0
- data/test/test_time_formatter.rb +282 -0
- data/test/test_time_parser.rb +231 -0
- data/test/test_unique_id.rb +47 -0
- metadata +454 -60
- data/COPYING +0 -14
- data/ChangeLog +0 -666
- data/lib/fluent/buffer.rb +0 -365
- data/lib/fluent/plugin/in_status.rb +0 -76
- data/test/plugin/test_in_status.rb +0 -38
- data/test/test_buffer.rb +0 -624
- data/test/test_parser.rb +0 -1305
|
@@ -1,604 +1,967 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
1
|
require_relative '../helper'
|
|
3
|
-
require 'fluent/test'
|
|
4
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'
|
|
5
7
|
|
|
6
|
-
require 'fileutils'
|
|
7
|
-
|
|
8
|
-
require 'stringio'
|
|
9
8
|
require 'msgpack'
|
|
10
9
|
|
|
11
|
-
module
|
|
12
|
-
class
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if Dir.exists? BUF_FILE_TMPDIR
|
|
17
|
-
FileUtils.remove_entry_secure BUF_FILE_TMPDIR
|
|
18
|
-
end
|
|
19
|
-
FileUtils.mkdir_p BUF_FILE_TMPDIR
|
|
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'
|
|
20
15
|
end
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
File.join(BUF_FILE_TMPDIR, unique + '.log' + (link ? '.link' : ''))
|
|
16
|
+
def multi_workers_ready?
|
|
17
|
+
true
|
|
24
18
|
end
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Fluent::FileBufferChunk.new(key, bufpath(unique), unique, opts[:mode] || "a+", opts[:symlink])
|
|
19
|
+
def write(chunk)
|
|
20
|
+
# drop
|
|
28
21
|
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
29
24
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
assert_equal bufpath('init1'), chunk.path
|
|
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
|
|
35
29
|
|
|
36
|
-
|
|
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
|
|
37
42
|
|
|
38
|
-
|
|
43
|
+
sub_test_case 'non configured buffer plugin instance' do
|
|
44
|
+
setup do
|
|
45
|
+
Fluent::Test.setup
|
|
39
46
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
@dir = File.expand_path('../../tmp/buffer_file_dir', __FILE__)
|
|
48
|
+
FileUtils.rm_rf @dir
|
|
49
|
+
FileUtils.mkdir_p @dir
|
|
50
|
+
end
|
|
44
51
|
|
|
45
|
-
|
|
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
|
|
46
59
|
|
|
47
|
-
|
|
48
|
-
|
|
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
|
|
49
66
|
end
|
|
50
67
|
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
53
76
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
assert chunk.respond_to?(:read)
|
|
60
|
-
assert chunk.respond_to?(:open)
|
|
61
|
-
assert chunk.respond_to?(:write_to)
|
|
62
|
-
assert chunk.respond_to?(:msgpack_each)
|
|
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
|
|
63
82
|
|
|
64
|
-
|
|
83
|
+
@d = FluentPluginFileBufferTest::DummyOutputPlugin.new
|
|
84
|
+
@p = Fluent::Plugin::FileBuffer.new
|
|
85
|
+
@p.owner = @d
|
|
65
86
|
end
|
|
66
87
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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)
|
|
71
94
|
|
|
72
|
-
|
|
73
|
-
|
|
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
|
|
74
100
|
end
|
|
75
|
-
chunk = filebufferchunk('e2', 'empty2')
|
|
76
|
-
assert !(chunk.empty?)
|
|
77
|
-
chunk.close
|
|
78
101
|
end
|
|
79
102
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
assert_equal 38, chunk.size
|
|
89
|
-
chunk.close
|
|
90
|
-
|
|
91
|
-
assert File.exists?(bufpath('append1'))
|
|
92
|
-
|
|
93
|
-
chunk = filebufferchunk('a1', 'append1', mode: 'r')
|
|
94
|
-
test_data = test_data1.force_encoding('ASCII-8BIT') + test_data2.force_encoding('ASCII-8BIT')
|
|
95
|
-
|
|
96
|
-
#### TODO: This assertion currently fails. Oops.
|
|
97
|
-
# FileBuffer#read does NOT do force_encoding('ASCII-8BIT'). So encoding of output string instance are 'UTF-8'.
|
|
98
|
-
# I think it is a kind of bug, but fixing it may break some behavior of buf_file. So I cannot be sure to fix it just now.
|
|
99
|
-
#
|
|
100
|
-
# assert_equal test_data, chunk.read
|
|
101
|
-
|
|
102
|
-
chunk.purge
|
|
103
|
-
|
|
104
|
-
assert !(File.exists?(bufpath('append1')))
|
|
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
|
|
105
111
|
end
|
|
106
112
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
assert_equal 38, chunk.size
|
|
116
|
-
chunk.close
|
|
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
|
|
117
121
|
end
|
|
118
122
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
assert_equal (d1.size + d2.size), chunk.size
|
|
128
|
-
|
|
129
|
-
read_data = chunk.read
|
|
130
|
-
assert_equal (d1 + d2), read_data
|
|
131
|
-
|
|
132
|
-
chunk.purge
|
|
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
|
|
133
131
|
end
|
|
134
132
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
|
144
142
|
|
|
145
|
-
|
|
146
|
-
|
|
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
|
|
147
171
|
end
|
|
148
|
-
|
|
172
|
+
end
|
|
149
173
|
|
|
150
|
-
|
|
174
|
+
test 'this is persistent plugin' do
|
|
175
|
+
assert @p.persistent?
|
|
151
176
|
end
|
|
152
177
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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)
|
|
156
184
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
d2 = "12345" * 200 + "\n"
|
|
160
|
-
chunk << d2
|
|
161
|
-
assert_equal (d1.size + d2.size), chunk.size
|
|
185
|
+
FileUtils.rm_r bufdir if File.exist?(bufdir)
|
|
186
|
+
assert !File.exist?(bufdir)
|
|
162
187
|
|
|
163
|
-
|
|
188
|
+
plugin.configure(config_element('buffer', '', {'path' => bufpath}))
|
|
189
|
+
assert !File.exist?(bufdir)
|
|
164
190
|
|
|
165
|
-
|
|
166
|
-
|
|
191
|
+
plugin.start
|
|
192
|
+
assert File.exist?(bufdir)
|
|
193
|
+
assert{ File.stat(bufdir).mode.to_s(8).end_with?('755') }
|
|
167
194
|
|
|
168
|
-
|
|
195
|
+
plugin.stop; plugin.before_shutdown; plugin.shutdown; plugin.after_shutdown; plugin.close; plugin.terminate
|
|
196
|
+
FileUtils.rm_r bufdir
|
|
169
197
|
end
|
|
170
198
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
assert chunk.empty?
|
|
199
|
+
test '#start creates directory for buffer chunks with specified permission' do
|
|
200
|
+
omit "NTFS doesn't support UNIX like permissions" if Fluent.windows?
|
|
174
201
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
chunk << d0
|
|
181
|
-
chunk << d1
|
|
182
|
-
chunk << d2
|
|
183
|
-
chunk << d3
|
|
184
|
-
chunk << d4
|
|
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)
|
|
185
207
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
store << data
|
|
189
|
-
end
|
|
208
|
+
FileUtils.rm_r bufdir if File.exist?(bufdir)
|
|
209
|
+
assert !File.exist?(bufdir)
|
|
190
210
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
assert_equal({"key1" => "value1", "key2" => "value2"}, store[1])
|
|
194
|
-
assert_equal "string1", store[2]
|
|
195
|
-
assert_equal 1, store[3]
|
|
196
|
-
assert_equal nil, store[4]
|
|
211
|
+
plugin.configure(config_element('buffer', '', {'path' => bufpath, 'dir_permission' => '0700'}))
|
|
212
|
+
assert !File.exist?(bufdir)
|
|
197
213
|
|
|
198
|
-
|
|
199
|
-
|
|
214
|
+
plugin.start
|
|
215
|
+
assert File.exist?(bufdir)
|
|
216
|
+
assert{ File.stat(bufdir).mode.to_s(8).end_with?('700') }
|
|
200
217
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
218
|
+
plugin.stop; plugin.before_shutdown; plugin.shutdown; plugin.after_shutdown; plugin.close; plugin.terminate
|
|
219
|
+
FileUtils.rm_r bufdir
|
|
220
|
+
end
|
|
204
221
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
d2 = "12345" * 200 + "\n"
|
|
208
|
-
chunk << d2
|
|
209
|
-
assert_equal (d1.size + d2.size), chunk.size
|
|
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?
|
|
210
224
|
|
|
211
|
-
|
|
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)
|
|
212
232
|
|
|
213
|
-
|
|
214
|
-
|
|
233
|
+
FileUtils.rm_r bufdir if File.exist?(bufdir)
|
|
234
|
+
assert !File.exist?(bufdir)
|
|
215
235
|
|
|
216
|
-
|
|
236
|
+
plugin.configure(config_element('buffer', '', {'path' => bufpath}))
|
|
237
|
+
assert !File.exist?(bufdir)
|
|
217
238
|
|
|
218
|
-
|
|
219
|
-
|
|
239
|
+
plugin.start
|
|
240
|
+
assert File.exist?(bufdir)
|
|
241
|
+
assert{ File.stat(bufdir).mode.to_s(8).end_with?('700') }
|
|
220
242
|
|
|
221
|
-
|
|
243
|
+
plugin.stop; plugin.before_shutdown; plugin.shutdown; plugin.after_shutdown; plugin.close; plugin.terminate
|
|
244
|
+
FileUtils.rm_r bufdir
|
|
245
|
+
end
|
|
246
|
+
end
|
|
222
247
|
|
|
223
|
-
|
|
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
|
|
224
303
|
end
|
|
225
304
|
end
|
|
226
305
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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', ''))
|
|
233
318
|
end
|
|
234
|
-
FileUtils.mkdir_p BUF_FILE_TMPDIR
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
def bufpath(basename)
|
|
238
|
-
File.join(BUF_FILE_TMPDIR, basename)
|
|
239
319
|
end
|
|
240
320
|
|
|
241
|
-
|
|
242
|
-
|
|
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
|
|
243
330
|
end
|
|
244
331
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
buf.configure({'buffer_path' => bufpath('configure1.*.log')})
|
|
251
|
-
assert_equal bufpath('configure1.*.log'), buf.buffer_path
|
|
252
|
-
assert_equal nil, buf.symlink_path
|
|
253
|
-
assert_equal false, buf.instance_eval{ @flush_at_shutdown }
|
|
254
|
-
|
|
255
|
-
buf2 = Fluent::FileBuffer.new
|
|
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)
|
|
256
337
|
|
|
257
|
-
|
|
258
|
-
assert_raise(Fluent::ConfigError){ buf2.configure({'buffer_path' => bufpath('configure1.*.log')}) }
|
|
338
|
+
@p.start
|
|
259
339
|
|
|
260
|
-
|
|
261
|
-
assert_equal bufpath('configure2.*.log'), buf2.buffer_path
|
|
262
|
-
assert_equal true, buf2.instance_eval{ @flush_at_shutdown }
|
|
340
|
+
assert Dir.exist?(expected_buffer_dir)
|
|
263
341
|
end
|
|
342
|
+
end
|
|
264
343
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
|
280
372
|
end
|
|
281
373
|
|
|
282
|
-
|
|
283
|
-
|
|
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
|
|
284
380
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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
|
|
289
460
|
end
|
|
290
461
|
end
|
|
291
462
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
assert_equal safe_chars, buf.send(:encode_key, safe_chars)
|
|
296
|
-
unsafe_chars = '-_.abcdefgxyzABCDEFGXYZ0123456789 ~/*()'
|
|
297
|
-
assert_equal safe_chars + '%20%7E%2F%2A%28%29', buf.send(:encode_key, unsafe_chars)
|
|
298
|
-
end
|
|
463
|
+
test '#resume returns staged/queued chunks with metadata' do
|
|
464
|
+
assert_equal 2, @p.stage.size
|
|
465
|
+
assert_equal 2, @p.queue.size
|
|
299
466
|
|
|
300
|
-
|
|
301
|
-
buf = Fluent::FileBuffer.new
|
|
302
|
-
safe_chars = '-_.abcdefgxyzABCDEFGXYZ0123456789'
|
|
303
|
-
assert_equal safe_chars, buf.send(:decode_key, safe_chars)
|
|
304
|
-
unsafe_chars = '-_.abcdefgxyzABCDEFGXYZ0123456789 ~/*()'
|
|
305
|
-
assert_equal unsafe_chars, buf.send(:decode_key, safe_chars + '%20%7E%2F%2A%28%29')
|
|
467
|
+
stage = @p.stage
|
|
306
468
|
|
|
307
|
-
|
|
308
|
-
assert_equal
|
|
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
|
|
309
478
|
end
|
|
310
479
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
prefix = buf.instance_eval{ @buffer_path_prefix }
|
|
315
|
-
suffix = buf.instance_eval{ @buffer_path_suffix }
|
|
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
|
|
316
483
|
|
|
317
|
-
|
|
318
|
-
assert path =~ /\A#{prefix}[-_.a-zA-Z0-9\%]+\.[bq][0-9a-f]+#{suffix}\Z/, "invalid format:#{path}"
|
|
319
|
-
assert tsuffix =~ /\A[0-9a-f]+\Z/, "invalid hexadecimal:#{tsuffix}"
|
|
484
|
+
queue = @p.queue
|
|
320
485
|
|
|
321
|
-
|
|
322
|
-
assert path =~ /\A#{prefix}[-_.a-zA-Z0-9\%]+\.[bq][0-9a-f]+#{suffix}\Z/, "invalid format:#{path}"
|
|
323
|
-
assert tsuffix =~ /\A[0-9a-f]+\Z/, "invalid hexadecimal:#{tsuffix}"
|
|
324
|
-
end
|
|
486
|
+
assert{ queue[0].modified_at < queue[1].modified_at }
|
|
325
487
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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
|
|
332
496
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
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
|
|
340
505
|
end
|
|
506
|
+
end
|
|
341
507
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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
|
|
347
557
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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
|
|
353
590
|
end
|
|
354
591
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
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
|
|
360
602
|
|
|
361
|
-
|
|
362
|
-
|
|
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'
|
|
363
605
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
|
368
611
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
end
|
|
612
|
+
@d.start
|
|
613
|
+
@p = @d.buffer
|
|
372
614
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
buf.configure({'buffer_path' => bufpath('enqueue1')})
|
|
376
|
-
prefix = buf.instance_eval{ @buffer_path_prefix }
|
|
377
|
-
suffix = buf.instance_eval{ @buffer_path_suffix }
|
|
615
|
+
assert_equal 2, @p.stage.size
|
|
616
|
+
assert_equal 3, @p.queue.size
|
|
378
617
|
|
|
379
|
-
|
|
380
|
-
chunk << "data1\ndata2\n"
|
|
618
|
+
stage = @p.stage
|
|
381
619
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
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
|
|
386
624
|
|
|
387
|
-
|
|
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
|
|
388
629
|
|
|
389
|
-
|
|
390
|
-
assert File.exists?(chunk.path)
|
|
391
|
-
assert !(File.exists?(old_path))
|
|
392
|
-
assert chunk.path =~ /\A#{prefix}[-_.a-zA-Z0-9\%]+\.q[0-9a-f]+#{suffix}\Z/, "enqueued chunk's path must be a 'q' buffer chunk"
|
|
630
|
+
queue = @p.queue
|
|
393
631
|
|
|
394
|
-
|
|
395
|
-
|
|
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)
|
|
396
635
|
end
|
|
397
636
|
|
|
398
|
-
#
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
prefix = buf.instance_eval{ @buffer_path_prefix }
|
|
405
|
-
suffix = buf.instance_eval{ @buffer_path_suffix }
|
|
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
|
|
406
643
|
|
|
407
|
-
|
|
408
|
-
|
|
644
|
+
@d.start
|
|
645
|
+
@p = @d.buffer
|
|
409
646
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
assert File.exists?(chunk.path)
|
|
413
|
-
# chunk key is empty
|
|
414
|
-
assert chunk.path =~ /\A#{prefix}\.b[0-9a-f]+#{suffix}\Z/, "path from new_chunk must be a 'b' buffer chunk"
|
|
647
|
+
assert_equal 2, @p.stage.size
|
|
648
|
+
assert_equal 1, @p.queue.size
|
|
415
649
|
|
|
416
|
-
|
|
650
|
+
stage = @p.stage
|
|
417
651
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
assert chunk.path =~ /\A#{prefix}\.q[0-9a-f]+#{suffix}\Z/, "enqueued chunk's path must be a 'q' buffer chunk"
|
|
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
|
|
423
656
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
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
|
|
427
661
|
|
|
428
|
-
|
|
429
|
-
buf = Fluent::FileBuffer.new
|
|
430
|
-
buf.configure({'buffer_path' => bufpath('before_shutdown1')})
|
|
431
|
-
buf.start
|
|
662
|
+
queue = @p.queue
|
|
432
663
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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
|
|
437
669
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
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"
|
|
443
681
|
end
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
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)
|
|
458
735
|
end
|
|
459
736
|
end
|
|
460
|
-
assert_equal 0, buf.instance_eval{ @enqueue_hook_times }
|
|
461
|
-
|
|
462
|
-
out = DummyOutput.new
|
|
463
|
-
assert_equal nil, out.written
|
|
464
|
-
|
|
465
|
-
buf.before_shutdown(out)
|
|
466
|
-
|
|
467
|
-
assert_equal 0, buf.instance_eval{ @enqueue_hook_times } # k0, k1, k2
|
|
468
|
-
assert_nil out.written
|
|
469
737
|
end
|
|
470
738
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
buf.start
|
|
475
|
-
|
|
476
|
-
# before_shutdown flushes all chunks in @map and @queue
|
|
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
|
|
477
742
|
|
|
478
|
-
|
|
479
|
-
c2 = [ buf.new_chunk('q0'), buf.new_chunk('q1') ]
|
|
743
|
+
queue = @p.queue
|
|
480
744
|
|
|
481
|
-
|
|
482
|
-
@map = {
|
|
483
|
-
'k0' => c1[0], 'k1' => c1[1], 'k2' => c1[2], 'k3' => c1[3],
|
|
484
|
-
'q0' => c2[0], 'q1' => c2[1]
|
|
485
|
-
}
|
|
486
|
-
end
|
|
487
|
-
c1[0] << "data1\ndata2\n"
|
|
488
|
-
c1[1] << "data1\ndata2\n"
|
|
489
|
-
c1[2] << "data1\ndata2\n"
|
|
490
|
-
# k3 chunk is empty!
|
|
491
|
-
|
|
492
|
-
c2[0] << "data1\ndata2\n"
|
|
493
|
-
c2[1] << "data1\ndata2\n"
|
|
494
|
-
buf.push('q0')
|
|
495
|
-
buf.push('q1')
|
|
745
|
+
m = metadata()
|
|
496
746
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
end
|
|
503
|
-
assert_equal 0, buf.instance_eval{ @enqueue_hook_times }
|
|
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
|
|
504
752
|
|
|
505
|
-
|
|
506
|
-
assert_equal
|
|
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
|
|
507
758
|
|
|
508
|
-
|
|
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
|
|
509
764
|
|
|
510
|
-
assert_equal
|
|
511
|
-
assert_equal
|
|
512
|
-
assert_equal
|
|
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
|
|
513
770
|
end
|
|
771
|
+
end
|
|
514
772
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
buf1 = Fluent::FileBuffer.new
|
|
519
|
-
buf1.configure({'buffer_path' => buffer_path_for_resume_test})
|
|
520
|
-
prefix = buf1.instance_eval{ @buffer_path_prefix }
|
|
521
|
-
suffix = buf1.instance_eval{ @buffer_path_suffix }
|
|
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__)
|
|
522
776
|
|
|
523
|
-
|
|
777
|
+
FileUtils.rm_rf @bufdir
|
|
778
|
+
FileUtils.mkdir_p @bufdir
|
|
524
779
|
|
|
525
|
-
|
|
526
|
-
|
|
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
|
|
527
825
|
|
|
528
|
-
|
|
529
|
-
|
|
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
|
|
530
829
|
|
|
531
|
-
|
|
532
|
-
assert chunk1.path =~ /\A#{prefix}[-_.a-zA-Z0-9\%]+\.b[0-9a-f]+#{suffix}\Z/, "path from new_chunk must be a 'b' buffer chunk"
|
|
830
|
+
queue = @p.queue
|
|
533
831
|
|
|
534
|
-
|
|
832
|
+
m = metadata()
|
|
535
833
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
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
|
|
540
839
|
|
|
541
|
-
|
|
840
|
+
assert File.exist?(@not_chunk)
|
|
841
|
+
end
|
|
842
|
+
end
|
|
542
843
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
844
|
+
sub_test_case 'there are existing broken file chunks' do
|
|
845
|
+
setup do
|
|
846
|
+
@bufdir = File.expand_path('../../tmp/broken_buffer_file', __FILE__)
|
|
847
|
+
FileUtils.mkdir_p @bufdir unless File.exist?(@bufdir)
|
|
848
|
+
@bufpath = File.join(@bufdir, 'broken_test.*.log')
|
|
849
|
+
|
|
850
|
+
Fluent::Test.setup
|
|
851
|
+
@d = FluentPluginFileBufferTest::DummyOutputPlugin.new
|
|
852
|
+
@p = Fluent::Plugin::FileBuffer.new
|
|
853
|
+
@p.owner = @d
|
|
854
|
+
@p.configure(config_element('buffer', '', {'path' => @bufpath}))
|
|
855
|
+
end
|
|
856
|
+
|
|
857
|
+
teardown do
|
|
858
|
+
if @p
|
|
859
|
+
@p.stop unless @p.stopped?
|
|
860
|
+
@p.before_shutdown unless @p.before_shutdown?
|
|
861
|
+
@p.shutdown unless @p.shutdown?
|
|
862
|
+
@p.after_shutdown unless @p.after_shutdown?
|
|
863
|
+
@p.close unless @p.closed?
|
|
864
|
+
@p.terminate unless @p.terminated?
|
|
865
|
+
end
|
|
866
|
+
if @bufdir
|
|
867
|
+
Dir.glob(File.join(@bufdir, '*')).each do |path|
|
|
868
|
+
next if ['.', '..'].include?(File.basename(path))
|
|
869
|
+
File.delete(path)
|
|
870
|
+
end
|
|
871
|
+
end
|
|
872
|
+
end
|
|
548
873
|
|
|
549
|
-
|
|
550
|
-
|
|
874
|
+
def create_first_chunk(mode)
|
|
875
|
+
cid = Fluent::UniqueId.generate
|
|
876
|
+
path = File.join(@bufdir, "broken_test.#{mode}#{Fluent::UniqueId.hex(cid)}.log")
|
|
877
|
+
File.open(path, 'wb') do |f|
|
|
878
|
+
f.write ["t1.test", event_time('2016-04-17 14:00:15 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
|
879
|
+
f.write ["t2.test", event_time('2016-04-17 14:00:17 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
|
880
|
+
f.write ["t3.test", event_time('2016-04-17 14:00:21 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
|
881
|
+
f.write ["t4.test", event_time('2016-04-17 14:00:28 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
|
882
|
+
end
|
|
883
|
+
write_metadata(
|
|
884
|
+
path + '.meta', cid, metadata(timekey: event_time('2016-04-17 14:00:00 -0700').to_i),
|
|
885
|
+
4, event_time('2016-04-17 14:00:00 -0700').to_i, event_time('2016-04-17 14:00:28 -0700').to_i
|
|
886
|
+
)
|
|
551
887
|
|
|
552
|
-
|
|
553
|
-
|
|
888
|
+
return cid, path
|
|
889
|
+
end
|
|
554
890
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
891
|
+
def create_second_chunk(mode)
|
|
892
|
+
cid = Fluent::UniqueId.generate
|
|
893
|
+
path = File.join(@bufdir, "broken_test.#{mode}#{Fluent::UniqueId.hex(cid)}.log")
|
|
894
|
+
File.open(path, 'wb') do |f|
|
|
895
|
+
f.write ["t1.test", event_time('2016-04-17 14:01:15 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
|
896
|
+
f.write ["t2.test", event_time('2016-04-17 14:01:17 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
|
897
|
+
f.write ["t3.test", event_time('2016-04-17 14:01:21 -0700').to_i, {"message" => "yay"}].to_json + "\n"
|
|
898
|
+
end
|
|
899
|
+
write_metadata(
|
|
900
|
+
path + '.meta', cid, metadata(timekey: event_time('2016-04-17 14:01:00 -0700').to_i),
|
|
901
|
+
3, event_time('2016-04-17 14:01:00 -0700').to_i, event_time('2016-04-17 14:01:25 -0700').to_i
|
|
902
|
+
)
|
|
559
903
|
|
|
560
|
-
|
|
561
|
-
assert_equal "data3\ndata4\n", resumed_chunk2.read
|
|
904
|
+
return cid, path
|
|
562
905
|
end
|
|
563
906
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
907
|
+
def compare_staged_chunk(staged, id, time, num, mode)
|
|
908
|
+
assert_equal 1, staged.size
|
|
909
|
+
m = metadata(timekey: event_time(time).to_i)
|
|
910
|
+
assert_equal id, staged[m].unique_id
|
|
911
|
+
assert_equal num, staged[m].size
|
|
912
|
+
assert_equal mode, staged[m].state
|
|
568
913
|
end
|
|
569
914
|
|
|
570
|
-
def
|
|
571
|
-
|
|
915
|
+
def compare_queued_chunk(queued, id, num, mode)
|
|
916
|
+
assert_equal 1, queued.size
|
|
917
|
+
assert_equal id, queued[0].unique_id
|
|
918
|
+
assert_equal num, queued[0].size
|
|
919
|
+
assert_equal mode, queued[0].state
|
|
920
|
+
end
|
|
572
921
|
|
|
573
|
-
|
|
574
|
-
|
|
922
|
+
def compare_log(plugin, msg)
|
|
923
|
+
logs = plugin.log.out.logs
|
|
924
|
+
assert { logs.any? { |log| log.include?(msg) } }
|
|
925
|
+
end
|
|
575
926
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
927
|
+
test '#resume ignores staged empty chunk' do
|
|
928
|
+
_, p1 = create_first_chunk('b')
|
|
929
|
+
File.open(p1, 'wb') { |f| } # create staged empty chunk file
|
|
930
|
+
c2id, _ = create_second_chunk('b')
|
|
579
931
|
|
|
580
|
-
|
|
581
|
-
|
|
932
|
+
@p.start
|
|
933
|
+
compare_staged_chunk(@p.stage, c2id, '2016-04-17 14:01:00 -0700', 3, :staged)
|
|
934
|
+
compare_log(@p, 'staged file chunk is empty')
|
|
935
|
+
end
|
|
582
936
|
|
|
583
|
-
|
|
937
|
+
test '#resume ignores staged broken metadata' do
|
|
938
|
+
c1id, _ = create_first_chunk('b')
|
|
939
|
+
_, p2 = create_second_chunk('b')
|
|
940
|
+
File.open(p2 + '.meta', 'wb') { |f| f.write("\0" * 70) } # create staged broken meta file
|
|
584
941
|
|
|
585
|
-
|
|
942
|
+
@p.start
|
|
943
|
+
compare_staged_chunk(@p.stage, c1id, '2016-04-17 14:00:00 -0700', 4, :staged)
|
|
944
|
+
compare_log(@p, 'staged meta file is broken')
|
|
945
|
+
end
|
|
586
946
|
|
|
587
|
-
|
|
588
|
-
|
|
947
|
+
test '#resume ignores enqueued empty chunk' do
|
|
948
|
+
_, p1 = create_first_chunk('q')
|
|
949
|
+
File.open(p1, 'wb') { |f| } # create enqueued empty chunk file
|
|
950
|
+
c2id, _ = create_second_chunk('q')
|
|
589
951
|
|
|
590
|
-
|
|
952
|
+
@p.start
|
|
953
|
+
compare_queued_chunk(@p.queue, c2id, 3, :queued)
|
|
954
|
+
compare_log(@p, 'enqueued file chunk is empty')
|
|
955
|
+
end
|
|
591
956
|
|
|
592
|
-
|
|
957
|
+
test '#resume ignores enqueued broken metadata' do
|
|
958
|
+
c1id, _ = create_first_chunk('q')
|
|
959
|
+
_, p2 = create_second_chunk('q')
|
|
960
|
+
File.open(p2 + '.meta', 'wb') { |f| f.write("\0" * 70) } # create enqueued broken meta file
|
|
593
961
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
# because current version of buffer plugin uses '.'(dot) as a one of chars for chunk encoding.
|
|
598
|
-
# I think that this is a mistake of design, but we cannot fix it because updated plugin become
|
|
599
|
-
# not to be able to resume existing file buffer chunk.
|
|
600
|
-
# We will fix it in next API version of buffer plugin.
|
|
601
|
-
assert_equal 1, map.size
|
|
962
|
+
@p.start
|
|
963
|
+
compare_queued_chunk(@p.queue, c1id, 4, :queued)
|
|
964
|
+
compare_log(@p, 'enqueued meta file is broken')
|
|
602
965
|
end
|
|
603
966
|
end
|
|
604
967
|
end
|