fluent-plugin-elasticsearch 5.0.2 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,13 +27,18 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
27
27
  @error_events << {:tag => tag, :time=>time, :record=>record, :error=>e}
28
28
  end
29
29
 
30
- def process_message(tag, meta, header, time, record, extracted_values)
30
+ def process_message(tag, meta, header, time, record, affinity_target_indices, extracted_values)
31
31
  return [meta, header, record]
32
32
  end
33
33
 
34
+ def get_affinity_target_indices(chunk)
35
+ indices = Hash.new
36
+ indices
37
+ end
38
+
34
39
  def append_record_to_messages(op, meta, header, record, msgs)
35
40
  if record.has_key?('raise') && record['raise']
36
- raise Exception('process_message')
41
+ raise 'process_message'
37
42
  end
38
43
  return true
39
44
  end
@@ -302,7 +307,7 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
302
307
  def test_retry_error
303
308
  records = []
304
309
  error_records = Hash.new(false)
305
- error_records.merge!({0=>true, 4=>true, 9=>true})
310
+ error_records.merge!({0=>true, 4=>true})
306
311
  10.times do |i|
307
312
  records << {time: 12345, record: {"message"=>"record #{i}","_id"=>i,"raise"=>error_records[i]}}
308
313
  end
@@ -386,6 +391,18 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
386
391
  "reason":"unrecognized error"
387
392
  }
388
393
  }
394
+ },
395
+ {
396
+ "create" : {
397
+ "_index" : "foo",
398
+ "_type" : "bar",
399
+ "_id" : "9",
400
+ "status" : 500,
401
+ "error" : {
402
+ "type" : "json_parse_exception",
403
+ "reason":"Invalid UTF-8 start byte 0x92\\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@204fe9c9; line: 1, column: 81]"
404
+ }
405
+ }
389
406
  }
390
407
  ]
391
408
  }))
@@ -400,12 +417,12 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
400
417
  next unless e.respond_to?(:retry_stream)
401
418
  e.retry_stream.each {|time, record| records << record}
402
419
  end
403
- assert_equal 2, records.length
404
- assert_equal 2, records[0]['_id']
405
- assert_equal 8, records[1]['_id']
420
+ assert_equal 2, records.length, "Exp. retry_stream to contain records"
421
+ assert_equal 2, records[0]['_id'], "Exp record with given ID to in retry_stream"
422
+ assert_equal 8, records[1]['_id'], "Exp record with given ID to in retry_stream"
406
423
  error_ids = @plugin.error_events.collect {|h| h[:record]['_id']}
407
- assert_equal 3, error_ids.length
408
- assert_equal [5, 6, 7], error_ids
424
+ assert_equal 4, error_ids.length, "Exp. a certain number of records to be dropped from retry_stream"
425
+ assert_equal [5, 6, 7, 9], error_ids, "Exp. specific records to be dropped from retry_stream"
409
426
  @plugin.error_events.collect {|h| h[:error]}.each do |e|
410
427
  assert_true e.respond_to?(:backtrace)
411
428
  end
@@ -19,7 +19,7 @@ class ElasticsearchFallbackSelectorTest < Test::Unit::TestCase
19
19
  end
20
20
 
21
21
  def stub_elastic_info(url="http://localhost:9200/", version="6.4.2")
22
- body ="{\"version\":{\"number\":\"#{version}\"}}"
22
+ body ="{\"version\":{\"number\":\"#{version}\", \"build_flavor\":\"default\"},\"tagline\" : \"You Know, for Search\"}"
23
23
  stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json' } })
24
24
  end
25
25
 
@@ -27,9 +27,15 @@ class TestElasticsearchIndexLifecycleManagement < Test::Unit::TestCase
27
27
  CODE
28
28
  end
29
29
 
30
+ def stub_elastic_info(url="http://localhost:9200/", version="7.9.0")
31
+ body ="{\"version\":{\"number\":\"#{version}\", \"build_flavor\":\"default\"},\"tagline\" : \"You Know, for Search\"}"
32
+ stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json' } })
33
+ end
34
+
30
35
  def test_xpack_info
31
36
  stub_request(:get, "http://localhost:9200/_xpack").
32
37
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
38
+ stub_elastic_info
33
39
  expected = {"features"=>{"ilm"=>{"available"=>true, "enabled"=>true}}}
34
40
  assert_equal(expected, xpack_info)
35
41
  end
@@ -37,18 +43,21 @@ class TestElasticsearchIndexLifecycleManagement < Test::Unit::TestCase
37
43
  def test_verify_ilm_working
38
44
  stub_request(:get, "http://localhost:9200/_xpack").
39
45
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
46
+ stub_elastic_info
40
47
  assert_nothing_raised { verify_ilm_working }
41
48
  end
42
49
 
43
50
  def test_ilm_policy_doesnt_exists
44
51
  stub_request(:get, "http://localhost:9200/_ilm/policy/%7B:policy_id=%3E%22fluentd-policy%22%7D").
45
52
  to_return(:status => 404, :body => "", :headers => {})
53
+ stub_elastic_info
46
54
  assert_false(ilm_policy_exists?(policy_id: "fluentd-policy"))
47
55
  end
48
56
 
49
57
  def test_ilm_policy_exists
50
58
  stub_request(:get, "http://localhost:9200/_ilm/policy/%7B:policy_id=%3E%22fluent-policy%22%7D").
51
59
  to_return(:status => 200, :body => "", :headers => {})
60
+ stub_elastic_info
52
61
  assert_true(ilm_policy_exists?(policy_id: "fluent-policy"))
53
62
  end
54
63
 
@@ -59,6 +68,7 @@ class TestElasticsearchIndexLifecycleManagement < Test::Unit::TestCase
59
68
  with(:body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}",
60
69
  :headers => {'Content-Type'=>'application/json'}).
61
70
  to_return(:status => 200, :body => "", :headers => {})
71
+ stub_elastic_info
62
72
  create_ilm_policy("fluent-policy")
63
73
 
64
74
  assert_requested(:put, "http://localhost:9200/_ilm/policy/fluent-policy", times: 1)
@@ -31,6 +31,11 @@ class ElasticsearchInputTest < Test::Unit::TestCase
31
31
  @driver ||= Fluent::Test::Driver::Input.new(Fluent::Plugin::ElasticsearchInput).configure(conf)
32
32
  end
33
33
 
34
+ def stub_elastic_info(url="http://localhost:9200/", version="7.9.0")
35
+ body ="{\"version\":{\"number\":\"#{version}\", \"build_flavor\":\"default\"},\"tagline\" : \"You Know, for Search\"}"
36
+ stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json' } })
37
+ end
38
+
34
39
  def sample_response(index_name="fluentd")
35
40
  {
36
41
  "took"=>4,
@@ -322,6 +327,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
322
327
  with(body: "{\"sort\":[\"_doc\"]}").
323
328
  to_return(status: 200, body: sample_response.to_s,
324
329
  headers: {'Content-Type' => 'application/json'})
330
+ stub_elastic_info
325
331
 
326
332
  driver(CONFIG)
327
333
  driver.run(expect_emits: 1, timeout: 10)
@@ -337,6 +343,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
337
343
  with(body: "{\"sort\":[\"_doc\"]}").
338
344
  to_return(status: 200, body: sample_response(index_name).to_s,
339
345
  headers: {'Content-Type' => 'application/json'})
346
+ stub_elastic_info
340
347
 
341
348
  driver(CONFIG + %[index_name #{index_name}])
342
349
  driver.run(expect_emits: 1, timeout: 10)
@@ -352,6 +359,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
352
359
  with(body: "{\"sort\":[\"_doc\"]}").
353
360
  to_return(status: 200, body: sample_response(index_name).to_s,
354
361
  headers: {'Content-Type' => 'application/json'})
362
+ stub_elastic_info
355
363
 
356
364
  driver(CONFIG + %[parse_timestamp])
357
365
  driver.run(expect_emits: 1, timeout: 10)
@@ -370,6 +378,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
370
378
  with(body: "{\"sort\":[\"_doc\"]}").
371
379
  to_return(status: 200, body: sample_response(index_name).to_s,
372
380
  headers: {'Content-Type' => 'application/json'})
381
+ stub_elastic_info
373
382
 
374
383
  driver(CONFIG + %[parse_timestamp true
375
384
  timestamp_key_format %Y-%m-%dT%H:%M:%S.%N%z
@@ -389,6 +398,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
389
398
  with(body: "{\"sort\":[\"_doc\"]}").
390
399
  to_return(status: 200, body: sample_response.to_s,
391
400
  headers: {'Content-Type' => 'application/json'})
401
+ stub_elastic_info
392
402
 
393
403
  driver(CONFIG + %[docinfo true])
394
404
  driver.run(expect_emits: 1, timeout: 10)
@@ -412,6 +422,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
412
422
  with(body: "{\"sort\":[\"_doc\"],\"slice\":{\"id\":1,\"max\":2}}").
413
423
  to_return(status: 200, body: sample_response.to_s,
414
424
  headers: {'Content-Type' => 'application/json'})
425
+ stub_elastic_info
415
426
 
416
427
  driver(CONFIG + %[num_slices 2])
417
428
  driver.run(expect_emits: 1, timeout: 10)
@@ -434,6 +445,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
434
445
  body: "{\"scroll_id\":\"WomkoUKG0QPB679Ulo6TqQgh3pIGRUmrl9qXXGK3EeiQh9rbYNasTkspZQcJ01uz\"}") do
435
446
  connection += 1
436
447
  end
448
+ stub_elastic_info
437
449
  scroll_request.to_return(lambda do |req|
438
450
  if connection <= 1
439
451
  {status: 200, body: sample_scroll_response_2.to_s,
@@ -10,7 +10,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
10
10
  include FlexMock::TestCase
11
11
  include Fluent::Test::Helpers
12
12
 
13
- attr_accessor :index_cmds, :index_command_counts
13
+ attr_accessor :index_cmds, :index_command_counts, :index_cmds_all_requests
14
14
 
15
15
  def setup
16
16
  Fluent::Test.setup
@@ -45,6 +45,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
45
45
  }.configure(conf)
46
46
  end
47
47
 
48
+ def elasticsearch_transport_layer_decoupling?
49
+ Gem::Version.create(::Elasticsearch::Transport::VERSION) >= Gem::Version.new("7.14.0")
50
+ end
51
+
48
52
  def default_type_name
49
53
  Fluent::Plugin::ElasticsearchOutput::DEFAULT_TYPE_NAME
50
54
  end
@@ -60,7 +64,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
60
64
  end
61
65
 
62
66
  def stub_elastic_info(url="http://localhost:9200/", version="6.4.2")
63
- body ="{\"version\":{\"number\":\"#{version}\"}}"
67
+ body ="{\"version\":{\"number\":\"#{version}\", \"build_flavor\":\"default\"},\"tagline\" : \"You Know, for Search\"}"
64
68
  stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json' } })
65
69
  end
66
70
 
@@ -70,6 +74,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
70
74
  end
71
75
  end
72
76
 
77
+ def stub_elastic_all_requests(url="http://localhost:9200/_bulk")
78
+ @index_cmds_all_requests = Array.new
79
+ stub_request(:post, url).with do |req|
80
+ @index_cmds = req.body.split("\n").map {|r| JSON.parse(r) }
81
+ @index_cmds_all_requests << @index_cmds
82
+ end
83
+ end
84
+
73
85
  def stub_elastic_unavailable(url="http://localhost:9200/_bulk")
74
86
  stub_request(:post, url).to_return(:status => [503, "Service Unavailable"])
75
87
  end
@@ -253,7 +265,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
253
265
  assert_true instance.verify_es_version_at_startup
254
266
  assert_equal Fluent::Plugin::ElasticsearchOutput::DEFAULT_ELASTICSEARCH_VERSION, instance.default_elasticsearch_version
255
267
  assert_false instance.log_es_400_reason
256
- assert_equal 20 * 1024 * 1024, Fluent::Plugin::ElasticsearchOutput::TARGET_BULK_BYTES
268
+ assert_equal -1, Fluent::Plugin::ElasticsearchOutput::DEFAULT_TARGET_BULK_BYTES
257
269
  assert_false instance.compression
258
270
  assert_equal :no_compression, instance.compression_level
259
271
  assert_true instance.http_backend_excon_nonblock
@@ -290,16 +302,25 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
290
302
  }
291
303
  instance = driver(config).instance
292
304
 
293
- assert_equal nil, instance.client.transport.options[:transport_options][:headers]["Content-Encoding"]
305
+ if elasticsearch_transport_layer_decoupling?
306
+ assert_equal nil, instance.client.transport.transport.options[:transport_options][:headers]["Content-Encoding"]
307
+ else
308
+ assert_equal nil, instance.client.transport.options[:transport_options][:headers]["Content-Encoding"]
309
+ end
294
310
 
295
311
  stub_request(:post, "http://localhost:9200/_bulk").
296
312
  to_return(status: 200, body: "", headers: {})
313
+ stub_elastic_info
297
314
  driver.run(default_tag: 'test') do
298
315
  driver.feed(sample_record)
299
316
  end
300
317
  compressable = instance.compressable_connection
301
318
 
302
- assert_equal "gzip", instance.client(nil, compressable).transport.options[:transport_options][:headers]["Content-Encoding"]
319
+ if elasticsearch_transport_layer_decoupling?
320
+ assert_equal "gzip", instance.client(nil, compressable).transport.transport.options[:transport_options][:headers]["Content-Encoding"]
321
+ else
322
+ assert_equal "gzip", instance.client(nil, compressable).transport.options[:transport_options][:headers]["Content-Encoding"]
323
+ end
303
324
  end
304
325
 
305
326
  test 'check compression option is passed to transport' do
@@ -310,16 +331,25 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
310
331
  }
311
332
  instance = driver(config).instance
312
333
 
313
- assert_equal false, instance.client.transport.options[:compression]
334
+ if elasticsearch_transport_layer_decoupling?
335
+ assert_equal false, instance.client.transport.transport.options[:compression]
336
+ else
337
+ assert_equal false, instance.client.transport.options[:compression]
338
+ end
314
339
 
315
340
  stub_request(:post, "http://localhost:9200/_bulk").
316
341
  to_return(status: 200, body: "", headers: {})
342
+ stub_elastic_info
317
343
  driver.run(default_tag: 'test') do
318
344
  driver.feed(sample_record)
319
345
  end
320
346
  compressable = instance.compressable_connection
321
347
 
322
- assert_equal true, instance.client(nil, compressable).transport.options[:compression]
348
+ if elasticsearch_transport_layer_decoupling?
349
+ assert_equal true, instance.client(nil, compressable).transport.transport.options[:compression]
350
+ else
351
+ assert_equal true, instance.client(nil, compressable).transport.options[:compression]
352
+ end
323
353
  end
324
354
 
325
355
  test 'check configure cloud_id based client' do
@@ -406,7 +436,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
406
436
  end
407
437
 
408
438
  def stub_elastic_info_bad(url="http://localhost:9200/", version="6.4.2")
409
- body ="{\"version\":{\"number\":\"#{version}\"}}"
439
+ body ="{\"version\":{\"number\":\"#{version}\",\"build_flavor\":\"default\"},\"tagline\":\"You Know, for Search\"}"
410
440
  stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'text/plain' } })
411
441
  end
412
442
 
@@ -423,9 +453,15 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
423
453
  scheme https
424
454
  @log_level info
425
455
  }
426
- d = create_driver(config, 7, "\"7.10.1\"")
427
- logs = d.logs
428
- assert_logs_include(logs, /can not dig version information. Assuming Elasticsearch 7/)
456
+ if elasticsearch_transport_layer_decoupling?
457
+ assert_raise(NoMethodError) do
458
+ d = create_driver(config, 7, "\"7.10.1\"")
459
+ end
460
+ else
461
+ d = create_driver(config, 7, "\"7.10.1\"")
462
+ logs = d.logs
463
+ assert_logs_include(logs, /can not dig version information. Assuming Elasticsearch 7/)
464
+ end
429
465
  end
430
466
  end
431
467
 
@@ -488,6 +524,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
488
524
  stub_request(:put, "http://localhost:9200/_ilm/policy/logstash-policy").
489
525
  with(body: "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
490
526
  to_return(status: 200, body: "", headers: {})
527
+ stub_elastic_info
491
528
 
492
529
  assert_nothing_raised {
493
530
  driver(config)
@@ -532,6 +569,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
532
569
  stub_request(:put, "http://localhost:9200/_ilm/policy/logstash-policy").
533
570
  with(body: "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"75gb\",\"max_age\":\"50d\"}}}}}}").
534
571
  to_return(status: 200, body: "", headers: {})
572
+ stub_elastic_info
535
573
 
536
574
  assert_nothing_raised {
537
575
  driver(config)
@@ -548,6 +586,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
548
586
  template_file #{template_file}
549
587
  ilm_policy_overwrite true
550
588
  }
589
+ stub_elastic_info
551
590
 
552
591
  assert_raise(Fluent::ConfigError) {
553
592
  driver(config)
@@ -930,6 +969,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
930
969
  stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
931
970
  with(basic_auth: ['john', 'doe']).
932
971
  to_return(:status => 200, :body => "", :headers => {})
972
+ stub_elastic_info("https://logs.google.com:777/es//")
933
973
 
934
974
  driver(config)
935
975
 
@@ -974,6 +1014,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
974
1014
  stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
975
1015
  with(basic_auth: ['john', 'doe']).
976
1016
  to_return(:status => 200, :body => "", :headers => {})
1017
+ stub_elastic_info("https://logs.google.com:777/es//")
977
1018
 
978
1019
  driver(config)
979
1020
 
@@ -1037,6 +1078,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1037
1078
  driver(config)
1038
1079
 
1039
1080
  elastic_request = stub_elastic("https://logs.google.com:777/es//_bulk")
1081
+ stub_elastic_info("https://logs.google.com:777/es//")
1040
1082
  driver.run(default_tag: 'test.template') do
1041
1083
  driver.feed(sample_record)
1042
1084
  end
@@ -1102,6 +1144,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1102
1144
  with(basic_auth: ['john', 'doe'],
1103
1145
  body: "{\"aliases\":{\"myapp_deflector-test.template\":{\"is_write_index\":true}}}").
1104
1146
  to_return(:status => 200, :body => "", :headers => {})
1147
+ stub_elastic_info("https://logs.google.com:777/es//")
1105
1148
 
1106
1149
  driver(config)
1107
1150
 
@@ -1212,6 +1255,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1212
1255
  with(basic_auth: ['john', 'doe'],
1213
1256
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
1214
1257
  to_return(:status => 200, :body => "", :headers => {})
1258
+ stub_elastic_info("https://logs.google.com:777/es//")
1215
1259
 
1216
1260
  driver(config)
1217
1261
 
@@ -1298,6 +1342,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1298
1342
  with(basic_auth: ['john', 'doe'],
1299
1343
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
1300
1344
  to_return(:status => 200, :body => "", :headers => {})
1345
+ stub_elastic_info("https://logs.google.com:777/es//")
1301
1346
 
1302
1347
  driver(config)
1303
1348
 
@@ -1389,6 +1434,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1389
1434
  with(basic_auth: ['john', 'doe'],
1390
1435
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"60gb\",\"max_age\":\"45d\"}}}}}}").
1391
1436
  to_return(:status => 200, :body => "", :headers => {})
1437
+ stub_elastic_info("https://logs.google.com:777/es//")
1392
1438
 
1393
1439
  driver(config)
1394
1440
 
@@ -1497,6 +1543,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1497
1543
  with(basic_auth: ['john', 'doe'],
1498
1544
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
1499
1545
  to_return(:status => 200, :body => "", :headers => {})
1546
+ stub_elastic_info("https://logs.google.com:777/es//")
1500
1547
 
1501
1548
  driver(config)
1502
1549
 
@@ -1581,6 +1628,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1581
1628
  with(basic_auth: ['john', 'doe'],
1582
1629
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"70gb\",\"max_age\":\"30d\"}}}}}}").
1583
1630
  to_return(:status => 200, :body => "", :headers => {})
1631
+ stub_elastic_info("https://logs.google.com:777/es//")
1584
1632
 
1585
1633
  driver(config)
1586
1634
 
@@ -1665,6 +1713,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1665
1713
  with(basic_auth: ['john', 'doe'],
1666
1714
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"70gb\",\"max_age\":\"30d\"}}}}}}").
1667
1715
  to_return(:status => 200, :body => "", :headers => {})
1716
+ stub_elastic_info("https://logs.google.com:777/es//")
1668
1717
 
1669
1718
  driver(config)
1670
1719
 
@@ -1756,6 +1805,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1756
1805
  with(basic_auth: ['john', 'doe'],
1757
1806
  body: "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"70gb\",\"max_age\":\"30d\"}}}}}}").
1758
1807
  to_return(:status => 200, :body => "", :headers => {})
1808
+ stub_elastic_info("https://logs.google.com:777/es//")
1759
1809
 
1760
1810
  driver(config)
1761
1811
 
@@ -1846,6 +1896,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1846
1896
  with(basic_auth: ['john', 'doe'],
1847
1897
  body: "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"80gb\",\"max_age\":\"20d\"}}}}}}").
1848
1898
  to_return(:status => 200, :body => "", :headers => {})
1899
+ stub_elastic_info("https://logs.google.com:777/es//")
1849
1900
 
1850
1901
  driver(config)
1851
1902
 
@@ -1971,6 +2022,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1971
2022
  with(basic_auth: ['john', 'doe'],
1972
2023
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
1973
2024
  to_return(:status => 200, :body => "", :headers => {})
2025
+ stub_elastic_info("https://logs.google.com:777/es//")
1974
2026
 
1975
2027
  driver(config)
1976
2028
 
@@ -2067,6 +2119,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2067
2119
  with(basic_auth: ['john', 'doe'],
2068
2120
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
2069
2121
  to_return(:status => 200, :body => "", :headers => {})
2122
+ stub_elastic_info("https://logs.google.com:777/es//")
2070
2123
 
2071
2124
  driver(config)
2072
2125
 
@@ -2163,6 +2216,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2163
2216
  with(basic_auth: ['john', 'doe'],
2164
2217
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
2165
2218
  to_return(:status => 200, :body => "", :headers => {})
2219
+ stub_elastic_info("https://logs.google.com:777/es//")
2166
2220
 
2167
2221
  driver(config)
2168
2222
 
@@ -2218,6 +2272,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2218
2272
  stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
2219
2273
  with(basic_auth: ['john', 'doe']).
2220
2274
  to_return(:status => 200, :body => "", :headers => {})
2275
+ stub_elastic_info("https://logs.google.com:777/es//")
2221
2276
 
2222
2277
  driver(config)
2223
2278
 
@@ -2270,6 +2325,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2270
2325
  driver(config)
2271
2326
 
2272
2327
  stub_elastic("https://logs.google.com:777/es//_bulk")
2328
+ stub_elastic_info("https://logs.google.com:777/es//")
2273
2329
  driver.run(default_tag: 'test.template') do
2274
2330
  driver.feed(sample_record)
2275
2331
  end
@@ -2321,6 +2377,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2321
2377
  driver(config)
2322
2378
 
2323
2379
  stub_elastic("https://logs-test.google.com:777/es//_bulk")
2380
+ stub_elastic_info("https://logs-test.google.com:777/es//")
2324
2381
  driver.run(default_tag: 'test') do
2325
2382
  driver.feed(sample_record)
2326
2383
  end
@@ -2381,6 +2438,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2381
2438
  stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/mylogs").
2382
2439
  with(basic_auth: ['john', 'doe']).
2383
2440
  to_return(:status => 200, :body => "", :headers => {})
2441
+ stub_elastic_info("https://logs.google.com:777/es//")
2384
2442
 
2385
2443
  driver(config)
2386
2444
 
@@ -2443,6 +2501,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2443
2501
  stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/myapp_deflector").
2444
2502
  with(basic_auth: ['john', 'doe']).
2445
2503
  to_return(:status => 200, :body => "", :headers => {})
2504
+ stub_elastic_info("https://logs.google.com:777/es//")
2446
2505
 
2447
2506
  driver(config)
2448
2507
 
@@ -2511,6 +2570,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2511
2570
  driver(config)
2512
2571
 
2513
2572
  elastic_request = stub_elastic("https://logs.google.com:777/es//_bulk")
2573
+ stub_elastic_info("https://logs.google.com:777/es//")
2514
2574
  driver.run(default_tag: 'custom-test') do
2515
2575
  driver.feed(sample_record)
2516
2576
  end
@@ -2610,7 +2670,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2610
2670
  with(basic_auth: ['john', 'doe'],
2611
2671
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
2612
2672
  to_return(:status => 200, :body => "", :headers => {})
2613
-
2673
+ stub_elastic_info("https://logs.google.com:777/es//")
2614
2674
  driver(config)
2615
2675
 
2616
2676
  assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs", times: 1)
@@ -2699,6 +2759,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2699
2759
  with(basic_auth: ['john', 'doe'],
2700
2760
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"60gb\",\"max_age\":\"45d\"}}}}}}").
2701
2761
  to_return(:status => 200, :body => "", :headers => {})
2762
+ stub_elastic_info("https://logs.google.com:777/es//")
2702
2763
 
2703
2764
  driver(config)
2704
2765
 
@@ -2728,6 +2789,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2728
2789
  }
2729
2790
 
2730
2791
  # Should raise error because multiple alias indices IllegalArgument Error on executing ILM feature
2792
+ stub_elastic_info("https://logs.google.com:777/es//")
2731
2793
  assert_raise(Fluent::ConfigError) do
2732
2794
  driver(config)
2733
2795
  end
@@ -2863,6 +2925,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2863
2925
  with(basic_auth: ['john', 'doe'],
2864
2926
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
2865
2927
  to_return(:status => 200, :body => "", :headers => {})
2928
+ stub_elastic_info("https://logs.google.com:777/es//")
2866
2929
 
2867
2930
  driver(config)
2868
2931
 
@@ -2953,7 +3016,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2953
3016
  with(basic_auth: ['john', 'doe'],
2954
3017
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"70gb\",\"max_age\":\"30d\"}}}}}}").
2955
3018
  to_return(:status => 200, :body => "", :headers => {})
2956
-
3019
+ stub_elastic_info("https://logs.google.com:777/es//")
2957
3020
  driver(config)
2958
3021
 
2959
3022
  assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs", times: 1)
@@ -2999,6 +3062,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2999
3062
  stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
3000
3063
  with(basic_auth: ['john', 'doe']).
3001
3064
  to_return(:status => 200, :body => "", :headers => {})
3065
+ stub_elastic_info("https://logs.google.com:777/es//")
3002
3066
 
3003
3067
  driver(config)
3004
3068
 
@@ -3045,6 +3109,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3045
3109
  stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
3046
3110
  with(basic_auth: ['john', 'doe']).
3047
3111
  to_return(:status => 200, :body => "", :headers => {})
3112
+ stub_elastic_info("https://logs.google.com:777/es//")
3048
3113
 
3049
3114
  driver(config)
3050
3115
 
@@ -3107,6 +3172,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3107
3172
  stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fd%7D-000001%3E/#{alias_endpoint}/myapp_deflector").
3108
3173
  with(basic_auth: ['john', 'doe']).
3109
3174
  to_return(:status => 200, :body => "", :headers => {})
3175
+ stub_elastic_info("https://logs.google.com:777/es//")
3110
3176
 
3111
3177
  driver(config)
3112
3178
 
@@ -3133,7 +3199,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3133
3199
  stub_request(:get, "https://logs.google.com:777/es//_template/logstash").
3134
3200
  with(basic_auth: ['john', 'doe']).
3135
3201
  to_return(:status => 404, :body => "", :headers => {})
3136
-
3202
+ stub_elastic_info("https://logs.google.com:777/es//")
3137
3203
 
3138
3204
  assert_raise(RuntimeError) {
3139
3205
  driver(config)
@@ -3185,7 +3251,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3185
3251
 
3186
3252
  driver(config)
3187
3253
 
3188
- stub_elastic("https://logs.google.com:777/es//_bulk")
3254
+ stub_elastic("https://logs-test.google.com:777/es//_bulk")
3255
+ stub_elastic_info("https://logs-test.google.com:777/es//")
3189
3256
  driver.run(default_tag: 'test') do
3190
3257
  driver.feed(sample_record)
3191
3258
  end
@@ -3225,6 +3292,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3225
3292
  connection_resets += 1
3226
3293
  raise Faraday::ConnectionFailed, "Test message"
3227
3294
  end
3295
+ stub_elastic_info("https://logs.google.com:778/es//")
3228
3296
 
3229
3297
  assert_raise(Fluent::Plugin::ElasticsearchError::RetryableOperationExhaustedFailure) do
3230
3298
  driver(config)
@@ -3266,6 +3334,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3266
3334
  retries += 1
3267
3335
  raise error
3268
3336
  end
3337
+ stub_elastic_info("https://logs.google.com:778/es//")
3269
3338
 
3270
3339
  assert_raise(Fluent::Plugin::ElasticsearchError::RetryableOperationExhaustedFailure) do
3271
3340
  driver(config)
@@ -3309,6 +3378,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3309
3378
  connection_resets += 1
3310
3379
  raise Faraday::ConnectionFailed, "Test message"
3311
3380
  end
3381
+ stub_elastic_info("https://logs.google.com:778/es//")
3312
3382
 
3313
3383
  driver(config)
3314
3384
 
@@ -3364,6 +3434,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3364
3434
  stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash3").
3365
3435
  with(basic_auth: ['john', 'doe']).
3366
3436
  to_return(:status => 200, :body => "", :headers => {})
3437
+ stub_elastic_info("https://logs.google.com:777/es//")
3367
3438
 
3368
3439
  driver(config)
3369
3440
 
@@ -3421,6 +3492,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3421
3492
  stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash3").
3422
3493
  with(basic_auth: ['john', 'doe']).
3423
3494
  to_return(:status => 200, :body => "", :headers => {})
3495
+ stub_elastic_info("https://logs.google.com:777/es//")
3424
3496
 
3425
3497
  driver(config)
3426
3498
 
@@ -3479,6 +3551,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3479
3551
  stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2").
3480
3552
  with(basic_auth: ['john', 'doe']).
3481
3553
  to_return(:status => 200, :body => "", :headers => {})
3554
+ stub_elastic_info("https://logs.google.com:777/es//")
3482
3555
 
3483
3556
  driver(config)
3484
3557
 
@@ -3529,6 +3602,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3529
3602
  stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2").
3530
3603
  with(basic_auth: ['john', 'doe']).
3531
3604
  to_return(:status => 200, :body => "", :headers => {})
3605
+ stub_elastic_info("https://logs.google.com:777/es//")
3532
3606
 
3533
3607
  assert_raise(RuntimeError) {
3534
3608
  driver(config)
@@ -3545,6 +3619,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3545
3619
  path /es/
3546
3620
  port 123
3547
3621
  }
3622
+ stub_elastic_info("https://host1:50")
3623
+ stub_elastic_info("https://host2:100")
3624
+ stub_elastic_info("https://host3:123")
3548
3625
  instance = driver(config).instance
3549
3626
 
3550
3627
  assert_equal 3, instance.get_connection_options[:hosts].length
@@ -3567,6 +3644,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3567
3644
  user default_user
3568
3645
  password default_password
3569
3646
  }
3647
+ stub_elastic_info("https://john:password@host1:443/elastic/")
3648
+ stub_elastic_info("http://host2")
3570
3649
  instance = driver(config).instance
3571
3650
 
3572
3651
  assert_equal 2, instance.get_connection_options[:hosts].length
@@ -3593,6 +3672,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3593
3672
  user default_user
3594
3673
  password default_password
3595
3674
  }
3675
+ stub_elastic_info("https://j%2Bhn:passw%40rd@host1:443/elastic/")
3676
+ stub_elastic_info("http://host2")
3677
+
3596
3678
  instance = driver(config).instance
3597
3679
 
3598
3680
  assert_equal 2, instance.get_connection_options[:hosts].length
@@ -3612,6 +3694,74 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3612
3694
  assert_equal '/default_path', host2[:path]
3613
3695
  end
3614
3696
 
3697
+ class IPv6AdressStringHostsTest < self
3698
+ def test_legacy_hosts_list
3699
+ config = %{
3700
+ hosts "[2404:7a80:d440:3000:192a:a292:bd7f:ca19]:50,host2:100,host3"
3701
+ scheme https
3702
+ path /es/
3703
+ port 123
3704
+ }
3705
+ instance = driver(config).instance
3706
+
3707
+ assert_raise(URI::InvalidURIError) do
3708
+ instance.get_connection_options[:hosts].length
3709
+ end
3710
+ end
3711
+
3712
+ def test_hosts_list
3713
+ config = %{
3714
+ hosts https://john:password@[2404:7a80:d440:3000:192a:a292:bd7f:ca19]:443/elastic/,http://host2
3715
+ path /default_path
3716
+ user default_user
3717
+ password default_password
3718
+ }
3719
+ instance = driver(config).instance
3720
+
3721
+ assert_equal 2, instance.get_connection_options[:hosts].length
3722
+ host1, host2 = instance.get_connection_options[:hosts]
3723
+
3724
+ assert_equal '[2404:7a80:d440:3000:192a:a292:bd7f:ca19]', host1[:host]
3725
+ assert_equal 443, host1[:port]
3726
+ assert_equal 'https', host1[:scheme]
3727
+ assert_equal 'john', host1[:user]
3728
+ assert_equal 'password', host1[:password]
3729
+ assert_equal '/elastic/', host1[:path]
3730
+
3731
+ assert_equal 'host2', host2[:host]
3732
+ assert_equal 'http', host2[:scheme]
3733
+ assert_equal 'default_user', host2[:user]
3734
+ assert_equal 'default_password', host2[:password]
3735
+ assert_equal '/default_path', host2[:path]
3736
+ end
3737
+
3738
+ def test_hosts_list_with_escape_placeholders
3739
+ config = %{
3740
+ hosts https://%{j+hn}:%{passw@rd}@[2404:7a80:d440:3000:192a:a292:bd7f:ca19]:443/elastic/,http://host2
3741
+ path /default_path
3742
+ user default_user
3743
+ password default_password
3744
+ }
3745
+ instance = driver(config).instance
3746
+
3747
+ assert_equal 2, instance.get_connection_options[:hosts].length
3748
+ host1, host2 = instance.get_connection_options[:hosts]
3749
+
3750
+ assert_equal '[2404:7a80:d440:3000:192a:a292:bd7f:ca19]', host1[:host]
3751
+ assert_equal 443, host1[:port]
3752
+ assert_equal 'https', host1[:scheme]
3753
+ assert_equal 'j%2Bhn', host1[:user]
3754
+ assert_equal 'passw%40rd', host1[:password]
3755
+ assert_equal '/elastic/', host1[:path]
3756
+
3757
+ assert_equal 'host2', host2[:host]
3758
+ assert_equal 'http', host2[:scheme]
3759
+ assert_equal 'default_user', host2[:user]
3760
+ assert_equal 'default_password', host2[:password]
3761
+ assert_equal '/default_path', host2[:path]
3762
+ end
3763
+ end
3764
+
3615
3765
  def test_single_host_params_and_defaults
3616
3766
  config = %{
3617
3767
  host logs.google.com
@@ -3665,6 +3815,46 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3665
3815
  assert(ports.none? { |p| p == 9200 })
3666
3816
  end
3667
3817
 
3818
+ class IPv6AdressStringHostTest < self
3819
+ def test_single_host_params_and_defaults
3820
+ config = %{
3821
+ host 2404:7a80:d440:3000:192a:a292:bd7f:ca19
3822
+ user john
3823
+ password doe
3824
+ }
3825
+ instance = driver(config).instance
3826
+
3827
+ assert_equal 1, instance.get_connection_options[:hosts].length
3828
+ host1 = instance.get_connection_options[:hosts][0]
3829
+
3830
+ assert_equal '[2404:7a80:d440:3000:192a:a292:bd7f:ca19]', host1[:host]
3831
+ assert_equal 9200, host1[:port]
3832
+ assert_equal 'http', host1[:scheme]
3833
+ assert_equal 'john', host1[:user]
3834
+ assert_equal 'doe', host1[:password]
3835
+ assert_equal nil, host1[:path]
3836
+ end
3837
+
3838
+ def test_single_host_params_and_defaults_with_escape_placeholders
3839
+ config = %{
3840
+ host 2404:7a80:d440:3000:192a:a292:bd7f:ca19
3841
+ user %{j+hn}
3842
+ password %{d@e}
3843
+ }
3844
+ instance = driver(config).instance
3845
+
3846
+ assert_equal 1, instance.get_connection_options[:hosts].length
3847
+ host1 = instance.get_connection_options[:hosts][0]
3848
+
3849
+ assert_equal '[2404:7a80:d440:3000:192a:a292:bd7f:ca19]', host1[:host]
3850
+ assert_equal 9200, host1[:port]
3851
+ assert_equal 'http', host1[:scheme]
3852
+ assert_equal 'j%2Bhn', host1[:user]
3853
+ assert_equal 'd%40e', host1[:password]
3854
+ assert_equal nil, host1[:path]
3855
+ end
3856
+ end
3857
+
3668
3858
  def test_password_is_required_if_specify_user
3669
3859
  config = %{
3670
3860
  user john
@@ -3685,6 +3875,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3685
3875
  elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
3686
3876
  with(headers: { "Content-Type" => "application/json" })
3687
3877
  end
3878
+ stub_elastic_info
3688
3879
  driver.run(default_tag: 'test') do
3689
3880
  driver.feed(sample_record)
3690
3881
  end
@@ -3696,6 +3887,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3696
3887
  to_return(:status => 200, :body => "", :headers => {})
3697
3888
  elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
3698
3889
  with(headers: {'custom' => 'header1','and_others' => 'header2' })
3890
+ stub_elastic_info
3699
3891
  driver.configure(%[custom_headers {"custom":"header1", "and_others":"header2"}])
3700
3892
  driver.run(default_tag: 'test') do
3701
3893
  driver.feed(sample_record)
@@ -3708,6 +3900,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3708
3900
  to_return(:status => 200, :body => "", :headers => {})
3709
3901
  elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
3710
3902
  with(headers: {'Authorization'=>'ApiKey dGVzdGF1dGhoZWFkZXI='})
3903
+ stub_elastic_info
3711
3904
  driver.configure(%[api_key testauthheader])
3712
3905
  driver.run(default_tag: 'test') do
3713
3906
  driver.feed(sample_record)
@@ -3718,6 +3911,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3718
3911
  def test_write_message_with_bad_chunk
3719
3912
  driver.configure("target_index_key bad_value\n@log_level debug\n")
3720
3913
  stub_elastic
3914
+ stub_elastic_info
3721
3915
  driver.run(default_tag: 'test') do
3722
3916
  driver.feed({'bad_value'=>"\255"})
3723
3917
  end
@@ -3733,6 +3927,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3733
3927
  def test_writes_to_default_index(data)
3734
3928
  version, index_name = data
3735
3929
  stub_elastic
3930
+ stub_elastic_info
3736
3931
  driver("", version)
3737
3932
  driver.run(default_tag: 'test') do
3738
3933
  driver.feed(sample_record)
@@ -3774,6 +3969,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3774
3969
 
3775
3970
  elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
3776
3971
  to_return(:status => 200, :headers => {'Content-Type' => 'Application/json'}, :body => compressed_body)
3972
+ stub_elastic_info("http://localhost:9200/")
3777
3973
 
3778
3974
  driver(config)
3779
3975
  driver.run(default_tag: 'test') do
@@ -3790,6 +3986,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3790
3986
  def test_writes_to_default_type(data)
3791
3987
  version, index_type = data
3792
3988
  stub_elastic
3989
+ stub_elastic_info
3793
3990
  driver("", version)
3794
3991
  driver.run(default_tag: 'test') do
3795
3992
  driver.feed(sample_record)
@@ -3800,6 +3997,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3800
3997
  def test_writes_to_speficied_index
3801
3998
  driver.configure("index_name myindex\n")
3802
3999
  stub_elastic
4000
+ stub_elastic_info
3803
4001
  driver.run(default_tag: 'test') do
3804
4002
  driver.feed(sample_record)
3805
4003
  end
@@ -3819,6 +4017,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3819
4017
  ]
3820
4018
  ))
3821
4019
  request = stub_elastic
4020
+ stub_elastic_info
3822
4021
  driver.run(default_tag: 'test') do
3823
4022
  driver.feed(sample_record('huge_record' => ("a" * 20 * 1024 * 1024)))
3824
4023
  driver.feed(sample_record('huge_record' => ("a" * 20 * 1024 * 1024)))
@@ -3843,6 +4042,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3843
4042
  body: /{"index":{"_index":"fluentd","_type":"fluentd"}}\n{"age":26,"request_id":"42","parent_id":"parent","routing_id":"routing","#{chunk_id_key}":".*"}\n/) do |req|
3844
4043
  @index_cmds = req.body.split("\n").map {|r| JSON.parse(r) }
3845
4044
  end
4045
+ stub_elastic_info
3846
4046
  driver.run(default_tag: 'test', shutdown: false) do
3847
4047
  driver.feed(sample_record)
3848
4048
  end
@@ -3872,6 +4072,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3872
4072
  ]
3873
4073
  ))
3874
4074
  request = stub_elastic
4075
+ stub_elastic_info
3875
4076
  driver.run(default_tag: 'test') do
3876
4077
  driver.feed(sample_record('huge_record' => ("a" * 20 * 1024 * 1024)))
3877
4078
  driver.feed(sample_record('huge_record' => ("a" * 20 * 1024 * 1024)))
@@ -3884,6 +4085,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3884
4085
  def test_writes_to_speficied_index_with_tag_placeholder
3885
4086
  driver.configure("index_name myindex.${tag}\n")
3886
4087
  stub_elastic
4088
+ stub_elastic_info
3887
4089
  driver.run(default_tag: 'test') do
3888
4090
  driver.feed(sample_record)
3889
4091
  end
@@ -3903,6 +4105,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3903
4105
  ]
3904
4106
  ))
3905
4107
  stub_elastic
4108
+ stub_elastic_info
3906
4109
  time = Time.parse Date.today.iso8601
3907
4110
  driver.run(default_tag: 'test') do
3908
4111
  driver.feed(time.to_i, sample_record)
@@ -3923,6 +4126,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3923
4126
  pipeline_id = "mypipeline"
3924
4127
  logstash_index = "myindex.#{pipeline_id}"
3925
4128
  stub_elastic
4129
+ stub_elastic_info
3926
4130
  driver.run(default_tag: 'test') do
3927
4131
  driver.feed(time.to_i, sample_record.merge({"pipeline_id" => pipeline_id}))
3928
4132
  end
@@ -3933,6 +4137,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3933
4137
  def test_writes_to_speficied_index_uppercase
3934
4138
  driver.configure("index_name MyIndex\n")
3935
4139
  stub_elastic
4140
+ stub_elastic_info
3936
4141
  driver.run(default_tag: 'test') do
3937
4142
  driver.feed(sample_record)
3938
4143
  end
@@ -3944,6 +4149,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3944
4149
  def test_writes_to_target_index_key
3945
4150
  driver.configure("target_index_key @target_index\n")
3946
4151
  stub_elastic
4152
+ stub_elastic_info
3947
4153
  record = sample_record.clone
3948
4154
  driver.run(default_tag: 'test') do
3949
4155
  driver.feed(sample_record.merge('@target_index' => 'local-override'))
@@ -3957,17 +4163,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3957
4163
  logstash_format true")
3958
4164
  time = Time.parse Date.today.iso8601
3959
4165
  stub_elastic
4166
+ stub_elastic_info
3960
4167
  driver.run(default_tag: 'test') do
3961
4168
  driver.feed(time.to_i, sample_record.merge('@target_index' => 'local-override'))
3962
4169
  end
3963
4170
  assert_equal('local-override', index_cmds.first['index']['_index'])
3964
4171
  end
3965
4172
 
3966
- def test_writes_to_target_index_key_logstash_uppercase
4173
+ def test_writes_to_target_index_key_logstash_uppercase
3967
4174
  driver.configure("target_index_key @target_index
3968
4175
  logstash_format true")
3969
4176
  time = Time.parse Date.today.iso8601
3970
4177
  stub_elastic
4178
+ stub_elastic_info
3971
4179
  driver.run(default_tag: 'test') do
3972
4180
  driver.feed(time.to_i, sample_record.merge('@target_index' => 'LOCAL-OVERRIDE'))
3973
4181
  end
@@ -3980,17 +4188,203 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3980
4188
  pipeline = "fluentd"
3981
4189
  driver.configure("pipeline #{pipeline}")
3982
4190
  stub_elastic
4191
+ stub_elastic_info
3983
4192
  driver.run(default_tag: 'test') do
3984
4193
  driver.feed(sample_record)
3985
4194
  end
3986
4195
  assert_equal(pipeline, index_cmds.first['index']['pipeline'])
3987
4196
  end
3988
4197
 
4198
+ def stub_elastic_affinity_target_index_search_with_body(url="http://localhost:9200/logstash-*/_search", ids, return_body_str)
4199
+ # Note: ids used in query is unique list of ids
4200
+ stub_request(:post, url)
4201
+ .with(
4202
+ body: "{\"query\":{\"ids\":{\"values\":#{ids.uniq.to_json}}},\"_source\":false,\"sort\":[{\"_index\":{\"order\":\"desc\"}}]}",
4203
+ )
4204
+ .to_return(lambda do |req|
4205
+ { :status => 200,
4206
+ :headers => { 'Content-Type' => 'json' },
4207
+ :body => return_body_str
4208
+ }
4209
+ end)
4210
+ end
4211
+
4212
+ def stub_elastic_affinity_target_index_search(url="http://localhost:9200/logstash-*/_search", ids, indices)
4213
+ # Example ids and indices arrays.
4214
+ # [ "3408a2c8eecd4fbfb82e45012b54fa82", "2816fc6ef4524b3f8f7e869002005433"]
4215
+ # [ "logstash-2021.04.28", "logstash-2021.04.29"]
4216
+ body = %({
4217
+ "took" : 31,
4218
+ "timed_out" : false,
4219
+ "_shards" : {
4220
+ "total" : 52,
4221
+ "successful" : 52,
4222
+ "skipped" : 48,
4223
+ "failed" : 0
4224
+ },
4225
+ "hits" : {
4226
+ "total" : {
4227
+ "value" : 356,
4228
+ "relation" : "eq"
4229
+ },
4230
+ "max_score" : null,
4231
+ "hits" : [
4232
+ {
4233
+ "_index" : "#{indices[0]}",
4234
+ "_type" : "_doc",
4235
+ "_id" : "#{ids[0]}",
4236
+ "_score" : null,
4237
+ "sort" : [
4238
+ "#{indices[0]}"
4239
+ ]
4240
+ },
4241
+ {
4242
+ "_index" : "#{indices[1]}",
4243
+ "_type" : "_doc",
4244
+ "_id" : "#{ids[1]}",
4245
+ "_score" : null,
4246
+ "sort" : [
4247
+ "#{indices[1]}"
4248
+ ]
4249
+ }
4250
+ ]
4251
+ }
4252
+ })
4253
+ stub_elastic_affinity_target_index_search_with_body(ids, body)
4254
+ end
4255
+
4256
+ def stub_elastic_affinity_target_index_search_return_empty(url="http://localhost:9200/logstash-*/_search", ids)
4257
+ empty_body = %({
4258
+ "took" : 5,
4259
+ "timed_out" : false,
4260
+ "_shards" : {
4261
+ "total" : 54,
4262
+ "successful" : 54,
4263
+ "skipped" : 53,
4264
+ "failed" : 0
4265
+ },
4266
+ "hits" : {
4267
+ "total" : {
4268
+ "value" : 0,
4269
+ "relation" : "eq"
4270
+ },
4271
+ "max_score" : null,
4272
+ "hits" : [ ]
4273
+ }
4274
+ })
4275
+ stub_elastic_affinity_target_index_search_with_body(ids, empty_body)
4276
+ end
4277
+
4278
+ def test_writes_to_affinity_target_index
4279
+ driver.configure("target_index_affinity true
4280
+ logstash_format true
4281
+ id_key my_id
4282
+ write_operation update")
4283
+
4284
+ my_id_value = "3408a2c8eecd4fbfb82e45012b54fa82"
4285
+ ids = [my_id_value]
4286
+ indices = ["logstash-2021.04.28"]
4287
+ stub_elastic
4288
+ stub_elastic_info
4289
+ stub_elastic_affinity_target_index_search(ids, indices)
4290
+ driver.run(default_tag: 'test') do
4291
+ driver.feed(sample_record('my_id' => my_id_value))
4292
+ end
4293
+ assert_equal('logstash-2021.04.28', index_cmds.first['update']['_index'])
4294
+ end
4295
+
4296
+ def test_writes_to_affinity_target_index_write_operation_upsert
4297
+ driver.configure("target_index_affinity true
4298
+ logstash_format true
4299
+ id_key my_id
4300
+ write_operation upsert")
4301
+
4302
+ my_id_value = "3408a2c8eecd4fbfb82e45012b54fa82"
4303
+ ids = [my_id_value]
4304
+ indices = ["logstash-2021.04.28"]
4305
+ stub_elastic
4306
+ stub_elastic_info
4307
+ stub_elastic_affinity_target_index_search(ids, indices)
4308
+ driver.run(default_tag: 'test') do
4309
+ driver.feed(sample_record('my_id' => my_id_value))
4310
+ end
4311
+ assert_equal('logstash-2021.04.28', index_cmds.first['update']['_index'])
4312
+ end
4313
+
4314
+ def test_writes_to_affinity_target_index_index_not_exists_yet
4315
+ driver.configure("target_index_affinity true
4316
+ logstash_format true
4317
+ id_key my_id
4318
+ write_operation update")
4319
+
4320
+ my_id_value = "3408a2c8eecd4fbfb82e45012b54fa82"
4321
+ ids = [my_id_value]
4322
+ stub_elastic
4323
+ stub_elastic_info
4324
+ stub_elastic_affinity_target_index_search_return_empty(ids)
4325
+ time = Time.parse Date.today.iso8601
4326
+ driver.run(default_tag: 'test') do
4327
+ driver.feed(time.to_i, sample_record('my_id' => my_id_value))
4328
+ end
4329
+ assert_equal("logstash-#{time.utc.strftime("%Y.%m.%d")}", index_cmds.first['update']['_index'])
4330
+ end
4331
+
4332
+ def test_writes_to_affinity_target_index_multiple_indices
4333
+ driver.configure("target_index_affinity true
4334
+ logstash_format true
4335
+ id_key my_id
4336
+ write_operation update")
4337
+
4338
+ my_id_value = "2816fc6ef4524b3f8f7e869002005433"
4339
+ my_id_value2 = "3408a2c8eecd4fbfb82e45012b54fa82"
4340
+ ids = [my_id_value, my_id_value2]
4341
+ indices = ["logstash-2021.04.29", "logstash-2021.04.28"]
4342
+ stub_elastic_info
4343
+ stub_elastic_all_requests
4344
+ stub_elastic_affinity_target_index_search(ids, indices)
4345
+ driver.run(default_tag: 'test') do
4346
+ driver.feed(sample_record('my_id' => my_id_value))
4347
+ driver.feed(sample_record('my_id' => my_id_value2))
4348
+ end
4349
+ assert_equal(2, index_cmds_all_requests.count)
4350
+ assert_equal('logstash-2021.04.29', index_cmds_all_requests[0].first['update']['_index'])
4351
+ assert_equal(my_id_value, index_cmds_all_requests[0].first['update']['_id'])
4352
+ assert_equal('logstash-2021.04.28', index_cmds_all_requests[1].first['update']['_index'])
4353
+ assert_equal(my_id_value2, index_cmds_all_requests[1].first['update']['_id'])
4354
+ end
4355
+
4356
+ def test_writes_to_affinity_target_index_same_id_dublicated_write_to_oldest_index
4357
+ driver.configure("target_index_affinity true
4358
+ logstash_format true
4359
+ id_key my_id
4360
+ write_operation update")
4361
+
4362
+ my_id_value = "2816fc6ef4524b3f8f7e869002005433"
4363
+ # It may happen than same id has inserted to two index while data inserted during rollover period
4364
+ ids = [my_id_value, my_id_value]
4365
+ # Simulate the used sorting here, as search sorts indices in DESC order to pick only oldest index per single _id
4366
+ indices = ["logstash-2021.04.29", "logstash-2021.04.28"]
4367
+
4368
+ stub_elastic_info
4369
+ stub_elastic_all_requests
4370
+ stub_elastic_affinity_target_index_search(ids, indices)
4371
+ driver.run(default_tag: 'test') do
4372
+ driver.feed(sample_record('my_id' => my_id_value))
4373
+ driver.feed(sample_record('my_id' => my_id_value))
4374
+ end
4375
+ assert_equal('logstash-2021.04.28', index_cmds.first['update']['_index'])
4376
+
4377
+ assert_equal(1, index_cmds_all_requests.count)
4378
+ assert_equal('logstash-2021.04.28', index_cmds_all_requests[0].first['update']['_index'])
4379
+ assert_equal(my_id_value, index_cmds_all_requests[0].first['update']['_id'])
4380
+ end
4381
+
3989
4382
  class PipelinePlaceholdersTest < self
3990
4383
  def test_writes_to_default_index_with_pipeline_tag_placeholder
3991
4384
  pipeline = "fluentd-${tag}"
3992
4385
  driver.configure("pipeline #{pipeline}")
3993
4386
  stub_elastic
4387
+ stub_elastic_info
3994
4388
  driver.run(default_tag: 'test.builtin.placeholder') do
3995
4389
  driver.feed(sample_record)
3996
4390
  end
@@ -4012,6 +4406,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4012
4406
  time = Time.parse Date.today.iso8601
4013
4407
  pipeline = "fluentd-#{time.getutc.strftime("%Y%m%d")}"
4014
4408
  stub_elastic
4409
+ stub_elastic_info
4015
4410
  driver.run(default_tag: 'test') do
4016
4411
  driver.feed(time.to_i, sample_record)
4017
4412
  end
@@ -4031,6 +4426,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4031
4426
  pipeline_id = "mypipeline"
4032
4427
  logstash_index = "fluentd-#{pipeline_id}"
4033
4428
  stub_elastic
4429
+ stub_elastic_info
4034
4430
  driver.run(default_tag: 'test') do
4035
4431
  driver.feed(time.to_i, sample_record.merge({"pipeline_id" => pipeline_id}))
4036
4432
  end
@@ -4041,6 +4437,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4041
4437
  def test_writes_to_target_index_key_fallack
4042
4438
  driver.configure("target_index_key @target_index\n")
4043
4439
  stub_elastic
4440
+ stub_elastic_info
4044
4441
  driver.run(default_tag: 'test') do
4045
4442
  driver.feed(sample_record)
4046
4443
  end
@@ -4053,6 +4450,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4053
4450
  time = Time.parse Date.today.iso8601
4054
4451
  logstash_index = "logstash-#{time.getutc.strftime("%Y.%m.%d")}"
4055
4452
  stub_elastic
4453
+ stub_elastic_info
4056
4454
  driver.run(default_tag: 'test') do
4057
4455
  driver.feed(time.to_i, sample_record)
4058
4456
  end
@@ -4066,6 +4464,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4066
4464
  def test_writes_to_speficied_type(data)
4067
4465
  driver('', data["es_version"]).configure("type_name mytype\n")
4068
4466
  stub_elastic
4467
+ stub_elastic_info
4069
4468
  driver.run(default_tag: 'test') do
4070
4469
  driver.feed(sample_record)
4071
4470
  end
@@ -4079,6 +4478,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4079
4478
  def test_writes_to_speficied_type_with_placeholders(data)
4080
4479
  driver('', data["es_version"]).configure("type_name mytype.${tag}\n")
4081
4480
  stub_elastic
4481
+ stub_elastic_info
4082
4482
  driver.run(default_tag: 'test') do
4083
4483
  driver.feed(sample_record)
4084
4484
  end
@@ -4093,6 +4493,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4093
4493
  driver('', data["es_version"])
4094
4494
  .configure("type_name mytype.${tag}\nsuppress_type_name true")
4095
4495
  stub_elastic
4496
+ stub_elastic_info
4096
4497
  driver.run(default_tag: 'test') do
4097
4498
  driver.feed(sample_record)
4098
4499
  end
@@ -4107,6 +4508,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4107
4508
  def test_writes_to_target_type_key(data)
4108
4509
  driver('', data["es_version"]).configure("target_type_key @target_type\n")
4109
4510
  stub_elastic
4511
+ stub_elastic_info
4110
4512
  record = sample_record.clone
4111
4513
  driver.run(default_tag: 'test') do
4112
4514
  driver.feed(sample_record.merge('@target_type' => 'local-override'))
@@ -4118,6 +4520,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4118
4520
  def test_writes_to_target_type_key_fallack_to_default
4119
4521
  driver.configure("target_type_key @target_type\n")
4120
4522
  stub_elastic
4523
+ stub_elastic_info
4121
4524
  driver.run(default_tag: 'test') do
4122
4525
  driver.feed(sample_record)
4123
4526
  end
@@ -4128,6 +4531,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4128
4531
  driver.configure("target_type_key @target_type
4129
4532
  type_name mytype")
4130
4533
  stub_elastic
4534
+ stub_elastic_info
4131
4535
  driver.run(default_tag: 'test') do
4132
4536
  driver.feed(sample_record)
4133
4537
  end
@@ -4142,6 +4546,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4142
4546
  def test_writes_to_target_type_key_nested(data)
4143
4547
  driver('', data["es_version"]).configure("target_type_key kubernetes.labels.log_type\n")
4144
4548
  stub_elastic
4549
+ stub_elastic_info
4145
4550
  driver.run(default_tag: 'test') do
4146
4551
  driver.feed(sample_record.merge('kubernetes' => {
4147
4552
  'labels' => {
@@ -4156,6 +4561,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4156
4561
  def test_writes_to_target_type_key_fallack_to_default_nested
4157
4562
  driver.configure("target_type_key kubernetes.labels.log_type\n")
4158
4563
  stub_elastic
4564
+ stub_elastic_info
4159
4565
  driver.run(default_tag: 'test') do
4160
4566
  driver.feed(sample_record.merge('kubernetes' => {
4161
4567
  'labels' => {
@@ -4169,6 +4575,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4169
4575
  def test_writes_to_speficied_host
4170
4576
  driver.configure("host 192.168.33.50\n")
4171
4577
  elastic_request = stub_elastic("http://192.168.33.50:9200/_bulk")
4578
+ stub_elastic_info("http://192.168.33.50:9200/")
4172
4579
  driver.run(default_tag: 'test') do
4173
4580
  driver.feed(sample_record)
4174
4581
  end
@@ -4178,6 +4585,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4178
4585
  def test_writes_to_speficied_port
4179
4586
  driver.configure("port 9201\n")
4180
4587
  elastic_request = stub_elastic("http://localhost:9201/_bulk")
4588
+ stub_elastic_info("http://localhost:9201")
4181
4589
  driver.run(default_tag: 'test') do
4182
4590
  driver.feed(sample_record)
4183
4591
  end
@@ -4193,6 +4601,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4193
4601
  hosts.each do |host_info|
4194
4602
  host, port = host_info
4195
4603
  stub_elastic_with_store_index_command_counts("http://#{host}:#{port}/_bulk")
4604
+ stub_elastic_info("http://#{host}:#{port}/")
4196
4605
  end
4197
4606
 
4198
4607
  driver.run(default_tag: 'test') do
@@ -4229,6 +4638,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4229
4638
  ]}
4230
4639
 
4231
4640
  stub_elastic
4641
+ stub_elastic_info
4232
4642
  driver.run(default_tag: 'test') do
4233
4643
  driver.feed(original_hash)
4234
4644
  end
@@ -4242,6 +4652,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4242
4652
  expected_output = {"foo" => {"bar" => "baz"}}
4243
4653
 
4244
4654
  stub_elastic
4655
+ stub_elastic_info
4245
4656
  driver.run(default_tag: 'test') do
4246
4657
  driver.feed(original_hash)
4247
4658
  end
@@ -4250,6 +4661,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4250
4661
 
4251
4662
  def test_makes_bulk_request
4252
4663
  stub_elastic
4664
+ stub_elastic_info
4253
4665
  driver.run(default_tag: 'test') do
4254
4666
  driver.feed(sample_record)
4255
4667
  driver.feed(sample_record.merge('age' => 27))
@@ -4257,8 +4669,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4257
4669
  assert_equal(4, index_cmds.count)
4258
4670
  end
4259
4671
 
4260
- def test_all_records_are_preserved_in_bulk
4672
+ def test_all_re
4261
4673
  stub_elastic
4674
+ stub_elastic_info
4262
4675
  driver.run(default_tag: 'test') do
4263
4676
  driver.feed(sample_record)
4264
4677
  driver.feed(sample_record.merge('age' => 27))
@@ -4274,6 +4687,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4274
4687
  dt = DateTime.new(2015, 6, 1, 0, 0, 1, "+01:00")
4275
4688
  logstash_index = "logstash-2015.05.31"
4276
4689
  stub_elastic
4690
+ stub_elastic_info
4277
4691
  driver.run(default_tag: 'test') do
4278
4692
  driver.feed(dt.to_time.to_i, sample_record)
4279
4693
  end
@@ -4288,6 +4702,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4288
4702
  time = Date.today.to_time
4289
4703
  index = "logstash-#{time.strftime("%Y.%m.%d")}"
4290
4704
  stub_elastic
4705
+ stub_elastic_info
4291
4706
  driver.run(default_tag: 'test') do
4292
4707
  driver.feed(time.to_i, sample_record)
4293
4708
  end
@@ -4300,6 +4715,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4300
4715
  time = Time.parse Date.today.iso8601
4301
4716
  logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m.%d")}"
4302
4717
  stub_elastic
4718
+ stub_elastic_info
4303
4719
  driver.run(default_tag: 'test') do
4304
4720
  driver.feed(time.to_i, sample_record)
4305
4721
  end
@@ -4314,6 +4730,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4314
4730
  time = Time.parse Date.today.iso8601
4315
4731
  logstash_index = "myprefix#{separator}#{time.getutc.strftime("%Y.%m.%d")}"
4316
4732
  stub_elastic
4733
+ stub_elastic_info
4317
4734
  driver.run(default_tag: 'test') do
4318
4735
  driver.feed(time.to_i, sample_record)
4319
4736
  end
@@ -4327,6 +4744,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4327
4744
  time = Time.parse Date.today.iso8601
4328
4745
  logstash_index = "myprefix-test-#{time.getutc.strftime("%Y.%m.%d")}"
4329
4746
  stub_elastic
4747
+ stub_elastic_info
4330
4748
  driver.run(default_tag: 'test') do
4331
4749
  driver.feed(time.to_i, sample_record)
4332
4750
  end
@@ -4349,6 +4767,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4349
4767
  time = Time.parse Date.today.iso8601
4350
4768
  logstash_index = "myprefix-#{time.getutc.strftime("%H")}-#{time.getutc.strftime("%Y.%m.%d")}"
4351
4769
  stub_elastic
4770
+ stub_elastic_info
4352
4771
  driver.run(default_tag: 'test') do
4353
4772
  driver.feed(time.to_i, sample_record)
4354
4773
  end
@@ -4369,6 +4788,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4369
4788
  pipeline_id = "mypipeline"
4370
4789
  logstash_index = "myprefix-#{pipeline_id}-#{time.getutc.strftime("%Y.%m.%d")}"
4371
4790
  stub_elastic
4791
+ stub_elastic_info
4372
4792
  driver.run(default_tag: 'test') do
4373
4793
  driver.feed(time.to_i, sample_record.merge({"pipeline_id" => pipeline_id}))
4374
4794
  end
@@ -4394,6 +4814,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4394
4814
  time = Time.parse Date.today.iso8601
4395
4815
  logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m.%d")}"
4396
4816
  stub_elastic
4817
+ stub_elastic_info
4397
4818
  driver.run(default_tag: 'test') do
4398
4819
  driver.feed(time.to_i, sample_record.merge('indexformat' => '%Y.%m.%d'))
4399
4820
  end
@@ -4417,6 +4838,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4417
4838
  time = Time.parse Date.today.iso8601
4418
4839
  logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m")}"
4419
4840
  stub_elastic
4841
+ stub_elastic_info
4420
4842
  driver.run(default_tag: 'test') do
4421
4843
  driver.feed(time.to_i, sample_record.merge('indexformat' => '%Y.%m'))
4422
4844
  end
@@ -4429,6 +4851,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4429
4851
  driver.configure("host ${tag}\n")
4430
4852
  time = Time.parse Date.today.iso8601
4431
4853
  elastic_request = stub_elastic("http://extracted-host:9200/_bulk")
4854
+ stub_elastic_info("http://extracted-host:9200/")
4432
4855
  driver.run(default_tag: 'extracted-host') do
4433
4856
  driver.feed(time.to_i, sample_record)
4434
4857
  end
@@ -4445,6 +4868,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4445
4868
  host, port = host_info
4446
4869
  host = "extracted-host" if host == '${tag}'
4447
4870
  stub_elastic_with_store_index_command_counts("http://#{host}:#{port}/_bulk")
4871
+ stub_elastic_info("http://#{host}:#{port}")
4448
4872
  end
4449
4873
 
4450
4874
  driver.run(default_tag: 'extracted-host') do
@@ -4479,8 +4903,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4479
4903
  ]
4480
4904
  ))
4481
4905
  stub_elastic
4906
+ stub_elastic_info
4482
4907
  time = Time.parse Date.today.iso8601
4483
4908
  elastic_request = stub_elastic("http://host-#{time.utc.strftime('%Y%m%d')}:9200/_bulk")
4909
+ stub_elastic_info("http://host-#{time.utc.strftime('%Y%m%d')}:9200/")
4484
4910
  driver.run(default_tag: 'test') do
4485
4911
  driver.feed(time.to_i, sample_record)
4486
4912
  end
@@ -4501,6 +4927,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4501
4927
  second_pipeline_id = "2"
4502
4928
  first_request = stub_elastic("http://myhost-1:9200/_bulk")
4503
4929
  second_request = stub_elastic("http://myhost-2:9200/_bulk")
4930
+ stub_elastic_info("http://myhost-1:9200/")
4931
+ stub_elastic_info("http://myhost-2:9200/")
4504
4932
  driver.run(default_tag: 'test') do
4505
4933
  driver.feed(time.to_i, sample_record.merge({"pipeline_id" => first_pipeline_id}))
4506
4934
  driver.feed(time.to_i, sample_record.merge({"pipeline_id" => second_pipeline_id}))
@@ -4521,6 +4949,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4521
4949
  time = Time.parse Date.today.iso8601
4522
4950
  pipeline_id = "1"
4523
4951
  request = stub_elastic_unavailable("http://myhost-1:9200/_bulk")
4952
+ stub_elastic_info("http://myhost-1:9200/")
4524
4953
  exception = assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
4525
4954
  driver.run(default_tag: 'test') do
4526
4955
  driver.feed(time.to_i, sample_record.merge({"pipeline_id" => pipeline_id}))
@@ -4536,6 +4965,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4536
4965
  time = Time.parse Date.today.iso8601
4537
4966
  logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m.%d")}"
4538
4967
  stub_elastic
4968
+ stub_elastic_info
4539
4969
  driver.run(default_tag: 'test') do
4540
4970
  driver.feed(time.to_i, sample_record)
4541
4971
  end
@@ -4550,6 +4980,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4550
4980
  time = Time.parse Date.today.iso8601
4551
4981
  logstash_index = "logstash-#{time.getutc.strftime("%Y.%m")}"
4552
4982
  stub_elastic
4983
+ stub_elastic_info
4553
4984
  driver.run(default_tag: 'test') do
4554
4985
  driver.feed(time.to_i, sample_record)
4555
4986
  end
@@ -4563,6 +4994,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4563
4994
  time = Time.parse Date.today.iso8601
4564
4995
  logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m")}"
4565
4996
  stub_elastic
4997
+ stub_elastic_info
4566
4998
  driver.run(default_tag: 'test') do
4567
4999
  driver.feed(time.to_i, sample_record)
4568
5000
  end
@@ -4589,6 +5021,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4589
5021
 
4590
5022
  def test_doesnt_add_logstash_timestamp_by_default
4591
5023
  stub_elastic
5024
+ stub_elastic_info
4592
5025
  driver.run(default_tag: 'test') do
4593
5026
  driver.feed(sample_record)
4594
5027
  end
@@ -4598,6 +5031,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4598
5031
  def test_adds_timestamp_when_logstash
4599
5032
  driver.configure("logstash_format true\n")
4600
5033
  stub_elastic
5034
+ stub_elastic_info
4601
5035
  ts = DateTime.now
4602
5036
  time = Fluent::EventTime.from_time(ts.to_time)
4603
5037
  driver.run(default_tag: 'test') do
@@ -4610,6 +5044,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4610
5044
  def test_adds_timestamp_when_include_timestamp
4611
5045
  driver.configure("include_timestamp true\n")
4612
5046
  stub_elastic
5047
+ stub_elastic_info
4613
5048
  ts = DateTime.now
4614
5049
  time = Fluent::EventTime.from_time(ts.to_time)
4615
5050
  driver.run(default_tag: 'test') do
@@ -4622,6 +5057,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4622
5057
  def test_uses_custom_timestamp_when_included_in_record
4623
5058
  driver.configure("logstash_format true\n")
4624
5059
  stub_elastic
5060
+ stub_elastic_info
4625
5061
  ts = DateTime.new(2001,2,3).iso8601
4626
5062
  driver.run(default_tag: 'test') do
4627
5063
  driver.feed(sample_record.merge!('@timestamp' => ts))
@@ -4633,6 +5069,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4633
5069
  def test_uses_custom_timestamp_when_included_in_record_without_logstash
4634
5070
  driver.configure("include_timestamp true\n")
4635
5071
  stub_elastic
5072
+ stub_elastic_info
4636
5073
  ts = DateTime.new(2001,2,3).iso8601
4637
5074
  driver.run(default_tag: 'test') do
4638
5075
  driver.feed(sample_record.merge!('@timestamp' => ts))
@@ -4645,6 +5082,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4645
5082
  driver.configure("logstash_format true
4646
5083
  time_key vtm\n")
4647
5084
  stub_elastic
5085
+ stub_elastic_info
4648
5086
  ts = DateTime.new(2001,2,3).iso8601(9)
4649
5087
  driver.run(default_tag: 'test') do
4650
5088
  driver.feed(sample_record.merge!('vtm' => ts))
@@ -4658,6 +5096,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4658
5096
  time_precision 3
4659
5097
  time_key vtm\n")
4660
5098
  stub_elastic
5099
+ stub_elastic_info
4661
5100
  time = Time.now
4662
5101
  float_time = time.to_f
4663
5102
  driver.run(default_tag: 'test') do
@@ -4672,6 +5111,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4672
5111
  time_key_format %Y-%m-%d %H:%M:%S.%N%z
4673
5112
  time_key vtm\n")
4674
5113
  stub_elastic
5114
+ stub_elastic_info
4675
5115
  ts = "2001-02-03 13:14:01.673+02:00"
4676
5116
  driver.run(default_tag: 'test') do
4677
5117
  driver.feed(sample_record.merge!('vtm' => ts))
@@ -4686,6 +5126,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4686
5126
  time_key_format %Y-%m-%d %H:%M:%S.%N%z
4687
5127
  time_key vtm\n")
4688
5128
  stub_elastic
5129
+ stub_elastic_info
4689
5130
  ts = "2001-02-03 13:14:01.673+02:00"
4690
5131
  time = Time.parse(ts)
4691
5132
  current_zone_offset = Time.new(2001, 02, 03).to_datetime.offset
@@ -4703,6 +5144,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4703
5144
  time_key_format %Y-%m-%d %H:%M:%S.%N%z
4704
5145
  time_key vtm\n")
4705
5146
  stub_elastic
5147
+ stub_elastic_info
4706
5148
  ts = "2001-02-03 13:14:01.673+02:00"
4707
5149
  driver.run(default_tag: 'test') do
4708
5150
  driver.feed(sample_record.merge!('vtm' => ts))
@@ -4717,6 +5159,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4717
5159
  time_key vtm
4718
5160
  time_key_exclude_timestamp true\n")
4719
5161
  stub_elastic
5162
+ stub_elastic_info
4720
5163
  ts = DateTime.new(2001,2,3).iso8601
4721
5164
  driver.run(default_tag: 'test') do
4722
5165
  driver.feed(sample_record.merge!('vtm' => ts))
@@ -4728,6 +5171,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4728
5171
  driver.configure("logstash_format true
4729
5172
  time_key_format %Y-%m-%dT%H:%M:%S.%N%z\n")
4730
5173
  stub_elastic
5174
+ stub_elastic_info
4731
5175
  ts = "2001-02-03T13:14:01.673+02:00"
4732
5176
  driver.run(default_tag: 'test') do
4733
5177
  driver.feed(sample_record.merge!('@timestamp' => ts))
@@ -4742,6 +5186,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4742
5186
  index_name test
4743
5187
  time_key_format %Y-%m-%dT%H:%M:%S.%N%z\n")
4744
5188
  stub_elastic
5189
+ stub_elastic_info
4745
5190
  ts = "2001-02-03T13:14:01.673+02:00"
4746
5191
  driver.run(default_tag: 'test') do
4747
5192
  driver.feed(sample_record.merge!('@timestamp' => ts))
@@ -4759,6 +5204,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4759
5204
  driver.configure("logstash_format true
4760
5205
  time_key_format %Y-%m-%dT%H:%M:%S.%N%z\n#{tag_config}\n")
4761
5206
  stub_elastic
5207
+ stub_elastic_info
4762
5208
 
4763
5209
  ts = "2001/02/03 13:14:01,673+02:00"
4764
5210
  index = "logstash-#{Time.now.getutc.strftime("%Y.%m.%d")}"
@@ -4779,6 +5225,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4779
5225
  driver.configure("logstash_format true
4780
5226
  time_key_format %a %b %d %H:%M:%S %Z %Y\n")
4781
5227
  stub_elastic
5228
+ stub_elastic_info
4782
5229
  ts = "Thu Nov 29 14:33:20 GMT 2001"
4783
5230
  driver.run(default_tag: 'test') do
4784
5231
  driver.feed(sample_record.merge!('@timestamp' => ts))
@@ -4791,6 +5238,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4791
5238
  def test_uses_nanosecond_precision_by_default
4792
5239
  driver.configure("logstash_format true\n")
4793
5240
  stub_elastic
5241
+ stub_elastic_info
4794
5242
  time = Fluent::EventTime.new(Time.now.to_i, 123456789)
4795
5243
  driver.run(default_tag: 'test') do
4796
5244
  driver.feed(time, sample_record)
@@ -4803,6 +5251,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4803
5251
  driver.configure("logstash_format true
4804
5252
  time_precision 3\n")
4805
5253
  stub_elastic
5254
+ stub_elastic_info
4806
5255
  time = Fluent::EventTime.new(Time.now.to_i, 123456789)
4807
5256
  driver.run(default_tag: 'test') do
4808
5257
  driver.feed(time, sample_record)
@@ -4813,6 +5262,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4813
5262
 
4814
5263
  def test_doesnt_add_tag_key_by_default
4815
5264
  stub_elastic
5265
+ stub_elastic_info
4816
5266
  driver.run(default_tag: 'test') do
4817
5267
  driver.feed(sample_record)
4818
5268
  end
@@ -4822,6 +5272,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4822
5272
  def test_adds_tag_key_when_configured
4823
5273
  driver.configure("include_tag_key true\n")
4824
5274
  stub_elastic
5275
+ stub_elastic_info
4825
5276
  driver.run(default_tag: 'mytag') do
4826
5277
  driver.feed(sample_record)
4827
5278
  end
@@ -4832,6 +5283,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4832
5283
  def test_adds_id_key_when_configured
4833
5284
  driver.configure("id_key request_id\n")
4834
5285
  stub_elastic
5286
+ stub_elastic_info
4835
5287
  driver.run(default_tag: 'test') do
4836
5288
  driver.feed(sample_record)
4837
5289
  end
@@ -4842,6 +5294,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4842
5294
  def test_adds_nested_id_key_with_dot
4843
5295
  driver.configure("id_key nested.request_id\n")
4844
5296
  stub_elastic
5297
+ stub_elastic_info
4845
5298
  driver.run(default_tag: 'test') do
4846
5299
  driver.feed(nested_sample_record)
4847
5300
  end
@@ -4851,6 +5304,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4851
5304
  def test_adds_nested_id_key_with_dollar_dot
4852
5305
  driver.configure("id_key $.nested.request_id\n")
4853
5306
  stub_elastic
5307
+ stub_elastic_info
4854
5308
  driver.run(default_tag: 'test') do
4855
5309
  driver.feed(nested_sample_record)
4856
5310
  end
@@ -4860,6 +5314,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4860
5314
  def test_adds_nested_id_key_with_bracket
4861
5315
  driver.configure("id_key $['nested']['request_id']\n")
4862
5316
  stub_elastic
5317
+ stub_elastic_info
4863
5318
  driver.run(default_tag: 'test') do
4864
5319
  driver.feed(nested_sample_record)
4865
5320
  end
@@ -4870,6 +5325,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4870
5325
  def test_doesnt_add_id_key_if_missing_when_configured
4871
5326
  driver.configure("id_key another_request_id\n")
4872
5327
  stub_elastic
5328
+ stub_elastic_info
4873
5329
  driver.run(default_tag: 'test') do
4874
5330
  driver.feed(sample_record)
4875
5331
  end
@@ -4878,6 +5334,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4878
5334
 
4879
5335
  def test_adds_id_key_when_not_configured
4880
5336
  stub_elastic
5337
+ stub_elastic_info
4881
5338
  driver.run(default_tag: 'test') do
4882
5339
  driver.feed(sample_record)
4883
5340
  end
@@ -4887,6 +5344,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4887
5344
  def test_adds_parent_key_when_configured
4888
5345
  driver.configure("parent_key parent_id\n")
4889
5346
  stub_elastic
5347
+ stub_elastic_info
4890
5348
  driver.run(default_tag: 'test') do
4891
5349
  driver.feed(sample_record)
4892
5350
  end
@@ -4897,6 +5355,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4897
5355
  def test_adds_nested_parent_key_with_dot
4898
5356
  driver.configure("parent_key nested.parent_id\n")
4899
5357
  stub_elastic
5358
+ stub_elastic_info
4900
5359
  driver.run(default_tag: 'test') do
4901
5360
  driver.feed(nested_sample_record)
4902
5361
  end
@@ -4906,6 +5365,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4906
5365
  def test_adds_nested_parent_key_with_dollar_dot
4907
5366
  driver.configure("parent_key $.nested.parent_id\n")
4908
5367
  stub_elastic
5368
+ stub_elastic_info
4909
5369
  driver.run(default_tag: 'test') do
4910
5370
  driver.feed(nested_sample_record)
4911
5371
  end
@@ -4915,6 +5375,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4915
5375
  def test_adds_nested_parent_key_with_bracket
4916
5376
  driver.configure("parent_key $['nested']['parent_id']\n")
4917
5377
  stub_elastic
5378
+ stub_elastic_info
4918
5379
  driver.run(default_tag: 'test') do
4919
5380
  driver.feed(nested_sample_record)
4920
5381
  end
@@ -4925,6 +5386,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4925
5386
  def test_doesnt_add_parent_key_if_missing_when_configured
4926
5387
  driver.configure("parent_key another_parent_id\n")
4927
5388
  stub_elastic
5389
+ stub_elastic_info
4928
5390
  driver.run(default_tag: 'test') do
4929
5391
  driver.feed(sample_record)
4930
5392
  end
@@ -4933,6 +5395,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4933
5395
 
4934
5396
  def test_adds_parent_key_when_not_configured
4935
5397
  stub_elastic
5398
+ stub_elastic_info
4936
5399
  driver.run(default_tag: 'test') do
4937
5400
  driver.feed(sample_record)
4938
5401
  end
@@ -4943,6 +5406,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4943
5406
  def test_es6
4944
5407
  driver("routing_key routing_id\n", 6)
4945
5408
  stub_elastic
5409
+ stub_elastic_info
4946
5410
  driver.run(default_tag: 'test') do
4947
5411
  driver.feed(sample_record)
4948
5412
  end
@@ -4952,6 +5416,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4952
5416
  def test_es7
4953
5417
  driver("routing_key routing_id\n", 7)
4954
5418
  stub_elastic
5419
+ stub_elastic_info
4955
5420
  driver.run(default_tag: 'test') do
4956
5421
  driver.feed(sample_record)
4957
5422
  end
@@ -4963,6 +5428,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4963
5428
  def test_adds_nested_routing_key_with_dot
4964
5429
  driver.configure("routing_key nested.routing_id\n")
4965
5430
  stub_elastic
5431
+ stub_elastic_info
4966
5432
  driver.run(default_tag: 'test') do
4967
5433
  driver.feed(nested_sample_record)
4968
5434
  end
@@ -4972,6 +5438,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4972
5438
  def test_adds_nested_routing_key_with_dollar_dot
4973
5439
  driver.configure("routing_key $.nested.routing_id\n")
4974
5440
  stub_elastic
5441
+ stub_elastic_info
4975
5442
  driver.run(default_tag: 'test') do
4976
5443
  driver.feed(nested_sample_record)
4977
5444
  end
@@ -4981,6 +5448,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4981
5448
  def test_adds_nested_routing_key_with_bracket
4982
5449
  driver.configure("routing_key $['nested']['routing_id']\n")
4983
5450
  stub_elastic
5451
+ stub_elastic_info
4984
5452
  driver.run(default_tag: 'test') do
4985
5453
  driver.feed(nested_sample_record)
4986
5454
  end
@@ -4991,6 +5459,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4991
5459
  def test_doesnt_add_routing_key_if_missing_when_configured
4992
5460
  driver.configure("routing_key another_routing_id\n")
4993
5461
  stub_elastic
5462
+ stub_elastic_info
4994
5463
  driver.run(default_tag: 'test') do
4995
5464
  driver.feed(sample_record)
4996
5465
  end
@@ -4999,6 +5468,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4999
5468
 
5000
5469
  def test_adds_routing_key_when_not_configured
5001
5470
  stub_elastic
5471
+ stub_elastic_info
5002
5472
  driver.run(default_tag: 'test') do
5003
5473
  driver.feed(sample_record)
5004
5474
  end
@@ -5008,6 +5478,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5008
5478
  def test_remove_one_key
5009
5479
  driver.configure("remove_keys key1\n")
5010
5480
  stub_elastic
5481
+ stub_elastic_info
5011
5482
  driver.run(default_tag: 'test') do
5012
5483
  driver.feed(sample_record.merge('key1' => 'v1', 'key2' => 'v2'))
5013
5484
  end
@@ -5018,6 +5489,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5018
5489
  def test_remove_multi_keys
5019
5490
  driver.configure("remove_keys key1, key2\n")
5020
5491
  stub_elastic
5492
+ stub_elastic_info
5021
5493
  driver.run(default_tag: 'test') do
5022
5494
  driver.feed(sample_record.merge('key1' => 'v1', 'key2' => 'v2'))
5023
5495
  end
@@ -5026,6 +5498,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5026
5498
  end
5027
5499
 
5028
5500
  def test_request_error
5501
+ stub_elastic_info
5029
5502
  stub_elastic_unavailable
5030
5503
  assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
5031
5504
  driver.run(default_tag: 'test', shutdown: false) do
@@ -5037,6 +5510,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5037
5510
  def test_request_forever
5038
5511
  omit("retry_forever test is unstable.") if ENV["CI"]
5039
5512
  stub_elastic
5513
+ stub_elastic_info
5040
5514
  driver.configure(Fluent::Config::Element.new(
5041
5515
  'ROOT', '', {
5042
5516
  '@type' => 'elasticsearch',
@@ -5061,6 +5535,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5061
5535
  connection_resets += 1
5062
5536
  raise Faraday::ConnectionFailed, "Test message"
5063
5537
  end
5538
+ stub_elastic_info
5064
5539
 
5065
5540
  assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
5066
5541
  driver.run(default_tag: 'test', shutdown: false) do
@@ -5077,6 +5552,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5077
5552
  connection_resets += 1
5078
5553
  raise ZeroDivisionError, "any not host_unreachable_exceptions exception"
5079
5554
  end
5555
+ stub_elastic_info
5080
5556
 
5081
5557
  driver.configure("reconnect_on_error true\n")
5082
5558
 
@@ -5103,6 +5579,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5103
5579
  connection_resets += 1
5104
5580
  raise ZeroDivisionError, "any not host_unreachable_exceptions exception"
5105
5581
  end
5582
+ stub_elastic_info
5106
5583
 
5107
5584
  driver.configure("reconnect_on_error false\n")
5108
5585
 
@@ -5146,6 +5623,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5146
5623
  })
5147
5624
  }
5148
5625
  end)
5626
+ stub_elastic_info
5149
5627
 
5150
5628
  driver.run(default_tag: 'test') do
5151
5629
  driver.feed(1, sample_record)
@@ -5217,6 +5695,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5217
5695
  })
5218
5696
  }
5219
5697
  end)
5698
+ stub_elastic_info
5220
5699
 
5221
5700
  # Check buffer fulfillment condition
5222
5701
  assert_raise(Fluent::Plugin::ElasticsearchOutput::RetryStreamEmitFailure) do
@@ -5263,6 +5742,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5263
5742
  })
5264
5743
  }
5265
5744
  end)
5745
+ stub_elastic_info
5746
+
5266
5747
  sample_record1 = sample_record('my_id' => 'abc')
5267
5748
  sample_record4 = sample_record('my_id' => 'xyz')
5268
5749
 
@@ -5312,6 +5793,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5312
5793
  })
5313
5794
  }
5314
5795
  end)
5796
+ stub_elastic_info
5797
+
5315
5798
  sample_record1 = sample_record('my_id' => 'abc')
5316
5799
  sample_record4 = sample_record('my_id' => 'xyz')
5317
5800
 
@@ -5382,6 +5865,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5382
5865
  })
5383
5866
  }
5384
5867
  end)
5868
+ stub_elastic_info
5385
5869
 
5386
5870
  driver.run(default_tag: 'test') do
5387
5871
  driver.feed(1, sample_record)
@@ -5398,6 +5882,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5398
5882
  def test_update_should_not_write_if_theres_no_id
5399
5883
  driver.configure("write_operation update\n")
5400
5884
  stub_elastic
5885
+ stub_elastic_info
5401
5886
  driver.run(default_tag: 'test') do
5402
5887
  driver.feed(sample_record)
5403
5888
  end
@@ -5407,6 +5892,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5407
5892
  def test_upsert_should_not_write_if_theres_no_id
5408
5893
  driver.configure("write_operation upsert\n")
5409
5894
  stub_elastic
5895
+ stub_elastic_info
5410
5896
  driver.run(default_tag: 'test') do
5411
5897
  driver.feed(sample_record)
5412
5898
  end
@@ -5416,6 +5902,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5416
5902
  def test_create_should_not_write_if_theres_no_id
5417
5903
  driver.configure("write_operation create\n")
5418
5904
  stub_elastic
5905
+ stub_elastic_info
5419
5906
  driver.run(default_tag: 'test') do
5420
5907
  driver.feed(sample_record)
5421
5908
  end
@@ -5426,6 +5913,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5426
5913
  driver.configure("write_operation update
5427
5914
  id_key request_id")
5428
5915
  stub_elastic
5916
+ stub_elastic_info
5429
5917
  driver.run(default_tag: 'test') do
5430
5918
  driver.feed(sample_record)
5431
5919
  end
@@ -5439,6 +5927,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5439
5927
  id_key request_id
5440
5928
  remove_keys_on_update parent_id")
5441
5929
  stub_elastic
5930
+ stub_elastic_info
5442
5931
  driver.run(default_tag: 'test') do
5443
5932
  driver.feed(sample_record)
5444
5933
  end
@@ -5450,6 +5939,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5450
5939
  driver.configure("write_operation upsert
5451
5940
  id_key request_id")
5452
5941
  stub_elastic
5942
+ stub_elastic_info
5453
5943
  driver.run(default_tag: 'test') do
5454
5944
  driver.feed(sample_record)
5455
5945
  end
@@ -5463,6 +5953,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5463
5953
  id_key request_id
5464
5954
  remove_keys_on_update parent_id")
5465
5955
  stub_elastic
5956
+ stub_elastic_info
5466
5957
  driver.run(default_tag: 'test') do
5467
5958
  driver.feed(sample_record)
5468
5959
  end
@@ -5477,6 +5968,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5477
5968
  id_key request_id
5478
5969
  remove_keys_on_update parent_id")
5479
5970
  stub_elastic
5971
+ stub_elastic_info
5480
5972
  driver.run(default_tag: 'test') do
5481
5973
  driver.feed(sample_record)
5482
5974
  end
@@ -5490,6 +5982,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5490
5982
  id_key id
5491
5983
  remove_keys_on_update foo,baz")
5492
5984
  stub_elastic
5985
+ stub_elastic_info
5493
5986
  driver.run(default_tag: 'test') do
5494
5987
  driver.feed("id" => 1, "foo" => "bar", "baz" => "quix", "zip" => "zam")
5495
5988
  end
@@ -5514,6 +6007,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5514
6007
  id_key id
5515
6008
  remove_keys_on_update_key keys_to_skip")
5516
6009
  stub_elastic
6010
+ stub_elastic_info
5517
6011
  driver.run(default_tag: 'test') do
5518
6012
  driver.feed("id" => 1, "foo" => "bar", "baz" => "quix", "keys_to_skip" => ["baz"])
5519
6013
  end
@@ -5538,6 +6032,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5538
6032
  remove_keys_on_update foo,bar
5539
6033
  remove_keys_on_update_key keys_to_skip")
5540
6034
  stub_elastic
6035
+ stub_elastic_info
5541
6036
  driver.run(default_tag: 'test') do
5542
6037
  driver.feed("id" => 1, "foo" => "bar", "baz" => "quix", "keys_to_skip" => ["baz"])
5543
6038
  end
@@ -5562,6 +6057,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5562
6057
  driver.configure("write_operation create
5563
6058
  id_key request_id")
5564
6059
  stub_elastic
6060
+ stub_elastic_info
5565
6061
  driver.run(default_tag: 'test') do
5566
6062
  driver.feed(sample_record)
5567
6063
  end
@@ -5570,6 +6066,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5570
6066
 
5571
6067
  def test_include_index_in_url
5572
6068
  stub_elastic('http://localhost:9200/logstash-2018.01.01/_bulk')
6069
+ stub_elastic_info('http://localhost:9200/')
5573
6070
 
5574
6071
  driver.configure("index_name logstash-2018.01.01
5575
6072
  include_index_in_url true")
@@ -5583,8 +6080,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5583
6080
 
5584
6081
  def test_use_simple_sniffer
5585
6082
  require 'fluent/plugin/elasticsearch_simple_sniffer'
5586
- stub_elastic_info
5587
6083
  stub_elastic
6084
+ stub_elastic_info
5588
6085
  config = %[
5589
6086
  sniffer_class_name Fluent::Plugin::ElasticsearchSimpleSniffer
5590
6087
  log_level debug
@@ -5608,6 +6105,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5608
6105
  remove_keys id
5609
6106
  suppress_doc_wrap true')
5610
6107
  stub_elastic
6108
+ stub_elastic_info
5611
6109
  doc_body = {'field' => 'value'}
5612
6110
  script_body = {'source' => 'ctx._source.counter += params.param1',
5613
6111
  'lang' => 'painless',
@@ -5634,6 +6132,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5634
6132
  remove_keys id
5635
6133
  suppress_doc_wrap true')
5636
6134
  stub_elastic
6135
+ stub_elastic_info
5637
6136
  doc_body = {'field' => 'value'}
5638
6137
  script_body = {'source' => 'ctx._source.counter += params.param1',
5639
6138
  'lang' => 'painless',
@@ -5660,6 +6159,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5660
6159
  def test_ignore_exception
5661
6160
  driver.configure('ignore_exceptions ["Elasticsearch::Transport::Transport::Errors::ServiceUnavailable"]')
5662
6161
  stub_elastic_unavailable
6162
+ stub_elastic_info
5663
6163
 
5664
6164
  driver.run(default_tag: 'test') do
5665
6165
  driver.feed(sample_record)
@@ -5669,6 +6169,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5669
6169
  def test_ignore_exception_with_superclass
5670
6170
  driver.configure('ignore_exceptions ["Elasticsearch::Transport::Transport::ServerError"]')
5671
6171
  stub_elastic_unavailable
6172
+ stub_elastic_info
5672
6173
 
5673
6174
  driver.run(default_tag: 'test') do
5674
6175
  driver.feed(sample_record)
@@ -5678,6 +6179,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5678
6179
  def test_ignore_excetion_handles_appropriate_ones
5679
6180
  driver.configure('ignore_exceptions ["Faraday::ConnectionFailed"]')
5680
6181
  stub_elastic_unavailable
6182
+ stub_elastic_info
5681
6183
 
5682
6184
  assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
5683
6185
  driver.run(default_tag: 'test', shutdown: false) do