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.

Files changed (252) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +6 -0
  3. data/.gitignore +2 -0
  4. data/.travis.yml +33 -21
  5. data/CONTRIBUTING.md +1 -0
  6. data/ChangeLog +810 -237
  7. data/README.md +0 -25
  8. data/Rakefile +2 -1
  9. data/Vagrantfile +17 -0
  10. data/appveyor.yml +35 -0
  11. data/example/filter_stdout.conf +5 -5
  12. data/example/in_forward.conf +2 -2
  13. data/example/in_http.conf +2 -2
  14. data/example/in_out_forward.conf +17 -0
  15. data/example/in_syslog.conf +2 -2
  16. data/example/in_tail.conf +2 -2
  17. data/example/in_tcp.conf +2 -2
  18. data/example/in_udp.conf +2 -2
  19. data/example/out_copy.conf +4 -4
  20. data/example/out_file.conf +2 -2
  21. data/example/out_forward.conf +2 -2
  22. data/example/out_forward_buf_file.conf +23 -0
  23. data/example/v0_12_filter.conf +8 -8
  24. data/fluent.conf +29 -0
  25. data/fluentd.gemspec +18 -11
  26. data/lib/fluent/agent.rb +60 -58
  27. data/lib/fluent/command/cat.rb +1 -1
  28. data/lib/fluent/command/debug.rb +7 -5
  29. data/lib/fluent/command/fluentd.rb +97 -2
  30. data/lib/fluent/compat/call_super_mixin.rb +67 -0
  31. data/lib/fluent/compat/filter.rb +50 -0
  32. data/lib/fluent/compat/formatter.rb +109 -0
  33. data/lib/fluent/compat/input.rb +50 -0
  34. data/lib/fluent/compat/output.rb +617 -0
  35. data/lib/fluent/compat/output_chain.rb +60 -0
  36. data/lib/fluent/compat/parser.rb +163 -0
  37. data/lib/fluent/compat/propagate_default.rb +62 -0
  38. data/lib/fluent/config.rb +23 -20
  39. data/lib/fluent/config/configure_proxy.rb +119 -70
  40. data/lib/fluent/config/dsl.rb +5 -18
  41. data/lib/fluent/config/element.rb +72 -8
  42. data/lib/fluent/config/error.rb +0 -3
  43. data/lib/fluent/config/literal_parser.rb +0 -2
  44. data/lib/fluent/config/parser.rb +4 -4
  45. data/lib/fluent/config/section.rb +39 -28
  46. data/lib/fluent/config/types.rb +2 -13
  47. data/lib/fluent/config/v1_parser.rb +1 -3
  48. data/lib/fluent/configurable.rb +48 -16
  49. data/lib/fluent/daemon.rb +15 -0
  50. data/lib/fluent/engine.rb +26 -52
  51. data/lib/fluent/env.rb +6 -4
  52. data/lib/fluent/event.rb +58 -11
  53. data/lib/fluent/event_router.rb +5 -5
  54. data/lib/fluent/filter.rb +2 -50
  55. data/lib/fluent/formatter.rb +4 -293
  56. data/lib/fluent/input.rb +2 -32
  57. data/lib/fluent/label.rb +2 -2
  58. data/lib/fluent/load.rb +3 -2
  59. data/lib/fluent/log.rb +107 -38
  60. data/lib/fluent/match.rb +0 -36
  61. data/lib/fluent/mixin.rb +117 -7
  62. data/lib/fluent/msgpack_factory.rb +62 -0
  63. data/lib/fluent/output.rb +7 -612
  64. data/lib/fluent/output_chain.rb +23 -0
  65. data/lib/fluent/parser.rb +4 -800
  66. data/lib/fluent/plugin.rb +100 -121
  67. data/lib/fluent/plugin/bare_output.rb +63 -0
  68. data/lib/fluent/plugin/base.rb +121 -0
  69. data/lib/fluent/plugin/buf_file.rb +101 -182
  70. data/lib/fluent/plugin/buf_memory.rb +9 -92
  71. data/lib/fluent/plugin/buffer.rb +473 -0
  72. data/lib/fluent/plugin/buffer/chunk.rb +135 -0
  73. data/lib/fluent/plugin/buffer/file_chunk.rb +339 -0
  74. data/lib/fluent/plugin/buffer/memory_chunk.rb +100 -0
  75. data/lib/fluent/plugin/exec_util.rb +80 -75
  76. data/lib/fluent/plugin/file_util.rb +33 -28
  77. data/lib/fluent/plugin/file_wrapper.rb +120 -0
  78. data/lib/fluent/plugin/filter.rb +51 -0
  79. data/lib/fluent/plugin/filter_grep.rb +13 -40
  80. data/lib/fluent/plugin/filter_record_transformer.rb +22 -18
  81. data/lib/fluent/plugin/formatter.rb +93 -0
  82. data/lib/fluent/plugin/formatter_csv.rb +48 -0
  83. data/lib/fluent/plugin/formatter_hash.rb +32 -0
  84. data/lib/fluent/plugin/formatter_json.rb +47 -0
  85. data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
  86. data/lib/fluent/plugin/formatter_msgpack.rb +32 -0
  87. data/lib/fluent/plugin/formatter_out_file.rb +45 -0
  88. data/lib/fluent/plugin/formatter_single_value.rb +34 -0
  89. data/lib/fluent/plugin/formatter_stdout.rb +39 -0
  90. data/lib/fluent/plugin/in_debug_agent.rb +4 -0
  91. data/lib/fluent/plugin/in_dummy.rb +22 -18
  92. data/lib/fluent/plugin/in_exec.rb +18 -8
  93. data/lib/fluent/plugin/in_forward.rb +36 -79
  94. data/lib/fluent/plugin/in_gc_stat.rb +4 -0
  95. data/lib/fluent/plugin/in_http.rb +21 -18
  96. data/lib/fluent/plugin/in_monitor_agent.rb +15 -48
  97. data/lib/fluent/plugin/in_object_space.rb +6 -1
  98. data/lib/fluent/plugin/in_stream.rb +7 -3
  99. data/lib/fluent/plugin/in_syslog.rb +46 -95
  100. data/lib/fluent/plugin/in_tail.rb +51 -595
  101. data/lib/fluent/plugin/in_tcp.rb +8 -1
  102. data/lib/fluent/plugin/in_udp.rb +8 -14
  103. data/lib/fluent/plugin/input.rb +33 -0
  104. data/lib/fluent/plugin/multi_output.rb +95 -0
  105. data/lib/fluent/plugin/out_buffered_null.rb +59 -0
  106. data/lib/fluent/plugin/out_copy.rb +11 -7
  107. data/lib/fluent/plugin/out_exec.rb +15 -11
  108. data/lib/fluent/plugin/out_exec_filter.rb +18 -10
  109. data/lib/fluent/plugin/out_file.rb +34 -5
  110. data/lib/fluent/plugin/out_forward.rb +19 -9
  111. data/lib/fluent/plugin/out_null.rb +0 -14
  112. data/lib/fluent/plugin/out_roundrobin.rb +11 -7
  113. data/lib/fluent/plugin/out_stdout.rb +5 -7
  114. data/lib/fluent/plugin/out_stream.rb +3 -1
  115. data/lib/fluent/plugin/output.rb +979 -0
  116. data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
  117. data/lib/fluent/plugin/parser.rb +244 -0
  118. data/lib/fluent/plugin/parser_apache.rb +24 -0
  119. data/lib/fluent/plugin/parser_apache2.rb +84 -0
  120. data/lib/fluent/plugin/parser_apache_error.rb +21 -0
  121. data/lib/fluent/plugin/parser_csv.rb +31 -0
  122. data/lib/fluent/plugin/parser_json.rb +79 -0
  123. data/lib/fluent/plugin/parser_ltsv.rb +50 -0
  124. data/lib/fluent/plugin/parser_multiline.rb +102 -0
  125. data/lib/fluent/plugin/parser_nginx.rb +24 -0
  126. data/lib/fluent/plugin/parser_none.rb +36 -0
  127. data/lib/fluent/plugin/parser_syslog.rb +82 -0
  128. data/lib/fluent/plugin/parser_tsv.rb +37 -0
  129. data/lib/fluent/plugin/socket_util.rb +120 -114
  130. data/lib/fluent/plugin/storage.rb +84 -0
  131. data/lib/fluent/plugin/storage_local.rb +116 -0
  132. data/lib/fluent/plugin/string_util.rb +16 -13
  133. data/lib/fluent/plugin_helper.rb +39 -0
  134. data/lib/fluent/plugin_helper/child_process.rb +298 -0
  135. data/lib/fluent/plugin_helper/compat_parameters.rb +99 -0
  136. data/lib/fluent/plugin_helper/event_emitter.rb +80 -0
  137. data/lib/fluent/plugin_helper/event_loop.rb +118 -0
  138. data/lib/fluent/plugin_helper/retry_state.rb +177 -0
  139. data/lib/fluent/plugin_helper/storage.rb +308 -0
  140. data/lib/fluent/plugin_helper/thread.rb +147 -0
  141. data/lib/fluent/plugin_helper/timer.rb +85 -0
  142. data/lib/fluent/plugin_id.rb +63 -0
  143. data/lib/fluent/process.rb +21 -30
  144. data/lib/fluent/registry.rb +21 -9
  145. data/lib/fluent/root_agent.rb +115 -40
  146. data/lib/fluent/supervisor.rb +330 -320
  147. data/lib/fluent/system_config.rb +42 -18
  148. data/lib/fluent/test.rb +6 -1
  149. data/lib/fluent/test/base.rb +23 -3
  150. data/lib/fluent/test/driver/base.rb +247 -0
  151. data/lib/fluent/test/driver/event_feeder.rb +98 -0
  152. data/lib/fluent/test/driver/filter.rb +35 -0
  153. data/lib/fluent/test/driver/input.rb +31 -0
  154. data/lib/fluent/test/driver/output.rb +78 -0
  155. data/lib/fluent/test/driver/test_event_router.rb +45 -0
  156. data/lib/fluent/test/filter_test.rb +0 -1
  157. data/lib/fluent/test/formatter_test.rb +2 -1
  158. data/lib/fluent/test/input_test.rb +23 -17
  159. data/lib/fluent/test/output_test.rb +28 -39
  160. data/lib/fluent/test/parser_test.rb +1 -1
  161. data/lib/fluent/time.rb +104 -1
  162. data/lib/fluent/{status.rb → unique_id.rb} +15 -24
  163. data/lib/fluent/version.rb +1 -1
  164. data/lib/fluent/winsvc.rb +72 -0
  165. data/test/compat/test_calls_super.rb +164 -0
  166. data/test/config/test_config_parser.rb +83 -0
  167. data/test/config/test_configurable.rb +547 -274
  168. data/test/config/test_configure_proxy.rb +146 -29
  169. data/test/config/test_dsl.rb +3 -181
  170. data/test/config/test_element.rb +274 -0
  171. data/test/config/test_literal_parser.rb +1 -1
  172. data/test/config/test_section.rb +79 -7
  173. data/test/config/test_system_config.rb +21 -0
  174. data/test/config/test_types.rb +3 -26
  175. data/test/helper.rb +78 -8
  176. data/test/plugin/test_bare_output.rb +118 -0
  177. data/test/plugin/test_base.rb +75 -0
  178. data/test/plugin/test_buf_file.rb +420 -521
  179. data/test/plugin/test_buf_memory.rb +32 -194
  180. data/test/plugin/test_buffer.rb +981 -0
  181. data/test/plugin/test_buffer_chunk.rb +110 -0
  182. data/test/plugin/test_buffer_file_chunk.rb +770 -0
  183. data/test/plugin/test_buffer_memory_chunk.rb +265 -0
  184. data/test/plugin/test_filter.rb +255 -0
  185. data/test/plugin/test_filter_grep.rb +2 -73
  186. data/test/plugin/test_filter_record_transformer.rb +24 -68
  187. data/test/plugin/test_filter_stdout.rb +6 -6
  188. data/test/plugin/test_in_debug_agent.rb +2 -0
  189. data/test/plugin/test_in_dummy.rb +11 -17
  190. data/test/plugin/test_in_exec.rb +6 -25
  191. data/test/plugin/test_in_forward.rb +112 -151
  192. data/test/plugin/test_in_gc_stat.rb +2 -0
  193. data/test/plugin/test_in_http.rb +106 -157
  194. data/test/plugin/test_in_object_space.rb +21 -5
  195. data/test/plugin/test_in_stream.rb +14 -13
  196. data/test/plugin/test_in_syslog.rb +30 -275
  197. data/test/plugin/test_in_tail.rb +95 -234
  198. data/test/plugin/test_in_tcp.rb +14 -0
  199. data/test/plugin/test_in_udp.rb +21 -13
  200. data/test/plugin/test_input.rb +122 -0
  201. data/test/plugin/test_multi_output.rb +180 -0
  202. data/test/plugin/test_out_buffered_null.rb +79 -0
  203. data/test/plugin/test_out_copy.rb +15 -2
  204. data/test/plugin/test_out_exec.rb +75 -25
  205. data/test/plugin/test_out_exec_filter.rb +74 -8
  206. data/test/plugin/test_out_file.rb +61 -7
  207. data/test/plugin/test_out_forward.rb +92 -15
  208. data/test/plugin/test_out_roundrobin.rb +1 -0
  209. data/test/plugin/test_out_stdout.rb +22 -13
  210. data/test/plugin/test_out_stream.rb +18 -0
  211. data/test/plugin/test_output.rb +515 -0
  212. data/test/plugin/test_output_as_buffered.rb +1540 -0
  213. data/test/plugin/test_output_as_buffered_overflow.rb +247 -0
  214. data/test/plugin/test_output_as_buffered_retries.rb +808 -0
  215. data/test/plugin/test_output_as_buffered_secondary.rb +776 -0
  216. data/test/plugin/test_output_as_standard.rb +362 -0
  217. data/test/plugin/test_owned_by.rb +35 -0
  218. data/test/plugin/test_storage.rb +167 -0
  219. data/test/plugin/test_storage_local.rb +8 -0
  220. data/test/plugin_helper/test_child_process.rb +599 -0
  221. data/test/plugin_helper/test_compat_parameters.rb +175 -0
  222. data/test/plugin_helper/test_event_emitter.rb +51 -0
  223. data/test/plugin_helper/test_event_loop.rb +52 -0
  224. data/test/plugin_helper/test_retry_state.rb +399 -0
  225. data/test/plugin_helper/test_storage.rb +411 -0
  226. data/test/plugin_helper/test_thread.rb +164 -0
  227. data/test/plugin_helper/test_timer.rb +100 -0
  228. data/test/scripts/exec_script.rb +0 -6
  229. data/test/scripts/fluent/plugin/out_test.rb +3 -0
  230. data/test/test_config.rb +13 -4
  231. data/test/test_event.rb +24 -13
  232. data/test/test_event_router.rb +8 -7
  233. data/test/test_event_time.rb +187 -0
  234. data/test/test_formatter.rb +13 -51
  235. data/test/test_input.rb +1 -1
  236. data/test/test_log.rb +239 -16
  237. data/test/test_mixin.rb +1 -1
  238. data/test/test_output.rb +53 -66
  239. data/test/test_parser.rb +105 -323
  240. data/test/test_plugin_helper.rb +81 -0
  241. data/test/test_root_agent.rb +4 -52
  242. data/test/test_supervisor.rb +272 -0
  243. data/test/test_unique_id.rb +47 -0
  244. metadata +180 -54
  245. data/lib/fluent/buffer.rb +0 -365
  246. data/lib/fluent/plugin/filter_parser.rb +0 -107
  247. data/lib/fluent/plugin/in_status.rb +0 -76
  248. data/lib/fluent/test/helpers.rb +0 -86
  249. data/test/plugin/data/log/foo/bar2 +0 -0
  250. data/test/plugin/test_filter_parser.rb +0 -744
  251. data/test/plugin/test_in_status.rb +0 -38
  252. 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
@@ -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,time,record|
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,time,record|
60
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time.to_s})
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,time,record|
98
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time.to_s})
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 { |tag, es|
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,time,record|
208
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time.to_s})
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,time,record|
229
- res = post("/#{tag}?time=#{time.to_s}", record.to_json, {"content-type"=>"application/json; charset=utf-8"})
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,time,record|
261
- res = post("/#{tag}", {"msgpack"=>record.to_msgpack, "time"=>time.to_s})
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, time, record|
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=#{time.to_s}", body)
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, time, record|
274
+ d.expected_emits.each { |tag, _time, record|
323
275
  body = record.map { |k, v| v }.to_csv
324
- res = post("/#{tag}?time=#{time.to_s}", body)
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,time,record|
341
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time.to_s})
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
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
305
+ test_in_http_cros_allowed = nil
306
+ acao = nil
354
307
 
355
- d.expect_emit "tag1", time, {"a"=>1}
356
- d.expect_emit "tag2", time, {"a"=>1}
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
- d.run do
359
- d.expected_emits.each {|tag,_time,record|
360
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s}, {"Origin"=>"http://foo.com"})
361
- assert_equal "200", res.code
362
- assert_equal "http://foo.com", res["Access-Control-Allow-Origin"]
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
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
330
+ test_in_http_cros_disallowed = nil
331
+ response_code = nil
372
332
 
373
- d.expected_emits_length = 0
374
- d.run do
375
- res = post("/tag1", {"json"=>{"a"=>1}.to_json, "time"=>time.to_s}, {"Origin"=>"http://bar.com"})
376
- assert_equal "403", res.code
377
- res = post("/tag2", {"json"=>{"a"=>1}.to_json, "time"=>time.to_s}, {"Origin"=>"http://bar.com"})
378
- assert_equal "403", res.code
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", "content-type" => "application/json"})
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
- # Revert the original Handler
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 = {}, &block)
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)