fluentd-hubspot 0.14.14.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.github/ISSUE_TEMPLATE.md +6 -0
- data/.gitignore +28 -0
- data/.travis.yml +51 -0
- data/AUTHORS +2 -0
- data/CONTRIBUTING.md +42 -0
- data/COPYING +14 -0
- data/ChangeLog +593 -0
- data/Gemfile +9 -0
- data/README.md +76 -0
- data/Rakefile +74 -0
- data/Vagrantfile +17 -0
- data/appveyor.yml +43 -0
- data/bin/fluent-binlog-reader +7 -0
- data/bin/fluent-debug +5 -0
- data/bin/fluent-plugin-config-format +5 -0
- data/bin/fluent-plugin-generate +5 -0
- data/code-of-conduct.md +3 -0
- data/example/copy_roundrobin.conf +39 -0
- data/example/filter_stdout.conf +22 -0
- data/example/in_dummy_blocks.conf +17 -0
- data/example/in_dummy_with_compression.conf +23 -0
- data/example/in_forward.conf +14 -0
- data/example/in_forward_client.conf +37 -0
- data/example/in_forward_shared_key.conf +15 -0
- data/example/in_forward_tls.conf +14 -0
- data/example/in_forward_users.conf +24 -0
- data/example/in_forward_workers.conf +21 -0
- data/example/in_http.conf +14 -0
- data/example/in_out_forward.conf +17 -0
- data/example/in_syslog.conf +15 -0
- data/example/in_tail.conf +14 -0
- data/example/in_tcp.conf +13 -0
- data/example/in_udp.conf +13 -0
- data/example/logevents.conf +25 -0
- data/example/multi_filters.conf +61 -0
- data/example/out_copy.conf +20 -0
- data/example/out_exec_filter.conf +42 -0
- data/example/out_file.conf +13 -0
- data/example/out_forward.conf +35 -0
- data/example/out_forward_buf_file.conf +23 -0
- data/example/out_forward_client.conf +109 -0
- data/example/out_forward_heartbeat_none.conf +16 -0
- data/example/out_forward_shared_key.conf +36 -0
- data/example/out_forward_tls.conf +18 -0
- data/example/out_forward_users.conf +65 -0
- data/example/out_null.conf +36 -0
- data/example/secondary_file.conf +41 -0
- data/example/suppress_config_dump.conf +7 -0
- data/example/v0_12_filter.conf +78 -0
- data/example/v1_literal_example.conf +36 -0
- data/fluent.conf +139 -0
- data/fluentd.gemspec +51 -0
- data/lib/fluent/agent.rb +163 -0
- data/lib/fluent/clock.rb +62 -0
- data/lib/fluent/command/binlog_reader.rb +234 -0
- data/lib/fluent/command/bundler_injection.rb +45 -0
- data/lib/fluent/command/cat.rb +330 -0
- data/lib/fluent/command/debug.rb +102 -0
- data/lib/fluent/command/fluentd.rb +301 -0
- data/lib/fluent/command/plugin_config_formatter.rb +258 -0
- data/lib/fluent/command/plugin_generator.rb +301 -0
- data/lib/fluent/compat/call_super_mixin.rb +67 -0
- data/lib/fluent/compat/detach_process_mixin.rb +25 -0
- data/lib/fluent/compat/exec_util.rb +129 -0
- data/lib/fluent/compat/file_util.rb +54 -0
- data/lib/fluent/compat/filter.rb +68 -0
- data/lib/fluent/compat/formatter.rb +111 -0
- data/lib/fluent/compat/formatter_utils.rb +85 -0
- data/lib/fluent/compat/handle_tag_and_time_mixin.rb +62 -0
- data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
- data/lib/fluent/compat/input.rb +59 -0
- data/lib/fluent/compat/output.rb +728 -0
- data/lib/fluent/compat/output_chain.rb +60 -0
- data/lib/fluent/compat/parser.rb +310 -0
- data/lib/fluent/compat/parser_utils.rb +40 -0
- data/lib/fluent/compat/propagate_default.rb +62 -0
- data/lib/fluent/compat/record_filter_mixin.rb +34 -0
- data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
- data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
- data/lib/fluent/compat/socket_util.rb +165 -0
- data/lib/fluent/compat/string_util.rb +34 -0
- data/lib/fluent/compat/structured_format_mixin.rb +26 -0
- data/lib/fluent/compat/type_converter.rb +90 -0
- data/lib/fluent/config.rb +56 -0
- data/lib/fluent/config/basic_parser.rb +123 -0
- data/lib/fluent/config/configure_proxy.rb +418 -0
- data/lib/fluent/config/dsl.rb +149 -0
- data/lib/fluent/config/element.rb +218 -0
- data/lib/fluent/config/error.rb +26 -0
- data/lib/fluent/config/literal_parser.rb +251 -0
- data/lib/fluent/config/parser.rb +107 -0
- data/lib/fluent/config/section.rb +223 -0
- data/lib/fluent/config/types.rb +136 -0
- data/lib/fluent/config/v1_parser.rb +190 -0
- data/lib/fluent/configurable.rb +200 -0
- data/lib/fluent/daemon.rb +15 -0
- data/lib/fluent/engine.rb +266 -0
- data/lib/fluent/env.rb +28 -0
- data/lib/fluent/error.rb +30 -0
- data/lib/fluent/event.rb +334 -0
- data/lib/fluent/event_router.rb +269 -0
- data/lib/fluent/filter.rb +21 -0
- data/lib/fluent/formatter.rb +23 -0
- data/lib/fluent/input.rb +21 -0
- data/lib/fluent/label.rb +46 -0
- data/lib/fluent/load.rb +35 -0
- data/lib/fluent/log.rb +546 -0
- data/lib/fluent/match.rb +178 -0
- data/lib/fluent/mixin.rb +31 -0
- data/lib/fluent/msgpack_factory.rb +62 -0
- data/lib/fluent/output.rb +29 -0
- data/lib/fluent/output_chain.rb +23 -0
- data/lib/fluent/parser.rb +23 -0
- data/lib/fluent/plugin.rb +183 -0
- data/lib/fluent/plugin/bare_output.rb +63 -0
- data/lib/fluent/plugin/base.rb +165 -0
- data/lib/fluent/plugin/buf_file.rb +184 -0
- data/lib/fluent/plugin/buf_memory.rb +34 -0
- data/lib/fluent/plugin/buffer.rb +617 -0
- data/lib/fluent/plugin/buffer/chunk.rb +221 -0
- data/lib/fluent/plugin/buffer/file_chunk.rb +364 -0
- data/lib/fluent/plugin/buffer/memory_chunk.rb +90 -0
- data/lib/fluent/plugin/compressable.rb +92 -0
- data/lib/fluent/plugin/exec_util.rb +22 -0
- data/lib/fluent/plugin/file_util.rb +22 -0
- data/lib/fluent/plugin/file_wrapper.rb +120 -0
- data/lib/fluent/plugin/filter.rb +93 -0
- data/lib/fluent/plugin/filter_grep.rb +75 -0
- data/lib/fluent/plugin/filter_parser.rb +119 -0
- data/lib/fluent/plugin/filter_record_transformer.rb +322 -0
- data/lib/fluent/plugin/filter_stdout.rb +53 -0
- data/lib/fluent/plugin/formatter.rb +50 -0
- data/lib/fluent/plugin/formatter_csv.rb +52 -0
- data/lib/fluent/plugin/formatter_hash.rb +33 -0
- data/lib/fluent/plugin/formatter_json.rb +55 -0
- data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
- data/lib/fluent/plugin/formatter_msgpack.rb +33 -0
- data/lib/fluent/plugin/formatter_out_file.rb +51 -0
- data/lib/fluent/plugin/formatter_single_value.rb +34 -0
- data/lib/fluent/plugin/formatter_stdout.rb +75 -0
- data/lib/fluent/plugin/formatter_tsv.rb +34 -0
- data/lib/fluent/plugin/in_debug_agent.rb +64 -0
- data/lib/fluent/plugin/in_dummy.rb +139 -0
- data/lib/fluent/plugin/in_exec.rb +108 -0
- data/lib/fluent/plugin/in_forward.rb +455 -0
- data/lib/fluent/plugin/in_gc_stat.rb +56 -0
- data/lib/fluent/plugin/in_http.rb +433 -0
- data/lib/fluent/plugin/in_monitor_agent.rb +448 -0
- data/lib/fluent/plugin/in_object_space.rb +93 -0
- data/lib/fluent/plugin/in_syslog.rb +209 -0
- data/lib/fluent/plugin/in_tail.rb +905 -0
- data/lib/fluent/plugin/in_tcp.rb +85 -0
- data/lib/fluent/plugin/in_udp.rb +81 -0
- data/lib/fluent/plugin/in_unix.rb +201 -0
- data/lib/fluent/plugin/input.rb +37 -0
- data/lib/fluent/plugin/multi_output.rb +157 -0
- data/lib/fluent/plugin/out_copy.rb +46 -0
- data/lib/fluent/plugin/out_exec.rb +105 -0
- data/lib/fluent/plugin/out_exec_filter.rb +317 -0
- data/lib/fluent/plugin/out_file.rb +302 -0
- data/lib/fluent/plugin/out_forward.rb +912 -0
- data/lib/fluent/plugin/out_null.rb +74 -0
- data/lib/fluent/plugin/out_relabel.rb +32 -0
- data/lib/fluent/plugin/out_roundrobin.rb +84 -0
- data/lib/fluent/plugin/out_secondary_file.rb +133 -0
- data/lib/fluent/plugin/out_stdout.rb +75 -0
- data/lib/fluent/plugin/out_stream.rb +130 -0
- data/lib/fluent/plugin/output.rb +1291 -0
- data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
- data/lib/fluent/plugin/parser.rb +191 -0
- data/lib/fluent/plugin/parser_apache.rb +28 -0
- data/lib/fluent/plugin/parser_apache2.rb +84 -0
- data/lib/fluent/plugin/parser_apache_error.rb +26 -0
- data/lib/fluent/plugin/parser_csv.rb +39 -0
- data/lib/fluent/plugin/parser_json.rb +81 -0
- data/lib/fluent/plugin/parser_ltsv.rb +42 -0
- data/lib/fluent/plugin/parser_msgpack.rb +50 -0
- data/lib/fluent/plugin/parser_multiline.rb +105 -0
- data/lib/fluent/plugin/parser_nginx.rb +28 -0
- data/lib/fluent/plugin/parser_none.rb +36 -0
- data/lib/fluent/plugin/parser_regexp.rb +63 -0
- data/lib/fluent/plugin/parser_syslog.rb +121 -0
- data/lib/fluent/plugin/parser_tsv.rb +42 -0
- data/lib/fluent/plugin/socket_util.rb +22 -0
- data/lib/fluent/plugin/storage.rb +84 -0
- data/lib/fluent/plugin/storage_local.rb +159 -0
- data/lib/fluent/plugin/string_util.rb +22 -0
- data/lib/fluent/plugin_helper.rb +70 -0
- data/lib/fluent/plugin_helper/cert_option.rb +159 -0
- data/lib/fluent/plugin_helper/child_process.rb +364 -0
- data/lib/fluent/plugin_helper/compat_parameters.rb +331 -0
- data/lib/fluent/plugin_helper/event_emitter.rb +93 -0
- data/lib/fluent/plugin_helper/event_loop.rb +161 -0
- data/lib/fluent/plugin_helper/extract.rb +104 -0
- data/lib/fluent/plugin_helper/formatter.rb +147 -0
- data/lib/fluent/plugin_helper/inject.rb +151 -0
- data/lib/fluent/plugin_helper/parser.rb +147 -0
- data/lib/fluent/plugin_helper/retry_state.rb +201 -0
- data/lib/fluent/plugin_helper/server.rb +738 -0
- data/lib/fluent/plugin_helper/socket.rb +241 -0
- data/lib/fluent/plugin_helper/socket_option.rb +69 -0
- data/lib/fluent/plugin_helper/storage.rb +349 -0
- data/lib/fluent/plugin_helper/thread.rb +179 -0
- data/lib/fluent/plugin_helper/timer.rb +91 -0
- data/lib/fluent/plugin_id.rb +80 -0
- data/lib/fluent/process.rb +22 -0
- data/lib/fluent/registry.rb +116 -0
- data/lib/fluent/root_agent.rb +323 -0
- data/lib/fluent/rpc.rb +94 -0
- data/lib/fluent/supervisor.rb +741 -0
- data/lib/fluent/system_config.rb +159 -0
- data/lib/fluent/test.rb +58 -0
- data/lib/fluent/test/base.rb +78 -0
- data/lib/fluent/test/driver/base.rb +224 -0
- data/lib/fluent/test/driver/base_owned.rb +70 -0
- data/lib/fluent/test/driver/base_owner.rb +135 -0
- data/lib/fluent/test/driver/event_feeder.rb +98 -0
- data/lib/fluent/test/driver/filter.rb +57 -0
- data/lib/fluent/test/driver/formatter.rb +30 -0
- data/lib/fluent/test/driver/input.rb +31 -0
- data/lib/fluent/test/driver/multi_output.rb +53 -0
- data/lib/fluent/test/driver/output.rb +102 -0
- data/lib/fluent/test/driver/parser.rb +30 -0
- data/lib/fluent/test/driver/test_event_router.rb +45 -0
- data/lib/fluent/test/filter_test.rb +77 -0
- data/lib/fluent/test/formatter_test.rb +65 -0
- data/lib/fluent/test/helpers.rb +134 -0
- data/lib/fluent/test/input_test.rb +174 -0
- data/lib/fluent/test/log.rb +79 -0
- data/lib/fluent/test/output_test.rb +156 -0
- data/lib/fluent/test/parser_test.rb +70 -0
- data/lib/fluent/test/startup_shutdown.rb +46 -0
- data/lib/fluent/time.rb +412 -0
- data/lib/fluent/timezone.rb +133 -0
- data/lib/fluent/unique_id.rb +39 -0
- data/lib/fluent/version.rb +21 -0
- data/lib/fluent/winsvc.rb +71 -0
- data/templates/new_gem/Gemfile +3 -0
- data/templates/new_gem/README.md.erb +43 -0
- data/templates/new_gem/Rakefile +13 -0
- data/templates/new_gem/fluent-plugin.gemspec.erb +27 -0
- data/templates/new_gem/lib/fluent/plugin/filter.rb.erb +14 -0
- data/templates/new_gem/lib/fluent/plugin/formatter.rb.erb +14 -0
- data/templates/new_gem/lib/fluent/plugin/input.rb.erb +11 -0
- data/templates/new_gem/lib/fluent/plugin/output.rb.erb +11 -0
- data/templates/new_gem/lib/fluent/plugin/parser.rb.erb +15 -0
- data/templates/new_gem/test/helper.rb.erb +8 -0
- data/templates/new_gem/test/plugin/test_filter.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_formatter.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_input.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_output.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_parser.rb.erb +18 -0
- data/templates/plugin_config_formatter/param.md-compact.erb +25 -0
- data/templates/plugin_config_formatter/param.md.erb +34 -0
- data/templates/plugin_config_formatter/section.md.erb +12 -0
- data/test/command/test_binlog_reader.rb +346 -0
- data/test/command/test_fluentd.rb +618 -0
- data/test/command/test_plugin_config_formatter.rb +275 -0
- data/test/command/test_plugin_generator.rb +66 -0
- data/test/compat/test_calls_super.rb +166 -0
- data/test/compat/test_parser.rb +92 -0
- data/test/config/assertions.rb +42 -0
- data/test/config/test_config_parser.rb +513 -0
- data/test/config/test_configurable.rb +1587 -0
- data/test/config/test_configure_proxy.rb +566 -0
- data/test/config/test_dsl.rb +415 -0
- data/test/config/test_element.rb +403 -0
- data/test/config/test_literal_parser.rb +297 -0
- data/test/config/test_section.rb +184 -0
- data/test/config/test_system_config.rb +168 -0
- data/test/config/test_types.rb +191 -0
- data/test/helper.rb +153 -0
- data/test/plugin/data/2010/01/20100102-030405.log +0 -0
- data/test/plugin/data/2010/01/20100102-030406.log +0 -0
- data/test/plugin/data/2010/01/20100102.log +0 -0
- data/test/plugin/data/log/bar +0 -0
- data/test/plugin/data/log/foo/bar.log +0 -0
- data/test/plugin/data/log/foo/bar2 +0 -0
- data/test/plugin/data/log/test.log +0 -0
- data/test/plugin/test_bare_output.rb +118 -0
- data/test/plugin/test_base.rb +115 -0
- data/test/plugin/test_buf_file.rb +843 -0
- data/test/plugin/test_buf_memory.rb +42 -0
- data/test/plugin/test_buffer.rb +1220 -0
- data/test/plugin/test_buffer_chunk.rb +198 -0
- data/test/plugin/test_buffer_file_chunk.rb +844 -0
- data/test/plugin/test_buffer_memory_chunk.rb +338 -0
- data/test/plugin/test_compressable.rb +84 -0
- data/test/plugin/test_file_util.rb +96 -0
- data/test/plugin/test_filter.rb +357 -0
- data/test/plugin/test_filter_grep.rb +119 -0
- data/test/plugin/test_filter_parser.rb +700 -0
- data/test/plugin/test_filter_record_transformer.rb +556 -0
- data/test/plugin/test_filter_stdout.rb +202 -0
- data/test/plugin/test_formatter_csv.rb +111 -0
- data/test/plugin/test_formatter_hash.rb +35 -0
- data/test/plugin/test_formatter_json.rb +51 -0
- data/test/plugin/test_formatter_ltsv.rb +59 -0
- data/test/plugin/test_formatter_msgpack.rb +28 -0
- data/test/plugin/test_formatter_out_file.rb +95 -0
- data/test/plugin/test_formatter_single_value.rb +38 -0
- data/test/plugin/test_in_debug_agent.rb +28 -0
- data/test/plugin/test_in_dummy.rb +192 -0
- data/test/plugin/test_in_exec.rb +245 -0
- data/test/plugin/test_in_forward.rb +1120 -0
- data/test/plugin/test_in_gc_stat.rb +39 -0
- data/test/plugin/test_in_http.rb +588 -0
- data/test/plugin/test_in_monitor_agent.rb +516 -0
- data/test/plugin/test_in_object_space.rb +64 -0
- data/test/plugin/test_in_syslog.rb +271 -0
- data/test/plugin/test_in_tail.rb +1216 -0
- data/test/plugin/test_in_tcp.rb +118 -0
- data/test/plugin/test_in_udp.rb +152 -0
- data/test/plugin/test_in_unix.rb +126 -0
- data/test/plugin/test_input.rb +126 -0
- data/test/plugin/test_multi_output.rb +180 -0
- data/test/plugin/test_out_copy.rb +160 -0
- data/test/plugin/test_out_exec.rb +310 -0
- data/test/plugin/test_out_exec_filter.rb +613 -0
- data/test/plugin/test_out_file.rb +873 -0
- data/test/plugin/test_out_forward.rb +685 -0
- data/test/plugin/test_out_null.rb +105 -0
- data/test/plugin/test_out_relabel.rb +28 -0
- data/test/plugin/test_out_roundrobin.rb +146 -0
- data/test/plugin/test_out_secondary_file.rb +442 -0
- data/test/plugin/test_out_stdout.rb +170 -0
- data/test/plugin/test_out_stream.rb +93 -0
- data/test/plugin/test_output.rb +870 -0
- data/test/plugin/test_output_as_buffered.rb +1932 -0
- data/test/plugin/test_output_as_buffered_compress.rb +165 -0
- data/test/plugin/test_output_as_buffered_overflow.rb +250 -0
- data/test/plugin/test_output_as_buffered_retries.rb +839 -0
- data/test/plugin/test_output_as_buffered_secondary.rb +877 -0
- data/test/plugin/test_output_as_standard.rb +374 -0
- data/test/plugin/test_owned_by.rb +35 -0
- data/test/plugin/test_parser.rb +359 -0
- data/test/plugin/test_parser_apache.rb +42 -0
- data/test/plugin/test_parser_apache2.rb +46 -0
- data/test/plugin/test_parser_apache_error.rb +45 -0
- data/test/plugin/test_parser_csv.rb +103 -0
- data/test/plugin/test_parser_json.rb +114 -0
- data/test/plugin/test_parser_labeled_tsv.rb +128 -0
- data/test/plugin/test_parser_multiline.rb +100 -0
- data/test/plugin/test_parser_nginx.rb +48 -0
- data/test/plugin/test_parser_none.rb +52 -0
- data/test/plugin/test_parser_regexp.rb +281 -0
- data/test/plugin/test_parser_syslog.rb +242 -0
- data/test/plugin/test_parser_tsv.rb +122 -0
- data/test/plugin/test_storage.rb +167 -0
- data/test/plugin/test_storage_local.rb +335 -0
- data/test/plugin/test_string_util.rb +26 -0
- data/test/plugin_helper/test_child_process.rb +794 -0
- data/test/plugin_helper/test_compat_parameters.rb +331 -0
- data/test/plugin_helper/test_event_emitter.rb +51 -0
- data/test/plugin_helper/test_event_loop.rb +52 -0
- data/test/plugin_helper/test_extract.rb +194 -0
- data/test/plugin_helper/test_formatter.rb +255 -0
- data/test/plugin_helper/test_inject.rb +519 -0
- data/test/plugin_helper/test_parser.rb +264 -0
- data/test/plugin_helper/test_retry_state.rb +422 -0
- data/test/plugin_helper/test_server.rb +1677 -0
- data/test/plugin_helper/test_storage.rb +542 -0
- data/test/plugin_helper/test_thread.rb +164 -0
- data/test/plugin_helper/test_timer.rb +132 -0
- data/test/scripts/exec_script.rb +32 -0
- data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +7 -0
- data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +7 -0
- data/test/scripts/fluent/plugin/formatter_known.rb +8 -0
- data/test/scripts/fluent/plugin/out_test.rb +81 -0
- data/test/scripts/fluent/plugin/out_test2.rb +80 -0
- data/test/scripts/fluent/plugin/parser_known.rb +4 -0
- data/test/test_clock.rb +164 -0
- data/test/test_config.rb +179 -0
- data/test/test_configdsl.rb +148 -0
- data/test/test_event.rb +515 -0
- data/test/test_event_router.rb +331 -0
- data/test/test_event_time.rb +186 -0
- data/test/test_filter.rb +121 -0
- data/test/test_formatter.rb +312 -0
- data/test/test_input.rb +31 -0
- data/test/test_log.rb +828 -0
- data/test/test_match.rb +137 -0
- data/test/test_mixin.rb +351 -0
- data/test/test_output.rb +273 -0
- data/test/test_plugin.rb +251 -0
- data/test/test_plugin_classes.rb +253 -0
- data/test/test_plugin_helper.rb +81 -0
- data/test/test_plugin_id.rb +101 -0
- data/test/test_process.rb +14 -0
- data/test/test_root_agent.rb +611 -0
- data/test/test_supervisor.rb +373 -0
- data/test/test_test_drivers.rb +135 -0
- data/test/test_time_formatter.rb +282 -0
- data/test/test_time_parser.rb +211 -0
- data/test/test_unique_id.rb +47 -0
- metadata +898 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/test/driver/input'
|
3
|
+
require 'fluent/plugin/in_gc_stat'
|
4
|
+
|
5
|
+
class GCStatInputTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
Fluent::Test.setup
|
8
|
+
end
|
9
|
+
|
10
|
+
CONFIG = %[
|
11
|
+
emit_interval 1
|
12
|
+
tag t1
|
13
|
+
]
|
14
|
+
|
15
|
+
def create_driver(conf=CONFIG)
|
16
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::GCStatInput).configure(conf)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_configure
|
20
|
+
d = create_driver
|
21
|
+
assert_equal(1, d.instance.emit_interval)
|
22
|
+
assert_equal("t1", d.instance.tag)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_emit
|
26
|
+
stat = GC.stat
|
27
|
+
stub(GC).stat { stat }
|
28
|
+
|
29
|
+
d = create_driver
|
30
|
+
d.run(expect_emits: 2)
|
31
|
+
|
32
|
+
events = d.events
|
33
|
+
assert(events.length > 0)
|
34
|
+
events.each_index {|i|
|
35
|
+
assert_equal(stat, events[i][2])
|
36
|
+
assert(events[i][1].is_a?(Fluent::EventTime))
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,588 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/test/driver/input'
|
3
|
+
require 'fluent/plugin/in_http'
|
4
|
+
require 'net/http'
|
5
|
+
require 'timecop'
|
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
|
+
|
20
|
+
def setup
|
21
|
+
Fluent::Test.setup
|
22
|
+
end
|
23
|
+
|
24
|
+
def teardown
|
25
|
+
Timecop.return
|
26
|
+
end
|
27
|
+
|
28
|
+
PORT = unused_port
|
29
|
+
CONFIG = %[
|
30
|
+
port #{PORT}
|
31
|
+
bind "127.0.0.1"
|
32
|
+
body_size_limit 10m
|
33
|
+
keepalive_timeout 5
|
34
|
+
respond_with_empty_img true
|
35
|
+
]
|
36
|
+
|
37
|
+
def create_driver(conf=CONFIG)
|
38
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::HttpInput).configure(conf)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_configure
|
42
|
+
d = create_driver
|
43
|
+
assert_equal PORT, d.instance.port
|
44
|
+
assert_equal '127.0.0.1', d.instance.bind
|
45
|
+
assert_equal 10*1024*1024, d.instance.body_size_limit
|
46
|
+
assert_equal 5, d.instance.keepalive_timeout
|
47
|
+
assert_equal false, d.instance.add_http_headers
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_time
|
51
|
+
d = create_driver
|
52
|
+
time = event_time("2011-01-02 13:14:15.123 UTC")
|
53
|
+
Timecop.freeze(Time.at(time))
|
54
|
+
|
55
|
+
events = [
|
56
|
+
["tag1", time, {"a" => 1}],
|
57
|
+
["tag2", time, {"a" => 2}],
|
58
|
+
]
|
59
|
+
res_codes = []
|
60
|
+
|
61
|
+
d.run(expect_records: 2) do
|
62
|
+
events.each do |tag, _time, record|
|
63
|
+
res = post("/#{tag}", {"json"=>record.to_json})
|
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
|
89
|
+
end
|
90
|
+
assert_equal ["200"], res_codes
|
91
|
+
assert_equal events, d.events
|
92
|
+
assert_equal_event_time time, d.events[0][1]
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_json
|
96
|
+
d = create_driver
|
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
|
111
|
+
end
|
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]
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_multi_json
|
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
|
139
|
+
|
140
|
+
def test_json_with_add_remote_addr
|
141
|
+
d = create_driver(CONFIG + "add_remote_addr true")
|
142
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
143
|
+
time_i = time.to_i
|
144
|
+
|
145
|
+
events = [
|
146
|
+
["tag1", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>1}],
|
147
|
+
["tag2", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>2}],
|
148
|
+
]
|
149
|
+
res_codes = []
|
150
|
+
d.run(expect_records: 2) do
|
151
|
+
events.each do |tag, _t, record|
|
152
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
|
153
|
+
res_codes << res.code
|
154
|
+
end
|
155
|
+
end
|
156
|
+
assert_equal ["200", "200"], res_codes
|
157
|
+
assert_equal events, d.events
|
158
|
+
assert_equal_event_time time, d.events[0][1]
|
159
|
+
assert_equal_event_time time, d.events[1][1]
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_multi_json_with_add_remote_addr
|
163
|
+
d = create_driver(CONFIG + "add_remote_addr true")
|
164
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
165
|
+
time_i = time.to_i
|
166
|
+
|
167
|
+
records = [{"a"=>1},{"a"=>2}]
|
168
|
+
tag = "tag1"
|
169
|
+
res_codes = []
|
170
|
+
|
171
|
+
d.run(expect_records: 2, timeout: 5) do
|
172
|
+
res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s})
|
173
|
+
res_codes << res.code
|
174
|
+
end
|
175
|
+
assert_equal ["200"], res_codes
|
176
|
+
|
177
|
+
assert_equal "tag1", d.events[0][0]
|
178
|
+
assert_equal_event_time time, d.events[0][1]
|
179
|
+
assert_equal 1, d.events[0][2]["a"]
|
180
|
+
assert{ d.events[0][2].has_key?("REMOTE_ADDR") && d.events[0][2]["REMOTE_ADDR"] =~ /^\d{1,4}(\.\d{1,4}){3}$/ }
|
181
|
+
|
182
|
+
assert_equal "tag1", d.events[1][0]
|
183
|
+
assert_equal_event_time time, d.events[1][1]
|
184
|
+
assert_equal 2, d.events[1][2]["a"]
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_json_with_add_remote_addr_given_x_forwarded_for
|
188
|
+
d = create_driver(CONFIG + "add_remote_addr true")
|
189
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
190
|
+
time_i = time.to_i
|
191
|
+
|
192
|
+
events = [
|
193
|
+
["tag1", time, {"a"=>1}],
|
194
|
+
["tag2", time, {"a"=>2}],
|
195
|
+
]
|
196
|
+
res_codes = []
|
197
|
+
|
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}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
|
201
|
+
res_codes << res.code
|
202
|
+
end
|
203
|
+
end
|
204
|
+
assert_equal ["200", "200"], res_codes
|
205
|
+
|
206
|
+
assert_equal "tag1", d.events[0][0]
|
207
|
+
assert_equal_event_time time, d.events[0][1]
|
208
|
+
assert_equal({"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}, d.events[0][2])
|
209
|
+
|
210
|
+
assert_equal "tag2", d.events[1][0]
|
211
|
+
assert_equal_event_time time, d.events[1][1]
|
212
|
+
assert_equal({"REMOTE_ADDR"=>"129.78.138.66", "a"=>2}, d.events[1][2])
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_multi_json_with_add_remote_addr_given_x_forwarded_for
|
216
|
+
d = create_driver(CONFIG + "add_remote_addr true")
|
217
|
+
|
218
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
219
|
+
time_i = time.to_i
|
220
|
+
records = [{"a"=>1},{"a"=>2}]
|
221
|
+
events = [
|
222
|
+
["tag1", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}],
|
223
|
+
["tag1", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>2}],
|
224
|
+
]
|
225
|
+
tag = "tag1"
|
226
|
+
res_codes = []
|
227
|
+
|
228
|
+
d.run(expect_records: 2, timeout: 5) do
|
229
|
+
res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
|
230
|
+
res_codes << res.code
|
231
|
+
end
|
232
|
+
assert_equal ["200"], res_codes
|
233
|
+
assert_equal events, d.events
|
234
|
+
assert_equal_event_time time, d.events[0][1]
|
235
|
+
assert_equal_event_time time, d.events[1][1]
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_multi_json_with_add_http_headers
|
239
|
+
d = create_driver(CONFIG + "add_http_headers true")
|
240
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
241
|
+
time_i = time.to_i
|
242
|
+
records = [{"a"=>1},{"a"=>2}]
|
243
|
+
tag = "tag1"
|
244
|
+
res_codes = []
|
245
|
+
|
246
|
+
d.run(expect_records: 2, timeout: 5) do
|
247
|
+
res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s})
|
248
|
+
res_codes << res.code
|
249
|
+
end
|
250
|
+
assert_equal ["200"], res_codes
|
251
|
+
|
252
|
+
assert_equal "tag1", d.events[0][0]
|
253
|
+
assert_equal_event_time time, d.events[0][1]
|
254
|
+
assert_equal 1, d.events[0][2]["a"]
|
255
|
+
|
256
|
+
assert_equal "tag1", d.events[1][0]
|
257
|
+
assert_equal_event_time time, d.events[1][1]
|
258
|
+
assert_equal 2, d.events[1][2]["a"]
|
259
|
+
|
260
|
+
assert include_http_header?(d.events[0][2])
|
261
|
+
assert include_http_header?(d.events[1][2])
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_json_with_add_http_headers
|
265
|
+
d = create_driver(CONFIG + "add_http_headers true")
|
266
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
267
|
+
time_i = time.to_i
|
268
|
+
events = [
|
269
|
+
["tag1", time, {"a"=>1}],
|
270
|
+
["tag2", time, {"a"=>2}],
|
271
|
+
]
|
272
|
+
res_codes = []
|
273
|
+
|
274
|
+
d.run(expect_records: 2) do
|
275
|
+
events.each do |tag, t, record|
|
276
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
|
277
|
+
res_codes << res.code
|
278
|
+
end
|
279
|
+
end
|
280
|
+
assert_equal ["200", "200"], res_codes
|
281
|
+
|
282
|
+
assert_equal "tag1", d.events[0][0]
|
283
|
+
assert_equal_event_time time, d.events[0][1]
|
284
|
+
assert_equal 1, d.events[0][2]["a"]
|
285
|
+
|
286
|
+
assert_equal "tag2", d.events[1][0]
|
287
|
+
assert_equal_event_time time, d.events[1][1]
|
288
|
+
assert_equal 2, d.events[1][2]["a"]
|
289
|
+
|
290
|
+
assert include_http_header?(d.events[0][2])
|
291
|
+
assert include_http_header?(d.events[1][2])
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_application_json
|
295
|
+
d = create_driver
|
296
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
297
|
+
time_i = time.to_i
|
298
|
+
events = [
|
299
|
+
["tag1", time, {"a"=>1}],
|
300
|
+
["tag2", time, {"a"=>2}],
|
301
|
+
]
|
302
|
+
res_codes = []
|
303
|
+
|
304
|
+
d.run(expect_records: 2) do
|
305
|
+
events.each do |tag, t, record|
|
306
|
+
res = post("/#{tag}?time=#{time_i.to_s}", record.to_json, {"Content-Type"=>"application/json; charset=utf-8"})
|
307
|
+
res_codes << res.code
|
308
|
+
end
|
309
|
+
end
|
310
|
+
assert_equal ["200", "200"], res_codes
|
311
|
+
assert_equal events, d.events
|
312
|
+
assert_equal_event_time time, d.events[0][1]
|
313
|
+
assert_equal_event_time time, d.events[1][1]
|
314
|
+
end
|
315
|
+
|
316
|
+
def test_application_msgpack
|
317
|
+
d = create_driver
|
318
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
319
|
+
time_i = time.to_i
|
320
|
+
events = [
|
321
|
+
["tag1", time, {"a"=>1}],
|
322
|
+
["tag2", time, {"a"=>2}],
|
323
|
+
]
|
324
|
+
res_codes = []
|
325
|
+
|
326
|
+
d.run(expect_records: 2) do
|
327
|
+
events.each do |tag, t, record|
|
328
|
+
res = post("/#{tag}?time=#{time_i.to_s}", record.to_msgpack, {"Content-Type"=>"application/msgpack"})
|
329
|
+
res_codes << res.code
|
330
|
+
end
|
331
|
+
end
|
332
|
+
assert_equal ["200", "200"], res_codes
|
333
|
+
assert_equal events, d.events
|
334
|
+
assert_equal_event_time time, d.events[0][1]
|
335
|
+
assert_equal_event_time time, d.events[1][1]
|
336
|
+
end
|
337
|
+
|
338
|
+
def test_msgpack
|
339
|
+
d = create_driver
|
340
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
341
|
+
time_i = time.to_i
|
342
|
+
|
343
|
+
events = [
|
344
|
+
["tag1", time, {"a"=>1}],
|
345
|
+
["tag2", time, {"a"=>2}],
|
346
|
+
]
|
347
|
+
res_codes = []
|
348
|
+
|
349
|
+
d.run(expect_records: 2) do
|
350
|
+
events.each do |tag, t, record|
|
351
|
+
res = post("/#{tag}", {"msgpack"=>record.to_msgpack, "time"=>time_i.to_s})
|
352
|
+
res_codes << res.code
|
353
|
+
end
|
354
|
+
end
|
355
|
+
assert_equal ["200", "200"], res_codes
|
356
|
+
assert_equal events, d.events
|
357
|
+
assert_equal_event_time time, d.events[0][1]
|
358
|
+
assert_equal_event_time time, d.events[1][1]
|
359
|
+
end
|
360
|
+
|
361
|
+
def test_multi_msgpack
|
362
|
+
d = create_driver
|
363
|
+
|
364
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
365
|
+
time_i = time.to_i
|
366
|
+
|
367
|
+
records = [{"a"=>1},{"a"=>2}]
|
368
|
+
events = [
|
369
|
+
["tag1", time, records[0]],
|
370
|
+
["tag1", time, records[1]],
|
371
|
+
]
|
372
|
+
tag = "tag1"
|
373
|
+
res_codes = []
|
374
|
+
d.run(expect_records: 2) do
|
375
|
+
res = post("/#{tag}", {"msgpack"=>records.to_msgpack, "time"=>time_i.to_s})
|
376
|
+
res_codes << res.code
|
377
|
+
end
|
378
|
+
assert_equal ["200"], res_codes
|
379
|
+
assert_equal events, d.events
|
380
|
+
assert_equal_event_time time, d.events[0][1]
|
381
|
+
assert_equal_event_time time, d.events[1][1]
|
382
|
+
end
|
383
|
+
|
384
|
+
def test_with_regexp
|
385
|
+
d = create_driver(CONFIG + %[
|
386
|
+
format /^(?<field_1>\\d+):(?<field_2>\\w+)$/
|
387
|
+
types field_1:integer
|
388
|
+
])
|
389
|
+
|
390
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
391
|
+
time_i = time.to_i
|
392
|
+
events = [
|
393
|
+
["tag1", time, {"field_1" => 1, "field_2" => 'str'}],
|
394
|
+
["tag2", time, {"field_1" => 2, "field_2" => 'str'}],
|
395
|
+
]
|
396
|
+
res_codes = []
|
397
|
+
|
398
|
+
d.run(expect_records: 2) do
|
399
|
+
events.each do |tag, t, record|
|
400
|
+
body = record.map { |k, v|
|
401
|
+
v.to_s
|
402
|
+
}.join(':')
|
403
|
+
res = post("/#{tag}?time=#{time_i.to_s}", body, {'Content-Type' => 'application/octet-stream'})
|
404
|
+
res_codes << res.code
|
405
|
+
end
|
406
|
+
end
|
407
|
+
assert_equal ["200", "200"], res_codes
|
408
|
+
assert_equal events, d.events
|
409
|
+
assert_equal_event_time time, d.events[0][1]
|
410
|
+
assert_equal_event_time time, d.events[1][1]
|
411
|
+
end
|
412
|
+
|
413
|
+
def test_with_csv
|
414
|
+
require 'csv'
|
415
|
+
|
416
|
+
d = create_driver(CONFIG + %[
|
417
|
+
format csv
|
418
|
+
keys foo,bar
|
419
|
+
])
|
420
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
421
|
+
time_i = time.to_i
|
422
|
+
events = [
|
423
|
+
["tag1", time, {"foo" => "1", "bar" => 'st"r'}],
|
424
|
+
["tag2", time, {"foo" => "2", "bar" => 'str'}],
|
425
|
+
]
|
426
|
+
res_codes = []
|
427
|
+
|
428
|
+
d.run(expect_records: 2) do
|
429
|
+
events.each do |tag, t, record|
|
430
|
+
body = record.map { |k, v| v }.to_csv
|
431
|
+
res = post("/#{tag}?time=#{time_i.to_s}", body, {'Content-Type' => 'text/comma-separated-values'})
|
432
|
+
res_codes << res.code
|
433
|
+
end
|
434
|
+
end
|
435
|
+
assert_equal ["200", "200"], res_codes
|
436
|
+
assert_equal events, d.events
|
437
|
+
assert_equal_event_time time, d.events[0][1]
|
438
|
+
assert_equal_event_time time, d.events[1][1]
|
439
|
+
end
|
440
|
+
|
441
|
+
def test_resonse_with_empty_img
|
442
|
+
d = create_driver(CONFIG + "respond_with_empty_img true")
|
443
|
+
assert_equal true, d.instance.respond_with_empty_img
|
444
|
+
|
445
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
446
|
+
time_i = time.to_i
|
447
|
+
events = [
|
448
|
+
["tag1", time, {"a"=>1}],
|
449
|
+
["tag2", time, {"a"=>2}],
|
450
|
+
]
|
451
|
+
res_codes = []
|
452
|
+
res_bodies = []
|
453
|
+
|
454
|
+
d.run do
|
455
|
+
events.each do |tag, _t, record|
|
456
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
|
457
|
+
res_codes << res.code
|
458
|
+
# Ruby returns ASCII-8 encoded string for GIF.
|
459
|
+
res_bodies << res.body.force_encoding("UTF-8")
|
460
|
+
end
|
461
|
+
end
|
462
|
+
assert_equal ["200", "200"], res_codes
|
463
|
+
assert_equal [Fluent::Plugin::HttpInput::EMPTY_GIF_IMAGE, Fluent::Plugin::HttpInput::EMPTY_GIF_IMAGE], res_bodies
|
464
|
+
assert_equal events, d.events
|
465
|
+
assert_equal_event_time time, d.events[0][1]
|
466
|
+
assert_equal_event_time time, d.events[1][1]
|
467
|
+
end
|
468
|
+
|
469
|
+
def test_cors_allowed
|
470
|
+
d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
|
471
|
+
assert_equal ["http://foo.com"], d.instance.cors_allow_origins
|
472
|
+
|
473
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
474
|
+
time_i = time.to_i
|
475
|
+
events = [
|
476
|
+
["tag1", time, {"a"=>1}],
|
477
|
+
["tag2", time, {"a"=>2}],
|
478
|
+
]
|
479
|
+
res_codes = []
|
480
|
+
res_headers = []
|
481
|
+
|
482
|
+
d.run do
|
483
|
+
events.each do |tag, _t, record|
|
484
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://foo.com"})
|
485
|
+
res_codes << res.code
|
486
|
+
res_headers << res["Access-Control-Allow-Origin"]
|
487
|
+
end
|
488
|
+
end
|
489
|
+
assert_equal ["200", "200"], res_codes
|
490
|
+
assert_equal ["http://foo.com", "http://foo.com"], res_headers
|
491
|
+
assert_equal events, d.events
|
492
|
+
assert_equal_event_time time, d.events[0][1]
|
493
|
+
assert_equal_event_time time, d.events[1][1]
|
494
|
+
end
|
495
|
+
|
496
|
+
def test_cors_disallowed
|
497
|
+
d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
|
498
|
+
assert_equal ["http://foo.com"], d.instance.cors_allow_origins
|
499
|
+
|
500
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
501
|
+
time_i = time.to_i
|
502
|
+
res_codes = []
|
503
|
+
|
504
|
+
d.end_if{ res_codes.size == 2 }
|
505
|
+
d.run do
|
506
|
+
res = post("/tag1", {"json"=>{"a"=>1}.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://bar.com"})
|
507
|
+
res_codes << res.code
|
508
|
+
res = post("/tag2", {"json"=>{"a"=>1}.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://bar.com"})
|
509
|
+
res_codes << res.code
|
510
|
+
end
|
511
|
+
assert_equal ["403", "403"], res_codes
|
512
|
+
end
|
513
|
+
|
514
|
+
$test_in_http_connection_object_ids = []
|
515
|
+
$test_in_http_content_types = []
|
516
|
+
$test_in_http_content_types_flag = false
|
517
|
+
module ContentTypeHook
|
518
|
+
def initialize(*args)
|
519
|
+
@io_handler = nil
|
520
|
+
super
|
521
|
+
end
|
522
|
+
def on_headers_complete(headers)
|
523
|
+
super
|
524
|
+
if $test_in_http_content_types_flag
|
525
|
+
$test_in_http_content_types << self.content_type
|
526
|
+
end
|
527
|
+
end
|
528
|
+
|
529
|
+
def on_message_begin
|
530
|
+
super
|
531
|
+
if $test_in_http_content_types_flag
|
532
|
+
$test_in_http_connection_object_ids << @io_handler.object_id
|
533
|
+
end
|
534
|
+
end
|
535
|
+
end
|
536
|
+
|
537
|
+
class Fluent::Plugin::HttpInput::Handler
|
538
|
+
prepend ContentTypeHook
|
539
|
+
end
|
540
|
+
|
541
|
+
def test_if_content_type_is_initialized_properly
|
542
|
+
# This test is to check if Fluent::HttpInput::Handler's @content_type is initialized properly.
|
543
|
+
# Especially when in Keep-Alive and the second request has no 'Content-Type'.
|
544
|
+
|
545
|
+
begin
|
546
|
+
d = create_driver
|
547
|
+
|
548
|
+
$test_in_http_content_types_flag = true
|
549
|
+
d.run do
|
550
|
+
# Send two requests the second one has no Content-Type in Keep-Alive
|
551
|
+
Net::HTTP.start("127.0.0.1", PORT) do |http|
|
552
|
+
req = Net::HTTP::Post.new("/foodb/bartbl", {"connection" => "keepalive", "Content-Type" => "application/json"})
|
553
|
+
res = http.request(req)
|
554
|
+
|
555
|
+
req = Net::HTTP::Get.new("/foodb/bartbl", {"connection" => "keepalive"})
|
556
|
+
res = http.request(req)
|
557
|
+
end
|
558
|
+
|
559
|
+
end
|
560
|
+
ensure
|
561
|
+
$test_in_http_content_types_flag = false
|
562
|
+
end
|
563
|
+
assert_equal(['application/json', ''], $test_in_http_content_types)
|
564
|
+
# Asserting keepalive
|
565
|
+
assert_equal $test_in_http_connection_object_ids[0], $test_in_http_connection_object_ids[1]
|
566
|
+
end
|
567
|
+
|
568
|
+
def post(path, params, header = {})
|
569
|
+
http = Net::HTTP.new("127.0.0.1", PORT)
|
570
|
+
req = Net::HTTP::Post.new(path, header)
|
571
|
+
if params.is_a?(String)
|
572
|
+
unless header.has_key?('Content-Type')
|
573
|
+
header['Content-Type'] = 'application/octet-stream'
|
574
|
+
end
|
575
|
+
req.body = params
|
576
|
+
else
|
577
|
+
unless header.has_key?('Content-Type')
|
578
|
+
header['Content-Type'] = 'application/x-www-form-urlencoded'
|
579
|
+
end
|
580
|
+
req.set_form_data(params)
|
581
|
+
end
|
582
|
+
http.request(req)
|
583
|
+
end
|
584
|
+
|
585
|
+
def include_http_header?(record)
|
586
|
+
record.keys.find { |header| header.start_with?('HTTP_') }
|
587
|
+
end
|
588
|
+
end
|