fluentd 0.12.40 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fluentd might be problematic. Click here for more details.
- checksums.yaml +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
data/test/plugin/test_in_http.rb
CHANGED
@@ -1,13 +1,30 @@
|
|
1
1
|
require_relative '../helper'
|
2
|
-
require 'fluent/test'
|
2
|
+
require 'fluent/test/driver/input'
|
3
3
|
require 'fluent/plugin/in_http'
|
4
4
|
require 'net/http'
|
5
|
+
require 'timecop'
|
5
6
|
|
6
7
|
class HttpInputTest < Test::Unit::TestCase
|
8
|
+
class << self
|
9
|
+
def startup
|
10
|
+
socket_manager_path = ServerEngine::SocketManager::Server.generate_path
|
11
|
+
@server = ServerEngine::SocketManager::Server.open(socket_manager_path)
|
12
|
+
ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = socket_manager_path.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def shutdown
|
16
|
+
@server.close
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
7
20
|
def setup
|
8
21
|
Fluent::Test.setup
|
9
22
|
end
|
10
23
|
|
24
|
+
def teardown
|
25
|
+
Timecop.return
|
26
|
+
end
|
27
|
+
|
11
28
|
PORT = unused_port
|
12
29
|
CONFIG = %[
|
13
30
|
port #{PORT}
|
@@ -18,7 +35,7 @@ class HttpInputTest < Test::Unit::TestCase
|
|
18
35
|
]
|
19
36
|
|
20
37
|
def create_driver(conf=CONFIG)
|
21
|
-
Fluent::Test::
|
38
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::HttpInput).configure(conf)
|
22
39
|
end
|
23
40
|
|
24
41
|
def test_configure
|
@@ -32,137 +49,252 @@ class HttpInputTest < Test::Unit::TestCase
|
|
32
49
|
|
33
50
|
def test_time
|
34
51
|
d = create_driver
|
52
|
+
time = event_time("2011-01-02 13:14:15.123 UTC")
|
53
|
+
Timecop.freeze(Time.at(time))
|
35
54
|
|
36
|
-
|
37
|
-
|
55
|
+
events = [
|
56
|
+
["tag1", time, {"a" => 1}],
|
57
|
+
["tag2", time, {"a" => 2}],
|
58
|
+
]
|
59
|
+
res_codes = []
|
38
60
|
|
39
|
-
d.
|
40
|
-
|
41
|
-
|
42
|
-
d.run do
|
43
|
-
d.expected_emits.each {|tag,time,record|
|
61
|
+
d.run(expect_records: 2) do
|
62
|
+
events.each do |tag, _time, record|
|
44
63
|
res = post("/#{tag}", {"json"=>record.to_json})
|
45
|
-
|
46
|
-
|
64
|
+
res_codes << res.code
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
assert_equal ["200", "200"], res_codes
|
69
|
+
assert_equal events, d.events
|
70
|
+
assert_equal_event_time time, d.events[0][1]
|
71
|
+
assert_equal_event_time time, d.events[1][1]
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_time_as_float
|
75
|
+
d = create_driver
|
76
|
+
time = event_time("2011-01-02 13:14:15.123 UTC")
|
77
|
+
float_time = time.to_f
|
78
|
+
|
79
|
+
events = [
|
80
|
+
["tag1", time, {"a"=>1}],
|
81
|
+
]
|
82
|
+
res_codes = []
|
83
|
+
|
84
|
+
d.run(expect_records: 1) do
|
85
|
+
events.each do |tag, t, record|
|
86
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>float_time.to_s})
|
87
|
+
res_codes << res.code
|
88
|
+
end
|
47
89
|
end
|
90
|
+
assert_equal ["200"], res_codes
|
91
|
+
assert_equal events, d.events
|
92
|
+
assert_equal_event_time time, d.events[0][1]
|
48
93
|
end
|
49
94
|
|
50
95
|
def test_json
|
51
96
|
d = create_driver
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
97
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
98
|
+
time_i = time.to_i
|
99
|
+
|
100
|
+
events = [
|
101
|
+
["tag1", time_i, {"a"=>1}],
|
102
|
+
["tag2", time_i, {"a"=>2}],
|
103
|
+
]
|
104
|
+
res_codes = []
|
105
|
+
|
106
|
+
d.run(expect_records: 2) do
|
107
|
+
events.each do |tag, t, record|
|
108
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>t.to_s})
|
109
|
+
res_codes << res.code
|
110
|
+
end
|
63
111
|
end
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
112
|
+
assert_equal ["200", "200"], res_codes
|
113
|
+
assert_equal events, d.events
|
114
|
+
assert_equal_event_time time, d.events[0][1]
|
115
|
+
assert_equal_event_time time, d.events[1][1]
|
68
116
|
end
|
69
117
|
|
70
118
|
def test_multi_json
|
71
119
|
d = create_driver
|
120
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
121
|
+
time_i = time.to_i
|
122
|
+
|
123
|
+
records = [{"a"=>1},{"a"=>2}]
|
124
|
+
events = [
|
125
|
+
["tag1", time_i, records[0]],
|
126
|
+
["tag1", time_i, records[1]],
|
127
|
+
]
|
128
|
+
tag = "tag1"
|
129
|
+
res_codes = []
|
130
|
+
d.run(expect_records: 2, timeout: 5) do
|
131
|
+
res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s})
|
132
|
+
res_codes << res.code
|
133
|
+
end
|
134
|
+
assert_equal ["200"], res_codes
|
135
|
+
assert_equal events, d.events
|
136
|
+
assert_equal_event_time time, d.events[0][1]
|
137
|
+
assert_equal_event_time time, d.events[1][1]
|
138
|
+
end
|
72
139
|
|
73
|
-
|
74
|
-
|
75
|
-
|
140
|
+
def test_multi_json_with_time_field
|
141
|
+
d = create_driver
|
142
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
143
|
+
time_i = time.to_i
|
144
|
+
time_f = time.to_f
|
145
|
+
|
146
|
+
records = [{"a" => 1, 'time' => time_i},{"a" => 2, 'time' => time_f}]
|
147
|
+
events = [
|
148
|
+
["tag1", time, {'a' => 1}],
|
149
|
+
["tag1", time, {'a' => 2}],
|
150
|
+
]
|
76
151
|
tag = "tag1"
|
152
|
+
res_codes = []
|
153
|
+
d.run(expect_records: 2, timeout: 5) do
|
154
|
+
res = post("/#{tag}", {"json" => records.to_json})
|
155
|
+
res_codes << res.code
|
156
|
+
end
|
157
|
+
assert_equal ["200"], res_codes
|
158
|
+
assert_equal events, d.events
|
159
|
+
assert_instance_of Fluent::EventTime, d.events[0][1]
|
160
|
+
assert_instance_of Fluent::EventTime, d.events[1][1]
|
161
|
+
assert_equal_event_time time, d.events[0][1]
|
162
|
+
assert_equal_event_time time, d.events[1][1]
|
163
|
+
end
|
77
164
|
|
78
|
-
|
79
|
-
|
80
|
-
|
165
|
+
def test_multi_json_with_nonexistent_time_key
|
166
|
+
d = create_driver(CONFIG + %[
|
167
|
+
<parse>
|
168
|
+
time_key missing
|
169
|
+
</parse>
|
170
|
+
])
|
171
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
172
|
+
time_i = time.to_i
|
173
|
+
time_f = time.to_f
|
81
174
|
|
82
|
-
|
83
|
-
|
84
|
-
|
175
|
+
records = [{"a" => 1, 'time' => time_i},{"a" => 2, 'time' => time_f}]
|
176
|
+
tag = "tag1"
|
177
|
+
res_codes = []
|
178
|
+
d.run(expect_records: 2, timeout: 5) do
|
179
|
+
res = post("/#{tag}", {"json" => records.to_json})
|
180
|
+
res_codes << res.code
|
85
181
|
end
|
86
|
-
|
182
|
+
assert_equal ["200"], res_codes
|
183
|
+
assert_equal 2, d.events.size
|
184
|
+
assert_not_equal time_i, d.events[0][1].sec # current time is used because "missing" field doesn't exist
|
185
|
+
assert_not_equal time_i, d.events[1][1].sec
|
87
186
|
end
|
88
187
|
|
89
188
|
def test_json_with_add_remote_addr
|
90
189
|
d = create_driver(CONFIG + "add_remote_addr true")
|
91
|
-
time =
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
190
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
191
|
+
time_i = time.to_i
|
192
|
+
|
193
|
+
events = [
|
194
|
+
["tag1", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>1}],
|
195
|
+
["tag2", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>2}],
|
196
|
+
]
|
197
|
+
res_codes = []
|
198
|
+
d.run(expect_records: 2) do
|
199
|
+
events.each do |tag, _t, record|
|
200
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
|
201
|
+
res_codes << res.code
|
202
|
+
end
|
101
203
|
end
|
102
|
-
|
204
|
+
assert_equal ["200", "200"], res_codes
|
205
|
+
assert_equal events, d.events
|
206
|
+
assert_equal_event_time time, d.events[0][1]
|
207
|
+
assert_equal_event_time time, d.events[1][1]
|
103
208
|
end
|
104
209
|
|
105
210
|
def test_multi_json_with_add_remote_addr
|
106
211
|
d = create_driver(CONFIG + "add_remote_addr true")
|
212
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
213
|
+
time_i = time.to_i
|
107
214
|
|
108
|
-
|
109
|
-
events = [{"a"=>1},{"a"=>2}]
|
215
|
+
records = [{"a"=>1},{"a"=>2}]
|
110
216
|
tag = "tag1"
|
217
|
+
res_codes = []
|
111
218
|
|
112
|
-
d.
|
113
|
-
|
114
|
-
|
115
|
-
d.run do
|
116
|
-
res = post("/#{tag}", {"json"=>events.to_json, "time"=>time.to_s})
|
117
|
-
assert_equal "200", res.code
|
219
|
+
d.run(expect_records: 2, timeout: 5) do
|
220
|
+
res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s})
|
221
|
+
res_codes << res.code
|
118
222
|
end
|
223
|
+
assert_equal ["200"], res_codes
|
119
224
|
|
225
|
+
assert_equal "tag1", d.events[0][0]
|
226
|
+
assert_equal_event_time time, d.events[0][1]
|
227
|
+
assert_equal 1, d.events[0][2]["a"]
|
228
|
+
assert{ d.events[0][2].has_key?("REMOTE_ADDR") && d.events[0][2]["REMOTE_ADDR"] =~ /^\d{1,4}(\.\d{1,4}){3}$/ }
|
229
|
+
|
230
|
+
assert_equal "tag1", d.events[1][0]
|
231
|
+
assert_equal_event_time time, d.events[1][1]
|
232
|
+
assert_equal 2, d.events[1][2]["a"]
|
120
233
|
end
|
121
234
|
|
122
235
|
def test_json_with_add_remote_addr_given_x_forwarded_for
|
123
236
|
d = create_driver(CONFIG + "add_remote_addr true")
|
124
|
-
time =
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
237
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
238
|
+
time_i = time.to_i
|
239
|
+
|
240
|
+
events = [
|
241
|
+
["tag1", time, {"a"=>1}],
|
242
|
+
["tag2", time, {"a"=>2}],
|
243
|
+
]
|
244
|
+
res_codes = []
|
245
|
+
|
246
|
+
d.run(expect_records: 2) do
|
247
|
+
events.each do |tag, _t, record|
|
248
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
|
249
|
+
res_codes << res.code
|
250
|
+
end
|
134
251
|
end
|
252
|
+
assert_equal ["200", "200"], res_codes
|
135
253
|
|
254
|
+
assert_equal "tag1", d.events[0][0]
|
255
|
+
assert_equal_event_time time, d.events[0][1]
|
256
|
+
assert_equal({"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}, d.events[0][2])
|
257
|
+
|
258
|
+
assert_equal "tag2", d.events[1][0]
|
259
|
+
assert_equal_event_time time, d.events[1][1]
|
260
|
+
assert_equal({"REMOTE_ADDR"=>"129.78.138.66", "a"=>2}, d.events[1][2])
|
136
261
|
end
|
137
262
|
|
138
263
|
def test_multi_json_with_add_remote_addr_given_x_forwarded_for
|
139
264
|
d = create_driver(CONFIG + "add_remote_addr true")
|
140
265
|
|
141
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
142
|
-
events = [{"a"=>1},{"a"=>2}]
|
143
266
|
tag = "tag1"
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
267
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
268
|
+
time_i = time.to_i
|
269
|
+
records = [{"a"=>1},{"a"=>2}]
|
270
|
+
events = [
|
271
|
+
[tag, time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}],
|
272
|
+
[tag, time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>2}],
|
273
|
+
]
|
274
|
+
res_codes = []
|
275
|
+
|
276
|
+
d.run(expect_records: 2, timeout: 5) do
|
277
|
+
res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
|
278
|
+
res_codes << res.code
|
151
279
|
end
|
152
|
-
|
280
|
+
assert_equal ["200"], res_codes
|
281
|
+
assert_equal events, d.events
|
282
|
+
assert_equal_event_time time, d.events[0][1]
|
283
|
+
assert_equal_event_time time, d.events[1][1]
|
153
284
|
end
|
154
285
|
|
155
286
|
def test_add_remote_addr_given_multi_x_forwarded_for
|
156
287
|
d = create_driver(CONFIG + "add_remote_addr true")
|
157
288
|
|
158
289
|
tag = "tag1"
|
159
|
-
time = event_time("2011-01-02 13:14:15 UTC")
|
290
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
291
|
+
time_i = time.to_i
|
160
292
|
record = {"a" => 1}
|
293
|
+
event = ["tag1", time, {"REMOTE_ADDR" => "129.78.138.66", "a" => 1}]
|
294
|
+
res_code = nil
|
161
295
|
|
162
|
-
d.
|
163
|
-
|
164
|
-
d.run do
|
165
|
-
res = post("/#{tag}", {"json" => record.to_json, "time" => time.to_s}) { |http, req|
|
296
|
+
d.run(expect_records: 1, timeout: 5) do
|
297
|
+
res = post("/#{tag}", {"json" => record.to_json, "time" => time_i.to_s}) { |http, req|
|
166
298
|
# net/http can't send multiple headers so overwrite it.
|
167
299
|
def req.each_capitalized
|
168
300
|
block_given? or return enum_for(__method__) { @header.size }
|
@@ -175,112 +307,189 @@ class HttpInputTest < Test::Unit::TestCase
|
|
175
307
|
req.add_field("X-Forwarded-For", "129.78.138.66, 127.0.0.1")
|
176
308
|
req.add_field("X-Forwarded-For", "8.8.8.8")
|
177
309
|
}
|
178
|
-
|
310
|
+
res_code = res.code
|
179
311
|
end
|
312
|
+
assert_equal "200", res_code
|
313
|
+
assert_equal event, d.events.first
|
314
|
+
assert_equal_event_time time, d.events.first[1]
|
180
315
|
end
|
181
316
|
|
182
317
|
def test_multi_json_with_add_http_headers
|
183
318
|
d = create_driver(CONFIG + "add_http_headers true")
|
184
|
-
|
185
|
-
|
186
|
-
|
319
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
320
|
+
time_i = time.to_i
|
321
|
+
records = [{"a"=>1},{"a"=>2}]
|
187
322
|
tag = "tag1"
|
323
|
+
res_codes = []
|
188
324
|
|
189
|
-
d.run do
|
190
|
-
res = post("/#{tag}", {"json"=>
|
191
|
-
|
325
|
+
d.run(expect_records: 2, timeout: 5) do
|
326
|
+
res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s})
|
327
|
+
res_codes << res.code
|
192
328
|
end
|
329
|
+
assert_equal ["200"], res_codes
|
330
|
+
|
331
|
+
assert_equal "tag1", d.events[0][0]
|
332
|
+
assert_equal_event_time time, d.events[0][1]
|
333
|
+
assert_equal 1, d.events[0][2]["a"]
|
193
334
|
|
194
|
-
|
195
|
-
|
196
|
-
|
335
|
+
assert_equal "tag1", d.events[1][0]
|
336
|
+
assert_equal_event_time time, d.events[1][1]
|
337
|
+
assert_equal 2, d.events[1][2]["a"]
|
338
|
+
|
339
|
+
assert include_http_header?(d.events[0][2])
|
340
|
+
assert include_http_header?(d.events[1][2])
|
197
341
|
end
|
198
342
|
|
199
343
|
def test_json_with_add_http_headers
|
200
344
|
d = create_driver(CONFIG + "add_http_headers true")
|
345
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
346
|
+
time_i = time.to_i
|
347
|
+
events = [
|
348
|
+
["tag1", time, {"a"=>1}],
|
349
|
+
["tag2", time, {"a"=>2}],
|
350
|
+
]
|
351
|
+
res_codes = []
|
352
|
+
|
353
|
+
d.run(expect_records: 2) do
|
354
|
+
events.each do |tag, t, record|
|
355
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
|
356
|
+
res_codes << res.code
|
357
|
+
end
|
358
|
+
end
|
359
|
+
assert_equal ["200", "200"], res_codes
|
201
360
|
|
202
|
-
|
361
|
+
assert_equal "tag1", d.events[0][0]
|
362
|
+
assert_equal_event_time time, d.events[0][1]
|
363
|
+
assert_equal 1, d.events[0][2]["a"]
|
203
364
|
|
204
|
-
|
365
|
+
assert_equal "tag2", d.events[1][0]
|
366
|
+
assert_equal_event_time time, d.events[1][1]
|
367
|
+
assert_equal 2, d.events[1][2]["a"]
|
205
368
|
|
206
|
-
d.
|
207
|
-
|
208
|
-
|
209
|
-
assert_equal "200", res.code
|
369
|
+
assert include_http_header?(d.events[0][2])
|
370
|
+
assert include_http_header?(d.events[1][2])
|
371
|
+
end
|
210
372
|
|
211
|
-
|
373
|
+
def test_multi_json_with_custom_parser
|
374
|
+
d = create_driver(CONFIG + %[
|
375
|
+
<parse>
|
376
|
+
@type json
|
377
|
+
keep_time_key true
|
378
|
+
time_key foo
|
379
|
+
time_format %iso8601
|
380
|
+
</parse>
|
381
|
+
])
|
382
|
+
|
383
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
384
|
+
time_s = Time.at(time).iso8601
|
385
|
+
|
386
|
+
records = [{"foo"=>time_s,"bar"=>"test1"},{"foo"=>time_s,"bar"=>"test2"}]
|
387
|
+
tag = "tag1"
|
388
|
+
res_codes = []
|
389
|
+
|
390
|
+
d.run(expect_records: 2, timeout: 5) do
|
391
|
+
res = post("/#{tag}", records.to_json, {"Content-Type"=>"application/octet-stream"})
|
392
|
+
res_codes << res.code
|
212
393
|
end
|
394
|
+
assert_equal ["200"], res_codes
|
213
395
|
|
214
|
-
|
215
|
-
|
216
|
-
|
396
|
+
assert_equal "tag1", d.events[0][0]
|
397
|
+
assert_equal_event_time time, d.events[0][1]
|
398
|
+
assert_equal d.events[0][2], records[0]
|
399
|
+
|
400
|
+
assert_equal "tag1", d.events[1][0]
|
401
|
+
assert_equal_event_time time, d.events[1][1]
|
402
|
+
assert_equal d.events[1][2], records[1]
|
217
403
|
end
|
218
404
|
|
219
405
|
def test_application_json
|
220
406
|
d = create_driver
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
407
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
408
|
+
time_i = time.to_i
|
409
|
+
events = [
|
410
|
+
["tag1", time, {"a"=>1}],
|
411
|
+
["tag2", time, {"a"=>2}],
|
412
|
+
]
|
413
|
+
res_codes = []
|
414
|
+
|
415
|
+
d.run(expect_records: 2) do
|
416
|
+
events.each do |tag, t, record|
|
417
|
+
res = post("/#{tag}?time=#{time_i.to_s}", record.to_json, {"Content-Type"=>"application/json; charset=utf-8"})
|
418
|
+
res_codes << res.code
|
419
|
+
end
|
232
420
|
end
|
421
|
+
assert_equal ["200", "200"], res_codes
|
422
|
+
assert_equal events, d.events
|
423
|
+
assert_equal_event_time time, d.events[0][1]
|
424
|
+
assert_equal_event_time time, d.events[1][1]
|
233
425
|
end
|
234
426
|
|
235
427
|
def test_application_msgpack
|
236
428
|
d = create_driver
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
429
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
430
|
+
time_i = time.to_i
|
431
|
+
events = [
|
432
|
+
["tag1", time, {"a"=>1}],
|
433
|
+
["tag2", time, {"a"=>2}],
|
434
|
+
]
|
435
|
+
res_codes = []
|
436
|
+
|
437
|
+
d.run(expect_records: 2) do
|
438
|
+
events.each do |tag, t, record|
|
439
|
+
res = post("/#{tag}?time=#{time_i.to_s}", record.to_msgpack, {"Content-Type"=>"application/msgpack"})
|
440
|
+
res_codes << res.code
|
441
|
+
end
|
248
442
|
end
|
443
|
+
assert_equal ["200", "200"], res_codes
|
444
|
+
assert_equal events, d.events
|
445
|
+
assert_equal_event_time time, d.events[0][1]
|
446
|
+
assert_equal_event_time time, d.events[1][1]
|
249
447
|
end
|
250
448
|
|
251
449
|
def test_msgpack
|
252
450
|
d = create_driver
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
451
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
452
|
+
time_i = time.to_i
|
453
|
+
|
454
|
+
events = [
|
455
|
+
["tag1", time, {"a"=>1}],
|
456
|
+
["tag2", time, {"a"=>2}],
|
457
|
+
]
|
458
|
+
res_codes = []
|
459
|
+
|
460
|
+
d.run(expect_records: 2) do
|
461
|
+
events.each do |tag, t, record|
|
462
|
+
res = post("/#{tag}", {"msgpack"=>record.to_msgpack, "time"=>time_i.to_s})
|
463
|
+
res_codes << res.code
|
464
|
+
end
|
264
465
|
end
|
466
|
+
assert_equal ["200", "200"], res_codes
|
467
|
+
assert_equal events, d.events
|
468
|
+
assert_equal_event_time time, d.events[0][1]
|
469
|
+
assert_equal_event_time time, d.events[1][1]
|
265
470
|
end
|
266
471
|
|
267
472
|
def test_multi_msgpack
|
268
473
|
d = create_driver
|
269
474
|
|
270
|
-
time =
|
475
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
476
|
+
time_i = time.to_i
|
271
477
|
|
272
|
-
|
478
|
+
records = [{"a"=>1},{"a"=>2}]
|
479
|
+
events = [
|
480
|
+
["tag1", time, records[0]],
|
481
|
+
["tag1", time, records[1]],
|
482
|
+
]
|
273
483
|
tag = "tag1"
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
d.run do
|
280
|
-
res = post("/#{tag}", {"msgpack"=>events.to_msgpack, "time"=>time.to_s})
|
281
|
-
assert_equal "200", res.code
|
484
|
+
res_codes = []
|
485
|
+
d.run(expect_records: 2) do
|
486
|
+
res = post("/#{tag}", {"msgpack"=>records.to_msgpack, "time"=>time_i.to_s})
|
487
|
+
res_codes << res.code
|
282
488
|
end
|
283
|
-
|
489
|
+
assert_equal ["200"], res_codes
|
490
|
+
assert_equal events, d.events
|
491
|
+
assert_equal_event_time time, d.events[0][1]
|
492
|
+
assert_equal_event_time time, d.events[1][1]
|
284
493
|
end
|
285
494
|
|
286
495
|
def test_with_regexp
|
@@ -289,20 +498,27 @@ class HttpInputTest < Test::Unit::TestCase
|
|
289
498
|
types field_1:integer
|
290
499
|
])
|
291
500
|
|
292
|
-
time =
|
293
|
-
|
294
|
-
|
295
|
-
|
501
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
502
|
+
time_i = time.to_i
|
503
|
+
events = [
|
504
|
+
["tag1", time, {"field_1" => 1, "field_2" => 'str'}],
|
505
|
+
["tag2", time, {"field_1" => 2, "field_2" => 'str'}],
|
506
|
+
]
|
507
|
+
res_codes = []
|
296
508
|
|
297
|
-
d.run do
|
298
|
-
|
509
|
+
d.run(expect_records: 2) do
|
510
|
+
events.each do |tag, t, record|
|
299
511
|
body = record.map { |k, v|
|
300
512
|
v.to_s
|
301
513
|
}.join(':')
|
302
|
-
res = post("/#{tag}?time=#{
|
303
|
-
|
304
|
-
|
514
|
+
res = post("/#{tag}?time=#{time_i.to_s}", body, {'Content-Type' => 'application/octet-stream'})
|
515
|
+
res_codes << res.code
|
516
|
+
end
|
305
517
|
end
|
518
|
+
assert_equal ["200", "200"], res_codes
|
519
|
+
assert_equal events, d.events
|
520
|
+
assert_equal_event_time time, d.events[0][1]
|
521
|
+
assert_equal_event_time time, d.events[1][1]
|
306
522
|
end
|
307
523
|
|
308
524
|
def test_with_csv
|
@@ -312,77 +528,248 @@ class HttpInputTest < Test::Unit::TestCase
|
|
312
528
|
format csv
|
313
529
|
keys foo,bar
|
314
530
|
])
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
531
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
532
|
+
time_i = time.to_i
|
533
|
+
events = [
|
534
|
+
["tag1", time, {"foo" => "1", "bar" => 'st"r'}],
|
535
|
+
["tag2", time, {"foo" => "2", "bar" => 'str'}],
|
536
|
+
]
|
537
|
+
res_codes = []
|
538
|
+
|
539
|
+
d.run(expect_records: 2) do
|
540
|
+
events.each do |tag, t, record|
|
323
541
|
body = record.map { |k, v| v }.to_csv
|
324
|
-
res = post("/#{tag}?time=#{
|
325
|
-
|
326
|
-
|
542
|
+
res = post("/#{tag}?time=#{time_i.to_s}", body, {'Content-Type' => 'text/comma-separated-values'})
|
543
|
+
res_codes << res.code
|
544
|
+
end
|
327
545
|
end
|
546
|
+
assert_equal ["200", "200"], res_codes
|
547
|
+
assert_equal events, d.events
|
548
|
+
assert_equal_event_time time, d.events[0][1]
|
549
|
+
assert_equal_event_time time, d.events[1][1]
|
328
550
|
end
|
329
551
|
|
330
552
|
def test_resonse_with_empty_img
|
331
553
|
d = create_driver(CONFIG + "respond_with_empty_img true")
|
332
554
|
assert_equal true, d.instance.respond_with_empty_img
|
333
555
|
|
334
|
-
time =
|
335
|
-
|
336
|
-
|
337
|
-
|
556
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
557
|
+
time_i = time.to_i
|
558
|
+
events = [
|
559
|
+
["tag1", time, {"a"=>1}],
|
560
|
+
["tag2", time, {"a"=>2}],
|
561
|
+
]
|
562
|
+
res_codes = []
|
563
|
+
res_bodies = []
|
338
564
|
|
339
565
|
d.run do
|
340
|
-
|
341
|
-
res = post("/#{tag}", {"json"=>record.to_json, "time"=>
|
342
|
-
|
566
|
+
events.each do |tag, _t, record|
|
567
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
|
568
|
+
res_codes << res.code
|
343
569
|
# Ruby returns ASCII-8 encoded string for GIF.
|
344
|
-
|
345
|
-
|
570
|
+
res_bodies << res.body.force_encoding("UTF-8")
|
571
|
+
end
|
346
572
|
end
|
573
|
+
assert_equal ["200", "200"], res_codes
|
574
|
+
assert_equal [Fluent::Plugin::HttpInput::EMPTY_GIF_IMAGE, Fluent::Plugin::HttpInput::EMPTY_GIF_IMAGE], res_bodies
|
575
|
+
assert_equal events, d.events
|
576
|
+
assert_equal_event_time time, d.events[0][1]
|
577
|
+
assert_equal_event_time time, d.events[1][1]
|
347
578
|
end
|
348
579
|
|
349
580
|
def test_cors_allowed
|
350
581
|
d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
|
351
582
|
assert_equal ["http://foo.com"], d.instance.cors_allow_origins
|
352
583
|
|
353
|
-
time =
|
584
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
585
|
+
time_i = time.to_i
|
586
|
+
events = [
|
587
|
+
["tag1", time, {"a"=>1}],
|
588
|
+
["tag2", time, {"a"=>2}],
|
589
|
+
]
|
590
|
+
res_codes = []
|
591
|
+
res_headers = []
|
592
|
+
|
593
|
+
d.run do
|
594
|
+
events.each do |tag, _t, record|
|
595
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://foo.com"})
|
596
|
+
res_codes << res.code
|
597
|
+
res_headers << res["Access-Control-Allow-Origin"]
|
598
|
+
end
|
599
|
+
end
|
600
|
+
assert_equal ["200", "200"], res_codes
|
601
|
+
assert_equal ["http://foo.com", "http://foo.com"], res_headers
|
602
|
+
assert_equal events, d.events
|
603
|
+
assert_equal_event_time time, d.events[0][1]
|
604
|
+
assert_equal_event_time time, d.events[1][1]
|
605
|
+
end
|
606
|
+
|
607
|
+
def test_cors_allowed_wildcard
|
608
|
+
d = create_driver(CONFIG + 'cors_allow_origins ["*"]')
|
354
609
|
|
355
|
-
|
356
|
-
|
610
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
611
|
+
events = [
|
612
|
+
["tag1", time, {"a"=>1}],
|
613
|
+
]
|
357
614
|
|
358
615
|
d.run do
|
359
|
-
|
360
|
-
|
616
|
+
events.each do |tag, time, record|
|
617
|
+
headers = {"Origin" => "http://foo.com"}
|
618
|
+
|
619
|
+
res = post("/#{tag}", {"json" => record.to_json, "time" => time.to_i}, headers)
|
620
|
+
|
361
621
|
assert_equal "200", res.code
|
362
|
-
assert_equal "
|
622
|
+
assert_equal "*", res["Access-Control-Allow-Origin"]
|
623
|
+
end
|
624
|
+
end
|
625
|
+
end
|
626
|
+
|
627
|
+
def test_cors_preflight
|
628
|
+
d = create_driver(CONFIG + 'cors_allow_origins ["*"]')
|
629
|
+
|
630
|
+
d.run do
|
631
|
+
header = {
|
632
|
+
"Origin" => "http://foo.com",
|
633
|
+
"Access-Control-Request-Method" => "POST",
|
634
|
+
"Access-Control-Request-Headers" => "Content-Type",
|
363
635
|
}
|
636
|
+
res = options("/cors.test", {}, header)
|
637
|
+
|
638
|
+
assert_equal "200", res.code
|
639
|
+
assert_equal "*", res["Access-Control-Allow-Origin"]
|
640
|
+
assert_equal "POST", res["Access-Control-Allow-Methods"]
|
641
|
+
end
|
642
|
+
end
|
643
|
+
|
644
|
+
def test_cors_allowed_wildcard_for_subdomain
|
645
|
+
d = create_driver(CONFIG + 'cors_allow_origins ["http://*.foo.com"]')
|
646
|
+
|
647
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
648
|
+
events = [
|
649
|
+
["tag1", time, {"a"=>1}],
|
650
|
+
]
|
651
|
+
|
652
|
+
d.run do
|
653
|
+
events.each do |tag, time, record|
|
654
|
+
headers = {"Origin" => "http://subdomain.foo.com"}
|
655
|
+
|
656
|
+
res = post("/#{tag}", {"json" => record.to_json, "time" => time.to_i}, headers)
|
657
|
+
|
658
|
+
assert_equal "200", res.code
|
659
|
+
assert_equal "http://subdomain.foo.com", res["Access-Control-Allow-Origin"]
|
660
|
+
end
|
364
661
|
end
|
365
662
|
end
|
663
|
+
|
664
|
+
def test_cors_allowed_exclude_empty_string
|
665
|
+
d = create_driver(CONFIG + 'cors_allow_origins ["", "http://*.foo.com"]')
|
666
|
+
|
667
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
668
|
+
events = [
|
669
|
+
["tag1", time, {"a"=>1}],
|
670
|
+
]
|
671
|
+
|
672
|
+
d.run do
|
673
|
+
events.each do |tag, time, record|
|
674
|
+
headers = {"Origin" => "http://subdomain.foo.com"}
|
675
|
+
|
676
|
+
res = post("/#{tag}", {"json" => record.to_json, "time" => time.to_i}, headers)
|
677
|
+
|
678
|
+
assert_equal "200", res.code
|
679
|
+
assert_equal "http://subdomain.foo.com", res["Access-Control-Allow-Origin"]
|
680
|
+
end
|
681
|
+
end
|
682
|
+
end
|
683
|
+
|
684
|
+
def test_cors_allowed_wildcard_preflight_for_subdomain
|
685
|
+
d = create_driver(CONFIG + 'cors_allow_origins ["http://*.foo.com"]')
|
686
|
+
|
687
|
+
d.run do
|
688
|
+
header = {
|
689
|
+
"Origin" => "http://subdomain.foo.com",
|
690
|
+
"Access-Control-Request-Method" => "POST",
|
691
|
+
"Access-Control-Request-Headers" => "Content-Type",
|
692
|
+
}
|
693
|
+
res = options("/cors.test", {}, header)
|
694
|
+
|
695
|
+
assert_equal "200", res.code
|
696
|
+
assert_equal "http://subdomain.foo.com", res["Access-Control-Allow-Origin"]
|
697
|
+
assert_equal "POST", res["Access-Control-Allow-Methods"]
|
698
|
+
end
|
699
|
+
end
|
700
|
+
|
701
|
+
def test_content_encoding_gzip
|
702
|
+
d = create_driver
|
703
|
+
|
704
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
705
|
+
events = [
|
706
|
+
["tag1", time, {"a"=>1}],
|
707
|
+
["tag2", time, {"a"=>2}],
|
708
|
+
]
|
709
|
+
res_codes = []
|
710
|
+
|
711
|
+
d.run do
|
712
|
+
events.each do |tag, time, record|
|
713
|
+
header = {'Content-Type'=>'application/json', 'Content-Encoding'=>'gzip'}
|
714
|
+
res = post("/#{tag}?time=#{time}", compress_gzip(record.to_json), header)
|
715
|
+
res_codes << res.code
|
716
|
+
end
|
717
|
+
end
|
718
|
+
assert_equal ["200", "200"], res_codes
|
719
|
+
assert_equal events, d.events
|
720
|
+
assert_equal_event_time time, d.events[0][1]
|
721
|
+
assert_equal_event_time time, d.events[1][1]
|
722
|
+
end
|
723
|
+
|
724
|
+
def test_content_encoding_deflate
|
725
|
+
d = create_driver
|
726
|
+
|
727
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
728
|
+
events = [
|
729
|
+
["tag1", time, {"a"=>1}],
|
730
|
+
["tag2", time, {"a"=>2}],
|
731
|
+
]
|
732
|
+
res_codes = []
|
733
|
+
|
734
|
+
d.run do
|
735
|
+
events.each do |tag, time, record|
|
736
|
+
header = {'Content-Type'=>'application/msgpack', 'Content-Encoding'=>'deflate'}
|
737
|
+
res = post("/#{tag}?time=#{time}", Zlib.deflate(record.to_msgpack), header)
|
738
|
+
res_codes << res.code
|
739
|
+
end
|
740
|
+
end
|
741
|
+
assert_equal ["200", "200"], res_codes
|
742
|
+
assert_equal events, d.events
|
743
|
+
assert_equal_event_time time, d.events[0][1]
|
744
|
+
assert_equal_event_time time, d.events[1][1]
|
745
|
+
end
|
366
746
|
|
367
747
|
def test_cors_disallowed
|
368
748
|
d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
|
369
749
|
assert_equal ["http://foo.com"], d.instance.cors_allow_origins
|
370
750
|
|
371
|
-
time =
|
751
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
752
|
+
time_i = time.to_i
|
753
|
+
res_codes = []
|
372
754
|
|
373
|
-
d.
|
755
|
+
d.end_if{ res_codes.size == 2 }
|
374
756
|
d.run do
|
375
|
-
res = post("/tag1", {"json"=>{"a"=>1}.to_json, "time"=>
|
376
|
-
|
377
|
-
res = post("/tag2", {"json"=>{"a"=>1}.to_json, "time"=>
|
378
|
-
|
757
|
+
res = post("/tag1", {"json"=>{"a"=>1}.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://bar.com"})
|
758
|
+
res_codes << res.code
|
759
|
+
res = post("/tag2", {"json"=>{"a"=>1}.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://bar.com"})
|
760
|
+
res_codes << res.code
|
379
761
|
end
|
762
|
+
assert_equal ["403", "403"], res_codes
|
380
763
|
end
|
381
764
|
|
382
765
|
$test_in_http_connection_object_ids = []
|
383
766
|
$test_in_http_content_types = []
|
384
767
|
$test_in_http_content_types_flag = false
|
385
768
|
module ContentTypeHook
|
769
|
+
def initialize(*args)
|
770
|
+
@io_handler = nil
|
771
|
+
super
|
772
|
+
end
|
386
773
|
def on_headers_complete(headers)
|
387
774
|
super
|
388
775
|
if $test_in_http_content_types_flag
|
@@ -398,64 +785,40 @@ class HttpInputTest < Test::Unit::TestCase
|
|
398
785
|
end
|
399
786
|
end
|
400
787
|
|
401
|
-
class Fluent::HttpInput::Handler
|
788
|
+
class Fluent::Plugin::HttpInput::Handler
|
402
789
|
prepend ContentTypeHook
|
403
790
|
end
|
404
791
|
|
405
792
|
def test_if_content_type_is_initialized_properly
|
406
793
|
# This test is to check if Fluent::HttpInput::Handler's @content_type is initialized properly.
|
407
794
|
# Especially when in Keep-Alive and the second request has no 'Content-Type'.
|
408
|
-
#
|
409
|
-
# Actually, in the current implementation of in_http, we can't test it directly.
|
410
|
-
# So we replace Fluent::HttpInput::Handler temporally with the extended Handler
|
411
|
-
# in order to collect @content_type(s) per request.
|
412
|
-
# Finally, we check those collected @content_type(s).
|
413
|
-
|
414
|
-
# Save the original Handler
|
415
|
-
orig_handler = Fluent::HttpInput::Handler
|
416
795
|
|
417
796
|
begin
|
418
|
-
# Create the extended Handler which can store @content_type per request
|
419
|
-
ext_handler = Class.new(Fluent::HttpInput::Handler) do
|
420
|
-
@@content_types = []
|
421
|
-
|
422
|
-
def self.content_types
|
423
|
-
@@content_types
|
424
|
-
end
|
425
|
-
|
426
|
-
def on_message_complete
|
427
|
-
@@content_types << @content_type
|
428
|
-
super
|
429
|
-
end
|
430
|
-
end
|
431
|
-
|
432
|
-
# Replace the original Handler temporally with the extended one
|
433
|
-
Fluent::HttpInput.module_eval do
|
434
|
-
remove_const(:Handler) if const_defined?(:Handler)
|
435
|
-
const_set(:Handler, ext_handler)
|
436
|
-
end
|
437
|
-
|
438
797
|
d = create_driver
|
439
798
|
|
799
|
+
$test_in_http_content_types_flag = true
|
440
800
|
d.run do
|
441
801
|
# Send two requests the second one has no Content-Type in Keep-Alive
|
442
802
|
Net::HTTP.start("127.0.0.1", PORT) do |http|
|
443
|
-
req = Net::HTTP::Post.new("/foodb/bartbl", {"connection" => "keepalive", "
|
444
|
-
|
445
|
-
|
803
|
+
req = Net::HTTP::Post.new("/foodb/bartbl", {"connection" => "keepalive", "Content-Type" => "application/json"})
|
804
|
+
http.request(req)
|
446
805
|
req = Net::HTTP::Get.new("/foodb/bartbl", {"connection" => "keepalive"})
|
447
|
-
|
806
|
+
http.request(req)
|
448
807
|
end
|
449
808
|
|
450
|
-
assert_equal(['application/json', ''], ext_handler.content_types)
|
451
809
|
end
|
452
810
|
ensure
|
453
|
-
|
454
|
-
Fluent::HttpInput.module_eval do
|
455
|
-
remove_const(:Handler) if const_defined?(:Handler)
|
456
|
-
const_set(:Handler, orig_handler)
|
457
|
-
end
|
811
|
+
$test_in_http_content_types_flag = false
|
458
812
|
end
|
813
|
+
assert_equal(['application/json', ''], $test_in_http_content_types)
|
814
|
+
# Asserting keepalive
|
815
|
+
assert_equal $test_in_http_connection_object_ids[0], $test_in_http_connection_object_ids[1]
|
816
|
+
end
|
817
|
+
|
818
|
+
def options(path, params, header = {})
|
819
|
+
http = Net::HTTP.new("127.0.0.1", PORT)
|
820
|
+
req = Net::HTTP::Options.new(path, header)
|
821
|
+
http.request(req)
|
459
822
|
end
|
460
823
|
|
461
824
|
def post(path, params, header = {}, &block)
|
@@ -463,13 +826,26 @@ class HttpInputTest < Test::Unit::TestCase
|
|
463
826
|
req = Net::HTTP::Post.new(path, header)
|
464
827
|
block.call(http, req) if block
|
465
828
|
if params.is_a?(String)
|
829
|
+
unless header.has_key?('Content-Type')
|
830
|
+
header['Content-Type'] = 'application/octet-stream'
|
831
|
+
end
|
466
832
|
req.body = params
|
467
833
|
else
|
834
|
+
unless header.has_key?('Content-Type')
|
835
|
+
header['Content-Type'] = 'application/x-www-form-urlencoded'
|
836
|
+
end
|
468
837
|
req.set_form_data(params)
|
469
838
|
end
|
470
839
|
http.request(req)
|
471
840
|
end
|
472
841
|
|
842
|
+
def compress_gzip(data)
|
843
|
+
io = StringIO.new
|
844
|
+
io.binmode
|
845
|
+
Zlib::GzipWriter.wrap(io) { |gz| gz.write data }
|
846
|
+
return io.string
|
847
|
+
end
|
848
|
+
|
473
849
|
def include_http_header?(record)
|
474
850
|
record.keys.find { |header| header.start_with?('HTTP_') }
|
475
851
|
end
|