fluentd 0.14.17-x64-mingw32 → 1.3.1-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.

Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +16 -5
  3. data/ADOPTERS.md +5 -0
  4. data/{ChangeLog → CHANGELOG.md} +495 -6
  5. data/CONTRIBUTING.md +5 -2
  6. data/GOVERNANCE.md +55 -0
  7. data/LICENSE +202 -0
  8. data/MAINTAINERS.md +7 -5
  9. data/README.md +17 -10
  10. data/bin/fluent-ca-generate +6 -0
  11. data/example/counter.conf +18 -0
  12. data/example/secondary_file.conf +3 -2
  13. data/fluentd.gemspec +3 -3
  14. data/lib/fluent/agent.rb +1 -1
  15. data/lib/fluent/command/binlog_reader.rb +11 -2
  16. data/lib/fluent/command/ca_generate.rb +181 -0
  17. data/lib/fluent/command/cat.rb +28 -15
  18. data/lib/fluent/command/debug.rb +4 -4
  19. data/lib/fluent/command/fluentd.rb +2 -2
  20. data/lib/fluent/command/plugin_config_formatter.rb +24 -2
  21. data/lib/fluent/command/plugin_generator.rb +26 -8
  22. data/lib/fluent/config/configure_proxy.rb +7 -1
  23. data/lib/fluent/config/dsl.rb +8 -5
  24. data/lib/fluent/config/element.rb +5 -0
  25. data/lib/fluent/config/literal_parser.rb +7 -1
  26. data/lib/fluent/config/types.rb +28 -2
  27. data/lib/fluent/config/v1_parser.rb +1 -2
  28. data/lib/fluent/configurable.rb +1 -0
  29. data/lib/fluent/counter.rb +23 -0
  30. data/lib/fluent/counter/base_socket.rb +46 -0
  31. data/lib/fluent/counter/client.rb +297 -0
  32. data/lib/fluent/counter/error.rb +86 -0
  33. data/lib/fluent/counter/mutex_hash.rb +163 -0
  34. data/lib/fluent/counter/server.rb +273 -0
  35. data/lib/fluent/counter/store.rb +205 -0
  36. data/lib/fluent/counter/validator.rb +145 -0
  37. data/lib/fluent/env.rb +1 -0
  38. data/lib/fluent/event_router.rb +1 -1
  39. data/lib/fluent/log.rb +119 -29
  40. data/lib/fluent/plugin/base.rb +12 -0
  41. data/lib/fluent/plugin/buf_file.rb +20 -16
  42. data/lib/fluent/plugin/buffer.rb +130 -32
  43. data/lib/fluent/plugin/buffer/file_chunk.rb +23 -4
  44. data/lib/fluent/plugin/compressable.rb +1 -1
  45. data/lib/fluent/plugin/filter_grep.rb +135 -21
  46. data/lib/fluent/plugin/filter_parser.rb +13 -2
  47. data/lib/fluent/plugin/filter_record_transformer.rb +16 -14
  48. data/lib/fluent/plugin/formatter_stdout.rb +3 -2
  49. data/lib/fluent/plugin/formatter_tsv.rb +5 -1
  50. data/lib/fluent/plugin/in_debug_agent.rb +8 -1
  51. data/lib/fluent/plugin/in_forward.rb +1 -1
  52. data/lib/fluent/plugin/in_http.rb +84 -3
  53. data/lib/fluent/plugin/in_monitor_agent.rb +7 -1
  54. data/lib/fluent/plugin/in_syslog.rb +31 -10
  55. data/lib/fluent/plugin/in_tail.rb +142 -53
  56. data/lib/fluent/plugin/in_tcp.rb +5 -6
  57. data/lib/fluent/plugin/in_udp.rb +6 -2
  58. data/lib/fluent/plugin/in_unix.rb +1 -1
  59. data/lib/fluent/plugin/multi_output.rb +1 -0
  60. data/lib/fluent/plugin/out_copy.rb +25 -2
  61. data/lib/fluent/plugin/out_file.rb +26 -7
  62. data/lib/fluent/plugin/out_forward.rb +81 -42
  63. data/lib/fluent/plugin/out_secondary_file.rb +2 -2
  64. data/lib/fluent/plugin/out_stdout.rb +0 -1
  65. data/lib/fluent/plugin/out_stream.rb +1 -1
  66. data/lib/fluent/plugin/output.rb +221 -57
  67. data/lib/fluent/plugin/parser_apache.rb +1 -1
  68. data/lib/fluent/plugin/parser_apache2.rb +5 -1
  69. data/lib/fluent/plugin/parser_apache_error.rb +1 -1
  70. data/lib/fluent/plugin/parser_json.rb +10 -3
  71. data/lib/fluent/plugin/parser_ltsv.rb +7 -0
  72. data/lib/fluent/plugin/parser_multiline.rb +2 -1
  73. data/lib/fluent/plugin/parser_nginx.rb +1 -1
  74. data/lib/fluent/plugin/parser_none.rb +1 -0
  75. data/lib/fluent/plugin/parser_regexp.rb +15 -14
  76. data/lib/fluent/plugin/parser_syslog.rb +9 -5
  77. data/lib/fluent/plugin_helper.rb +2 -0
  78. data/lib/fluent/plugin_helper/cert_option.rb +28 -9
  79. data/lib/fluent/plugin_helper/compat_parameters.rb +3 -1
  80. data/lib/fluent/plugin_helper/counter.rb +51 -0
  81. data/lib/fluent/plugin_helper/event_loop.rb +9 -0
  82. data/lib/fluent/plugin_helper/record_accessor.rb +210 -0
  83. data/lib/fluent/plugin_helper/retry_state.rb +15 -7
  84. data/lib/fluent/plugin_helper/server.rb +87 -25
  85. data/lib/fluent/plugin_helper/socket_option.rb +5 -2
  86. data/lib/fluent/plugin_helper/timer.rb +8 -7
  87. data/lib/fluent/root_agent.rb +18 -9
  88. data/lib/fluent/supervisor.rb +63 -23
  89. data/lib/fluent/system_config.rb +30 -2
  90. data/lib/fluent/test/helpers.rb +1 -1
  91. data/lib/fluent/time.rb +15 -7
  92. data/lib/fluent/timezone.rb +26 -2
  93. data/lib/fluent/version.rb +1 -1
  94. data/templates/new_gem/README.md.erb +2 -2
  95. data/templates/new_gem/lib/fluent/plugin/filter.rb.erb +1 -1
  96. data/templates/new_gem/lib/fluent/plugin/input.rb.erb +1 -1
  97. data/templates/new_gem/lib/fluent/plugin/output.rb.erb +1 -1
  98. data/templates/new_gem/lib/fluent/plugin/parser.rb.erb +4 -4
  99. data/test/command/test_ca_generate.rb +70 -0
  100. data/test/command/test_fluentd.rb +2 -2
  101. data/test/command/test_plugin_config_formatter.rb +8 -7
  102. data/test/command/test_plugin_generator.rb +65 -39
  103. data/test/config/test_config_parser.rb +7 -2
  104. data/test/config/test_configurable.rb +7 -2
  105. data/test/config/test_configure_proxy.rb +41 -3
  106. data/test/config/test_dsl.rb +10 -10
  107. data/test/config/test_element.rb +10 -0
  108. data/test/config/test_literal_parser.rb +8 -0
  109. data/test/config/test_plugin_configuration.rb +56 -0
  110. data/test/config/test_system_config.rb +19 -1
  111. data/test/config/test_types.rb +37 -0
  112. data/test/counter/test_client.rb +559 -0
  113. data/test/counter/test_error.rb +44 -0
  114. data/test/counter/test_mutex_hash.rb +179 -0
  115. data/test/counter/test_server.rb +589 -0
  116. data/test/counter/test_store.rb +258 -0
  117. data/test/counter/test_validator.rb +137 -0
  118. data/test/plugin/test_buf_file.rb +124 -0
  119. data/test/plugin/test_buffer.rb +3 -2
  120. data/test/plugin/test_filter_grep.rb +580 -2
  121. data/test/plugin/test_filter_parser.rb +33 -2
  122. data/test/plugin/test_filter_record_transformer.rb +22 -1
  123. data/test/plugin/test_formatter_ltsv.rb +3 -0
  124. data/test/plugin/test_formatter_tsv.rb +68 -0
  125. data/test/plugin/test_in_debug_agent.rb +21 -0
  126. data/test/plugin/test_in_exec.rb +3 -5
  127. data/test/plugin/test_in_http.rb +178 -0
  128. data/test/plugin/test_in_monitor_agent.rb +1 -1
  129. data/test/plugin/test_in_syslog.rb +64 -0
  130. data/test/plugin/test_in_tail.rb +116 -6
  131. data/test/plugin/test_in_tcp.rb +21 -0
  132. data/test/plugin/test_in_udp.rb +78 -0
  133. data/test/plugin/test_metadata.rb +89 -0
  134. data/test/plugin/test_out_copy.rb +31 -0
  135. data/test/plugin/test_out_file.rb +108 -2
  136. data/test/plugin/test_out_forward.rb +195 -2
  137. data/test/plugin/test_out_secondary_file.rb +14 -0
  138. data/test/plugin/test_output.rb +159 -45
  139. data/test/plugin/test_output_as_buffered.rb +19 -0
  140. data/test/plugin/test_output_as_buffered_backup.rb +307 -0
  141. data/test/plugin/test_output_as_buffered_retries.rb +70 -0
  142. data/test/plugin/test_output_as_buffered_secondary.rb +1 -1
  143. data/test/plugin/test_parser_apache2.rb +1 -0
  144. data/test/plugin/test_parser_labeled_tsv.rb +17 -0
  145. data/test/plugin/test_parser_nginx.rb +40 -0
  146. data/test/plugin/test_parser_regexp.rb +6 -7
  147. data/test/plugin/test_parser_syslog.rb +155 -5
  148. data/test/plugin_helper/test_child_process.rb +4 -4
  149. data/test/plugin_helper/test_compat_parameters.rb +22 -0
  150. data/test/plugin_helper/test_record_accessor.rb +197 -0
  151. data/test/plugin_helper/test_retry_state.rb +20 -0
  152. data/test/plugin_helper/test_server.rb +30 -2
  153. data/test/test_config.rb +3 -3
  154. data/test/test_configdsl.rb +2 -2
  155. data/test/test_log.rb +51 -1
  156. data/test/test_root_agent.rb +33 -0
  157. data/test/test_supervisor.rb +105 -0
  158. metadata +68 -8
  159. data/COPYING +0 -14
@@ -209,10 +209,13 @@ class ParserFilterTest < Test::Unit::TestCase
209
209
 
210
210
  end
211
211
 
212
- def test_filter_with_reserved_data
212
+ data(:keep_key_name => false,
213
+ :remove_key_name => true)
214
+ def test_filter_with_reserved_data(remove_key_name)
213
215
  d1 = create_driver(%[
214
216
  key_name data
215
217
  reserve_data yes
218
+ remove_key_name_field #{remove_key_name}
216
219
  <parse>
217
220
  @type regexp
218
221
  expression /^(?<x>\\d)(?<y>\\d) (?<t>.+)$/
@@ -230,6 +233,7 @@ class ParserFilterTest < Test::Unit::TestCase
230
233
  d2 = create_driver(%[
231
234
  key_name data
232
235
  reserve_data yes
236
+ remove_key_name_field #{remove_key_name}
233
237
  <parse>
234
238
  @type json
235
239
  </parse>
@@ -244,7 +248,11 @@ class ParserFilterTest < Test::Unit::TestCase
244
248
 
245
249
  first = filtered[0]
246
250
  assert_equal_event_time time, first[0]
247
- assert_equal '{"xxx":"first","yyy":"second"}', first[1]['data']
251
+ if remove_key_name
252
+ assert_not_include first[1], 'data'
253
+ else
254
+ assert_equal '{"xxx":"first","yyy":"second"}', first[1]['data']
255
+ end
248
256
  assert_equal 'first', first[1]['xxx']
249
257
  assert_equal 'second', first[1]['yyy']
250
258
 
@@ -390,6 +398,29 @@ class ParserFilterTest < Test::Unit::TestCase
390
398
  assert_equal 'value"ThreeYes!', first[1]['key3']
391
399
  end
392
400
 
401
+ def test_filter_with_nested_record
402
+ d = create_driver(%[
403
+ key_name $.data.log
404
+ <parse>
405
+ @type csv
406
+ keys key1,key2,key3
407
+ </parse>
408
+ ])
409
+ time = @default_time.to_i
410
+ d.run do
411
+ d.feed(@tag, time, {'data' => {'log' => 'value1,"value2","value""ThreeYes!"'}, 'xxx' => 'x', 'yyy' => 'y'})
412
+ end
413
+ filtered = d.filtered
414
+ assert_equal 1, filtered.length
415
+
416
+ first = filtered[0]
417
+ assert_equal time, first[0]
418
+ assert_nil first[1]['data']
419
+ assert_equal 'value1', first[1]['key1']
420
+ assert_equal 'value2', first[1]['key2']
421
+ assert_equal 'value"ThreeYes!', first[1]['key3']
422
+ end
423
+
393
424
  CONFIG_HASH_VALUE_FIELD = %[
394
425
  key_name data
395
426
  hash_value_field parsed
@@ -44,7 +44,7 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
44
44
  d = create_driver(config)
45
45
  d.run {
46
46
  msgs.each { |msg|
47
- d.feed(@tag, @time, {'foo' => 'bar', 'message' => msg})
47
+ d.feed(@tag, @time, {'foo' => 'bar', 'message' => msg, 'nest' => {'k1' => 'v1', 'k2' => 'v2'}})
48
48
  }
49
49
  }
50
50
  d.filtered
@@ -68,6 +68,7 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
68
68
  assert_equal(@tag, r['tag'])
69
69
  assert_equal(Time.at(@time).localtime.to_s, r['time'])
70
70
  assert_equal("#{@hostname} #{@tag_parts[-1]} #{msgs[i]}", r['message'])
71
+ assert_equal({'k1' => 'v1', 'k2' => 'v2'}, r['nest'])
71
72
  end
72
73
  end
73
74
 
@@ -83,6 +84,14 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
83
84
  end
84
85
  end
85
86
 
87
+ test 'remove_keys with nested key' do
88
+ config = CONFIG + %[remove_keys $.nest.k1]
89
+ filtered = filter(config)
90
+ filtered.each_with_index do |(_t, r), i|
91
+ assert_not_include(r['nest'], 'k1')
92
+ end
93
+ end
94
+
86
95
  test 'renew_record' do
87
96
  config = CONFIG + %[renew_record true]
88
97
  msgs = ['1', '2']
@@ -137,6 +146,18 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
137
146
  end
138
147
  end
139
148
 
149
+ test 'keep_keys that are not present in the original record should not be included in the result record' do
150
+ config = %[renew_record true\nkeep_keys foo, bar, baz, message]
151
+ msgs = ['1', '2', nil]
152
+ filtered = filter(config, msgs)
153
+ filtered.each_with_index do |(_t, r), i|
154
+ assert_equal('bar', r['foo'])
155
+ assert_equal(msgs[i], r['message'])
156
+ assert_equal(false, r.has_key?('bar'))
157
+ assert_equal(false, r.has_key?('baz'))
158
+ end
159
+ end
160
+
140
161
  test 'enable_ruby' do
141
162
  config = %[
142
163
  enable_ruby yes
@@ -23,14 +23,17 @@ class LabeledTSVFormatterTest < ::Test::Unit::TestCase
23
23
  d = create_driver
24
24
  assert_equal "\t", d.instance.delimiter
25
25
  assert_equal ":", d.instance.label_delimiter
26
+ assert_equal true, d.instance.add_newline
26
27
 
27
28
  d = create_driver(
28
29
  'delimiter' => ',',
29
30
  'label_delimiter' => '=',
31
+ 'add_newline' => false,
30
32
  )
31
33
 
32
34
  assert_equal ",", d.instance.delimiter
33
35
  assert_equal "=", d.instance.label_delimiter
36
+ assert_equal false, d.instance.add_newline
34
37
  end
35
38
 
36
39
  def test_format
@@ -0,0 +1,68 @@
1
+ require_relative '../helper'
2
+ require 'fluent/test/driver/formatter'
3
+ require 'fluent/plugin/formatter_tsv'
4
+
5
+ class TSVFormatterTest < ::Test::Unit::TestCase
6
+ def setup
7
+ @time = event_time
8
+ end
9
+
10
+ def create_driver(conf = "")
11
+ Fluent::Test::Driver::Formatter.new(Fluent::Plugin::TSVFormatter).configure(conf)
12
+ end
13
+
14
+ def tag
15
+ "tag"
16
+ end
17
+
18
+ def record
19
+ {'message' => 'awesome', 'greeting' => 'hello'}
20
+ end
21
+
22
+ def test_config_params
23
+ d = create_driver(
24
+ 'keys' => 'message,greeting',
25
+ )
26
+ assert_equal ["message", "greeting"], d.instance.keys
27
+ assert_equal "\t", d.instance.delimiter
28
+ assert_equal true, d.instance.add_newline
29
+
30
+ d = create_driver(
31
+ 'keys' => 'message,greeting',
32
+ 'delimiter' => ',',
33
+ 'add_newline' => false,
34
+ )
35
+ assert_equal ["message", "greeting"], d.instance.keys
36
+ assert_equal ",", d.instance.delimiter
37
+ assert_equal false, d.instance.add_newline
38
+ end
39
+
40
+ def test_format
41
+ d = create_driver(
42
+ 'keys' => 'message,greeting',
43
+ )
44
+ formatted = d.instance.format(tag, @time, record)
45
+
46
+ assert_equal("awesome\thello\n", formatted)
47
+ end
48
+
49
+ def test_format_without_newline
50
+ d = create_driver(
51
+ 'keys' => 'message,greeting',
52
+ 'add_newline' => false,
53
+ )
54
+ formatted = d.instance.format(tag, @time, record)
55
+
56
+ assert_equal("awesome\thello", formatted)
57
+ end
58
+
59
+ def test_format_with_customized_delimiters
60
+ d = create_driver(
61
+ 'keys' => 'message,greeting',
62
+ 'delimiter' => ',',
63
+ )
64
+ formatted = d.instance.format(tag, @time, record)
65
+
66
+ assert_equal("awesome,hello\n", formatted)
67
+ end
68
+ end
@@ -25,4 +25,25 @@ class DebugAgentInputTest < Test::Unit::TestCase
25
25
  create_driver %[unix_path #{TMP_DIR}/does_not_exist/test_path]
26
26
  end
27
27
  end
28
+
29
+ def test_multi_worker_environment_with_port
30
+ Fluent::SystemConfig.overwrite_system_config('workers' => 4) do
31
+ d = Fluent::Test::Driver::Input.new(Fluent::Plugin::DebugAgentInput)
32
+ d.instance.instance_eval { @_fluentd_worker_id = 2 }
33
+ d.configure('port 24230')
34
+
35
+ assert_true d.instance.multi_workers_ready?
36
+ assert_equal(24232, d.instance.instance_variable_get(:@port))
37
+ end
38
+ end
39
+
40
+ def test_multi_worker_environment_with_unix_path
41
+ Fluent::SystemConfig.overwrite_system_config('workers' => 4) do
42
+ d = Fluent::Test::Driver::Input.new(Fluent::Plugin::DebugAgentInput)
43
+ d.instance.instance_eval { @_fluentd_worker_id = 2 }
44
+ d.configure("unix_path #{TMP_DIR}/test_path")
45
+
46
+ assert_false d.instance.multi_workers_ready?
47
+ end
48
+ end
28
49
  end
@@ -131,9 +131,7 @@ EOC
131
131
  d = create_driver REGEXP_CONFIG
132
132
  assert{ d.instance.parser.is_a? Fluent::Plugin::RegexpParser }
133
133
  assert_equal "regex_tag", d.instance.tag
134
- expression = <<'EXP'.chomp
135
- (?<time>[^\]]*) (?<message>[^ ]*)
136
- EXP
134
+ expression = /(?<time>[^\]]*) (?<message>[^ ]*)/
137
135
  assert_equal expression, d.instance.parser.expression
138
136
  assert_nil d.instance.extract_config
139
137
  end
@@ -194,8 +192,8 @@ EXP
194
192
  test 'configure_with_regexp' do
195
193
  d = create_driver REGEXP_CONFIG_COMPAT
196
194
  assert{ d.instance.parser.is_a? Fluent::Plugin::RegexpParser }
197
- assert_equal '(?<time>[^\]]*) (?<message>[^ ]*)', d.instance.parser.expression
198
- assert_equal 'regex_tag', d.instance.tag
195
+ assert_equal(/(?<time>[^\]]*) (?<message>[^ ]*)/, d.instance.parser.expression)
196
+ assert_equal('regex_tag', d.instance.tag)
199
197
  end
200
198
  end
201
199
 
@@ -137,6 +137,54 @@ class HttpInputTest < Test::Unit::TestCase
137
137
  assert_equal_event_time time, d.events[1][1]
138
138
  end
139
139
 
140
+ def test_multi_json_with_time_field
141
+ d = create_driver
142
+ time = event_time("2011-01-02 13:14:15 UTC")
143
+ time_i = time.to_i
144
+ time_f = time.to_f
145
+
146
+ records = [{"a" => 1, 'time' => time_i},{"a" => 2, 'time' => time_f}]
147
+ events = [
148
+ ["tag1", time, {'a' => 1}],
149
+ ["tag1", time, {'a' => 2}],
150
+ ]
151
+ tag = "tag1"
152
+ res_codes = []
153
+ d.run(expect_records: 2, timeout: 5) do
154
+ res = post("/#{tag}", {"json" => records.to_json})
155
+ res_codes << res.code
156
+ end
157
+ assert_equal ["200"], res_codes
158
+ assert_equal events, d.events
159
+ assert_instance_of Fluent::EventTime, d.events[0][1]
160
+ assert_instance_of Fluent::EventTime, d.events[1][1]
161
+ assert_equal_event_time time, d.events[0][1]
162
+ assert_equal_event_time time, d.events[1][1]
163
+ end
164
+
165
+ def test_multi_json_with_nonexistent_time_key
166
+ d = create_driver(CONFIG + %[
167
+ <parse>
168
+ time_key missing
169
+ </parse>
170
+ ])
171
+ time = event_time("2011-01-02 13:14:15 UTC")
172
+ time_i = time.to_i
173
+ time_f = time.to_f
174
+
175
+ records = [{"a" => 1, 'time' => time_i},{"a" => 2, 'time' => time_f}]
176
+ tag = "tag1"
177
+ res_codes = []
178
+ d.run(expect_records: 2, timeout: 5) do
179
+ res = post("/#{tag}", {"json" => records.to_json})
180
+ res_codes << res.code
181
+ end
182
+ assert_equal ["200"], res_codes
183
+ assert_equal 2, d.events.size
184
+ assert_not_equal time_i, d.events[0][1].sec # current time is used because "missing" field doesn't exist
185
+ assert_not_equal time_i, d.events[1][1].sec
186
+ end
187
+
140
188
  def test_json_with_add_remote_addr
141
189
  d = create_driver(CONFIG + "add_remote_addr true")
142
190
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -322,6 +370,38 @@ class HttpInputTest < Test::Unit::TestCase
322
370
  assert include_http_header?(d.events[1][2])
323
371
  end
324
372
 
373
+ def test_multi_json_with_custom_parser
374
+ d = create_driver(CONFIG + %[
375
+ <parse>
376
+ @type json
377
+ keep_time_key true
378
+ time_key foo
379
+ time_format %iso8601
380
+ </parse>
381
+ ])
382
+
383
+ time = event_time("2011-01-02 13:14:15 UTC")
384
+ time_s = Time.at(time).iso8601
385
+
386
+ records = [{"foo"=>time_s,"bar"=>"test1"},{"foo"=>time_s,"bar"=>"test2"}]
387
+ tag = "tag1"
388
+ res_codes = []
389
+
390
+ d.run(expect_records: 2, timeout: 5) do
391
+ res = post("/#{tag}", records.to_json, {"Content-Type"=>"application/octet-stream"})
392
+ res_codes << res.code
393
+ end
394
+ assert_equal ["200"], res_codes
395
+
396
+ assert_equal "tag1", d.events[0][0]
397
+ assert_equal_event_time time, d.events[0][1]
398
+ assert_equal d.events[0][2], records[0]
399
+
400
+ assert_equal "tag1", d.events[1][0]
401
+ assert_equal_event_time time, d.events[1][1]
402
+ assert_equal d.events[1][2], records[1]
403
+ end
404
+
325
405
  def test_application_json
326
406
  d = create_driver
327
407
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -524,6 +604,91 @@ class HttpInputTest < Test::Unit::TestCase
524
604
  assert_equal_event_time time, d.events[1][1]
525
605
  end
526
606
 
607
+ def test_cors_allowed_wildcard
608
+ d = create_driver(CONFIG + 'cors_allow_origins ["*"]')
609
+
610
+ time = event_time("2011-01-02 13:14:15 UTC")
611
+ events = [
612
+ ["tag1", time, {"a"=>1}],
613
+ ]
614
+
615
+ d.run do
616
+ events.each do |tag, time, record|
617
+ headers = {"Origin" => "http://foo.com"}
618
+
619
+ res = post("/#{tag}", {"json" => record.to_json, "time" => time.to_i}, headers)
620
+
621
+ assert_equal "200", res.code
622
+ assert_equal "*", res["Access-Control-Allow-Origin"]
623
+ end
624
+ end
625
+ end
626
+
627
+ def test_cors_preflight
628
+ d = create_driver(CONFIG + 'cors_allow_origins ["*"]')
629
+
630
+ d.run do
631
+ header = {
632
+ "Origin" => "http://foo.com",
633
+ "Access-Control-Request-Method" => "POST",
634
+ "Access-Control-Request-Headers" => "Content-Type",
635
+ }
636
+ res = options("/cors.test", {}, header)
637
+
638
+ assert_equal "200", res.code
639
+ assert_equal "*", res["Access-Control-Allow-Origin"]
640
+ assert_equal "POST", res["Access-Control-Allow-Methods"]
641
+ end
642
+ end
643
+
644
+ def test_content_encoding_gzip
645
+ d = create_driver
646
+
647
+ time = event_time("2011-01-02 13:14:15 UTC")
648
+ events = [
649
+ ["tag1", time, {"a"=>1}],
650
+ ["tag2", time, {"a"=>2}],
651
+ ]
652
+ res_codes = []
653
+ res_headers = []
654
+
655
+ d.run do
656
+ events.each do |tag, time, record|
657
+ header = {'Content-Type'=>'application/json', 'Content-Encoding'=>'gzip'}
658
+ res = post("/#{tag}?time=#{time}", compress_gzip(record.to_json), header)
659
+ res_codes << res.code
660
+ end
661
+ end
662
+ assert_equal ["200", "200"], res_codes
663
+ assert_equal events, d.events
664
+ assert_equal_event_time time, d.events[0][1]
665
+ assert_equal_event_time time, d.events[1][1]
666
+ end
667
+
668
+ def test_content_encoding_deflate
669
+ d = create_driver
670
+
671
+ time = event_time("2011-01-02 13:14:15 UTC")
672
+ events = [
673
+ ["tag1", time, {"a"=>1}],
674
+ ["tag2", time, {"a"=>2}],
675
+ ]
676
+ res_codes = []
677
+ res_headers = []
678
+
679
+ d.run do
680
+ events.each do |tag, time, record|
681
+ header = {'Content-Type'=>'application/msgpack', 'Content-Encoding'=>'deflate'}
682
+ res = post("/#{tag}?time=#{time}", Zlib.deflate(record.to_msgpack), header)
683
+ res_codes << res.code
684
+ end
685
+ end
686
+ assert_equal ["200", "200"], res_codes
687
+ assert_equal events, d.events
688
+ assert_equal_event_time time, d.events[0][1]
689
+ assert_equal_event_time time, d.events[1][1]
690
+ end
691
+
527
692
  def test_cors_disallowed
528
693
  d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
529
694
  assert_equal ["http://foo.com"], d.instance.cors_allow_origins
@@ -596,6 +761,12 @@ class HttpInputTest < Test::Unit::TestCase
596
761
  assert_equal $test_in_http_connection_object_ids[0], $test_in_http_connection_object_ids[1]
597
762
  end
598
763
 
764
+ def options(path, params, header = {})
765
+ http = Net::HTTP.new("127.0.0.1", PORT)
766
+ req = Net::HTTP::Options.new(path, header)
767
+ http.request(req)
768
+ end
769
+
599
770
  def post(path, params, header = {}, &block)
600
771
  http = Net::HTTP.new("127.0.0.1", PORT)
601
772
  req = Net::HTTP::Post.new(path, header)
@@ -614,6 +785,13 @@ class HttpInputTest < Test::Unit::TestCase
614
785
  http.request(req)
615
786
  end
616
787
 
788
+ def compress_gzip(data)
789
+ io = StringIO.new
790
+ io.binmode
791
+ Zlib::GzipWriter.wrap(io) { |gz| gz.write data }
792
+ return io.string
793
+ end
794
+
617
795
  def include_http_header?(record)
618
796
  record.keys.find { |header| header.start_with?('HTTP_') }
619
797
  end