fluentd 0.14.4-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fluentd might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.github/ISSUE_TEMPLATE.md +6 -0
- data/.gitignore +26 -0
- data/.travis.yml +45 -0
- data/AUTHORS +2 -0
- data/CONTRIBUTING.md +35 -0
- data/COPYING +14 -0
- data/ChangeLog +276 -0
- data/Gemfile +9 -0
- data/README.md +51 -0
- data/Rakefile +53 -0
- data/Vagrantfile +17 -0
- data/appveyor.yml +41 -0
- data/bin/fluent-debug +5 -0
- data/example/copy_roundrobin.conf +39 -0
- data/example/filter_stdout.conf +22 -0
- data/example/in_forward.conf +11 -0
- data/example/in_http.conf +14 -0
- data/example/in_out_forward.conf +17 -0
- data/example/in_syslog.conf +15 -0
- data/example/in_tail.conf +14 -0
- data/example/in_tcp.conf +13 -0
- data/example/in_udp.conf +13 -0
- data/example/multi_filters.conf +61 -0
- data/example/out_buffered_null.conf +32 -0
- data/example/out_copy.conf +20 -0
- data/example/out_file.conf +13 -0
- data/example/out_forward.conf +35 -0
- data/example/out_forward_buf_file.conf +23 -0
- data/example/v0_12_filter.conf +78 -0
- data/example/v1_literal_example.conf +36 -0
- data/fluent.conf +139 -0
- data/fluentd.gemspec +51 -0
- data/lib/fluent/agent.rb +194 -0
- data/lib/fluent/command/bundler_injection.rb +45 -0
- data/lib/fluent/command/cat.rb +319 -0
- data/lib/fluent/command/debug.rb +102 -0
- data/lib/fluent/command/fluentd.rb +273 -0
- data/lib/fluent/compat/call_super_mixin.rb +67 -0
- data/lib/fluent/compat/exec_util.rb +129 -0
- data/lib/fluent/compat/file_util.rb +54 -0
- data/lib/fluent/compat/filter.rb +68 -0
- data/lib/fluent/compat/formatter.rb +111 -0
- data/lib/fluent/compat/formatter_utils.rb +85 -0
- data/lib/fluent/compat/handle_tag_and_time_mixin.rb +62 -0
- data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
- data/lib/fluent/compat/input.rb +49 -0
- data/lib/fluent/compat/output.rb +677 -0
- data/lib/fluent/compat/output_chain.rb +60 -0
- data/lib/fluent/compat/parser.rb +180 -0
- data/lib/fluent/compat/parser_utils.rb +40 -0
- data/lib/fluent/compat/propagate_default.rb +62 -0
- data/lib/fluent/compat/record_filter_mixin.rb +34 -0
- data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
- data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
- data/lib/fluent/compat/socket_util.rb +165 -0
- data/lib/fluent/compat/string_util.rb +34 -0
- data/lib/fluent/compat/structured_format_mixin.rb +26 -0
- data/lib/fluent/compat/type_converter.rb +90 -0
- data/lib/fluent/config.rb +56 -0
- data/lib/fluent/config/basic_parser.rb +123 -0
- data/lib/fluent/config/configure_proxy.rb +366 -0
- data/lib/fluent/config/dsl.rb +149 -0
- data/lib/fluent/config/element.rb +218 -0
- data/lib/fluent/config/error.rb +26 -0
- data/lib/fluent/config/literal_parser.rb +251 -0
- data/lib/fluent/config/parser.rb +107 -0
- data/lib/fluent/config/section.rb +212 -0
- data/lib/fluent/config/types.rb +136 -0
- data/lib/fluent/config/v1_parser.rb +190 -0
- data/lib/fluent/configurable.rb +176 -0
- data/lib/fluent/daemon.rb +15 -0
- data/lib/fluent/engine.rb +220 -0
- data/lib/fluent/env.rb +27 -0
- data/lib/fluent/event.rb +287 -0
- data/lib/fluent/event_router.rb +259 -0
- data/lib/fluent/filter.rb +21 -0
- data/lib/fluent/formatter.rb +23 -0
- data/lib/fluent/input.rb +21 -0
- data/lib/fluent/label.rb +38 -0
- data/lib/fluent/load.rb +36 -0
- data/lib/fluent/log.rb +445 -0
- data/lib/fluent/match.rb +141 -0
- data/lib/fluent/mixin.rb +31 -0
- data/lib/fluent/msgpack_factory.rb +62 -0
- data/lib/fluent/output.rb +26 -0
- data/lib/fluent/output_chain.rb +23 -0
- data/lib/fluent/parser.rb +23 -0
- data/lib/fluent/plugin.rb +161 -0
- data/lib/fluent/plugin/bare_output.rb +63 -0
- data/lib/fluent/plugin/base.rb +130 -0
- data/lib/fluent/plugin/buf_file.rb +154 -0
- data/lib/fluent/plugin/buf_memory.rb +34 -0
- data/lib/fluent/plugin/buffer.rb +603 -0
- data/lib/fluent/plugin/buffer/chunk.rb +160 -0
- data/lib/fluent/plugin/buffer/file_chunk.rb +323 -0
- data/lib/fluent/plugin/buffer/memory_chunk.rb +90 -0
- data/lib/fluent/plugin/exec_util.rb +22 -0
- data/lib/fluent/plugin/file_util.rb +22 -0
- data/lib/fluent/plugin/file_wrapper.rb +120 -0
- data/lib/fluent/plugin/filter.rb +93 -0
- data/lib/fluent/plugin/filter_grep.rb +75 -0
- data/lib/fluent/plugin/filter_record_transformer.rb +342 -0
- data/lib/fluent/plugin/filter_stdout.rb +53 -0
- data/lib/fluent/plugin/formatter.rb +45 -0
- data/lib/fluent/plugin/formatter_csv.rb +47 -0
- data/lib/fluent/plugin/formatter_hash.rb +29 -0
- data/lib/fluent/plugin/formatter_json.rb +44 -0
- data/lib/fluent/plugin/formatter_ltsv.rb +41 -0
- data/lib/fluent/plugin/formatter_msgpack.rb +29 -0
- data/lib/fluent/plugin/formatter_out_file.rb +78 -0
- data/lib/fluent/plugin/formatter_single_value.rb +34 -0
- data/lib/fluent/plugin/formatter_stdout.rb +74 -0
- data/lib/fluent/plugin/in_debug_agent.rb +64 -0
- data/lib/fluent/plugin/in_dummy.rb +135 -0
- data/lib/fluent/plugin/in_exec.rb +149 -0
- data/lib/fluent/plugin/in_forward.rb +366 -0
- data/lib/fluent/plugin/in_gc_stat.rb +52 -0
- data/lib/fluent/plugin/in_http.rb +422 -0
- data/lib/fluent/plugin/in_monitor_agent.rb +401 -0
- data/lib/fluent/plugin/in_object_space.rb +90 -0
- data/lib/fluent/plugin/in_syslog.rb +204 -0
- data/lib/fluent/plugin/in_tail.rb +838 -0
- data/lib/fluent/plugin/in_tcp.rb +41 -0
- data/lib/fluent/plugin/in_udp.rb +37 -0
- data/lib/fluent/plugin/in_unix.rb +201 -0
- data/lib/fluent/plugin/input.rb +33 -0
- data/lib/fluent/plugin/multi_output.rb +95 -0
- data/lib/fluent/plugin/out_buffered_null.rb +59 -0
- data/lib/fluent/plugin/out_buffered_stdout.rb +70 -0
- data/lib/fluent/plugin/out_copy.rb +42 -0
- data/lib/fluent/plugin/out_exec.rb +114 -0
- data/lib/fluent/plugin/out_exec_filter.rb +393 -0
- data/lib/fluent/plugin/out_file.rb +167 -0
- data/lib/fluent/plugin/out_forward.rb +646 -0
- data/lib/fluent/plugin/out_null.rb +27 -0
- data/lib/fluent/plugin/out_relabel.rb +28 -0
- data/lib/fluent/plugin/out_roundrobin.rb +80 -0
- data/lib/fluent/plugin/out_stdout.rb +48 -0
- data/lib/fluent/plugin/out_stream.rb +130 -0
- data/lib/fluent/plugin/output.rb +1020 -0
- data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
- data/lib/fluent/plugin/parser.rb +175 -0
- data/lib/fluent/plugin/parser_apache.rb +28 -0
- data/lib/fluent/plugin/parser_apache2.rb +84 -0
- data/lib/fluent/plugin/parser_apache_error.rb +26 -0
- data/lib/fluent/plugin/parser_csv.rb +33 -0
- data/lib/fluent/plugin/parser_json.rb +79 -0
- data/lib/fluent/plugin/parser_ltsv.rb +50 -0
- data/lib/fluent/plugin/parser_multiline.rb +104 -0
- data/lib/fluent/plugin/parser_nginx.rb +28 -0
- data/lib/fluent/plugin/parser_none.rb +36 -0
- data/lib/fluent/plugin/parser_regexp.rb +73 -0
- data/lib/fluent/plugin/parser_syslog.rb +82 -0
- data/lib/fluent/plugin/parser_tsv.rb +37 -0
- data/lib/fluent/plugin/socket_util.rb +22 -0
- data/lib/fluent/plugin/storage.rb +84 -0
- data/lib/fluent/plugin/storage_local.rb +132 -0
- data/lib/fluent/plugin/string_util.rb +22 -0
- data/lib/fluent/plugin_helper.rb +42 -0
- data/lib/fluent/plugin_helper/child_process.rb +298 -0
- data/lib/fluent/plugin_helper/compat_parameters.rb +224 -0
- data/lib/fluent/plugin_helper/event_emitter.rb +80 -0
- data/lib/fluent/plugin_helper/event_loop.rb +118 -0
- data/lib/fluent/plugin_helper/formatter.rb +149 -0
- data/lib/fluent/plugin_helper/inject.rb +125 -0
- data/lib/fluent/plugin_helper/parser.rb +147 -0
- data/lib/fluent/plugin_helper/retry_state.rb +177 -0
- data/lib/fluent/plugin_helper/storage.rb +331 -0
- data/lib/fluent/plugin_helper/thread.rb +147 -0
- data/lib/fluent/plugin_helper/timer.rb +90 -0
- data/lib/fluent/plugin_id.rb +63 -0
- data/lib/fluent/process.rb +504 -0
- data/lib/fluent/registry.rb +99 -0
- data/lib/fluent/root_agent.rb +314 -0
- data/lib/fluent/rpc.rb +94 -0
- data/lib/fluent/supervisor.rb +680 -0
- data/lib/fluent/system_config.rb +122 -0
- data/lib/fluent/test.rb +56 -0
- data/lib/fluent/test/base.rb +85 -0
- data/lib/fluent/test/driver/base.rb +179 -0
- data/lib/fluent/test/driver/base_owned.rb +70 -0
- data/lib/fluent/test/driver/base_owner.rb +125 -0
- data/lib/fluent/test/driver/event_feeder.rb +98 -0
- data/lib/fluent/test/driver/filter.rb +57 -0
- data/lib/fluent/test/driver/formatter.rb +30 -0
- data/lib/fluent/test/driver/input.rb +31 -0
- data/lib/fluent/test/driver/multi_output.rb +52 -0
- data/lib/fluent/test/driver/output.rb +76 -0
- data/lib/fluent/test/driver/parser.rb +30 -0
- data/lib/fluent/test/driver/test_event_router.rb +45 -0
- data/lib/fluent/test/filter_test.rb +77 -0
- data/lib/fluent/test/formatter_test.rb +65 -0
- data/lib/fluent/test/helpers.rb +79 -0
- data/lib/fluent/test/input_test.rb +172 -0
- data/lib/fluent/test/log.rb +73 -0
- data/lib/fluent/test/output_test.rb +156 -0
- data/lib/fluent/test/parser_test.rb +70 -0
- data/lib/fluent/time.rb +175 -0
- data/lib/fluent/timezone.rb +133 -0
- data/lib/fluent/unique_id.rb +39 -0
- data/lib/fluent/version.rb +21 -0
- data/lib/fluent/winsvc.rb +71 -0
- data/test/compat/test_calls_super.rb +166 -0
- data/test/compat/test_parser.rb +82 -0
- data/test/config/assertions.rb +42 -0
- data/test/config/test_config_parser.rb +507 -0
- data/test/config/test_configurable.rb +1194 -0
- data/test/config/test_configure_proxy.rb +386 -0
- data/test/config/test_dsl.rb +415 -0
- data/test/config/test_element.rb +403 -0
- data/test/config/test_literal_parser.rb +297 -0
- data/test/config/test_section.rb +184 -0
- data/test/config/test_system_config.rb +120 -0
- data/test/config/test_types.rb +171 -0
- data/test/helper.rb +119 -0
- data/test/plugin/data/2010/01/20100102-030405.log +0 -0
- data/test/plugin/data/2010/01/20100102-030406.log +0 -0
- data/test/plugin/data/2010/01/20100102.log +0 -0
- data/test/plugin/data/log/bar +0 -0
- data/test/plugin/data/log/foo/bar.log +0 -0
- data/test/plugin/data/log/test.log +0 -0
- data/test/plugin/test_bare_output.rb +118 -0
- data/test/plugin/test_base.rb +75 -0
- data/test/plugin/test_buf_file.rb +571 -0
- data/test/plugin/test_buf_memory.rb +42 -0
- data/test/plugin/test_buffer.rb +1200 -0
- data/test/plugin/test_buffer_chunk.rb +168 -0
- data/test/plugin/test_buffer_file_chunk.rb +771 -0
- data/test/plugin/test_buffer_memory_chunk.rb +265 -0
- data/test/plugin/test_file_util.rb +96 -0
- data/test/plugin/test_filter.rb +353 -0
- data/test/plugin/test_filter_grep.rb +119 -0
- data/test/plugin/test_filter_record_transformer.rb +600 -0
- data/test/plugin/test_filter_stdout.rb +211 -0
- data/test/plugin/test_formatter_csv.rb +94 -0
- data/test/plugin/test_formatter_json.rb +30 -0
- data/test/plugin/test_formatter_ltsv.rb +52 -0
- data/test/plugin/test_formatter_msgpack.rb +28 -0
- data/test/plugin/test_formatter_out_file.rb +95 -0
- data/test/plugin/test_formatter_single_value.rb +38 -0
- data/test/plugin/test_in_debug_agent.rb +28 -0
- data/test/plugin/test_in_dummy.rb +188 -0
- data/test/plugin/test_in_exec.rb +133 -0
- data/test/plugin/test_in_forward.rb +635 -0
- data/test/plugin/test_in_gc_stat.rb +39 -0
- data/test/plugin/test_in_http.rb +442 -0
- data/test/plugin/test_in_monitor_agent.rb +329 -0
- data/test/plugin/test_in_object_space.rb +64 -0
- data/test/plugin/test_in_syslog.rb +205 -0
- data/test/plugin/test_in_tail.rb +1001 -0
- data/test/plugin/test_in_tcp.rb +102 -0
- data/test/plugin/test_in_udp.rb +121 -0
- data/test/plugin/test_in_unix.rb +126 -0
- data/test/plugin/test_input.rb +122 -0
- data/test/plugin/test_multi_output.rb +180 -0
- data/test/plugin/test_out_buffered_null.rb +79 -0
- data/test/plugin/test_out_buffered_stdout.rb +122 -0
- data/test/plugin/test_out_copy.rb +160 -0
- data/test/plugin/test_out_exec.rb +155 -0
- data/test/plugin/test_out_exec_filter.rb +262 -0
- data/test/plugin/test_out_file.rb +383 -0
- data/test/plugin/test_out_forward.rb +590 -0
- data/test/plugin/test_out_null.rb +29 -0
- data/test/plugin/test_out_relabel.rb +28 -0
- data/test/plugin/test_out_roundrobin.rb +146 -0
- data/test/plugin/test_out_stdout.rb +92 -0
- data/test/plugin/test_out_stream.rb +93 -0
- data/test/plugin/test_output.rb +568 -0
- data/test/plugin/test_output_as_buffered.rb +1604 -0
- data/test/plugin/test_output_as_buffered_overflow.rb +250 -0
- data/test/plugin/test_output_as_buffered_retries.rb +839 -0
- data/test/plugin/test_output_as_buffered_secondary.rb +817 -0
- data/test/plugin/test_output_as_standard.rb +374 -0
- data/test/plugin/test_owned_by.rb +35 -0
- data/test/plugin/test_parser_apache.rb +42 -0
- data/test/plugin/test_parser_apache2.rb +38 -0
- data/test/plugin/test_parser_apache_error.rb +45 -0
- data/test/plugin/test_parser_base.rb +32 -0
- data/test/plugin/test_parser_csv.rb +104 -0
- data/test/plugin/test_parser_json.rb +107 -0
- data/test/plugin/test_parser_labeled_tsv.rb +129 -0
- data/test/plugin/test_parser_multiline.rb +100 -0
- data/test/plugin/test_parser_nginx.rb +48 -0
- data/test/plugin/test_parser_none.rb +53 -0
- data/test/plugin/test_parser_regexp.rb +277 -0
- data/test/plugin/test_parser_syslog.rb +66 -0
- data/test/plugin/test_parser_time.rb +46 -0
- data/test/plugin/test_parser_tsv.rb +121 -0
- data/test/plugin/test_storage.rb +167 -0
- data/test/plugin/test_storage_local.rb +8 -0
- data/test/plugin/test_string_util.rb +26 -0
- data/test/plugin_helper/test_child_process.rb +608 -0
- data/test/plugin_helper/test_compat_parameters.rb +242 -0
- data/test/plugin_helper/test_event_emitter.rb +51 -0
- data/test/plugin_helper/test_event_loop.rb +52 -0
- data/test/plugin_helper/test_formatter.rb +252 -0
- data/test/plugin_helper/test_inject.rb +487 -0
- data/test/plugin_helper/test_parser.rb +263 -0
- data/test/plugin_helper/test_retry_state.rb +399 -0
- data/test/plugin_helper/test_storage.rb +521 -0
- data/test/plugin_helper/test_thread.rb +164 -0
- data/test/plugin_helper/test_timer.rb +131 -0
- data/test/scripts/exec_script.rb +32 -0
- data/test/scripts/fluent/plugin/formatter_known.rb +8 -0
- data/test/scripts/fluent/plugin/out_test.rb +81 -0
- data/test/scripts/fluent/plugin/out_test2.rb +80 -0
- data/test/scripts/fluent/plugin/parser_known.rb +4 -0
- data/test/test_config.rb +179 -0
- data/test/test_configdsl.rb +148 -0
- data/test/test_event.rb +329 -0
- data/test/test_event_router.rb +331 -0
- data/test/test_event_time.rb +184 -0
- data/test/test_filter.rb +121 -0
- data/test/test_formatter.rb +319 -0
- data/test/test_input.rb +31 -0
- data/test/test_log.rb +572 -0
- data/test/test_match.rb +137 -0
- data/test/test_mixin.rb +351 -0
- data/test/test_output.rb +214 -0
- data/test/test_plugin_classes.rb +136 -0
- data/test/test_plugin_helper.rb +81 -0
- data/test/test_process.rb +48 -0
- data/test/test_root_agent.rb +278 -0
- data/test/test_supervisor.rb +339 -0
- data/test/test_time_formatter.rb +186 -0
- data/test/test_unique_id.rb +47 -0
- metadata +823 -0
@@ -0,0 +1,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,442 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/test'
|
3
|
+
require 'fluent/plugin/in_http'
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
class HttpInputTest < Test::Unit::TestCase
|
7
|
+
class << self
|
8
|
+
def startup
|
9
|
+
socket_manager_path = ServerEngine::SocketManager::Server.generate_path
|
10
|
+
@server = ServerEngine::SocketManager::Server.open(socket_manager_path)
|
11
|
+
ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = socket_manager_path.to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
def shutdown
|
15
|
+
@server.close
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup
|
20
|
+
Fluent::Test.setup
|
21
|
+
end
|
22
|
+
|
23
|
+
PORT = unused_port
|
24
|
+
CONFIG = %[
|
25
|
+
port #{PORT}
|
26
|
+
bind "127.0.0.1"
|
27
|
+
body_size_limit 10m
|
28
|
+
keepalive_timeout 5
|
29
|
+
respond_with_empty_img true
|
30
|
+
]
|
31
|
+
|
32
|
+
def create_driver(conf=CONFIG)
|
33
|
+
Fluent::Test::InputTestDriver.new(Fluent::HttpInput).configure(conf, true)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_configure
|
37
|
+
d = create_driver
|
38
|
+
assert_equal PORT, d.instance.port
|
39
|
+
assert_equal '127.0.0.1', d.instance.bind
|
40
|
+
assert_equal 10*1024*1024, d.instance.body_size_limit
|
41
|
+
assert_equal 5, d.instance.keepalive_timeout
|
42
|
+
assert_equal false, d.instance.add_http_headers
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_time
|
46
|
+
d = create_driver
|
47
|
+
|
48
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
49
|
+
Fluent::Engine.now = time
|
50
|
+
|
51
|
+
d.expect_emit "tag1", time, {"a"=>1}
|
52
|
+
d.expect_emit "tag2", time, {"a"=>2}
|
53
|
+
|
54
|
+
d.run do
|
55
|
+
d.expected_emits.each {|tag,_time,record|
|
56
|
+
res = post("/#{tag}", {"json"=>record.to_json})
|
57
|
+
assert_equal "200", res.code
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_time_as_float
|
63
|
+
d = create_driver
|
64
|
+
|
65
|
+
float_time = Time.parse("2011-01-02 13:14:15.123 UTC").to_f
|
66
|
+
time = Fluent::EventTime.from_time(Time.at(float_time))
|
67
|
+
|
68
|
+
d.expect_emit "tag1", time, {"a"=>1}
|
69
|
+
|
70
|
+
d.run do
|
71
|
+
d.expected_emits.each {|tag,_time,record|
|
72
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>float_time.to_s})
|
73
|
+
assert_equal "200", res.code
|
74
|
+
}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_json
|
79
|
+
d = create_driver
|
80
|
+
|
81
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
82
|
+
|
83
|
+
d.expect_emit "tag1", time, {"a"=>1}
|
84
|
+
d.expect_emit "tag2", time, {"a"=>2}
|
85
|
+
|
86
|
+
d.run do
|
87
|
+
d.expected_emits.each {|tag,_time,record|
|
88
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s})
|
89
|
+
assert_equal "200", res.code
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
d.emit_streams.each { |tag, es|
|
94
|
+
assert !include_http_header?(es.first[1])
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_multi_json
|
99
|
+
d = create_driver
|
100
|
+
|
101
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
102
|
+
|
103
|
+
events = [{"a"=>1},{"a"=>2}]
|
104
|
+
tag = "tag1"
|
105
|
+
|
106
|
+
events.each { |ev|
|
107
|
+
d.expect_emit tag, time, ev
|
108
|
+
}
|
109
|
+
|
110
|
+
d.run do
|
111
|
+
res = post("/#{tag}", {"json"=>events.to_json, "time"=>time.to_s})
|
112
|
+
assert_equal "200", res.code
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_json_with_add_remote_addr
|
118
|
+
d = create_driver(CONFIG + "add_remote_addr true")
|
119
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
120
|
+
|
121
|
+
d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>1}
|
122
|
+
d.expect_emit "tag2", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>2}
|
123
|
+
|
124
|
+
d.run do
|
125
|
+
d.expected_emits.each {|tag,_time,record|
|
126
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s})
|
127
|
+
assert_equal "200", res.code
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_multi_json_with_add_remote_addr
|
134
|
+
d = create_driver(CONFIG + "add_remote_addr true")
|
135
|
+
|
136
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
137
|
+
events = [{"a"=>1},{"a"=>2}]
|
138
|
+
tag = "tag1"
|
139
|
+
|
140
|
+
d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>1}
|
141
|
+
d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>2}
|
142
|
+
|
143
|
+
d.run do
|
144
|
+
res = post("/#{tag}", {"json"=>events.to_json, "time"=>time.to_s})
|
145
|
+
assert_equal "200", res.code
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_json_with_add_remote_addr_given_x_forwarded_for
|
151
|
+
d = create_driver(CONFIG + "add_remote_addr true")
|
152
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
153
|
+
|
154
|
+
d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}
|
155
|
+
d.expect_emit "tag2", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}
|
156
|
+
|
157
|
+
d.run do
|
158
|
+
d.expected_emits.each {|tag,_time,record|
|
159
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
|
160
|
+
assert_equal "200", res.code
|
161
|
+
}
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_multi_json_with_add_remote_addr_given_x_forwarded_for
|
167
|
+
d = create_driver(CONFIG + "add_remote_addr true")
|
168
|
+
|
169
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
170
|
+
events = [{"a"=>1},{"a"=>2}]
|
171
|
+
tag = "tag1"
|
172
|
+
|
173
|
+
d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}
|
174
|
+
d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>2}
|
175
|
+
|
176
|
+
d.run do
|
177
|
+
res = post("/#{tag}", {"json"=>events.to_json, "time"=>time.to_s}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
|
178
|
+
assert_equal "200", res.code
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_multi_json_with_add_http_headers
|
184
|
+
d = create_driver(CONFIG + "add_http_headers true")
|
185
|
+
|
186
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
187
|
+
events = [{"a"=>1},{"a"=>2}]
|
188
|
+
tag = "tag1"
|
189
|
+
|
190
|
+
d.run do
|
191
|
+
res = post("/#{tag}", {"json"=>events.to_json, "time"=>time.to_s})
|
192
|
+
assert_equal "200", res.code
|
193
|
+
end
|
194
|
+
|
195
|
+
d.emit_streams.each { |_tag, es|
|
196
|
+
assert include_http_header?(es.first[1])
|
197
|
+
}
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_json_with_add_http_headers
|
201
|
+
d = create_driver(CONFIG + "add_http_headers true")
|
202
|
+
|
203
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
204
|
+
|
205
|
+
records = [["tag1", time, {"a"=>1}], ["tag2", time, {"a"=>2}]]
|
206
|
+
|
207
|
+
d.run do
|
208
|
+
records.each {|tag,_time,record|
|
209
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s})
|
210
|
+
assert_equal "200", res.code
|
211
|
+
|
212
|
+
}
|
213
|
+
end
|
214
|
+
|
215
|
+
d.emit_streams.each { |tag, es|
|
216
|
+
assert include_http_header?(es.first[1])
|
217
|
+
}
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_application_json
|
221
|
+
d = create_driver
|
222
|
+
|
223
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
224
|
+
|
225
|
+
d.expect_emit "tag1", time, {"a"=>1}
|
226
|
+
d.expect_emit "tag2", time, {"a"=>2}
|
227
|
+
|
228
|
+
d.run do
|
229
|
+
d.expected_emits.each {|tag,_time,record|
|
230
|
+
res = post("/#{tag}?time=#{_time.to_s}", record.to_json, {"Content-Type"=>"application/json; charset=utf-8"})
|
231
|
+
assert_equal "200", res.code
|
232
|
+
}
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_msgpack
|
237
|
+
d = create_driver
|
238
|
+
|
239
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
240
|
+
|
241
|
+
d.expect_emit "tag1", time, {"a"=>1}
|
242
|
+
d.expect_emit "tag2", time, {"a"=>2}
|
243
|
+
|
244
|
+
d.run do
|
245
|
+
d.expected_emits.each {|tag,_time,record|
|
246
|
+
res = post("/#{tag}", {"msgpack"=>record.to_msgpack, "time"=>_time.to_s})
|
247
|
+
assert_equal "200", res.code
|
248
|
+
}
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_multi_msgpack
|
253
|
+
d = create_driver
|
254
|
+
|
255
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
256
|
+
|
257
|
+
events = [{"a"=>1},{"a"=>2}]
|
258
|
+
tag = "tag1"
|
259
|
+
|
260
|
+
events.each { |ev|
|
261
|
+
d.expect_emit tag, time, ev
|
262
|
+
}
|
263
|
+
|
264
|
+
d.run do
|
265
|
+
res = post("/#{tag}", {"msgpack"=>events.to_msgpack, "time"=>time.to_s})
|
266
|
+
assert_equal "200", res.code
|
267
|
+
end
|
268
|
+
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_with_regexp
|
272
|
+
d = create_driver(CONFIG + %[
|
273
|
+
format /^(?<field_1>\\d+):(?<field_2>\\w+)$/
|
274
|
+
types field_1:integer
|
275
|
+
])
|
276
|
+
|
277
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
278
|
+
|
279
|
+
d.expect_emit "tag1", time, {"field_1" => 1, "field_2" => 'str'}
|
280
|
+
d.expect_emit "tag2", time, {"field_1" => 2, "field_2" => 'str'}
|
281
|
+
|
282
|
+
d.run do
|
283
|
+
d.expected_emits.each { |tag, _time, record|
|
284
|
+
body = record.map { |k, v|
|
285
|
+
v.to_s
|
286
|
+
}.join(':')
|
287
|
+
res = post("/#{tag}?time=#{_time.to_s}", body, {'Content-Type' => 'application/octet-stream'})
|
288
|
+
assert_equal "200", res.code
|
289
|
+
}
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_with_csv
|
294
|
+
require 'csv'
|
295
|
+
|
296
|
+
d = create_driver(CONFIG + %[
|
297
|
+
format csv
|
298
|
+
keys foo,bar
|
299
|
+
])
|
300
|
+
|
301
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
302
|
+
|
303
|
+
d.expect_emit "tag1", time, {"foo" => "1", "bar" => 'st"r'}
|
304
|
+
d.expect_emit "tag2", time, {"foo" => "2", "bar" => 'str'}
|
305
|
+
|
306
|
+
d.run do
|
307
|
+
d.expected_emits.each { |tag, _time, record|
|
308
|
+
body = record.map { |k, v| v }.to_csv
|
309
|
+
res = post("/#{tag}?time=#{_time.to_s}", body, {'Content-Type' => 'text/comma-separated-values'})
|
310
|
+
assert_equal "200", res.code
|
311
|
+
}
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
def test_resonse_with_empty_img
|
316
|
+
d = create_driver(CONFIG + "respond_with_empty_img true")
|
317
|
+
assert_equal true, d.instance.respond_with_empty_img
|
318
|
+
|
319
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
320
|
+
|
321
|
+
d.expect_emit "tag1", time, {"a"=>1}
|
322
|
+
d.expect_emit "tag2", time, {"a"=>2}
|
323
|
+
|
324
|
+
d.run do
|
325
|
+
d.expected_emits.each {|tag,_time,record|
|
326
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s})
|
327
|
+
assert_equal "200", res.code
|
328
|
+
# Ruby returns ASCII-8 encoded string for GIF.
|
329
|
+
assert_equal Fluent::HttpInput::EMPTY_GIF_IMAGE, res.body.force_encoding("UTF-8")
|
330
|
+
}
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
def test_cors_allowed
|
335
|
+
d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
|
336
|
+
assert_equal ["http://foo.com"], d.instance.cors_allow_origins
|
337
|
+
|
338
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
339
|
+
|
340
|
+
d.expect_emit "tag1", time, {"a"=>1}
|
341
|
+
d.expect_emit "tag2", time, {"a"=>1}
|
342
|
+
|
343
|
+
d.run do
|
344
|
+
d.expected_emits.each {|tag,_time,record|
|
345
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s}, {"Origin"=>"http://foo.com"})
|
346
|
+
assert_equal "200", res.code
|
347
|
+
assert_equal "http://foo.com", res["Access-Control-Allow-Origin"]
|
348
|
+
}
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
def test_cors_disallowed
|
353
|
+
d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
|
354
|
+
assert_equal ["http://foo.com"], d.instance.cors_allow_origins
|
355
|
+
|
356
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
357
|
+
|
358
|
+
d.expected_emits_length = 0
|
359
|
+
d.run do
|
360
|
+
res = post("/tag1", {"json"=>{"a"=>1}.to_json, "time"=>time.to_s}, {"Origin"=>"http://bar.com"})
|
361
|
+
assert_equal "403", res.code
|
362
|
+
|
363
|
+
res = post("/tag2", {"json"=>{"a"=>1}.to_json, "time"=>time.to_s}, {"Origin"=>"http://bar.com"})
|
364
|
+
assert_equal "403", res.code
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
$test_in_http_connection_object_ids = []
|
369
|
+
$test_in_http_content_types = []
|
370
|
+
$test_in_http_content_types_flag = false
|
371
|
+
module ContentTypeHook
|
372
|
+
def initialize(*args)
|
373
|
+
@io_handler = nil
|
374
|
+
super
|
375
|
+
end
|
376
|
+
def on_headers_complete(headers)
|
377
|
+
super
|
378
|
+
if $test_in_http_content_types_flag
|
379
|
+
$test_in_http_content_types << self.content_type
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
def on_message_begin
|
384
|
+
super
|
385
|
+
if $test_in_http_content_types_flag
|
386
|
+
$test_in_http_connection_object_ids << @io_handler.object_id
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
class Fluent::HttpInput::Handler
|
392
|
+
prepend ContentTypeHook
|
393
|
+
end
|
394
|
+
|
395
|
+
def test_if_content_type_is_initialized_properly
|
396
|
+
# This test is to check if Fluent::HttpInput::Handler's @content_type is initialized properly.
|
397
|
+
# Especially when in Keep-Alive and the second request has no 'Content-Type'.
|
398
|
+
|
399
|
+
begin
|
400
|
+
d = create_driver
|
401
|
+
|
402
|
+
$test_in_http_content_types_flag = true
|
403
|
+
d.run do
|
404
|
+
# Send two requests the second one has no Content-Type in Keep-Alive
|
405
|
+
Net::HTTP.start("127.0.0.1", PORT) do |http|
|
406
|
+
req = Net::HTTP::Post.new("/foodb/bartbl", {"connection" => "keepalive", "Content-Type" => "application/json"})
|
407
|
+
res = http.request(req)
|
408
|
+
|
409
|
+
req = Net::HTTP::Get.new("/foodb/bartbl", {"connection" => "keepalive"})
|
410
|
+
res = http.request(req)
|
411
|
+
end
|
412
|
+
|
413
|
+
end
|
414
|
+
ensure
|
415
|
+
$test_in_http_content_types_flag = false
|
416
|
+
end
|
417
|
+
assert_equal(['application/json', ''], $test_in_http_content_types)
|
418
|
+
# Asserting keepalive
|
419
|
+
assert_equal $test_in_http_connection_object_ids[0], $test_in_http_connection_object_ids[1]
|
420
|
+
end
|
421
|
+
|
422
|
+
def post(path, params, header = {})
|
423
|
+
http = Net::HTTP.new("127.0.0.1", PORT)
|
424
|
+
req = Net::HTTP::Post.new(path, header)
|
425
|
+
if params.is_a?(String)
|
426
|
+
unless header.has_key?('Content-Type')
|
427
|
+
header['Content-Type'] = 'application/octet-stream'
|
428
|
+
end
|
429
|
+
req.body = params
|
430
|
+
else
|
431
|
+
unless header.has_key?('Content-Type')
|
432
|
+
header['Content-Type'] = 'application/x-www-form-urlencoded'
|
433
|
+
end
|
434
|
+
req.set_form_data(params)
|
435
|
+
end
|
436
|
+
http.request(req)
|
437
|
+
end
|
438
|
+
|
439
|
+
def include_http_header?(record)
|
440
|
+
record.keys.find { |header| header.start_with?('HTTP_') }
|
441
|
+
end
|
442
|
+
end
|