fluentd 0.12.40 → 0.14.0
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 +4 -4
- data/.github/ISSUE_TEMPLATE.md +6 -0
- data/.gitignore +2 -0
- data/.travis.yml +33 -21
- data/CONTRIBUTING.md +1 -0
- data/ChangeLog +810 -237
- data/README.md +0 -25
- data/Rakefile +2 -1
- data/Vagrantfile +17 -0
- data/appveyor.yml +35 -0
- data/example/filter_stdout.conf +5 -5
- data/example/in_forward.conf +2 -2
- data/example/in_http.conf +2 -2
- data/example/in_out_forward.conf +17 -0
- data/example/in_syslog.conf +2 -2
- data/example/in_tail.conf +2 -2
- data/example/in_tcp.conf +2 -2
- data/example/in_udp.conf +2 -2
- data/example/out_copy.conf +4 -4
- data/example/out_file.conf +2 -2
- data/example/out_forward.conf +2 -2
- data/example/out_forward_buf_file.conf +23 -0
- data/example/v0_12_filter.conf +8 -8
- data/fluent.conf +29 -0
- data/fluentd.gemspec +18 -11
- data/lib/fluent/agent.rb +60 -58
- data/lib/fluent/command/cat.rb +1 -1
- data/lib/fluent/command/debug.rb +7 -5
- data/lib/fluent/command/fluentd.rb +97 -2
- data/lib/fluent/compat/call_super_mixin.rb +67 -0
- data/lib/fluent/compat/filter.rb +50 -0
- data/lib/fluent/compat/formatter.rb +109 -0
- data/lib/fluent/compat/input.rb +50 -0
- data/lib/fluent/compat/output.rb +617 -0
- data/lib/fluent/compat/output_chain.rb +60 -0
- data/lib/fluent/compat/parser.rb +163 -0
- data/lib/fluent/compat/propagate_default.rb +62 -0
- data/lib/fluent/config.rb +23 -20
- data/lib/fluent/config/configure_proxy.rb +119 -70
- data/lib/fluent/config/dsl.rb +5 -18
- data/lib/fluent/config/element.rb +72 -8
- data/lib/fluent/config/error.rb +0 -3
- data/lib/fluent/config/literal_parser.rb +0 -2
- data/lib/fluent/config/parser.rb +4 -4
- data/lib/fluent/config/section.rb +39 -28
- data/lib/fluent/config/types.rb +2 -13
- data/lib/fluent/config/v1_parser.rb +1 -3
- data/lib/fluent/configurable.rb +48 -16
- data/lib/fluent/daemon.rb +15 -0
- data/lib/fluent/engine.rb +26 -52
- data/lib/fluent/env.rb +6 -4
- data/lib/fluent/event.rb +58 -11
- data/lib/fluent/event_router.rb +5 -5
- 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 +2 -2
- data/lib/fluent/load.rb +3 -2
- data/lib/fluent/log.rb +107 -38
- data/lib/fluent/match.rb +0 -36
- data/lib/fluent/mixin.rb +117 -7
- data/lib/fluent/msgpack_factory.rb +62 -0
- data/lib/fluent/output.rb +7 -612
- data/lib/fluent/output_chain.rb +23 -0
- data/lib/fluent/parser.rb +4 -800
- data/lib/fluent/plugin.rb +100 -121
- data/lib/fluent/plugin/bare_output.rb +63 -0
- data/lib/fluent/plugin/base.rb +121 -0
- data/lib/fluent/plugin/buf_file.rb +101 -182
- data/lib/fluent/plugin/buf_memory.rb +9 -92
- data/lib/fluent/plugin/buffer.rb +473 -0
- data/lib/fluent/plugin/buffer/chunk.rb +135 -0
- data/lib/fluent/plugin/buffer/file_chunk.rb +339 -0
- data/lib/fluent/plugin/buffer/memory_chunk.rb +100 -0
- data/lib/fluent/plugin/exec_util.rb +80 -75
- data/lib/fluent/plugin/file_util.rb +33 -28
- data/lib/fluent/plugin/file_wrapper.rb +120 -0
- data/lib/fluent/plugin/filter.rb +51 -0
- data/lib/fluent/plugin/filter_grep.rb +13 -40
- data/lib/fluent/plugin/filter_record_transformer.rb +22 -18
- data/lib/fluent/plugin/formatter.rb +93 -0
- data/lib/fluent/plugin/formatter_csv.rb +48 -0
- data/lib/fluent/plugin/formatter_hash.rb +32 -0
- data/lib/fluent/plugin/formatter_json.rb +47 -0
- data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
- data/lib/fluent/plugin/formatter_msgpack.rb +32 -0
- data/lib/fluent/plugin/formatter_out_file.rb +45 -0
- data/lib/fluent/plugin/formatter_single_value.rb +34 -0
- data/lib/fluent/plugin/formatter_stdout.rb +39 -0
- data/lib/fluent/plugin/in_debug_agent.rb +4 -0
- data/lib/fluent/plugin/in_dummy.rb +22 -18
- data/lib/fluent/plugin/in_exec.rb +18 -8
- data/lib/fluent/plugin/in_forward.rb +36 -79
- data/lib/fluent/plugin/in_gc_stat.rb +4 -0
- data/lib/fluent/plugin/in_http.rb +21 -18
- data/lib/fluent/plugin/in_monitor_agent.rb +15 -48
- data/lib/fluent/plugin/in_object_space.rb +6 -1
- data/lib/fluent/plugin/in_stream.rb +7 -3
- data/lib/fluent/plugin/in_syslog.rb +46 -95
- data/lib/fluent/plugin/in_tail.rb +51 -595
- data/lib/fluent/plugin/in_tcp.rb +8 -1
- data/lib/fluent/plugin/in_udp.rb +8 -14
- 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_copy.rb +11 -7
- data/lib/fluent/plugin/out_exec.rb +15 -11
- data/lib/fluent/plugin/out_exec_filter.rb +18 -10
- data/lib/fluent/plugin/out_file.rb +34 -5
- data/lib/fluent/plugin/out_forward.rb +19 -9
- data/lib/fluent/plugin/out_null.rb +0 -14
- data/lib/fluent/plugin/out_roundrobin.rb +11 -7
- data/lib/fluent/plugin/out_stdout.rb +5 -7
- data/lib/fluent/plugin/out_stream.rb +3 -1
- data/lib/fluent/plugin/output.rb +979 -0
- data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
- data/lib/fluent/plugin/parser.rb +244 -0
- data/lib/fluent/plugin/parser_apache.rb +24 -0
- data/lib/fluent/plugin/parser_apache2.rb +84 -0
- data/lib/fluent/plugin/parser_apache_error.rb +21 -0
- data/lib/fluent/plugin/parser_csv.rb +31 -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 +102 -0
- data/lib/fluent/plugin/parser_nginx.rb +24 -0
- data/lib/fluent/plugin/parser_none.rb +36 -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 +120 -114
- data/lib/fluent/plugin/storage.rb +84 -0
- data/lib/fluent/plugin/storage_local.rb +116 -0
- data/lib/fluent/plugin/string_util.rb +16 -13
- data/lib/fluent/plugin_helper.rb +39 -0
- data/lib/fluent/plugin_helper/child_process.rb +298 -0
- data/lib/fluent/plugin_helper/compat_parameters.rb +99 -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/retry_state.rb +177 -0
- data/lib/fluent/plugin_helper/storage.rb +308 -0
- data/lib/fluent/plugin_helper/thread.rb +147 -0
- data/lib/fluent/plugin_helper/timer.rb +85 -0
- data/lib/fluent/plugin_id.rb +63 -0
- data/lib/fluent/process.rb +21 -30
- data/lib/fluent/registry.rb +21 -9
- data/lib/fluent/root_agent.rb +115 -40
- data/lib/fluent/supervisor.rb +330 -320
- data/lib/fluent/system_config.rb +42 -18
- data/lib/fluent/test.rb +6 -1
- data/lib/fluent/test/base.rb +23 -3
- data/lib/fluent/test/driver/base.rb +247 -0
- data/lib/fluent/test/driver/event_feeder.rb +98 -0
- data/lib/fluent/test/driver/filter.rb +35 -0
- data/lib/fluent/test/driver/input.rb +31 -0
- data/lib/fluent/test/driver/output.rb +78 -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 +2 -1
- data/lib/fluent/test/input_test.rb +23 -17
- data/lib/fluent/test/output_test.rb +28 -39
- data/lib/fluent/test/parser_test.rb +1 -1
- data/lib/fluent/time.rb +104 -1
- data/lib/fluent/{status.rb → unique_id.rb} +15 -24
- data/lib/fluent/version.rb +1 -1
- data/lib/fluent/winsvc.rb +72 -0
- data/test/compat/test_calls_super.rb +164 -0
- data/test/config/test_config_parser.rb +83 -0
- data/test/config/test_configurable.rb +547 -274
- data/test/config/test_configure_proxy.rb +146 -29
- data/test/config/test_dsl.rb +3 -181
- data/test/config/test_element.rb +274 -0
- data/test/config/test_literal_parser.rb +1 -1
- data/test/config/test_section.rb +79 -7
- data/test/config/test_system_config.rb +21 -0
- data/test/config/test_types.rb +3 -26
- data/test/helper.rb +78 -8
- data/test/plugin/test_bare_output.rb +118 -0
- data/test/plugin/test_base.rb +75 -0
- data/test/plugin/test_buf_file.rb +420 -521
- data/test/plugin/test_buf_memory.rb +32 -194
- data/test/plugin/test_buffer.rb +981 -0
- data/test/plugin/test_buffer_chunk.rb +110 -0
- data/test/plugin/test_buffer_file_chunk.rb +770 -0
- data/test/plugin/test_buffer_memory_chunk.rb +265 -0
- data/test/plugin/test_filter.rb +255 -0
- data/test/plugin/test_filter_grep.rb +2 -73
- data/test/plugin/test_filter_record_transformer.rb +24 -68
- data/test/plugin/test_filter_stdout.rb +6 -6
- data/test/plugin/test_in_debug_agent.rb +2 -0
- data/test/plugin/test_in_dummy.rb +11 -17
- data/test/plugin/test_in_exec.rb +6 -25
- data/test/plugin/test_in_forward.rb +112 -151
- data/test/plugin/test_in_gc_stat.rb +2 -0
- data/test/plugin/test_in_http.rb +106 -157
- data/test/plugin/test_in_object_space.rb +21 -5
- data/test/plugin/test_in_stream.rb +14 -13
- data/test/plugin/test_in_syslog.rb +30 -275
- data/test/plugin/test_in_tail.rb +95 -234
- data/test/plugin/test_in_tcp.rb +14 -0
- data/test/plugin/test_in_udp.rb +21 -13
- 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_copy.rb +15 -2
- data/test/plugin/test_out_exec.rb +75 -25
- data/test/plugin/test_out_exec_filter.rb +74 -8
- data/test/plugin/test_out_file.rb +61 -7
- data/test/plugin/test_out_forward.rb +92 -15
- data/test/plugin/test_out_roundrobin.rb +1 -0
- data/test/plugin/test_out_stdout.rb +22 -13
- data/test/plugin/test_out_stream.rb +18 -0
- data/test/plugin/test_output.rb +515 -0
- data/test/plugin/test_output_as_buffered.rb +1540 -0
- data/test/plugin/test_output_as_buffered_overflow.rb +247 -0
- data/test/plugin/test_output_as_buffered_retries.rb +808 -0
- data/test/plugin/test_output_as_buffered_secondary.rb +776 -0
- data/test/plugin/test_output_as_standard.rb +362 -0
- data/test/plugin/test_owned_by.rb +35 -0
- data/test/plugin/test_storage.rb +167 -0
- data/test/plugin/test_storage_local.rb +8 -0
- data/test/plugin_helper/test_child_process.rb +599 -0
- data/test/plugin_helper/test_compat_parameters.rb +175 -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_retry_state.rb +399 -0
- data/test/plugin_helper/test_storage.rb +411 -0
- data/test/plugin_helper/test_thread.rb +164 -0
- data/test/plugin_helper/test_timer.rb +100 -0
- data/test/scripts/exec_script.rb +0 -6
- data/test/scripts/fluent/plugin/out_test.rb +3 -0
- data/test/test_config.rb +13 -4
- data/test/test_event.rb +24 -13
- data/test/test_event_router.rb +8 -7
- data/test/test_event_time.rb +187 -0
- data/test/test_formatter.rb +13 -51
- data/test/test_input.rb +1 -1
- data/test/test_log.rb +239 -16
- data/test/test_mixin.rb +1 -1
- data/test/test_output.rb +53 -66
- data/test/test_parser.rb +105 -323
- data/test/test_plugin_helper.rb +81 -0
- data/test/test_root_agent.rb +4 -52
- data/test/test_supervisor.rb +272 -0
- data/test/test_unique_id.rb +47 -0
- metadata +180 -54
- data/lib/fluent/buffer.rb +0 -365
- data/lib/fluent/plugin/filter_parser.rb +0 -107
- data/lib/fluent/plugin/in_status.rb +0 -76
- data/lib/fluent/test/helpers.rb +0 -86
- data/test/plugin/data/log/foo/bar2 +0 -0
- data/test/plugin/test_filter_parser.rb +0 -744
- data/test/plugin/test_in_status.rb +0 -38
- data/test/test_buffer.rb +0 -624
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative '../helper'
|
2
2
|
require 'fluent/test'
|
3
|
+
require 'fluent/plugin/in_gc_stat'
|
3
4
|
|
4
5
|
class GCStatInputTest < Test::Unit::TestCase
|
5
6
|
def setup
|
@@ -33,5 +34,6 @@ class GCStatInputTest < Test::Unit::TestCase
|
|
33
34
|
emits = d.emits
|
34
35
|
assert(emits.length > 0)
|
35
36
|
assert_equal(stat, emits[0][2])
|
37
|
+
assert(emits[0][1].is_a?(Fluent::EventTime))
|
36
38
|
end
|
37
39
|
end
|
data/test/plugin/test_in_http.rb
CHANGED
@@ -4,6 +4,18 @@ require 'fluent/plugin/in_http'
|
|
4
4
|
require 'net/http'
|
5
5
|
|
6
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
|
+
|
7
19
|
def setup
|
8
20
|
Fluent::Test.setup
|
9
21
|
end
|
@@ -33,31 +45,47 @@ class HttpInputTest < Test::Unit::TestCase
|
|
33
45
|
def test_time
|
34
46
|
d = create_driver
|
35
47
|
|
36
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
48
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
37
49
|
Fluent::Engine.now = time
|
38
50
|
|
39
51
|
d.expect_emit "tag1", time, {"a"=>1}
|
40
52
|
d.expect_emit "tag2", time, {"a"=>2}
|
41
53
|
|
42
54
|
d.run do
|
43
|
-
d.expected_emits.each {|tag,
|
55
|
+
d.expected_emits.each {|tag,_time,record|
|
44
56
|
res = post("/#{tag}", {"json"=>record.to_json})
|
45
57
|
assert_equal "200", res.code
|
46
58
|
}
|
47
59
|
end
|
48
60
|
end
|
49
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
|
+
|
50
78
|
def test_json
|
51
79
|
d = create_driver
|
52
80
|
|
53
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
81
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
54
82
|
|
55
83
|
d.expect_emit "tag1", time, {"a"=>1}
|
56
84
|
d.expect_emit "tag2", time, {"a"=>2}
|
57
85
|
|
58
86
|
d.run do
|
59
|
-
d.expected_emits.each {|tag,
|
60
|
-
res = post("/#{tag}", {"json"=>record.to_json, "time"=>
|
87
|
+
d.expected_emits.each {|tag,_time,record|
|
88
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s})
|
61
89
|
assert_equal "200", res.code
|
62
90
|
}
|
63
91
|
end
|
@@ -70,7 +98,7 @@ class HttpInputTest < Test::Unit::TestCase
|
|
70
98
|
def test_multi_json
|
71
99
|
d = create_driver
|
72
100
|
|
73
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
101
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
74
102
|
|
75
103
|
events = [{"a"=>1},{"a"=>2}]
|
76
104
|
tag = "tag1"
|
@@ -94,8 +122,8 @@ class HttpInputTest < Test::Unit::TestCase
|
|
94
122
|
d.expect_emit "tag2", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>2}
|
95
123
|
|
96
124
|
d.run do
|
97
|
-
d.expected_emits.each {|tag,
|
98
|
-
res = post("/#{tag}", {"json"=>record.to_json, "time"=>
|
125
|
+
d.expected_emits.each {|tag,_time,record|
|
126
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s})
|
99
127
|
assert_equal "200", res.code
|
100
128
|
}
|
101
129
|
end
|
@@ -119,66 +147,6 @@ class HttpInputTest < Test::Unit::TestCase
|
|
119
147
|
|
120
148
|
end
|
121
149
|
|
122
|
-
def test_json_with_add_remote_addr_given_x_forwarded_for
|
123
|
-
d = create_driver(CONFIG + "add_remote_addr true")
|
124
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
125
|
-
|
126
|
-
d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}
|
127
|
-
d.expect_emit "tag2", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}
|
128
|
-
|
129
|
-
d.run do
|
130
|
-
d.expected_emits.each {|tag,_time,record|
|
131
|
-
res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
|
132
|
-
assert_equal "200", res.code
|
133
|
-
}
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_multi_json_with_add_remote_addr_given_x_forwarded_for
|
139
|
-
d = create_driver(CONFIG + "add_remote_addr true")
|
140
|
-
|
141
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
142
|
-
events = [{"a"=>1},{"a"=>2}]
|
143
|
-
tag = "tag1"
|
144
|
-
|
145
|
-
d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}
|
146
|
-
d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>2}
|
147
|
-
|
148
|
-
d.run do
|
149
|
-
res = post("/#{tag}", {"json"=>events.to_json, "time"=>time.to_s}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
|
150
|
-
assert_equal "200", res.code
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_add_remote_addr_given_multi_x_forwarded_for
|
156
|
-
d = create_driver(CONFIG + "add_remote_addr true")
|
157
|
-
|
158
|
-
tag = "tag1"
|
159
|
-
time = event_time("2011-01-02 13:14:15 UTC").to_i
|
160
|
-
record = {"a" => 1}
|
161
|
-
|
162
|
-
d.expect_emit tag, time, {"REMOTE_ADDR"=>"129.78.138.66", "a" => 1}
|
163
|
-
|
164
|
-
d.run do
|
165
|
-
res = post("/#{tag}", {"json" => record.to_json, "time" => time.to_s}) { |http, req|
|
166
|
-
# net/http can't send multiple headers so overwrite it.
|
167
|
-
def req.each_capitalized
|
168
|
-
block_given? or return enum_for(__method__) { @header.size }
|
169
|
-
@header.each do |k, vs|
|
170
|
-
vs.each { |v|
|
171
|
-
yield capitalize(k), v
|
172
|
-
}
|
173
|
-
end
|
174
|
-
end
|
175
|
-
req.add_field("X-Forwarded-For", "129.78.138.66, 127.0.0.1")
|
176
|
-
req.add_field("X-Forwarded-For", "8.8.8.8")
|
177
|
-
}
|
178
|
-
assert_equal "200", res.code
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
150
|
def test_multi_json_with_add_http_headers
|
183
151
|
d = create_driver(CONFIG + "add_http_headers true")
|
184
152
|
|
@@ -191,7 +159,7 @@ class HttpInputTest < Test::Unit::TestCase
|
|
191
159
|
assert_equal "200", res.code
|
192
160
|
end
|
193
161
|
|
194
|
-
d.emit_streams.each { |
|
162
|
+
d.emit_streams.each { |_tag, es|
|
195
163
|
assert include_http_header?(es.first[1])
|
196
164
|
}
|
197
165
|
end
|
@@ -199,13 +167,13 @@ class HttpInputTest < Test::Unit::TestCase
|
|
199
167
|
def test_json_with_add_http_headers
|
200
168
|
d = create_driver(CONFIG + "add_http_headers true")
|
201
169
|
|
202
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
170
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
203
171
|
|
204
172
|
records = [["tag1", time, {"a"=>1}], ["tag2", time, {"a"=>2}]]
|
205
173
|
|
206
174
|
d.run do
|
207
|
-
records.each {|tag,
|
208
|
-
res = post("/#{tag}", {"json"=>record.to_json, "time"=>
|
175
|
+
records.each {|tag,_time,record|
|
176
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s})
|
209
177
|
assert_equal "200", res.code
|
210
178
|
|
211
179
|
}
|
@@ -219,46 +187,30 @@ class HttpInputTest < Test::Unit::TestCase
|
|
219
187
|
def test_application_json
|
220
188
|
d = create_driver
|
221
189
|
|
222
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
190
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
223
191
|
|
224
192
|
d.expect_emit "tag1", time, {"a"=>1}
|
225
193
|
d.expect_emit "tag2", time, {"a"=>2}
|
226
194
|
|
227
195
|
d.run do
|
228
|
-
d.expected_emits.each {|tag,
|
229
|
-
res = post("/#{tag}?time=#{
|
196
|
+
d.expected_emits.each {|tag,_time,record|
|
197
|
+
res = post("/#{tag}?time=#{_time.to_s}", record.to_json, {"Content-Type"=>"application/json; charset=utf-8"})
|
230
198
|
assert_equal "200", res.code
|
231
199
|
}
|
232
200
|
end
|
233
201
|
end
|
234
202
|
|
235
|
-
def test_application_msgpack
|
236
|
-
d = create_driver
|
237
|
-
|
238
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
239
|
-
|
240
|
-
d.expect_emit "tag1", time, {"a"=>1}
|
241
|
-
d.expect_emit "tag2", time, {"a"=>2}
|
242
|
-
|
243
|
-
d.run do
|
244
|
-
d.expected_emits.each {|tag,time,record|
|
245
|
-
res = post("/#{tag}?time=#{time.to_s}", record.to_msgpack, {"content-type"=>"application/msgpack; charset=utf-8"})
|
246
|
-
assert_equal "200", res.code
|
247
|
-
}
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
203
|
def test_msgpack
|
252
204
|
d = create_driver
|
253
205
|
|
254
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
206
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
255
207
|
|
256
208
|
d.expect_emit "tag1", time, {"a"=>1}
|
257
209
|
d.expect_emit "tag2", time, {"a"=>2}
|
258
210
|
|
259
211
|
d.run do
|
260
|
-
d.expected_emits.each {|tag,
|
261
|
-
res = post("/#{tag}", {"msgpack"=>record.to_msgpack, "time"=>
|
212
|
+
d.expected_emits.each {|tag,_time,record|
|
213
|
+
res = post("/#{tag}", {"msgpack"=>record.to_msgpack, "time"=>_time.to_s})
|
262
214
|
assert_equal "200", res.code
|
263
215
|
}
|
264
216
|
end
|
@@ -267,7 +219,7 @@ class HttpInputTest < Test::Unit::TestCase
|
|
267
219
|
def test_multi_msgpack
|
268
220
|
d = create_driver
|
269
221
|
|
270
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
222
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
271
223
|
|
272
224
|
events = [{"a"=>1},{"a"=>2}]
|
273
225
|
tag = "tag1"
|
@@ -289,17 +241,17 @@ class HttpInputTest < Test::Unit::TestCase
|
|
289
241
|
types field_1:integer
|
290
242
|
])
|
291
243
|
|
292
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
244
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
293
245
|
|
294
246
|
d.expect_emit "tag1", time, {"field_1" => 1, "field_2" => 'str'}
|
295
247
|
d.expect_emit "tag2", time, {"field_1" => 2, "field_2" => 'str'}
|
296
248
|
|
297
249
|
d.run do
|
298
|
-
d.expected_emits.each { |tag,
|
250
|
+
d.expected_emits.each { |tag, _time, record|
|
299
251
|
body = record.map { |k, v|
|
300
252
|
v.to_s
|
301
253
|
}.join(':')
|
302
|
-
res = post("/#{tag}?time=#{
|
254
|
+
res = post("/#{tag}?time=#{_time.to_s}", body, {'Content-Type' => 'application/octet-stream'})
|
303
255
|
assert_equal "200", res.code
|
304
256
|
}
|
305
257
|
end
|
@@ -313,15 +265,15 @@ class HttpInputTest < Test::Unit::TestCase
|
|
313
265
|
keys foo,bar
|
314
266
|
])
|
315
267
|
|
316
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
268
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
317
269
|
|
318
270
|
d.expect_emit "tag1", time, {"foo" => "1", "bar" => 'st"r'}
|
319
271
|
d.expect_emit "tag2", time, {"foo" => "2", "bar" => 'str'}
|
320
272
|
|
321
273
|
d.run do
|
322
|
-
d.expected_emits.each { |tag,
|
274
|
+
d.expected_emits.each { |tag, _time, record|
|
323
275
|
body = record.map { |k, v| v }.to_csv
|
324
|
-
res = post("/#{tag}?time=#{
|
276
|
+
res = post("/#{tag}?time=#{_time.to_s}", body, {'Content-Type' => 'text/comma-separated-values'})
|
325
277
|
assert_equal "200", res.code
|
326
278
|
}
|
327
279
|
end
|
@@ -331,14 +283,14 @@ class HttpInputTest < Test::Unit::TestCase
|
|
331
283
|
d = create_driver(CONFIG + "respond_with_empty_img true")
|
332
284
|
assert_equal true, d.instance.respond_with_empty_img
|
333
285
|
|
334
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
286
|
+
time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
|
335
287
|
|
336
288
|
d.expect_emit "tag1", time, {"a"=>1}
|
337
289
|
d.expect_emit "tag2", time, {"a"=>2}
|
338
290
|
|
339
291
|
d.run do
|
340
|
-
d.expected_emits.each {|tag,
|
341
|
-
res = post("/#{tag}", {"json"=>record.to_json, "time"=>
|
292
|
+
d.expected_emits.each {|tag,_time,record|
|
293
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s})
|
342
294
|
assert_equal "200", res.code
|
343
295
|
# Ruby returns ASCII-8 encoded string for GIF.
|
344
296
|
assert_equal Fluent::HttpInput::EMPTY_GIF_IMAGE, res.body.force_encoding("UTF-8")
|
@@ -350,39 +302,60 @@ class HttpInputTest < Test::Unit::TestCase
|
|
350
302
|
d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
|
351
303
|
assert_equal ["http://foo.com"], d.instance.cors_allow_origins
|
352
304
|
|
353
|
-
|
305
|
+
test_in_http_cros_allowed = nil
|
306
|
+
acao = nil
|
354
307
|
|
355
|
-
|
356
|
-
|
308
|
+
begin
|
309
|
+
d.run do
|
310
|
+
Net::HTTP.start("127.0.0.1", PORT) do |http|
|
311
|
+
req = Net::HTTP::Post.new("/foo/bar", {"Origin" => "http://foo.com", "Content-Type" => "application/octet-stream"})
|
312
|
+
res = http.request(req)
|
357
313
|
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
314
|
+
acao = res["Access-Control-Allow-Origin"]
|
315
|
+
end
|
316
|
+
end
|
317
|
+
test_in_http_cros_allowed = true
|
318
|
+
rescue
|
319
|
+
test_in_http_cros_allowed = false
|
364
320
|
end
|
321
|
+
|
322
|
+
assert_equal true, test_in_http_cros_allowed
|
323
|
+
assert_equal "http://foo.com", acao
|
365
324
|
end
|
366
325
|
|
367
326
|
def test_cors_disallowed
|
368
327
|
d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
|
369
328
|
assert_equal ["http://foo.com"], d.instance.cors_allow_origins
|
370
329
|
|
371
|
-
|
330
|
+
test_in_http_cros_disallowed = nil
|
331
|
+
response_code = nil
|
372
332
|
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
333
|
+
begin
|
334
|
+
d.run do
|
335
|
+
Net::HTTP.start("127.0.0.1", PORT) do |http|
|
336
|
+
req = Net::HTTP::Post.new("/foo/bar", {"Origin" => "http://bar.com", "Content-Type" => "application/octet-stream"})
|
337
|
+
res = http.request(req)
|
338
|
+
|
339
|
+
response_code = res.code
|
340
|
+
end
|
341
|
+
end
|
342
|
+
test_in_http_cros_disallowed = true
|
343
|
+
rescue
|
344
|
+
test_in_http_cros_disallowed = false
|
379
345
|
end
|
346
|
+
|
347
|
+
assert_equal true, test_in_http_cros_disallowed
|
348
|
+
assert_equal "403", response_code
|
380
349
|
end
|
381
350
|
|
382
351
|
$test_in_http_connection_object_ids = []
|
383
352
|
$test_in_http_content_types = []
|
384
353
|
$test_in_http_content_types_flag = false
|
385
354
|
module ContentTypeHook
|
355
|
+
def initialize(*args)
|
356
|
+
@io_handler = nil
|
357
|
+
super
|
358
|
+
end
|
386
359
|
def on_headers_complete(headers)
|
387
360
|
super
|
388
361
|
if $test_in_http_content_types_flag
|
@@ -405,66 +378,42 @@ class HttpInputTest < Test::Unit::TestCase
|
|
405
378
|
def test_if_content_type_is_initialized_properly
|
406
379
|
# This test is to check if Fluent::HttpInput::Handler's @content_type is initialized properly.
|
407
380
|
# 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
381
|
|
417
382
|
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
383
|
d = create_driver
|
439
384
|
|
385
|
+
$test_in_http_content_types_flag = true
|
440
386
|
d.run do
|
441
387
|
# Send two requests the second one has no Content-Type in Keep-Alive
|
442
388
|
Net::HTTP.start("127.0.0.1", PORT) do |http|
|
443
|
-
req = Net::HTTP::Post.new("/foodb/bartbl", {"connection" => "keepalive", "
|
389
|
+
req = Net::HTTP::Post.new("/foodb/bartbl", {"connection" => "keepalive", "Content-Type" => "application/json"})
|
444
390
|
res = http.request(req)
|
445
391
|
|
446
392
|
req = Net::HTTP::Get.new("/foodb/bartbl", {"connection" => "keepalive"})
|
447
393
|
res = http.request(req)
|
448
394
|
end
|
449
395
|
|
450
|
-
assert_equal(['application/json', ''], ext_handler.content_types)
|
451
396
|
end
|
452
397
|
ensure
|
453
|
-
|
454
|
-
Fluent::HttpInput.module_eval do
|
455
|
-
remove_const(:Handler) if const_defined?(:Handler)
|
456
|
-
const_set(:Handler, orig_handler)
|
457
|
-
end
|
398
|
+
$test_in_http_content_types_flag = false
|
458
399
|
end
|
400
|
+
assert_equal(['application/json', ''], $test_in_http_content_types)
|
401
|
+
# Asserting keepalive
|
402
|
+
assert_equal $test_in_http_connection_object_ids[0], $test_in_http_connection_object_ids[1]
|
459
403
|
end
|
460
404
|
|
461
|
-
def post(path, params, header = {}
|
405
|
+
def post(path, params, header = {})
|
462
406
|
http = Net::HTTP.new("127.0.0.1", PORT)
|
463
407
|
req = Net::HTTP::Post.new(path, header)
|
464
|
-
block.call(http, req) if block
|
465
408
|
if params.is_a?(String)
|
409
|
+
unless header.has_key?('Content-Type')
|
410
|
+
header['Content-Type'] = 'application/octet-stream'
|
411
|
+
end
|
466
412
|
req.body = params
|
467
413
|
else
|
414
|
+
unless header.has_key?('Content-Type')
|
415
|
+
header['Content-Type'] = 'application/x-www-form-urlencoded'
|
416
|
+
end
|
468
417
|
req.set_form_data(params)
|
469
418
|
end
|
470
419
|
http.request(req)
|