fluentd 0.14.7-x64-mingw32 → 0.14.10-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 +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +2 -0
- data/CONTRIBUTING.md +6 -1
- data/ChangeLog +95 -0
- data/Rakefile +21 -0
- data/appveyor.yml +1 -0
- data/code-of-conduct.md +3 -0
- data/example/out_exec_filter.conf +42 -0
- data/fluentd.gemspec +1 -1
- data/lib/fluent/agent.rb +2 -2
- data/lib/fluent/command/binlog_reader.rb +1 -1
- data/lib/fluent/command/cat.rb +15 -4
- data/lib/fluent/compat/output.rb +14 -9
- data/lib/fluent/compat/parser.rb +141 -11
- data/lib/fluent/config/configure_proxy.rb +2 -11
- data/lib/fluent/config/section.rb +8 -1
- data/lib/fluent/configurable.rb +1 -3
- data/lib/fluent/env.rb +1 -1
- data/lib/fluent/log.rb +1 -1
- data/lib/fluent/plugin/base.rb +17 -0
- data/lib/fluent/plugin/filter_parser.rb +108 -0
- data/lib/fluent/plugin/filter_record_transformer.rb +14 -35
- data/lib/fluent/plugin/filter_stdout.rb +1 -1
- data/lib/fluent/plugin/formatter.rb +5 -0
- data/lib/fluent/plugin/formatter_msgpack.rb +4 -0
- data/lib/fluent/plugin/formatter_stdout.rb +3 -2
- data/lib/fluent/plugin/formatter_tsv.rb +34 -0
- data/lib/fluent/plugin/in_exec.rb +48 -93
- data/lib/fluent/plugin/in_forward.rb +66 -265
- data/lib/fluent/plugin/in_http.rb +68 -65
- data/lib/fluent/plugin/in_monitor_agent.rb +8 -4
- data/lib/fluent/plugin/in_syslog.rb +42 -58
- data/lib/fluent/plugin/in_tail.rb +29 -14
- data/lib/fluent/plugin/in_tcp.rb +54 -14
- data/lib/fluent/plugin/in_udp.rb +49 -13
- data/lib/fluent/plugin/multi_output.rb +1 -3
- data/lib/fluent/plugin/out_exec.rb +58 -71
- data/lib/fluent/plugin/out_exec_filter.rb +199 -279
- data/lib/fluent/plugin/out_file.rb +172 -81
- data/lib/fluent/plugin/out_forward.rb +229 -206
- data/lib/fluent/plugin/out_stdout.rb +6 -21
- data/lib/fluent/plugin/output.rb +90 -59
- data/lib/fluent/plugin/parser.rb +121 -61
- data/lib/fluent/plugin/parser_csv.rb +9 -3
- data/lib/fluent/plugin/parser_json.rb +37 -35
- data/lib/fluent/plugin/parser_ltsv.rb +11 -19
- data/lib/fluent/plugin/parser_msgpack.rb +50 -0
- data/lib/fluent/plugin/parser_regexp.rb +15 -42
- data/lib/fluent/plugin/parser_tsv.rb +8 -3
- data/lib/fluent/plugin_helper.rb +10 -1
- data/lib/fluent/plugin_helper/child_process.rb +139 -73
- data/lib/fluent/plugin_helper/compat_parameters.rb +93 -4
- data/lib/fluent/plugin_helper/event_emitter.rb +14 -1
- data/lib/fluent/plugin_helper/event_loop.rb +24 -6
- data/lib/fluent/plugin_helper/extract.rb +16 -4
- data/lib/fluent/plugin_helper/formatter.rb +9 -11
- data/lib/fluent/plugin_helper/inject.rb +16 -1
- data/lib/fluent/plugin_helper/parser.rb +3 -3
- data/lib/fluent/plugin_helper/server.rb +494 -0
- data/lib/fluent/plugin_helper/socket.rb +101 -0
- data/lib/fluent/plugin_helper/socket_option.rb +84 -0
- data/lib/fluent/plugin_helper/timer.rb +1 -0
- data/lib/fluent/root_agent.rb +1 -1
- data/lib/fluent/test/driver/base.rb +95 -49
- data/lib/fluent/test/driver/base_owner.rb +18 -8
- data/lib/fluent/test/driver/multi_output.rb +2 -1
- data/lib/fluent/test/driver/output.rb +29 -6
- data/lib/fluent/test/helpers.rb +3 -1
- data/lib/fluent/test/log.rb +4 -0
- data/lib/fluent/test/startup_shutdown.rb +13 -0
- data/lib/fluent/time.rb +14 -8
- data/lib/fluent/version.rb +1 -1
- data/lib/fluent/winsvc.rb +1 -1
- data/test/command/test_binlog_reader.rb +5 -1
- data/test/compat/test_parser.rb +10 -0
- data/test/config/test_configurable.rb +193 -0
- data/test/config/test_configure_proxy.rb +0 -43
- data/test/helper.rb +36 -1
- data/test/plugin/test_base.rb +16 -0
- data/test/plugin/test_filter_parser.rb +665 -0
- data/test/plugin/test_filter_record_transformer.rb +36 -100
- data/test/plugin/test_filter_stdout.rb +18 -27
- data/test/plugin/test_in_dummy.rb +1 -1
- data/test/plugin/test_in_exec.rb +206 -94
- data/test/plugin/test_in_forward.rb +268 -347
- data/test/plugin/test_in_http.rb +310 -186
- data/test/plugin/test_in_monitor_agent.rb +65 -35
- data/test/plugin/test_in_syslog.rb +39 -3
- data/test/plugin/test_in_tcp.rb +78 -62
- data/test/plugin/test_in_udp.rb +101 -80
- data/test/plugin/test_out_exec.rb +223 -68
- data/test/plugin/test_out_exec_filter.rb +520 -169
- data/test/plugin/test_out_file.rb +637 -177
- data/test/plugin/test_out_forward.rb +242 -234
- data/test/plugin/test_out_null.rb +1 -1
- data/test/plugin/test_out_secondary_file.rb +4 -2
- data/test/plugin/test_out_stdout.rb +14 -35
- data/test/plugin/test_output_as_buffered.rb +60 -2
- data/test/plugin/test_parser.rb +359 -0
- data/test/plugin/test_parser_csv.rb +1 -2
- data/test/plugin/test_parser_json.rb +3 -4
- data/test/plugin/test_parser_labeled_tsv.rb +1 -2
- data/test/plugin/test_parser_none.rb +1 -2
- data/test/plugin/test_parser_regexp.rb +8 -4
- data/test/plugin/test_parser_tsv.rb +4 -3
- data/test/plugin_helper/test_child_process.rb +184 -0
- data/test/plugin_helper/test_compat_parameters.rb +88 -1
- data/test/plugin_helper/test_extract.rb +0 -1
- data/test/plugin_helper/test_formatter.rb +5 -2
- data/test/plugin_helper/test_inject.rb +21 -0
- data/test/plugin_helper/test_parser.rb +6 -5
- data/test/plugin_helper/test_server.rb +905 -0
- data/test/test_event_time.rb +3 -1
- data/test/test_output.rb +53 -2
- data/test/test_plugin_classes.rb +20 -0
- data/test/test_root_agent.rb +139 -0
- data/test/test_test_drivers.rb +135 -0
- metadata +28 -8
- data/test/plugin/test_parser_base.rb +0 -32
data/test/plugin/test_in_http.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require_relative '../helper'
|
2
|
-
require 'fluent/test'
|
2
|
+
require 'fluent/test/driver/input'
|
3
3
|
require 'fluent/plugin/in_http'
|
4
4
|
require 'net/http'
|
5
|
+
require 'timecop'
|
5
6
|
|
6
7
|
class HttpInputTest < Test::Unit::TestCase
|
7
8
|
class << self
|
@@ -20,6 +21,10 @@ class HttpInputTest < Test::Unit::TestCase
|
|
20
21
|
Fluent::Test.setup
|
21
22
|
end
|
22
23
|
|
24
|
+
def teardown
|
25
|
+
Timecop.return
|
26
|
+
end
|
27
|
+
|
23
28
|
PORT = unused_port
|
24
29
|
CONFIG = %[
|
25
30
|
port #{PORT}
|
@@ -30,7 +35,7 @@ class HttpInputTest < Test::Unit::TestCase
|
|
30
35
|
]
|
31
36
|
|
32
37
|
def create_driver(conf=CONFIG)
|
33
|
-
Fluent::Test::
|
38
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::HttpInput).configure(conf)
|
34
39
|
end
|
35
40
|
|
36
41
|
def test_configure
|
@@ -44,228 +49,314 @@ class HttpInputTest < Test::Unit::TestCase
|
|
44
49
|
|
45
50
|
def test_time
|
46
51
|
d = create_driver
|
52
|
+
time = event_time("2011-01-02 13:14:15.123 UTC")
|
53
|
+
Timecop.freeze(Time.at(time))
|
47
54
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
55
|
+
events = [
|
56
|
+
["tag1", time, {"a" => 1}],
|
57
|
+
["tag2", time, {"a" => 2}],
|
58
|
+
]
|
59
|
+
res_codes = []
|
53
60
|
|
54
|
-
d.run do
|
55
|
-
|
61
|
+
d.run(expect_records: 2) do
|
62
|
+
events.each do |tag, _time, record|
|
56
63
|
res = post("/#{tag}", {"json"=>record.to_json})
|
57
|
-
|
58
|
-
|
64
|
+
res_codes << res.code
|
65
|
+
end
|
59
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]
|
60
72
|
end
|
61
73
|
|
62
74
|
def test_time_as_float
|
63
75
|
d = create_driver
|
76
|
+
time = event_time("2011-01-02 13:14:15.123 UTC")
|
77
|
+
float_time = time.to_f
|
64
78
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
79
|
+
events = [
|
80
|
+
["tag1", time, {"a"=>1}],
|
81
|
+
]
|
82
|
+
res_codes = []
|
69
83
|
|
70
|
-
d.run do
|
71
|
-
|
84
|
+
d.run(expect_records: 1) do
|
85
|
+
events.each do |tag, t, record|
|
72
86
|
res = post("/#{tag}", {"json"=>record.to_json, "time"=>float_time.to_s})
|
73
|
-
|
74
|
-
|
87
|
+
res_codes << res.code
|
88
|
+
end
|
75
89
|
end
|
90
|
+
assert_equal ["200"], res_codes
|
91
|
+
assert_equal events, d.events
|
92
|
+
assert_equal_event_time time, d.events[0][1]
|
76
93
|
end
|
77
94
|
|
78
95
|
def test_json
|
79
96
|
d = create_driver
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
91
111
|
end
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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]
|
96
116
|
end
|
97
117
|
|
98
118
|
def test_multi_json
|
99
119
|
d = create_driver
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
+
]
|
104
128
|
tag = "tag1"
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
d.run do
|
111
|
-
res = post("/#{tag}", {"json"=>events.to_json, "time"=>time.to_s})
|
112
|
-
assert_equal "200", res.code
|
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
|
113
133
|
end
|
114
|
-
|
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]
|
115
138
|
end
|
116
139
|
|
117
140
|
def test_json_with_add_remote_addr
|
118
141
|
d = create_driver(CONFIG + "add_remote_addr true")
|
119
|
-
time =
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
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
|
129
155
|
end
|
130
|
-
|
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]
|
131
160
|
end
|
132
161
|
|
133
162
|
def test_multi_json_with_add_remote_addr
|
134
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
|
135
166
|
|
136
|
-
|
137
|
-
events = [{"a"=>1},{"a"=>2}]
|
167
|
+
records = [{"a"=>1},{"a"=>2}]
|
138
168
|
tag = "tag1"
|
169
|
+
res_codes = []
|
139
170
|
|
140
|
-
d.
|
141
|
-
|
142
|
-
|
143
|
-
d.run do
|
144
|
-
res = post("/#{tag}", {"json"=>events.to_json, "time"=>time.to_s})
|
145
|
-
assert_equal "200", res.code
|
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
|
146
174
|
end
|
175
|
+
assert_equal ["200"], res_codes
|
147
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"]
|
148
185
|
end
|
149
186
|
|
150
187
|
def test_json_with_add_remote_addr_given_x_forwarded_for
|
151
188
|
d = create_driver(CONFIG + "add_remote_addr true")
|
152
|
-
time =
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
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
|
162
203
|
end
|
204
|
+
assert_equal ["200", "200"], res_codes
|
163
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])
|
164
213
|
end
|
165
214
|
|
166
215
|
def test_multi_json_with_add_remote_addr_given_x_forwarded_for
|
167
216
|
d = create_driver(CONFIG + "add_remote_addr true")
|
168
217
|
|
169
|
-
time =
|
170
|
-
|
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
|
+
]
|
171
225
|
tag = "tag1"
|
226
|
+
res_codes = []
|
172
227
|
|
173
|
-
d.
|
174
|
-
|
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
|
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
|
179
231
|
end
|
180
|
-
|
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]
|
181
236
|
end
|
182
237
|
|
183
238
|
def test_multi_json_with_add_http_headers
|
184
239
|
d = create_driver(CONFIG + "add_http_headers true")
|
185
|
-
|
186
|
-
|
187
|
-
|
240
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
241
|
+
time_i = time.to_i
|
242
|
+
records = [{"a"=>1},{"a"=>2}]
|
188
243
|
tag = "tag1"
|
244
|
+
res_codes = []
|
189
245
|
|
190
|
-
d.run do
|
191
|
-
res = post("/#{tag}", {"json"=>
|
192
|
-
|
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
|
193
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"]
|
194
255
|
|
195
|
-
|
196
|
-
|
197
|
-
|
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])
|
198
262
|
end
|
199
263
|
|
200
264
|
def test_json_with_add_http_headers
|
201
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
|
202
281
|
|
203
|
-
|
204
|
-
|
205
|
-
|
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"]
|
206
285
|
|
207
|
-
d.
|
208
|
-
|
209
|
-
|
210
|
-
assert_equal "200", res.code
|
211
|
-
|
212
|
-
}
|
213
|
-
end
|
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"]
|
214
289
|
|
215
|
-
d.
|
216
|
-
|
217
|
-
}
|
290
|
+
assert include_http_header?(d.events[0][2])
|
291
|
+
assert include_http_header?(d.events[1][2])
|
218
292
|
end
|
219
293
|
|
220
294
|
def test_application_json
|
221
295
|
d = create_driver
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
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
|
233
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]
|
234
314
|
end
|
235
315
|
|
236
316
|
def test_msgpack
|
237
317
|
d = create_driver
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
318
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
319
|
+
time_i = time.to_i
|
320
|
+
|
321
|
+
events = [
|
322
|
+
["tag1", time, {"a"=>1}],
|
323
|
+
["tag2", time, {"a"=>2}],
|
324
|
+
]
|
325
|
+
res_codes = []
|
326
|
+
|
327
|
+
d.run(expect_records: 2) do
|
328
|
+
events.each do |tag, t, record|
|
329
|
+
res = post("/#{tag}", {"msgpack"=>record.to_msgpack, "time"=>time_i.to_s})
|
330
|
+
res_codes << res.code
|
331
|
+
end
|
249
332
|
end
|
333
|
+
assert_equal ["200", "200"], res_codes
|
334
|
+
assert_equal events, d.events
|
335
|
+
assert_equal_event_time time, d.events[0][1]
|
336
|
+
assert_equal_event_time time, d.events[1][1]
|
250
337
|
end
|
251
338
|
|
252
339
|
def test_multi_msgpack
|
253
340
|
d = create_driver
|
254
341
|
|
255
|
-
time =
|
342
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
343
|
+
time_i = time.to_i
|
256
344
|
|
257
|
-
|
345
|
+
records = [{"a"=>1},{"a"=>2}]
|
346
|
+
events = [
|
347
|
+
["tag1", time, records[0]],
|
348
|
+
["tag1", time, records[1]],
|
349
|
+
]
|
258
350
|
tag = "tag1"
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
d.run do
|
265
|
-
res = post("/#{tag}", {"msgpack"=>events.to_msgpack, "time"=>time.to_s})
|
266
|
-
assert_equal "200", res.code
|
351
|
+
res_codes = []
|
352
|
+
d.run(expect_records: 2) do
|
353
|
+
res = post("/#{tag}", {"msgpack"=>records.to_msgpack, "time"=>time_i.to_s})
|
354
|
+
res_codes << res.code
|
267
355
|
end
|
268
|
-
|
356
|
+
assert_equal ["200"], res_codes
|
357
|
+
assert_equal events, d.events
|
358
|
+
assert_equal_event_time time, d.events[0][1]
|
359
|
+
assert_equal_event_time time, d.events[1][1]
|
269
360
|
end
|
270
361
|
|
271
362
|
def test_with_regexp
|
@@ -274,20 +365,27 @@ class HttpInputTest < Test::Unit::TestCase
|
|
274
365
|
types field_1:integer
|
275
366
|
])
|
276
367
|
|
277
|
-
time =
|
368
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
369
|
+
time_i = time.to_i
|
370
|
+
events = [
|
371
|
+
["tag1", time, {"field_1" => 1, "field_2" => 'str'}],
|
372
|
+
["tag2", time, {"field_1" => 2, "field_2" => 'str'}],
|
373
|
+
]
|
374
|
+
res_codes = []
|
278
375
|
|
279
|
-
d.
|
280
|
-
|
281
|
-
|
282
|
-
d.run do
|
283
|
-
d.expected_emits.each { |tag, _time, record|
|
376
|
+
d.run(expect_records: 2) do
|
377
|
+
events.each do |tag, t, record|
|
284
378
|
body = record.map { |k, v|
|
285
379
|
v.to_s
|
286
380
|
}.join(':')
|
287
|
-
res = post("/#{tag}?time=#{
|
288
|
-
|
289
|
-
|
381
|
+
res = post("/#{tag}?time=#{time_i.to_s}", body, {'Content-Type' => 'application/octet-stream'})
|
382
|
+
res_codes << res.code
|
383
|
+
end
|
290
384
|
end
|
385
|
+
assert_equal ["200", "200"], res_codes
|
386
|
+
assert_equal events, d.events
|
387
|
+
assert_equal_event_time time, d.events[0][1]
|
388
|
+
assert_equal_event_time time, d.events[1][1]
|
291
389
|
end
|
292
390
|
|
293
391
|
def test_with_csv
|
@@ -297,72 +395,98 @@ class HttpInputTest < Test::Unit::TestCase
|
|
297
395
|
format csv
|
298
396
|
keys foo,bar
|
299
397
|
])
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
398
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
399
|
+
time_i = time.to_i
|
400
|
+
events = [
|
401
|
+
["tag1", time, {"foo" => "1", "bar" => 'st"r'}],
|
402
|
+
["tag2", time, {"foo" => "2", "bar" => 'str'}],
|
403
|
+
]
|
404
|
+
res_codes = []
|
405
|
+
|
406
|
+
d.run(expect_records: 2) do
|
407
|
+
events.each do |tag, t, record|
|
308
408
|
body = record.map { |k, v| v }.to_csv
|
309
|
-
res = post("/#{tag}?time=#{
|
310
|
-
|
311
|
-
|
409
|
+
res = post("/#{tag}?time=#{time_i.to_s}", body, {'Content-Type' => 'text/comma-separated-values'})
|
410
|
+
res_codes << res.code
|
411
|
+
end
|
312
412
|
end
|
413
|
+
assert_equal ["200", "200"], res_codes
|
414
|
+
assert_equal events, d.events
|
415
|
+
assert_equal_event_time time, d.events[0][1]
|
416
|
+
assert_equal_event_time time, d.events[1][1]
|
313
417
|
end
|
314
418
|
|
315
419
|
def test_resonse_with_empty_img
|
316
420
|
d = create_driver(CONFIG + "respond_with_empty_img true")
|
317
421
|
assert_equal true, d.instance.respond_with_empty_img
|
318
422
|
|
319
|
-
time =
|
320
|
-
|
321
|
-
|
322
|
-
|
423
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
424
|
+
time_i = time.to_i
|
425
|
+
events = [
|
426
|
+
["tag1", time, {"a"=>1}],
|
427
|
+
["tag2", time, {"a"=>2}],
|
428
|
+
]
|
429
|
+
res_codes = []
|
430
|
+
res_bodies = []
|
323
431
|
|
324
432
|
d.run do
|
325
|
-
|
326
|
-
res = post("/#{tag}", {"json"=>record.to_json, "time"=>
|
327
|
-
|
433
|
+
events.each do |tag, _t, record|
|
434
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
|
435
|
+
res_codes << res.code
|
328
436
|
# Ruby returns ASCII-8 encoded string for GIF.
|
329
|
-
|
330
|
-
|
437
|
+
res_bodies << res.body.force_encoding("UTF-8")
|
438
|
+
end
|
331
439
|
end
|
440
|
+
assert_equal ["200", "200"], res_codes
|
441
|
+
assert_equal [Fluent::Plugin::HttpInput::EMPTY_GIF_IMAGE, Fluent::Plugin::HttpInput::EMPTY_GIF_IMAGE], res_bodies
|
442
|
+
assert_equal events, d.events
|
443
|
+
assert_equal_event_time time, d.events[0][1]
|
444
|
+
assert_equal_event_time time, d.events[1][1]
|
332
445
|
end
|
333
446
|
|
334
447
|
def test_cors_allowed
|
335
448
|
d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
|
336
449
|
assert_equal ["http://foo.com"], d.instance.cors_allow_origins
|
337
450
|
|
338
|
-
time =
|
339
|
-
|
340
|
-
|
341
|
-
|
451
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
452
|
+
time_i = time.to_i
|
453
|
+
events = [
|
454
|
+
["tag1", time, {"a"=>1}],
|
455
|
+
["tag2", time, {"a"=>2}],
|
456
|
+
]
|
457
|
+
res_codes = []
|
458
|
+
res_headers = []
|
342
459
|
|
343
460
|
d.run do
|
344
|
-
|
345
|
-
res = post("/#{tag}", {"json"=>record.to_json, "time"=>
|
346
|
-
|
347
|
-
|
348
|
-
|
461
|
+
events.each do |tag, _t, record|
|
462
|
+
res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://foo.com"})
|
463
|
+
res_codes << res.code
|
464
|
+
res_headers << res["Access-Control-Allow-Origin"]
|
465
|
+
end
|
349
466
|
end
|
467
|
+
assert_equal ["200", "200"], res_codes
|
468
|
+
assert_equal ["http://foo.com", "http://foo.com"], res_headers
|
469
|
+
assert_equal events, d.events
|
470
|
+
assert_equal_event_time time, d.events[0][1]
|
471
|
+
assert_equal_event_time time, d.events[1][1]
|
350
472
|
end
|
351
473
|
|
352
474
|
def test_cors_disallowed
|
353
475
|
d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
|
354
476
|
assert_equal ["http://foo.com"], d.instance.cors_allow_origins
|
355
477
|
|
356
|
-
time =
|
478
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
479
|
+
time_i = time.to_i
|
480
|
+
res_codes = []
|
357
481
|
|
358
|
-
d.
|
482
|
+
d.end_if{ res_codes.size == 2 }
|
359
483
|
d.run do
|
360
|
-
res = post("/tag1", {"json"=>{"a"=>1}.to_json, "time"=>
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
assert_equal "403", res.code
|
484
|
+
res = post("/tag1", {"json"=>{"a"=>1}.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://bar.com"})
|
485
|
+
res_codes << res.code
|
486
|
+
res = post("/tag2", {"json"=>{"a"=>1}.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://bar.com"})
|
487
|
+
res_codes << res.code
|
365
488
|
end
|
489
|
+
assert_equal ["403", "403"], res_codes
|
366
490
|
end
|
367
491
|
|
368
492
|
$test_in_http_connection_object_ids = []
|
@@ -388,7 +512,7 @@ class HttpInputTest < Test::Unit::TestCase
|
|
388
512
|
end
|
389
513
|
end
|
390
514
|
|
391
|
-
class Fluent::HttpInput::Handler
|
515
|
+
class Fluent::Plugin::HttpInput::Handler
|
392
516
|
prepend ContentTypeHook
|
393
517
|
end
|
394
518
|
|