fluent-plugin-elasticsearch 5.0.0 → 5.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +6 -0
  3. data/.github/workflows/linux.yml +5 -2
  4. data/.github/workflows/macos.yml +5 -2
  5. data/.github/workflows/windows.yml +5 -2
  6. data/Gemfile +1 -1
  7. data/History.md +65 -1
  8. data/README.Troubleshooting.md +91 -0
  9. data/README.md +129 -4
  10. data/fluent-plugin-elasticsearch.gemspec +2 -1
  11. data/lib/fluent/plugin/elasticsearch_compat.rb +30 -0
  12. data/lib/fluent/plugin/elasticsearch_error_handler.rb +19 -4
  13. data/lib/fluent/plugin/elasticsearch_fallback_selector.rb +2 -2
  14. data/lib/fluent/plugin/elasticsearch_index_lifecycle_management.rb +18 -4
  15. data/lib/fluent/plugin/elasticsearch_index_template.rb +20 -4
  16. data/lib/fluent/plugin/elasticsearch_simple_sniffer.rb +2 -1
  17. data/lib/fluent/plugin/filter_elasticsearch_genid.rb +1 -1
  18. data/lib/fluent/plugin/in_elasticsearch.rb +2 -1
  19. data/lib/fluent/plugin/oj_serializer.rb +2 -1
  20. data/lib/fluent/plugin/out_elasticsearch.rb +80 -19
  21. data/lib/fluent/plugin/out_elasticsearch_data_stream.rb +132 -62
  22. data/lib/fluent/plugin/out_elasticsearch_dynamic.rb +3 -1
  23. data/test/plugin/mock_chunk.dat +0 -0
  24. data/test/plugin/test_elasticsearch_error_handler.rb +130 -23
  25. data/test/plugin/test_elasticsearch_fallback_selector.rb +16 -8
  26. data/test/plugin/test_elasticsearch_index_lifecycle_management.rb +55 -15
  27. data/test/plugin/test_filter_elasticsearch_genid.rb +16 -16
  28. data/test/plugin/test_in_elasticsearch.rb +20 -0
  29. data/test/plugin/test_out_elasticsearch.rb +795 -134
  30. data/test/plugin/test_out_elasticsearch_data_stream.rb +717 -117
  31. data/test/plugin/test_out_elasticsearch_dynamic.rb +150 -18
  32. metadata +21 -5
  33. data/.travis.yml +0 -40
  34. data/appveyor.yml +0 -20
@@ -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
@@ -19,7 +19,15 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
19
19
  log.out.logs.slice!(0, log.out.logs.length)
20
20
  end
21
21
 
22
- def driver(conf='', es_version=5, client_version="\"5.0\"")
22
+ def elasticsearch_version
23
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.14.0")
24
+ TRANSPORT_CLASS::VERSION.split(".")[0..1].join(".")
25
+ else
26
+ "7.17".freeze
27
+ end
28
+ end
29
+
30
+ def driver(conf='', es_version=elasticsearch_version.to_i, client_version="\"#{elasticsearch_version}\"")
23
31
  # For request stub to detect compatibility.
24
32
  @es_version ||= es_version
25
33
  @client_version ||= client_version
@@ -45,6 +53,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
45
53
  }.configure(conf)
46
54
  end
47
55
 
56
+ def elasticsearch_transport_layer_decoupling?
57
+ Gem::Version.create(::TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.14.0")
58
+ end
59
+
60
+ def elastic_transport_layer?
61
+ Gem::Version.create(::TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
62
+ end
63
+
48
64
  def default_type_name
49
65
  Fluent::Plugin::ElasticsearchOutput::DEFAULT_TYPE_NAME
50
66
  end
@@ -59,9 +75,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
59
75
  }
60
76
  end
61
77
 
62
- def stub_elastic_info(url="http://localhost:9200/", version="6.4.2")
63
- body ="{\"version\":{\"number\":\"#{version}\"}}"
64
- stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json' } })
78
+ def stub_elastic_info(url="http://localhost:9200/", version=elasticsearch_version)
79
+ body ="{\"version\":{\"number\":\"#{version}\", \"build_flavor\":\"default\"},\"tagline\" : \"You Know, for Search\"}"
80
+ stub_request(:get, url)
81
+ .to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json', 'X-elastic-product' => 'Elasticsearch' } })
65
82
  end
66
83
 
67
84
  def stub_elastic(url="http://localhost:9200/_bulk")
@@ -70,6 +87,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
70
87
  end
71
88
  end
72
89
 
90
+ def stub_elastic_all_requests(url="http://localhost:9200/_bulk")
91
+ @index_cmds_all_requests = Array.new
92
+ stub_request(:post, url).with do |req|
93
+ @index_cmds = req.body.split("\n").map {|r| JSON.parse(r) }
94
+ @index_cmds_all_requests << @index_cmds
95
+ end
96
+ end
97
+
73
98
  def stub_elastic_unavailable(url="http://localhost:9200/_bulk")
74
99
  stub_request(:post, url).to_return(:status => [503, "Service Unavailable"])
75
100
  end
@@ -253,7 +278,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
253
278
  assert_true instance.verify_es_version_at_startup
254
279
  assert_equal Fluent::Plugin::ElasticsearchOutput::DEFAULT_ELASTICSEARCH_VERSION, instance.default_elasticsearch_version
255
280
  assert_false instance.log_es_400_reason
256
- assert_equal 20 * 1024 * 1024, Fluent::Plugin::ElasticsearchOutput::TARGET_BULK_BYTES
281
+ assert_equal -1, Fluent::Plugin::ElasticsearchOutput::DEFAULT_TARGET_BULK_BYTES
257
282
  assert_false instance.compression
258
283
  assert_equal :no_compression, instance.compression_level
259
284
  assert_true instance.http_backend_excon_nonblock
@@ -261,7 +286,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
261
286
  end
262
287
 
263
288
  test 'configure compression' do
264
- omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.2.0")
289
+ omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.2.0")
265
290
 
266
291
  config = %{
267
292
  compression_level best_compression
@@ -272,7 +297,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
272
297
  end
273
298
 
274
299
  test 'check compression strategy' do
275
- omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.2.0")
300
+ omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.2.0")
276
301
 
277
302
  config = %{
278
303
  compression_level best_speed
@@ -283,43 +308,69 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
283
308
  end
284
309
 
285
310
  test 'check content-encoding header with compression' do
286
- omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.2.0")
311
+ omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.2.0")
287
312
 
288
313
  config = %{
289
314
  compression_level best_compression
290
315
  }
291
316
  instance = driver(config).instance
292
317
 
293
- assert_equal nil, instance.client.transport.options[:transport_options][:headers]["Content-Encoding"]
318
+ if elastic_transport_layer?
319
+ assert_equal nil, instance.client.transport.options[:transport_options][:headers]["Content-Encoding"]
320
+ elsif elasticsearch_transport_layer_decoupling?
321
+ assert_equal nil, instance.client.transport.transport.options[:transport_options][:headers]["Content-Encoding"]
322
+ else
323
+ assert_equal nil, instance.client.transport.options[:transport_options][:headers]["Content-Encoding"]
324
+ end
294
325
 
295
326
  stub_request(:post, "http://localhost:9200/_bulk").
296
327
  to_return(status: 200, body: "", headers: {})
328
+ stub_elastic_info
297
329
  driver.run(default_tag: 'test') do
298
330
  driver.feed(sample_record)
299
331
  end
300
332
  compressable = instance.compressable_connection
301
333
 
302
- assert_equal "gzip", instance.client(nil, compressable).transport.options[:transport_options][:headers]["Content-Encoding"]
334
+ if elastic_transport_layer?
335
+ assert_equal "gzip", instance.client(nil, compressable).transport.options[:transport_options][:headers]["Content-Encoding"]
336
+ elsif elasticsearch_transport_layer_decoupling?
337
+ assert_equal "gzip", instance.client(nil, compressable).transport.transport.options[:transport_options][:headers]["Content-Encoding"]
338
+ else
339
+ assert_equal "gzip", instance.client(nil, compressable).transport.options[:transport_options][:headers]["Content-Encoding"]
340
+ end
303
341
  end
304
342
 
305
343
  test 'check compression option is passed to transport' do
306
- omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.2.0")
344
+ omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.2.0")
307
345
 
308
346
  config = %{
309
347
  compression_level best_compression
310
348
  }
311
349
  instance = driver(config).instance
312
350
 
313
- assert_equal false, instance.client.transport.options[:compression]
351
+ if elastic_transport_layer?
352
+ assert_equal false, instance.client.transport.options[:compression]
353
+ elsif elasticsearch_transport_layer_decoupling?
354
+ assert_equal false, instance.client.transport.transport.options[:compression]
355
+ else
356
+ assert_equal false, instance.client.transport.options[:compression]
357
+ end
314
358
 
315
359
  stub_request(:post, "http://localhost:9200/_bulk").
316
360
  to_return(status: 200, body: "", headers: {})
361
+ stub_elastic_info
317
362
  driver.run(default_tag: 'test') do
318
363
  driver.feed(sample_record)
319
364
  end
320
365
  compressable = instance.compressable_connection
321
366
 
322
- assert_equal true, instance.client(nil, compressable).transport.options[:compression]
367
+ if elastic_transport_layer?
368
+ assert_equal true, instance.client(nil, compressable).transport.options[:compression]
369
+ elsif elasticsearch_transport_layer_decoupling?
370
+ assert_equal true, instance.client(nil, compressable).transport.transport.options[:compression]
371
+ else
372
+ assert_equal true, instance.client(nil, compressable).transport.options[:compression]
373
+ end
323
374
  end
324
375
 
325
376
  test 'check configure cloud_id based client' do
@@ -406,12 +457,12 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
406
457
  end
407
458
 
408
459
  def stub_elastic_info_bad(url="http://localhost:9200/", version="6.4.2")
409
- body ="{\"version\":{\"number\":\"#{version}\"}}"
460
+ body ="{\"version\":{\"number\":\"#{version}\",\"build_flavor\":\"default\"},\"tagline\":\"You Know, for Search\"}"
410
461
  stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'text/plain' } })
411
462
  end
412
463
 
413
464
  test 'handle invalid client.info' do
414
- stub_elastic_info_bad("https://logs.fluentd.com:24225/es//", "7.7.1")
465
+ stub_elastic_info_bad("https://logs.fluentd.com:24225/es//", elasticsearch_version)
415
466
  config = %{
416
467
  host logs.fluentd.com
417
468
  port 24225
@@ -423,9 +474,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
423
474
  scheme https
424
475
  @log_level info
425
476
  }
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/)
477
+ if elastic_transport_layer?
478
+ assert_raise(NoMethodError) do
479
+ d = create_driver(config, 8, "\"8.0.0\"")
480
+ end
481
+ elsif elasticsearch_transport_layer_decoupling?
482
+ assert_raise(NoMethodError) do
483
+ d = create_driver(config, 7, "\"7.10.1\"")
484
+ end
485
+ else
486
+ d = create_driver(config, 7, "\"7.10.1\"")
487
+ logs = d.logs
488
+ assert_logs_include(logs, /can not dig version information. Assuming Elasticsearch 7/)
489
+ end
429
490
  end
430
491
  end
431
492
 
@@ -445,21 +506,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
445
506
 
446
507
  sub_test_case 'ILM default config' do
447
508
  setup do
448
- begin
449
- require "elasticsearch/xpack"
450
- rescue LoadError
451
- omit "ILM testcase needs elasticsearch-xpack gem."
509
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) < Gem::Version.new("8.0.0")
510
+ begin
511
+ require "elasticsearch/xpack"
512
+ rescue LoadError
513
+ omit "ILM testcase needs elasticsearch-xpack gem."
514
+ end
515
+ end
516
+ end
517
+
518
+ def ilm_endpoint
519
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
520
+ '_enrich'.freeze
521
+ else
522
+ '_ilm'.freeze
452
523
  end
453
524
  end
454
525
 
455
526
  data("legacy_template" => [true, "_template"],
456
527
  "new_template" => [false, "_index_template"])
457
528
  test 'valid configuration of index lifecycle management' do |data|
458
- if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.4.0")
529
+ if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.4.0")
459
530
  omit "elastisearch-ruby v7.4.0 or later is needed for ILM."
460
531
  end
461
532
  use_legacy_template_flag, endpoint = data
462
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
533
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
463
534
  omit "elastisearch-ruby v7.8.0 or later is needed."
464
535
  end
465
536
  cwd = File.dirname(__FILE__)
@@ -483,11 +554,12 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
483
554
  stub_request(:get, "http://localhost:9200/_xpack").
484
555
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}',
485
556
  :headers => {"Content-Type"=> "application/json"})
486
- stub_request(:get, "http://localhost:9200/_ilm/policy/logstash-policy").
557
+ stub_request(:get, "http://localhost:9200/#{ilm_endpoint}/policy/logstash-policy").
487
558
  to_return(status: 404, body: "", headers: {})
488
- stub_request(:put, "http://localhost:9200/_ilm/policy/logstash-policy").
559
+ stub_request(:put, "http://localhost:9200/#{ilm_endpoint}/policy/logstash-policy").
489
560
  with(body: "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
490
561
  to_return(status: 200, body: "", headers: {})
562
+ stub_elastic_info
491
563
 
492
564
  assert_nothing_raised {
493
565
  driver(config)
@@ -497,11 +569,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
497
569
  data("legacy_template" => [true, "_template"],
498
570
  "new_template" => [false, "_index_template"])
499
571
  test 'valid configuration of overwriting ilm_policy' do |data|
500
- if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.4.0")
572
+ if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.4.0")
501
573
  omit "elastisearch-ruby v7.4.0 or later is needed for ILM."
502
574
  end
503
575
  use_legacy_template_flag, endpoint = data
504
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
576
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
505
577
  omit "elastisearch-ruby v7.8.0 or later is needed."
506
578
  end
507
579
  cwd = File.dirname(__FILE__)
@@ -527,11 +599,12 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
527
599
  stub_request(:get, "http://localhost:9200/_xpack").
528
600
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}',
529
601
  :headers => {"Content-Type"=> "application/json"})
530
- stub_request(:get, "http://localhost:9200/_ilm/policy/logstash-policy").
602
+ stub_request(:get, "http://localhost:9200/#{ilm_endpoint}/policy/logstash-policy").
531
603
  to_return(status: 200, body: "", headers: {})
532
- stub_request(:put, "http://localhost:9200/_ilm/policy/logstash-policy").
604
+ stub_request(:put, "http://localhost:9200/#{ilm_endpoint}/policy/logstash-policy").
533
605
  with(body: "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"75gb\",\"max_age\":\"50d\"}}}}}}").
534
606
  to_return(status: 200, body: "", headers: {})
607
+ stub_elastic_info
535
608
 
536
609
  assert_nothing_raised {
537
610
  driver(config)
@@ -548,6 +621,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
548
621
  template_file #{template_file}
549
622
  ilm_policy_overwrite true
550
623
  }
624
+ stub_elastic_info
551
625
 
552
626
  assert_raise(Fluent::ConfigError) {
553
627
  driver(config)
@@ -846,6 +920,67 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
846
920
  end
847
921
  end
848
922
 
923
+ class GetElasticsearchIncompatibleVersionTest < self
924
+ def create_driver(conf='', client_version="7.14")
925
+ # For request stub to detect compatibility.
926
+ @client_version ||= client_version
927
+ # Ensure original implementation existence.
928
+ Fluent::Plugin::ElasticsearchOutput.module_eval(<<-CODE)
929
+ def detect_es_major_version
930
+ begin
931
+ @_es_info ||= client.info
932
+ rescue ::Elasticsearch::UnsupportedProductError => e
933
+ raise Fluent::ConfigError, "Using Elasticsearch client #{@client_version} is not compatible for your Elasticsearch server. Please check your using elasticsearch gem version and Elasticsearch server."
934
+ end
935
+ begin
936
+ unless version = @_es_info.dig("version", "number")
937
+ version = @default_elasticsearch_version
938
+ end
939
+ rescue NoMethodError => e
940
+ log.warn "#{@_es_info} can not dig version information. Assuming Elasticsearch #{@default_elasticsearch_version}", error: e
941
+ version = @default_elasticsearch_version
942
+ end
943
+ version.to_i
944
+ end
945
+ CODE
946
+ Fluent::Plugin::ElasticsearchOutput.module_eval(<<-CODE)
947
+ def client_library_version
948
+ #{@client_version}
949
+ end
950
+ CODE
951
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::ElasticsearchOutput).configure(conf)
952
+ end
953
+
954
+ def test_incompatible_es_version
955
+ if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.14.0")
956
+ omit "This test is not effective before elasticsearch 7.14"
957
+ end
958
+ config = %{
959
+ host logs.google.com
960
+ port 778
961
+ scheme https
962
+ path /es/
963
+ user john
964
+ password doe
965
+ verify_es_version_at_startup true
966
+ max_retry_get_es_version 1
967
+ }
968
+
969
+ connection_resets = 0
970
+ stub_request(:get, "https://logs.google.com:778/es//").
971
+ with(basic_auth: ['john', 'doe']) do |req|
972
+ connection_resets += 1
973
+ raise ::Elasticsearch::UnsupportedProductError
974
+ end
975
+
976
+ assert_raise(Fluent::ConfigError) do
977
+ create_driver(config)
978
+ end
979
+
980
+ assert_equal(1, connection_resets)
981
+ end
982
+ end
983
+
849
984
  class GetElasticsearchVersionWithFallbackTest < self
850
985
  def create_driver(conf='', client_version="\"5.0\"")
851
986
  # For request stub to detect compatibility.
@@ -907,7 +1042,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
907
1042
  "new_template" => [false, "_index_template"])
908
1043
  def test_template_already_present(data)
909
1044
  use_legacy_template_flag, endpoint = data
910
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
1045
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
911
1046
  omit "elastisearch-ruby v7.8.0 or later is needed."
912
1047
  end
913
1048
  config = %{
@@ -930,6 +1065,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
930
1065
  stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
931
1066
  with(basic_auth: ['john', 'doe']).
932
1067
  to_return(:status => 200, :body => "", :headers => {})
1068
+ stub_elastic_info("https://logs.google.com:777/es//")
933
1069
 
934
1070
  driver(config)
935
1071
 
@@ -940,7 +1076,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
940
1076
  "new_template" => [false, "_index_template"])
941
1077
  def test_template_create(data)
942
1078
  use_legacy_template_flag, endpoint = data
943
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
1079
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
944
1080
  omit "elastisearch-ruby v7.8.0 or later is needed."
945
1081
  end
946
1082
  cwd = File.dirname(__FILE__)
@@ -974,6 +1110,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
974
1110
  stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
975
1111
  with(basic_auth: ['john', 'doe']).
976
1112
  to_return(:status => 200, :body => "", :headers => {})
1113
+ stub_elastic_info("https://logs.google.com:777/es//")
977
1114
 
978
1115
  driver(config)
979
1116
 
@@ -984,7 +1121,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
984
1121
  "new_template" => [false, "_index_template"])
985
1122
  def test_template_create_with_rollover_index_and_template_related_placeholders(data)
986
1123
  use_legacy_template_flag, endpoint = data
987
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
1124
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
988
1125
  omit "elastisearch-ruby v7.8.0 or later is needed."
989
1126
  end
990
1127
  cwd = File.dirname(__FILE__)
@@ -1037,6 +1174,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1037
1174
  driver(config)
1038
1175
 
1039
1176
  elastic_request = stub_elastic("https://logs.google.com:777/es//_bulk")
1177
+ stub_elastic_info("https://logs.google.com:777/es//")
1040
1178
  driver.run(default_tag: 'test.template') do
1041
1179
  driver.feed(sample_record)
1042
1180
  end
@@ -1052,7 +1190,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1052
1190
  "new_template" => [false, "_index_template"])
1053
1191
  def test_template_create_with_rollover_index_and_template_related_placeholders_with_truncating_caches(data)
1054
1192
  use_legacy_template_flag, endpoint = data
1055
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
1193
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
1056
1194
  omit "elastisearch-ruby v7.8.0 or later is needed."
1057
1195
  end
1058
1196
  cwd = File.dirname(__FILE__)
@@ -1102,6 +1240,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1102
1240
  with(basic_auth: ['john', 'doe'],
1103
1241
  body: "{\"aliases\":{\"myapp_deflector-test.template\":{\"is_write_index\":true}}}").
1104
1242
  to_return(:status => 200, :body => "", :headers => {})
1243
+ stub_elastic_info("https://logs.google.com:777/es//")
1105
1244
 
1106
1245
  driver(config)
1107
1246
 
@@ -1125,21 +1264,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1125
1264
 
1126
1265
  class TemplateIndexLifecycleManagementTest < self
1127
1266
  def setup
1128
- begin
1129
- require "elasticsearch/xpack"
1130
- rescue LoadError
1131
- omit "ILM testcase needs elasticsearch-xpack gem."
1267
+ if Gem::Version.new(Elasticsearch::VERSION) < Gem::Version.new("8.0.0")
1268
+ begin
1269
+ require "elasticsearch/xpack"
1270
+ rescue LoadError
1271
+ omit "ILM testcase needs elasticsearch-xpack gem."
1272
+ end
1132
1273
  end
1133
- if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.4.0")
1274
+ if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.4.0")
1134
1275
  omit "elastisearch-ruby v7.4.0 or later is needed for ILM."
1135
1276
  end
1136
1277
  end
1137
1278
 
1279
+ def ilm_endpoint
1280
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
1281
+ '_enrich'.freeze
1282
+ else
1283
+ '_ilm'.freeze
1284
+ end
1285
+ end
1286
+
1138
1287
  data("legacy_template" => [true, "_template"],
1139
1288
  "new_template" => [false, "_index_template"])
1140
1289
  def test_template_create_with_rollover_index_and_default_ilm(data)
1141
1290
  use_legacy_template_flag, endpoint = data
1142
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
1291
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
1143
1292
  omit "elastisearch-ruby v7.8.0 or later is needed."
1144
1293
  end
1145
1294
  cwd = File.dirname(__FILE__)
@@ -1205,13 +1354,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1205
1354
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
1206
1355
  with(basic_auth: ['john', 'doe']).
1207
1356
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
1208
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
1357
+ stub_request(:get, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/logstash-policy").
1209
1358
  with(basic_auth: ['john', 'doe']).
1210
1359
  to_return(:status => 404, :body => "", :headers => {})
1211
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
1360
+ stub_request(:put, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/logstash-policy").
1212
1361
  with(basic_auth: ['john', 'doe'],
1213
1362
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
1214
1363
  to_return(:status => 200, :body => "", :headers => {})
1364
+ stub_elastic_info("https://logs.google.com:777/es//")
1215
1365
 
1216
1366
  driver(config)
1217
1367
 
@@ -1222,7 +1372,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1222
1372
  "new_template" => [false, "_index_template"])
1223
1373
  def test_template_create_with_rollover_index_and_default_ilm_on_logstash_format(data)
1224
1374
  use_legacy_template_flag, endpoint = data
1225
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
1375
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
1226
1376
  omit "elastisearch-ruby v7.8.0 or later is needed."
1227
1377
  end
1228
1378
  cwd = File.dirname(__FILE__)
@@ -1291,13 +1441,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1291
1441
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
1292
1442
  with(basic_auth: ['john', 'doe']).
1293
1443
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
1294
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
1444
+ stub_request(:get, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/logstash-policy").
1295
1445
  with(basic_auth: ['john', 'doe']).
1296
1446
  to_return(:status => 404, :body => "", :headers => {})
1297
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
1447
+ stub_request(:put, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/logstash-policy").
1298
1448
  with(basic_auth: ['john', 'doe'],
1299
1449
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
1300
1450
  to_return(:status => 200, :body => "", :headers => {})
1451
+ stub_elastic_info("https://logs.google.com:777/es//")
1301
1452
 
1302
1453
  driver(config)
1303
1454
 
@@ -1314,7 +1465,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1314
1465
  "new_template" => [false, "_index_template"])
1315
1466
  def test_template_create_with_rollover_index_and_default_ilm_and_ilm_policy_overwrite(data)
1316
1467
  use_legacy_template_flag, endpoint = data
1317
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
1468
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
1318
1469
  omit "elastisearch-ruby v7.8.0 or later is needed."
1319
1470
  end
1320
1471
  cwd = File.dirname(__FILE__)
@@ -1382,13 +1533,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1382
1533
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
1383
1534
  with(basic_auth: ['john', 'doe']).
1384
1535
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
1385
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
1536
+ stub_request(:get, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/logstash-policy").
1386
1537
  with(basic_auth: ['john', 'doe']).
1387
1538
  to_return(:status => 200, :body => "", :headers => {})
1388
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
1539
+ stub_request(:put, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/logstash-policy").
1389
1540
  with(basic_auth: ['john', 'doe'],
1390
1541
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"60gb\",\"max_age\":\"45d\"}}}}}}").
1391
1542
  to_return(:status => 200, :body => "", :headers => {})
1543
+ stub_elastic_info("https://logs.google.com:777/es//")
1392
1544
 
1393
1545
  driver(config)
1394
1546
 
@@ -1424,7 +1576,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1424
1576
  "new_template" => [false, "_index_template"])
1425
1577
  def test_template_create_with_rollover_index_and_default_ilm_with_empty_index_date_pattern(data)
1426
1578
  use_legacy_template_flag, endpoint = data
1427
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
1579
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
1428
1580
  omit "elastisearch-ruby v7.8.0 or later is needed."
1429
1581
  end
1430
1582
  cwd = File.dirname(__FILE__)
@@ -1490,13 +1642,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1490
1642
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
1491
1643
  with(basic_auth: ['john', 'doe']).
1492
1644
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
1493
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
1645
+ stub_request(:get, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/logstash-policy").
1494
1646
  with(basic_auth: ['john', 'doe']).
1495
1647
  to_return(:status => 404, :body => "", :headers => {})
1496
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
1648
+ stub_request(:put, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/logstash-policy").
1497
1649
  with(basic_auth: ['john', 'doe'],
1498
1650
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
1499
1651
  to_return(:status => 200, :body => "", :headers => {})
1652
+ stub_elastic_info("https://logs.google.com:777/es//")
1500
1653
 
1501
1654
  driver(config)
1502
1655
 
@@ -1507,7 +1660,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1507
1660
  "new_template" => [false, "_index_template"])
1508
1661
  def test_template_create_with_rollover_index_and_custom_ilm(data)
1509
1662
  use_legacy_template_flag, endpoint = data
1510
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
1663
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
1511
1664
  omit "elastisearch-ruby v7.8.0 or later is needed."
1512
1665
  end
1513
1666
  cwd = File.dirname(__FILE__)
@@ -1574,13 +1727,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1574
1727
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
1575
1728
  with(basic_auth: ['john', 'doe']).
1576
1729
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
1577
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
1730
+ stub_request(:get, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy").
1578
1731
  with(basic_auth: ['john', 'doe']).
1579
1732
  to_return(:status => 404, :body => "", :headers => {})
1580
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
1733
+ stub_request(:put, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy").
1581
1734
  with(basic_auth: ['john', 'doe'],
1582
1735
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"70gb\",\"max_age\":\"30d\"}}}}}}").
1583
1736
  to_return(:status => 200, :body => "", :headers => {})
1737
+ stub_elastic_info("https://logs.google.com:777/es//")
1584
1738
 
1585
1739
  driver(config)
1586
1740
 
@@ -1591,7 +1745,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1591
1745
  "new_template" => [false, "_index_template"])
1592
1746
  def test_template_create_with_rollover_index_and_ilm_policies_and_placeholderstest_template_create_with_rollover_index_and_ilm_policies_and_placeholders(data)
1593
1747
  use_legacy_template_flag, endpoint = data
1594
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
1748
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
1595
1749
  omit "elastisearch-ruby v7.8.0 or later is needed."
1596
1750
  end
1597
1751
  cwd = File.dirname(__FILE__)
@@ -1658,13 +1812,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1658
1812
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
1659
1813
  with(basic_auth: ['john', 'doe']).
1660
1814
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
1661
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
1815
+ stub_request(:get, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy").
1662
1816
  with(basic_auth: ['john', 'doe']).
1663
1817
  to_return(:status => 404, :body => "", :headers => {})
1664
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
1818
+ stub_request(:put, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy").
1665
1819
  with(basic_auth: ['john', 'doe'],
1666
1820
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"70gb\",\"max_age\":\"30d\"}}}}}}").
1667
1821
  to_return(:status => 200, :body => "", :headers => {})
1822
+ stub_elastic_info("https://logs.google.com:777/es//")
1668
1823
 
1669
1824
  driver(config)
1670
1825
 
@@ -1682,7 +1837,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1682
1837
  "new_template" => [false, "_index_template"])
1683
1838
  def test_tag_placeholder(data)
1684
1839
  use_legacy_template_flag, endpoint = data
1685
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
1840
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
1686
1841
  omit "elastisearch-ruby v7.8.0 or later is needed."
1687
1842
  end
1688
1843
  cwd = File.dirname(__FILE__)
@@ -1749,13 +1904,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1749
1904
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
1750
1905
  with(basic_auth: ['john', 'doe']).
1751
1906
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
1752
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
1907
+ stub_request(:get, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy").
1753
1908
  with(basic_auth: ['john', 'doe']).
1754
1909
  to_return(:status => 404, :body => "", :headers => {})
1755
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
1910
+ stub_request(:put, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy").
1756
1911
  with(basic_auth: ['john', 'doe'],
1757
1912
  body: "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"70gb\",\"max_age\":\"30d\"}}}}}}").
1758
1913
  to_return(:status => 200, :body => "", :headers => {})
1914
+ stub_elastic_info("https://logs.google.com:777/es//")
1759
1915
 
1760
1916
  driver(config)
1761
1917
 
@@ -1772,7 +1928,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1772
1928
  "new_template" => [false, "_index_template"])
1773
1929
  def test_tag_placeholder_with_multiple_policies(data)
1774
1930
  use_legacy_template_flag, endpoint = data
1775
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
1931
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
1776
1932
  omit "elastisearch-ruby v7.8.0 or later is needed."
1777
1933
  end
1778
1934
  cwd = File.dirname(__FILE__)
@@ -1839,13 +1995,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1839
1995
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
1840
1996
  with(basic_auth: ['john', 'doe']).
1841
1997
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
1842
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy2").
1998
+ stub_request(:get, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy2").
1843
1999
  with(basic_auth: ['john', 'doe']).
1844
2000
  to_return(:status => 404, :body => "", :headers => {})
1845
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy2").
2001
+ stub_request(:put, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy2").
1846
2002
  with(basic_auth: ['john', 'doe'],
1847
2003
  body: "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"80gb\",\"max_age\":\"20d\"}}}}}}").
1848
2004
  to_return(:status => 200, :body => "", :headers => {})
2005
+ stub_elastic_info("https://logs.google.com:777/es//")
1849
2006
 
1850
2007
  driver(config)
1851
2008
 
@@ -1863,7 +2020,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1863
2020
  "new_template" => [false, "_index_template"])
1864
2021
  def test_template_create_with_rollover_index_and_default_ilm_and_placeholders(data)
1865
2022
  use_legacy_template_flag, endpoint = data
1866
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
2023
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
1867
2024
  omit "elastisearch-ruby v7.8.0 or later is needed."
1868
2025
  end
1869
2026
  cwd = File.dirname(__FILE__)
@@ -1929,10 +2086,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1929
2086
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
1930
2087
  with(basic_auth: ['john', 'doe']).
1931
2088
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
1932
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
2089
+ stub_request(:get, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/logstash-policy").
1933
2090
  with(basic_auth: ['john', 'doe']).
1934
2091
  to_return(:status => 404, :body => "", :headers => {})
1935
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
2092
+ stub_request(:put, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/logstash-policy").
1936
2093
  with(basic_auth: ['john', 'doe'],
1937
2094
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
1938
2095
  to_return(:status => 200, :body => "", :headers => {})
@@ -1964,13 +2121,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1964
2121
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
1965
2122
  with(basic_auth: ['john', 'doe']).
1966
2123
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
1967
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
2124
+ stub_request(:get, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/logstash-policy").
1968
2125
  with(basic_auth: ['john', 'doe']).
1969
2126
  to_return(:status => 404, :body => "", :headers => {})
1970
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
2127
+ stub_request(:put, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/logstash-policy").
1971
2128
  with(basic_auth: ['john', 'doe'],
1972
2129
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
1973
2130
  to_return(:status => 200, :body => "", :headers => {})
2131
+ stub_elastic_info("https://logs.google.com:777/es//")
1974
2132
 
1975
2133
  driver(config)
1976
2134
 
@@ -1993,7 +2151,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1993
2151
  "new_template" => [false, "_index_template"])
1994
2152
  def test_template_create_with_rollover_index_and_default_ilm_and_placeholders_and_index_separator(data)
1995
2153
  use_legacy_template_flag, endpoint = data
1996
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
2154
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
1997
2155
  omit "elastisearch-ruby v7.8.0 or later is needed."
1998
2156
  end
1999
2157
  cwd = File.dirname(__FILE__)
@@ -2060,13 +2218,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2060
2218
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
2061
2219
  with(basic_auth: ['john', 'doe']).
2062
2220
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
2063
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
2221
+ stub_request(:get, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/logstash-policy").
2064
2222
  with(basic_auth: ['john', 'doe']).
2065
2223
  to_return(:status => 404, :body => "", :headers => {})
2066
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
2224
+ stub_request(:put, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/logstash-policy").
2067
2225
  with(basic_auth: ['john', 'doe'],
2068
2226
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
2069
2227
  to_return(:status => 200, :body => "", :headers => {})
2228
+ stub_elastic_info("https://logs.google.com:777/es//")
2070
2229
 
2071
2230
  driver(config)
2072
2231
 
@@ -2085,7 +2244,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2085
2244
  "new_template" => [false, "_index_template"])
2086
2245
  def test_template_create_with_rollover_index_and_default_ilm_and_custom_and_time_placeholders(data)
2087
2246
  use_legacy_template_flag, endpoint = data
2088
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
2247
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
2089
2248
  omit "elastisearch-ruby v7.8.0 or later is needed."
2090
2249
  end
2091
2250
  cwd = File.dirname(__FILE__)
@@ -2156,13 +2315,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2156
2315
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
2157
2316
  with(basic_auth: ['john', 'doe']).
2158
2317
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
2159
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
2318
+ stub_request(:get, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/logstash-policy").
2160
2319
  with(basic_auth: ['john', 'doe']).
2161
2320
  to_return(:status => 404, :body => "", :headers => {})
2162
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
2321
+ stub_request(:put, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/logstash-policy").
2163
2322
  with(basic_auth: ['john', 'doe'],
2164
2323
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
2165
2324
  to_return(:status => 200, :body => "", :headers => {})
2325
+ stub_elastic_info("https://logs.google.com:777/es//")
2166
2326
 
2167
2327
  driver(config)
2168
2328
 
@@ -2183,7 +2343,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2183
2343
  def test_custom_template_create(data)
2184
2344
  use_legacy_template_flag, endpoint = data
2185
2345
 
2186
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
2346
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
2187
2347
  omit "elastisearch-ruby v7.8.0 or later is needed."
2188
2348
  end
2189
2349
  cwd = File.dirname(__FILE__)
@@ -2218,6 +2378,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2218
2378
  stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
2219
2379
  with(basic_auth: ['john', 'doe']).
2220
2380
  to_return(:status => 200, :body => "", :headers => {})
2381
+ stub_elastic_info("https://logs.google.com:777/es//")
2221
2382
 
2222
2383
  driver(config)
2223
2384
 
@@ -2228,7 +2389,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2228
2389
  "new_template" => [false, "_index_template"])
2229
2390
  def test_custom_template_create_with_customize_template_related_placeholders(data)
2230
2391
  use_legacy_template_flag, endpoint = data
2231
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
2392
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
2232
2393
  omit "elastisearch-ruby v7.8.0 or later is needed."
2233
2394
  end
2234
2395
  cwd = File.dirname(__FILE__)
@@ -2270,6 +2431,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2270
2431
  driver(config)
2271
2432
 
2272
2433
  stub_elastic("https://logs.google.com:777/es//_bulk")
2434
+ stub_elastic_info("https://logs.google.com:777/es//")
2273
2435
  driver.run(default_tag: 'test.template') do
2274
2436
  driver.feed(sample_record)
2275
2437
  end
@@ -2281,7 +2443,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2281
2443
  "new_template" => [false, "_index_template"])
2282
2444
  def test_custom_template_installation_for_host_placeholder(data)
2283
2445
  use_legacy_template_flag, endpoint = data
2284
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
2446
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
2285
2447
  omit "elastisearch-ruby v7.8.0 or later is needed."
2286
2448
  end
2287
2449
  cwd = File.dirname(__FILE__)
@@ -2321,6 +2483,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2321
2483
  driver(config)
2322
2484
 
2323
2485
  stub_elastic("https://logs-test.google.com:777/es//_bulk")
2486
+ stub_elastic_info("https://logs-test.google.com:777/es//")
2324
2487
  driver.run(default_tag: 'test') do
2325
2488
  driver.feed(sample_record)
2326
2489
  end
@@ -2330,7 +2493,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2330
2493
  "new_template" => [false, "_index_template"])
2331
2494
  def test_custom_template_with_rollover_index_create(data)
2332
2495
  use_legacy_template_flag, endpoint = data
2333
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
2496
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
2334
2497
  omit "elastisearch-ruby v7.8.0 or later is needed."
2335
2498
  end
2336
2499
  cwd = File.dirname(__FILE__)
@@ -2381,6 +2544,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2381
2544
  stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/mylogs").
2382
2545
  with(basic_auth: ['john', 'doe']).
2383
2546
  to_return(:status => 200, :body => "", :headers => {})
2547
+ stub_elastic_info("https://logs.google.com:777/es//")
2384
2548
 
2385
2549
  driver(config)
2386
2550
 
@@ -2391,7 +2555,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2391
2555
  "new_template" => [false, "_index_template"])
2392
2556
  def test_custom_template_with_rollover_index_create_and_deflector_alias(data)
2393
2557
  use_legacy_template_flag, endpoint = data
2394
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
2558
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
2395
2559
  omit "elastisearch-ruby v7.8.0 or later is needed."
2396
2560
  end
2397
2561
  cwd = File.dirname(__FILE__)
@@ -2443,6 +2607,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2443
2607
  stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/myapp_deflector").
2444
2608
  with(basic_auth: ['john', 'doe']).
2445
2609
  to_return(:status => 200, :body => "", :headers => {})
2610
+ stub_elastic_info("https://logs.google.com:777/es//")
2446
2611
 
2447
2612
  driver(config)
2448
2613
 
@@ -2453,7 +2618,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2453
2618
  "new_template" => [false, "_index_template"])
2454
2619
  def test_custom_template_with_rollover_index_create_with_logstash_format(data)
2455
2620
  use_legacy_template_flag, endpoint = data
2456
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
2621
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
2457
2622
  omit "elastisearch-ruby v7.8.0 or later is needed."
2458
2623
  end
2459
2624
  cwd = File.dirname(__FILE__)
@@ -2511,6 +2676,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2511
2676
  driver(config)
2512
2677
 
2513
2678
  elastic_request = stub_elastic("https://logs.google.com:777/es//_bulk")
2679
+ stub_elastic_info("https://logs.google.com:777/es//")
2514
2680
  driver.run(default_tag: 'custom-test') do
2515
2681
  driver.feed(sample_record)
2516
2682
  end
@@ -2519,21 +2685,32 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2519
2685
 
2520
2686
  class CustomTemplateIndexLifecycleManagementTest < self
2521
2687
  def setup
2522
- begin
2523
- require "elasticsearch/xpack"
2524
- rescue LoadError
2525
- omit "ILM testcase needs elasticsearch-xpack gem."
2688
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) < Gem::Version.new("8.0.0")
2689
+ begin
2690
+ require "elasticsearch/xpack"
2691
+ rescue LoadError
2692
+ omit "ILM testcase needs elasticsearch-xpack gem."
2693
+ end
2526
2694
  end
2527
- if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.4.0")
2695
+ if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.4.0")
2528
2696
  omit "elastisearch-ruby v7.4.0 or later is needed."
2529
2697
  end
2530
2698
  end
2531
2699
 
2700
+
2701
+ def ilm_endpoint
2702
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
2703
+ '_enrich'.freeze
2704
+ else
2705
+ '_ilm'.freeze
2706
+ end
2707
+ end
2708
+
2532
2709
  data("legacy_template" => [true, "_template"],
2533
2710
  "new_template" => [false, "_index_template"])
2534
2711
  def test_custom_template_with_rollover_index_create_and_default_ilm(data)
2535
2712
  use_legacy_template_flag, endpoint = data
2536
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
2713
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
2537
2714
  omit "elastisearch-ruby v7.8.0 or later is needed."
2538
2715
  end
2539
2716
  cwd = File.dirname(__FILE__)
@@ -2603,14 +2780,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2603
2780
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
2604
2781
  with(basic_auth: ['john', 'doe']).
2605
2782
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
2606
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
2783
+ stub_request(:get, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy").
2607
2784
  with(basic_auth: ['john', 'doe']).
2608
2785
  to_return(:status => 404, :body => "", :headers => {})
2609
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
2786
+ stub_request(:put, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy").
2610
2787
  with(basic_auth: ['john', 'doe'],
2611
2788
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
2612
2789
  to_return(:status => 200, :body => "", :headers => {})
2613
-
2790
+ stub_elastic_info("https://logs.google.com:777/es//")
2614
2791
  driver(config)
2615
2792
 
2616
2793
  assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs", times: 1)
@@ -2620,7 +2797,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2620
2797
  "new_template" => [false, "_index_template"])
2621
2798
  def test_custom_template_with_rollover_index_create_and_default_ilm_and_ilm_policy_overwrite(data)
2622
2799
  use_legacy_template_flag, endpoint = data
2623
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
2800
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
2624
2801
  omit "elastisearch-ruby v7.8.0 or later is needed."
2625
2802
  end
2626
2803
  cwd = File.dirname(__FILE__)
@@ -2692,13 +2869,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2692
2869
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
2693
2870
  with(basic_auth: ['john', 'doe']).
2694
2871
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
2695
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
2872
+ stub_request(:get, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy").
2696
2873
  with(basic_auth: ['john', 'doe']).
2697
2874
  to_return(:status => 200, :body => "", :headers => {})
2698
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
2875
+ stub_request(:put, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy").
2699
2876
  with(basic_auth: ['john', 'doe'],
2700
2877
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"60gb\",\"max_age\":\"45d\"}}}}}}").
2701
2878
  to_return(:status => 200, :body => "", :headers => {})
2879
+ stub_elastic_info("https://logs.google.com:777/es//")
2702
2880
 
2703
2881
  driver(config)
2704
2882
 
@@ -2728,6 +2906,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2728
2906
  }
2729
2907
 
2730
2908
  # Should raise error because multiple alias indices IllegalArgument Error on executing ILM feature
2909
+ stub_elastic_info("https://logs.google.com:777/es//")
2731
2910
  assert_raise(Fluent::ConfigError) do
2732
2911
  driver(config)
2733
2912
  end
@@ -2737,7 +2916,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2737
2916
  "new_template" => [false, "_index_template"])
2738
2917
  def test_custom_template_with_rollover_index_create_and_default_ilm_and_placeholders(data)
2739
2918
  use_legacy_template_flag, endpoint = data
2740
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
2919
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
2741
2920
  omit "elastisearch-ruby v7.8.0 or later is needed."
2742
2921
  end
2743
2922
  cwd = File.dirname(__FILE__)
@@ -2809,10 +2988,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2809
2988
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
2810
2989
  with(basic_auth: ['john', 'doe']).
2811
2990
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
2812
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
2991
+ stub_request(:get, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy").
2813
2992
  with(basic_auth: ['john', 'doe']).
2814
2993
  to_return(:status => 404, :body => "", :headers => {})
2815
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
2994
+ stub_request(:put, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy").
2816
2995
  with(basic_auth: ['john', 'doe'],
2817
2996
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
2818
2997
  to_return(:status => 200, :body => "", :headers => {})
@@ -2856,13 +3035,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2856
3035
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
2857
3036
  with(basic_auth: ['john', 'doe']).
2858
3037
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
2859
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
3038
+ stub_request(:get, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy").
2860
3039
  with(basic_auth: ['john', 'doe']).
2861
3040
  to_return(:status => 404, :body => "", :headers => {})
2862
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
3041
+ stub_request(:put, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy").
2863
3042
  with(basic_auth: ['john', 'doe'],
2864
3043
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
2865
3044
  to_return(:status => 200, :body => "", :headers => {})
3045
+ stub_elastic_info("https://logs.google.com:777/es//")
2866
3046
 
2867
3047
  driver(config)
2868
3048
 
@@ -2883,7 +3063,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2883
3063
  "new_template" => [false, "_index_template"])
2884
3064
  def test_custom_template_with_rollover_index_create_and_custom_ilm(data)
2885
3065
  use_legacy_template_flag, endpoint = data
2886
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
3066
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
2887
3067
  omit "elastisearch-ruby v7.8.0 or later is needed."
2888
3068
  end
2889
3069
  cwd = File.dirname(__FILE__)
@@ -2946,14 +3126,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2946
3126
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
2947
3127
  with(basic_auth: ['john', 'doe']).
2948
3128
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
2949
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
3129
+ stub_request(:get, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy").
2950
3130
  with(basic_auth: ['john', 'doe']).
2951
3131
  to_return(:status => 404, :body => "", :headers => {})
2952
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
3132
+ stub_request(:put, "https://logs.google.com:777/es//#{ilm_endpoint}/policy/fluentd-policy").
2953
3133
  with(basic_auth: ['john', 'doe'],
2954
3134
  :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"70gb\",\"max_age\":\"30d\"}}}}}}").
2955
3135
  to_return(:status => 200, :body => "", :headers => {})
2956
-
3136
+ stub_elastic_info("https://logs.google.com:777/es//")
2957
3137
  driver(config)
2958
3138
 
2959
3139
  assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs", times: 1)
@@ -2964,7 +3144,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2964
3144
  "new_template" => [false, "_index_template"])
2965
3145
  def test_template_overwrite(data)
2966
3146
  use_legacy_template_flag, endpoint = data
2967
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
3147
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
2968
3148
  omit "elastisearch-ruby v7.8.0 or later is needed."
2969
3149
  end
2970
3150
  cwd = File.dirname(__FILE__)
@@ -2999,6 +3179,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2999
3179
  stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
3000
3180
  with(basic_auth: ['john', 'doe']).
3001
3181
  to_return(:status => 200, :body => "", :headers => {})
3182
+ stub_elastic_info("https://logs.google.com:777/es//")
3002
3183
 
3003
3184
  driver(config)
3004
3185
 
@@ -3009,7 +3190,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3009
3190
  "new_template" => [false, "_index_template"])
3010
3191
  def test_custom_template_overwrite(data)
3011
3192
  use_legacy_template_flag, endpoint = data
3012
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
3193
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
3013
3194
  omit "elastisearch-ruby v7.8.0 or later is needed."
3014
3195
  end
3015
3196
  cwd = File.dirname(__FILE__)
@@ -3045,6 +3226,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3045
3226
  stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
3046
3227
  with(basic_auth: ['john', 'doe']).
3047
3228
  to_return(:status => 200, :body => "", :headers => {})
3229
+ stub_elastic_info("https://logs.google.com:777/es//")
3048
3230
 
3049
3231
  driver(config)
3050
3232
 
@@ -3055,7 +3237,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3055
3237
  "new_template" => [false, "_index_template"])
3056
3238
  def test_custom_template_with_rollover_index_overwrite(data)
3057
3239
  use_legacy_template_flag, endpoint = data
3058
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
3240
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
3059
3241
  omit "elastisearch-ruby v7.8.0 or later is needed."
3060
3242
  end
3061
3243
  cwd = File.dirname(__FILE__)
@@ -3107,6 +3289,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3107
3289
  stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fd%7D-000001%3E/#{alias_endpoint}/myapp_deflector").
3108
3290
  with(basic_auth: ['john', 'doe']).
3109
3291
  to_return(:status => 200, :body => "", :headers => {})
3292
+ stub_elastic_info("https://logs.google.com:777/es//")
3110
3293
 
3111
3294
  driver(config)
3112
3295
 
@@ -3133,7 +3316,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3133
3316
  stub_request(:get, "https://logs.google.com:777/es//_template/logstash").
3134
3317
  with(basic_auth: ['john', 'doe']).
3135
3318
  to_return(:status => 404, :body => "", :headers => {})
3136
-
3319
+ stub_elastic_info("https://logs.google.com:777/es//")
3137
3320
 
3138
3321
  assert_raise(RuntimeError) {
3139
3322
  driver(config)
@@ -3144,7 +3327,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3144
3327
  "new_template" => [false, "_index_template"])
3145
3328
  def test_template_create_for_host_placeholder(data)
3146
3329
  use_legacy_template_flag, endpoint = data
3147
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
3330
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
3148
3331
  omit "elastisearch-ruby v7.8.0 or later is needed."
3149
3332
  end
3150
3333
  cwd = File.dirname(__FILE__)
@@ -3185,7 +3368,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3185
3368
 
3186
3369
  driver(config)
3187
3370
 
3188
- stub_elastic("https://logs.google.com:777/es//_bulk")
3371
+ stub_elastic("https://logs-test.google.com:777/es//_bulk")
3372
+ stub_elastic_info("https://logs-test.google.com:777/es//")
3189
3373
  driver.run(default_tag: 'test') do
3190
3374
  driver.feed(sample_record)
3191
3375
  end
@@ -3195,7 +3379,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3195
3379
  "new_template" => [false, "_index_template"])
3196
3380
  def test_template_retry_install_fails(data)
3197
3381
  use_legacy_template_flag, endpoint = data
3198
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
3382
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
3199
3383
  omit "elastisearch-ruby v7.8.0 or later is needed."
3200
3384
  end
3201
3385
  cwd = File.dirname(__FILE__)
@@ -3225,6 +3409,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3225
3409
  connection_resets += 1
3226
3410
  raise Faraday::ConnectionFailed, "Test message"
3227
3411
  end
3412
+ stub_elastic_info("https://logs.google.com:778/es//")
3228
3413
 
3229
3414
  assert_raise(Fluent::Plugin::ElasticsearchError::RetryableOperationExhaustedFailure) do
3230
3415
  driver(config)
@@ -3233,13 +3418,13 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3233
3418
  assert_equal(4, connection_resets)
3234
3419
  end
3235
3420
 
3236
- transport_errors_handled_separately = [Elasticsearch::Transport::Transport::Errors::NotFound]
3237
- transport_errors = Elasticsearch::Transport::Transport::Errors.constants.map { |err| [err, Elasticsearch::Transport::Transport::Errors.const_get(err)] }
3421
+ transport_errors_handled_separately = [TRANSPORT_CLASS::Transport::Errors::NotFound]
3422
+ transport_errors = TRANSPORT_CLASS::Transport::Errors.constants.map { |err| [err, TRANSPORT_CLASS::Transport::Errors.const_get(err)] }
3238
3423
  transport_errors_hash = Hash[transport_errors.select { |err| !transport_errors_handled_separately.include?(err[1]) } ]
3239
3424
 
3240
3425
  data(transport_errors_hash)
3241
3426
  def test_template_retry_transport_errors(error)
3242
- endpoint, use_legacy_template_flag = if Gem::Version.create(::Elasticsearch::Transport::VERSION) >= Gem::Version.create("7.8.0")
3427
+ endpoint, use_legacy_template_flag = if Gem::Version.create(::TRANSPORT_CLASS::VERSION) >= Gem::Version.create("7.8.0")
3243
3428
  ["_index_template".freeze, false]
3244
3429
  else
3245
3430
  ["_template".freeze, true]
@@ -3266,6 +3451,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3266
3451
  retries += 1
3267
3452
  raise error
3268
3453
  end
3454
+ stub_elastic_info("https://logs.google.com:778/es//")
3269
3455
 
3270
3456
  assert_raise(Fluent::Plugin::ElasticsearchError::RetryableOperationExhaustedFailure) do
3271
3457
  driver(config)
@@ -3278,7 +3464,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3278
3464
  "new_template" => [false, "_index_template"])
3279
3465
  def test_template_retry_install_does_not_fail(data)
3280
3466
  use_legacy_template_flag, endpoint = data
3281
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
3467
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
3282
3468
  omit "elastisearch-ruby v7.8.0 or later is needed."
3283
3469
  end
3284
3470
  cwd = File.dirname(__FILE__)
@@ -3309,6 +3495,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3309
3495
  connection_resets += 1
3310
3496
  raise Faraday::ConnectionFailed, "Test message"
3311
3497
  end
3498
+ stub_elastic_info("https://logs.google.com:778/es//")
3312
3499
 
3313
3500
  driver(config)
3314
3501
 
@@ -3319,7 +3506,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3319
3506
  "new_template" => [false, "_index_template"])
3320
3507
  def test_templates_create(data)
3321
3508
  use_legacy_template_flag, endpoint = data
3322
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
3509
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
3323
3510
  omit "elastisearch-ruby v7.8.0 or later is needed."
3324
3511
  end
3325
3512
  cwd = File.dirname(__FILE__)
@@ -3364,6 +3551,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3364
3551
  stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash3").
3365
3552
  with(basic_auth: ['john', 'doe']).
3366
3553
  to_return(:status => 200, :body => "", :headers => {})
3554
+ stub_elastic_info("https://logs.google.com:777/es//")
3367
3555
 
3368
3556
  driver(config)
3369
3557
 
@@ -3376,7 +3564,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3376
3564
  "new_template" => [false, "_index_template"])
3377
3565
  def test_templates_overwrite(data)
3378
3566
  use_legacy_template_flag, endpoint = data
3379
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
3567
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
3380
3568
  omit "elastisearch-ruby v7.8.0 or later is needed."
3381
3569
  end
3382
3570
  cwd = File.dirname(__FILE__)
@@ -3421,6 +3609,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3421
3609
  stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash3").
3422
3610
  with(basic_auth: ['john', 'doe']).
3423
3611
  to_return(:status => 200, :body => "", :headers => {})
3612
+ stub_elastic_info("https://logs.google.com:777/es//")
3424
3613
 
3425
3614
  driver(config)
3426
3615
 
@@ -3433,7 +3622,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3433
3622
  "new_template" => [false, "_index_template"])
3434
3623
  def test_templates_are_also_used(data)
3435
3624
  use_legacy_template_flag, endpoint = data
3436
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
3625
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
3437
3626
  omit "elastisearch-ruby v7.8.0 or later is needed."
3438
3627
  end
3439
3628
  cwd = File.dirname(__FILE__)
@@ -3479,6 +3668,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3479
3668
  stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2").
3480
3669
  with(basic_auth: ['john', 'doe']).
3481
3670
  to_return(:status => 200, :body => "", :headers => {})
3671
+ stub_elastic_info("https://logs.google.com:777/es//")
3482
3672
 
3483
3673
  driver(config)
3484
3674
 
@@ -3492,7 +3682,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3492
3682
  "new_template" => [false, "_index_template"])
3493
3683
  def test_templates_can_be_partially_created_if_error_occurs(data)
3494
3684
  use_legacy_template_flag, endpoint = data
3495
- if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
3685
+ if !use_legacy_template_flag && Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.8.0")
3496
3686
  omit "elastisearch-ruby v7.8.0 or later is needed."
3497
3687
  end
3498
3688
  cwd = File.dirname(__FILE__)
@@ -3529,6 +3719,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3529
3719
  stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2").
3530
3720
  with(basic_auth: ['john', 'doe']).
3531
3721
  to_return(:status => 200, :body => "", :headers => {})
3722
+ stub_elastic_info("https://logs.google.com:777/es//")
3532
3723
 
3533
3724
  assert_raise(RuntimeError) {
3534
3725
  driver(config)
@@ -3545,6 +3736,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3545
3736
  path /es/
3546
3737
  port 123
3547
3738
  }
3739
+ stub_elastic_info("https://host1:50")
3740
+ stub_elastic_info("https://host2:100")
3741
+ stub_elastic_info("https://host3:123")
3548
3742
  instance = driver(config).instance
3549
3743
 
3550
3744
  assert_equal 3, instance.get_connection_options[:hosts].length
@@ -3567,6 +3761,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3567
3761
  user default_user
3568
3762
  password default_password
3569
3763
  }
3764
+ stub_elastic_info("https://john:password@host1:443/elastic/")
3765
+ stub_elastic_info("http://host2")
3570
3766
  instance = driver(config).instance
3571
3767
 
3572
3768
  assert_equal 2, instance.get_connection_options[:hosts].length
@@ -3593,6 +3789,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3593
3789
  user default_user
3594
3790
  password default_password
3595
3791
  }
3792
+ stub_elastic_info("https://j%2Bhn:passw%40rd@host1:443/elastic/")
3793
+ stub_elastic_info("http://host2")
3794
+
3596
3795
  instance = driver(config).instance
3597
3796
 
3598
3797
  assert_equal 2, instance.get_connection_options[:hosts].length
@@ -3612,6 +3811,74 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3612
3811
  assert_equal '/default_path', host2[:path]
3613
3812
  end
3614
3813
 
3814
+ class IPv6AdressStringHostsTest < self
3815
+ def test_legacy_hosts_list
3816
+ config = %{
3817
+ hosts "[2404:7a80:d440:3000:192a:a292:bd7f:ca19]:50,host2:100,host3"
3818
+ scheme https
3819
+ path /es/
3820
+ port 123
3821
+ }
3822
+ instance = driver(config).instance
3823
+
3824
+ assert_raise(URI::InvalidURIError) do
3825
+ instance.get_connection_options[:hosts].length
3826
+ end
3827
+ end
3828
+
3829
+ def test_hosts_list
3830
+ config = %{
3831
+ hosts https://john:password@[2404:7a80:d440:3000:192a:a292:bd7f:ca19]:443/elastic/,http://host2
3832
+ path /default_path
3833
+ user default_user
3834
+ password default_password
3835
+ }
3836
+ instance = driver(config).instance
3837
+
3838
+ assert_equal 2, instance.get_connection_options[:hosts].length
3839
+ host1, host2 = instance.get_connection_options[:hosts]
3840
+
3841
+ assert_equal '[2404:7a80:d440:3000:192a:a292:bd7f:ca19]', host1[:host]
3842
+ assert_equal 443, host1[:port]
3843
+ assert_equal 'https', host1[:scheme]
3844
+ assert_equal 'john', host1[:user]
3845
+ assert_equal 'password', host1[:password]
3846
+ assert_equal '/elastic/', host1[:path]
3847
+
3848
+ assert_equal 'host2', host2[:host]
3849
+ assert_equal 'http', host2[:scheme]
3850
+ assert_equal 'default_user', host2[:user]
3851
+ assert_equal 'default_password', host2[:password]
3852
+ assert_equal '/default_path', host2[:path]
3853
+ end
3854
+
3855
+ def test_hosts_list_with_escape_placeholders
3856
+ config = %{
3857
+ hosts https://%{j+hn}:%{passw@rd}@[2404:7a80:d440:3000:192a:a292:bd7f:ca19]:443/elastic/,http://host2
3858
+ path /default_path
3859
+ user default_user
3860
+ password default_password
3861
+ }
3862
+ instance = driver(config).instance
3863
+
3864
+ assert_equal 2, instance.get_connection_options[:hosts].length
3865
+ host1, host2 = instance.get_connection_options[:hosts]
3866
+
3867
+ assert_equal '[2404:7a80:d440:3000:192a:a292:bd7f:ca19]', host1[:host]
3868
+ assert_equal 443, host1[:port]
3869
+ assert_equal 'https', host1[:scheme]
3870
+ assert_equal 'j%2Bhn', host1[:user]
3871
+ assert_equal 'passw%40rd', host1[:password]
3872
+ assert_equal '/elastic/', host1[:path]
3873
+
3874
+ assert_equal 'host2', host2[:host]
3875
+ assert_equal 'http', host2[:scheme]
3876
+ assert_equal 'default_user', host2[:user]
3877
+ assert_equal 'default_password', host2[:password]
3878
+ assert_equal '/default_path', host2[:path]
3879
+ end
3880
+ end
3881
+
3615
3882
  def test_single_host_params_and_defaults
3616
3883
  config = %{
3617
3884
  host logs.google.com
@@ -3665,6 +3932,46 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3665
3932
  assert(ports.none? { |p| p == 9200 })
3666
3933
  end
3667
3934
 
3935
+ class IPv6AdressStringHostTest < self
3936
+ def test_single_host_params_and_defaults
3937
+ config = %{
3938
+ host 2404:7a80:d440:3000:192a:a292:bd7f:ca19
3939
+ user john
3940
+ password doe
3941
+ }
3942
+ instance = driver(config).instance
3943
+
3944
+ assert_equal 1, instance.get_connection_options[:hosts].length
3945
+ host1 = instance.get_connection_options[:hosts][0]
3946
+
3947
+ assert_equal '[2404:7a80:d440:3000:192a:a292:bd7f:ca19]', host1[:host]
3948
+ assert_equal 9200, host1[:port]
3949
+ assert_equal 'http', host1[:scheme]
3950
+ assert_equal 'john', host1[:user]
3951
+ assert_equal 'doe', host1[:password]
3952
+ assert_equal nil, host1[:path]
3953
+ end
3954
+
3955
+ def test_single_host_params_and_defaults_with_escape_placeholders
3956
+ config = %{
3957
+ host 2404:7a80:d440:3000:192a:a292:bd7f:ca19
3958
+ user %{j+hn}
3959
+ password %{d@e}
3960
+ }
3961
+ instance = driver(config).instance
3962
+
3963
+ assert_equal 1, instance.get_connection_options[:hosts].length
3964
+ host1 = instance.get_connection_options[:hosts][0]
3965
+
3966
+ assert_equal '[2404:7a80:d440:3000:192a:a292:bd7f:ca19]', host1[:host]
3967
+ assert_equal 9200, host1[:port]
3968
+ assert_equal 'http', host1[:scheme]
3969
+ assert_equal 'j%2Bhn', host1[:user]
3970
+ assert_equal 'd%40e', host1[:password]
3971
+ assert_equal nil, host1[:path]
3972
+ end
3973
+ end
3974
+
3668
3975
  def test_password_is_required_if_specify_user
3669
3976
  config = %{
3670
3977
  user john
@@ -3685,6 +3992,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3685
3992
  elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
3686
3993
  with(headers: { "Content-Type" => "application/json" })
3687
3994
  end
3995
+ stub_elastic_info
3688
3996
  driver.run(default_tag: 'test') do
3689
3997
  driver.feed(sample_record)
3690
3998
  end
@@ -3696,6 +4004,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3696
4004
  to_return(:status => 200, :body => "", :headers => {})
3697
4005
  elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
3698
4006
  with(headers: {'custom' => 'header1','and_others' => 'header2' })
4007
+ stub_elastic_info
3699
4008
  driver.configure(%[custom_headers {"custom":"header1", "and_others":"header2"}])
3700
4009
  driver.run(default_tag: 'test') do
3701
4010
  driver.feed(sample_record)
@@ -3708,6 +4017,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3708
4017
  to_return(:status => 200, :body => "", :headers => {})
3709
4018
  elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
3710
4019
  with(headers: {'Authorization'=>'ApiKey dGVzdGF1dGhoZWFkZXI='})
4020
+ stub_elastic_info
3711
4021
  driver.configure(%[api_key testauthheader])
3712
4022
  driver.run(default_tag: 'test') do
3713
4023
  driver.feed(sample_record)
@@ -3718,6 +4028,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3718
4028
  def test_write_message_with_bad_chunk
3719
4029
  driver.configure("target_index_key bad_value\n@log_level debug\n")
3720
4030
  stub_elastic
4031
+ stub_elastic_info
3721
4032
  driver.run(default_tag: 'test') do
3722
4033
  driver.feed({'bad_value'=>"\255"})
3723
4034
  end
@@ -3733,6 +4044,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3733
4044
  def test_writes_to_default_index(data)
3734
4045
  version, index_name = data
3735
4046
  stub_elastic
4047
+ stub_elastic_info
3736
4048
  driver("", version)
3737
4049
  driver.run(default_tag: 'test') do
3738
4050
  driver.feed(sample_record)
@@ -3751,7 +4063,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3751
4063
 
3752
4064
 
3753
4065
  def test_writes_to_default_index_with_compression
3754
- omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.2.0")
4066
+ omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.2.0")
3755
4067
 
3756
4068
  config = %[
3757
4069
  compression_level default_compression
@@ -3774,6 +4086,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3774
4086
 
3775
4087
  elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
3776
4088
  to_return(:status => 200, :headers => {'Content-Type' => 'Application/json'}, :body => compressed_body)
4089
+ stub_elastic_info("http://localhost:9200/")
3777
4090
 
3778
4091
  driver(config)
3779
4092
  driver.run(default_tag: 'test') do
@@ -3790,6 +4103,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3790
4103
  def test_writes_to_default_type(data)
3791
4104
  version, index_type = data
3792
4105
  stub_elastic
4106
+ stub_elastic_info
3793
4107
  driver("", version)
3794
4108
  driver.run(default_tag: 'test') do
3795
4109
  driver.feed(sample_record)
@@ -3800,6 +4114,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3800
4114
  def test_writes_to_speficied_index
3801
4115
  driver.configure("index_name myindex\n")
3802
4116
  stub_elastic
4117
+ stub_elastic_info
3803
4118
  driver.run(default_tag: 'test') do
3804
4119
  driver.feed(sample_record)
3805
4120
  end
@@ -3819,6 +4134,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3819
4134
  ]
3820
4135
  ))
3821
4136
  request = stub_elastic
4137
+ stub_elastic_info
3822
4138
  driver.run(default_tag: 'test') do
3823
4139
  driver.feed(sample_record('huge_record' => ("a" * 20 * 1024 * 1024)))
3824
4140
  driver.feed(sample_record('huge_record' => ("a" * 20 * 1024 * 1024)))
@@ -3838,11 +4154,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3838
4154
  }, [])
3839
4155
  ]
3840
4156
  ))
4157
+ index_part = if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
4158
+ '{"index":{"_index":"fluentd"}}'
4159
+ elsif Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.0.0")
4160
+ '{"index":{"_index":"fluentd","_type":"_doc"}}'
4161
+ else
4162
+ '{"index":{"_index":"fluentd","_type":"fluentd"}}'
4163
+ end
3841
4164
  stub_request(:post, "http://localhost:9200/_bulk").
3842
4165
  with(
3843
- body: /{"index":{"_index":"fluentd","_type":"fluentd"}}\n{"age":26,"request_id":"42","parent_id":"parent","routing_id":"routing","#{chunk_id_key}":".*"}\n/) do |req|
4166
+ body: /#{index_part}\n{"age":26,"request_id":"42","parent_id":"parent","routing_id":"routing","#{chunk_id_key}":".*"}\n/) do |req|
3844
4167
  @index_cmds = req.body.split("\n").map {|r| JSON.parse(r) }
3845
4168
  end
4169
+ stub_elastic_info
3846
4170
  driver.run(default_tag: 'test', shutdown: false) do
3847
4171
  driver.feed(sample_record)
3848
4172
  end
@@ -3872,6 +4196,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3872
4196
  ]
3873
4197
  ))
3874
4198
  request = stub_elastic
4199
+ stub_elastic_info
3875
4200
  driver.run(default_tag: 'test') do
3876
4201
  driver.feed(sample_record('huge_record' => ("a" * 20 * 1024 * 1024)))
3877
4202
  driver.feed(sample_record('huge_record' => ("a" * 20 * 1024 * 1024)))
@@ -3884,6 +4209,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3884
4209
  def test_writes_to_speficied_index_with_tag_placeholder
3885
4210
  driver.configure("index_name myindex.${tag}\n")
3886
4211
  stub_elastic
4212
+ stub_elastic_info
3887
4213
  driver.run(default_tag: 'test') do
3888
4214
  driver.feed(sample_record)
3889
4215
  end
@@ -3903,6 +4229,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3903
4229
  ]
3904
4230
  ))
3905
4231
  stub_elastic
4232
+ stub_elastic_info
3906
4233
  time = Time.parse Date.today.iso8601
3907
4234
  driver.run(default_tag: 'test') do
3908
4235
  driver.feed(time.to_i, sample_record)
@@ -3923,6 +4250,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3923
4250
  pipeline_id = "mypipeline"
3924
4251
  logstash_index = "myindex.#{pipeline_id}"
3925
4252
  stub_elastic
4253
+ stub_elastic_info
3926
4254
  driver.run(default_tag: 'test') do
3927
4255
  driver.feed(time.to_i, sample_record.merge({"pipeline_id" => pipeline_id}))
3928
4256
  end
@@ -3933,6 +4261,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3933
4261
  def test_writes_to_speficied_index_uppercase
3934
4262
  driver.configure("index_name MyIndex\n")
3935
4263
  stub_elastic
4264
+ stub_elastic_info
3936
4265
  driver.run(default_tag: 'test') do
3937
4266
  driver.feed(sample_record)
3938
4267
  end
@@ -3944,6 +4273,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3944
4273
  def test_writes_to_target_index_key
3945
4274
  driver.configure("target_index_key @target_index\n")
3946
4275
  stub_elastic
4276
+ stub_elastic_info
3947
4277
  record = sample_record.clone
3948
4278
  driver.run(default_tag: 'test') do
3949
4279
  driver.feed(sample_record.merge('@target_index' => 'local-override'))
@@ -3957,17 +4287,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3957
4287
  logstash_format true")
3958
4288
  time = Time.parse Date.today.iso8601
3959
4289
  stub_elastic
4290
+ stub_elastic_info
3960
4291
  driver.run(default_tag: 'test') do
3961
4292
  driver.feed(time.to_i, sample_record.merge('@target_index' => 'local-override'))
3962
4293
  end
3963
4294
  assert_equal('local-override', index_cmds.first['index']['_index'])
3964
4295
  end
3965
4296
 
3966
- def test_writes_to_target_index_key_logstash_uppercase
4297
+ def test_writes_to_target_index_key_logstash_uppercase
3967
4298
  driver.configure("target_index_key @target_index
3968
4299
  logstash_format true")
3969
4300
  time = Time.parse Date.today.iso8601
3970
4301
  stub_elastic
4302
+ stub_elastic_info
3971
4303
  driver.run(default_tag: 'test') do
3972
4304
  driver.feed(time.to_i, sample_record.merge('@target_index' => 'LOCAL-OVERRIDE'))
3973
4305
  end
@@ -3980,17 +4312,203 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
3980
4312
  pipeline = "fluentd"
3981
4313
  driver.configure("pipeline #{pipeline}")
3982
4314
  stub_elastic
4315
+ stub_elastic_info
3983
4316
  driver.run(default_tag: 'test') do
3984
4317
  driver.feed(sample_record)
3985
4318
  end
3986
4319
  assert_equal(pipeline, index_cmds.first['index']['pipeline'])
3987
4320
  end
3988
4321
 
4322
+ def stub_elastic_affinity_target_index_search_with_body(url="http://localhost:9200/logstash-*/_search", ids, return_body_str)
4323
+ # Note: ids used in query is unique list of ids
4324
+ stub_request(:post, url)
4325
+ .with(
4326
+ body: "{\"query\":{\"ids\":{\"values\":#{ids.uniq.to_json}}},\"_source\":false,\"sort\":[{\"_index\":{\"order\":\"desc\"}}]}",
4327
+ )
4328
+ .to_return(lambda do |req|
4329
+ { :status => 200,
4330
+ :headers => { 'Content-Type' => 'json' },
4331
+ :body => return_body_str
4332
+ }
4333
+ end)
4334
+ end
4335
+
4336
+ def stub_elastic_affinity_target_index_search(url="http://localhost:9200/logstash-*/_search", ids, indices)
4337
+ # Example ids and indices arrays.
4338
+ # [ "3408a2c8eecd4fbfb82e45012b54fa82", "2816fc6ef4524b3f8f7e869002005433"]
4339
+ # [ "logstash-2021.04.28", "logstash-2021.04.29"]
4340
+ body = %({
4341
+ "took" : 31,
4342
+ "timed_out" : false,
4343
+ "_shards" : {
4344
+ "total" : 52,
4345
+ "successful" : 52,
4346
+ "skipped" : 48,
4347
+ "failed" : 0
4348
+ },
4349
+ "hits" : {
4350
+ "total" : {
4351
+ "value" : 356,
4352
+ "relation" : "eq"
4353
+ },
4354
+ "max_score" : null,
4355
+ "hits" : [
4356
+ {
4357
+ "_index" : "#{indices[0]}",
4358
+ "_type" : "_doc",
4359
+ "_id" : "#{ids[0]}",
4360
+ "_score" : null,
4361
+ "sort" : [
4362
+ "#{indices[0]}"
4363
+ ]
4364
+ },
4365
+ {
4366
+ "_index" : "#{indices[1]}",
4367
+ "_type" : "_doc",
4368
+ "_id" : "#{ids[1]}",
4369
+ "_score" : null,
4370
+ "sort" : [
4371
+ "#{indices[1]}"
4372
+ ]
4373
+ }
4374
+ ]
4375
+ }
4376
+ })
4377
+ stub_elastic_affinity_target_index_search_with_body(ids, body)
4378
+ end
4379
+
4380
+ def stub_elastic_affinity_target_index_search_return_empty(url="http://localhost:9200/logstash-*/_search", ids)
4381
+ empty_body = %({
4382
+ "took" : 5,
4383
+ "timed_out" : false,
4384
+ "_shards" : {
4385
+ "total" : 54,
4386
+ "successful" : 54,
4387
+ "skipped" : 53,
4388
+ "failed" : 0
4389
+ },
4390
+ "hits" : {
4391
+ "total" : {
4392
+ "value" : 0,
4393
+ "relation" : "eq"
4394
+ },
4395
+ "max_score" : null,
4396
+ "hits" : [ ]
4397
+ }
4398
+ })
4399
+ stub_elastic_affinity_target_index_search_with_body(ids, empty_body)
4400
+ end
4401
+
4402
+ def test_writes_to_affinity_target_index
4403
+ driver.configure("target_index_affinity true
4404
+ logstash_format true
4405
+ id_key my_id
4406
+ write_operation update")
4407
+
4408
+ my_id_value = "3408a2c8eecd4fbfb82e45012b54fa82"
4409
+ ids = [my_id_value]
4410
+ indices = ["logstash-2021.04.28"]
4411
+ stub_elastic
4412
+ stub_elastic_info
4413
+ stub_elastic_affinity_target_index_search(ids, indices)
4414
+ driver.run(default_tag: 'test') do
4415
+ driver.feed(sample_record('my_id' => my_id_value))
4416
+ end
4417
+ assert_equal('logstash-2021.04.28', index_cmds.first['update']['_index'])
4418
+ end
4419
+
4420
+ def test_writes_to_affinity_target_index_write_operation_upsert
4421
+ driver.configure("target_index_affinity true
4422
+ logstash_format true
4423
+ id_key my_id
4424
+ write_operation upsert")
4425
+
4426
+ my_id_value = "3408a2c8eecd4fbfb82e45012b54fa82"
4427
+ ids = [my_id_value]
4428
+ indices = ["logstash-2021.04.28"]
4429
+ stub_elastic
4430
+ stub_elastic_info
4431
+ stub_elastic_affinity_target_index_search(ids, indices)
4432
+ driver.run(default_tag: 'test') do
4433
+ driver.feed(sample_record('my_id' => my_id_value))
4434
+ end
4435
+ assert_equal('logstash-2021.04.28', index_cmds.first['update']['_index'])
4436
+ end
4437
+
4438
+ def test_writes_to_affinity_target_index_index_not_exists_yet
4439
+ driver.configure("target_index_affinity true
4440
+ logstash_format true
4441
+ id_key my_id
4442
+ write_operation update")
4443
+
4444
+ my_id_value = "3408a2c8eecd4fbfb82e45012b54fa82"
4445
+ ids = [my_id_value]
4446
+ stub_elastic
4447
+ stub_elastic_info
4448
+ stub_elastic_affinity_target_index_search_return_empty(ids)
4449
+ time = Time.parse Date.today.iso8601
4450
+ driver.run(default_tag: 'test') do
4451
+ driver.feed(time.to_i, sample_record('my_id' => my_id_value))
4452
+ end
4453
+ assert_equal("logstash-#{time.utc.strftime("%Y.%m.%d")}", index_cmds.first['update']['_index'])
4454
+ end
4455
+
4456
+ def test_writes_to_affinity_target_index_multiple_indices
4457
+ driver.configure("target_index_affinity true
4458
+ logstash_format true
4459
+ id_key my_id
4460
+ write_operation update")
4461
+
4462
+ my_id_value = "2816fc6ef4524b3f8f7e869002005433"
4463
+ my_id_value2 = "3408a2c8eecd4fbfb82e45012b54fa82"
4464
+ ids = [my_id_value, my_id_value2]
4465
+ indices = ["logstash-2021.04.29", "logstash-2021.04.28"]
4466
+ stub_elastic_info
4467
+ stub_elastic_all_requests
4468
+ stub_elastic_affinity_target_index_search(ids, indices)
4469
+ driver.run(default_tag: 'test') do
4470
+ driver.feed(sample_record('my_id' => my_id_value))
4471
+ driver.feed(sample_record('my_id' => my_id_value2))
4472
+ end
4473
+ assert_equal(2, index_cmds_all_requests.count)
4474
+ assert_equal('logstash-2021.04.29', index_cmds_all_requests[0].first['update']['_index'])
4475
+ assert_equal(my_id_value, index_cmds_all_requests[0].first['update']['_id'])
4476
+ assert_equal('logstash-2021.04.28', index_cmds_all_requests[1].first['update']['_index'])
4477
+ assert_equal(my_id_value2, index_cmds_all_requests[1].first['update']['_id'])
4478
+ end
4479
+
4480
+ def test_writes_to_affinity_target_index_same_id_dublicated_write_to_oldest_index
4481
+ driver.configure("target_index_affinity true
4482
+ logstash_format true
4483
+ id_key my_id
4484
+ write_operation update")
4485
+
4486
+ my_id_value = "2816fc6ef4524b3f8f7e869002005433"
4487
+ # It may happen than same id has inserted to two index while data inserted during rollover period
4488
+ ids = [my_id_value, my_id_value]
4489
+ # Simulate the used sorting here, as search sorts indices in DESC order to pick only oldest index per single _id
4490
+ indices = ["logstash-2021.04.29", "logstash-2021.04.28"]
4491
+
4492
+ stub_elastic_info
4493
+ stub_elastic_all_requests
4494
+ stub_elastic_affinity_target_index_search(ids, indices)
4495
+ driver.run(default_tag: 'test') do
4496
+ driver.feed(sample_record('my_id' => my_id_value))
4497
+ driver.feed(sample_record('my_id' => my_id_value))
4498
+ end
4499
+ assert_equal('logstash-2021.04.28', index_cmds.first['update']['_index'])
4500
+
4501
+ assert_equal(1, index_cmds_all_requests.count)
4502
+ assert_equal('logstash-2021.04.28', index_cmds_all_requests[0].first['update']['_index'])
4503
+ assert_equal(my_id_value, index_cmds_all_requests[0].first['update']['_id'])
4504
+ end
4505
+
3989
4506
  class PipelinePlaceholdersTest < self
3990
4507
  def test_writes_to_default_index_with_pipeline_tag_placeholder
3991
4508
  pipeline = "fluentd-${tag}"
3992
4509
  driver.configure("pipeline #{pipeline}")
3993
4510
  stub_elastic
4511
+ stub_elastic_info
3994
4512
  driver.run(default_tag: 'test.builtin.placeholder') do
3995
4513
  driver.feed(sample_record)
3996
4514
  end
@@ -4012,6 +4530,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4012
4530
  time = Time.parse Date.today.iso8601
4013
4531
  pipeline = "fluentd-#{time.getutc.strftime("%Y%m%d")}"
4014
4532
  stub_elastic
4533
+ stub_elastic_info
4015
4534
  driver.run(default_tag: 'test') do
4016
4535
  driver.feed(time.to_i, sample_record)
4017
4536
  end
@@ -4031,6 +4550,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4031
4550
  pipeline_id = "mypipeline"
4032
4551
  logstash_index = "fluentd-#{pipeline_id}"
4033
4552
  stub_elastic
4553
+ stub_elastic_info
4034
4554
  driver.run(default_tag: 'test') do
4035
4555
  driver.feed(time.to_i, sample_record.merge({"pipeline_id" => pipeline_id}))
4036
4556
  end
@@ -4041,6 +4561,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4041
4561
  def test_writes_to_target_index_key_fallack
4042
4562
  driver.configure("target_index_key @target_index\n")
4043
4563
  stub_elastic
4564
+ stub_elastic_info
4044
4565
  driver.run(default_tag: 'test') do
4045
4566
  driver.feed(sample_record)
4046
4567
  end
@@ -4053,6 +4574,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4053
4574
  time = Time.parse Date.today.iso8601
4054
4575
  logstash_index = "logstash-#{time.getutc.strftime("%Y.%m.%d")}"
4055
4576
  stub_elastic
4577
+ stub_elastic_info
4056
4578
  driver.run(default_tag: 'test') do
4057
4579
  driver.feed(time.to_i, sample_record)
4058
4580
  end
@@ -4066,6 +4588,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4066
4588
  def test_writes_to_speficied_type(data)
4067
4589
  driver('', data["es_version"]).configure("type_name mytype\n")
4068
4590
  stub_elastic
4591
+ stub_elastic_info
4069
4592
  driver.run(default_tag: 'test') do
4070
4593
  driver.feed(sample_record)
4071
4594
  end
@@ -4079,6 +4602,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4079
4602
  def test_writes_to_speficied_type_with_placeholders(data)
4080
4603
  driver('', data["es_version"]).configure("type_name mytype.${tag}\n")
4081
4604
  stub_elastic
4605
+ stub_elastic_info
4082
4606
  driver.run(default_tag: 'test') do
4083
4607
  driver.feed(sample_record)
4084
4608
  end
@@ -4093,6 +4617,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4093
4617
  driver('', data["es_version"])
4094
4618
  .configure("type_name mytype.${tag}\nsuppress_type_name true")
4095
4619
  stub_elastic
4620
+ stub_elastic_info
4096
4621
  driver.run(default_tag: 'test') do
4097
4622
  driver.feed(sample_record)
4098
4623
  end
@@ -4107,6 +4632,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4107
4632
  def test_writes_to_target_type_key(data)
4108
4633
  driver('', data["es_version"]).configure("target_type_key @target_type\n")
4109
4634
  stub_elastic
4635
+ stub_elastic_info
4110
4636
  record = sample_record.clone
4111
4637
  driver.run(default_tag: 'test') do
4112
4638
  driver.feed(sample_record.merge('@target_type' => 'local-override'))
@@ -4118,20 +4644,34 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4118
4644
  def test_writes_to_target_type_key_fallack_to_default
4119
4645
  driver.configure("target_type_key @target_type\n")
4120
4646
  stub_elastic
4647
+ stub_elastic_info
4121
4648
  driver.run(default_tag: 'test') do
4122
4649
  driver.feed(sample_record)
4123
4650
  end
4124
- assert_equal(default_type_name, index_cmds.first['index']['_type'])
4651
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
4652
+ assert_nil(index_cmds.first['index']['_type'])
4653
+ elsif Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.0.0")
4654
+ assert_equal("_doc", index_cmds.first['index']['_type'])
4655
+ else
4656
+ assert_equal("fluentd", index_cmds.first['index']['_type'])
4657
+ end
4125
4658
  end
4126
4659
 
4127
4660
  def test_writes_to_target_type_key_fallack_to_type_name
4128
4661
  driver.configure("target_type_key @target_type
4129
4662
  type_name mytype")
4130
4663
  stub_elastic
4664
+ stub_elastic_info
4131
4665
  driver.run(default_tag: 'test') do
4132
4666
  driver.feed(sample_record)
4133
4667
  end
4134
- assert_equal('mytype', index_cmds.first['index']['_type'])
4668
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
4669
+ assert_nil(index_cmds.first['index']['_type'])
4670
+ elsif Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.0.0")
4671
+ assert_equal("_doc", index_cmds.first['index']['_type'])
4672
+ else
4673
+ assert_equal("fluentd", index_cmds.first['index']['_type'])
4674
+ end
4135
4675
  end
4136
4676
 
4137
4677
  data("old" => {"es_version" => 2, "_type" => "local-override"},
@@ -4142,6 +4682,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4142
4682
  def test_writes_to_target_type_key_nested(data)
4143
4683
  driver('', data["es_version"]).configure("target_type_key kubernetes.labels.log_type\n")
4144
4684
  stub_elastic
4685
+ stub_elastic_info
4145
4686
  driver.run(default_tag: 'test') do
4146
4687
  driver.feed(sample_record.merge('kubernetes' => {
4147
4688
  'labels' => {
@@ -4156,6 +4697,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4156
4697
  def test_writes_to_target_type_key_fallack_to_default_nested
4157
4698
  driver.configure("target_type_key kubernetes.labels.log_type\n")
4158
4699
  stub_elastic
4700
+ stub_elastic_info
4159
4701
  driver.run(default_tag: 'test') do
4160
4702
  driver.feed(sample_record.merge('kubernetes' => {
4161
4703
  'labels' => {
@@ -4163,12 +4705,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4163
4705
  }
4164
4706
  }))
4165
4707
  end
4166
- assert_equal(default_type_name, index_cmds.first['index']['_type'])
4708
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
4709
+ assert_nil(index_cmds.first['index']['_type'])
4710
+ elsif Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.0.0")
4711
+ assert_equal("_doc", index_cmds.first['index']['_type'])
4712
+ else
4713
+ assert_equal("fluentd", index_cmds.first['index']['_type'])
4714
+ end
4167
4715
  end
4168
4716
 
4169
4717
  def test_writes_to_speficied_host
4170
4718
  driver.configure("host 192.168.33.50\n")
4171
4719
  elastic_request = stub_elastic("http://192.168.33.50:9200/_bulk")
4720
+ stub_elastic_info("http://192.168.33.50:9200/")
4172
4721
  driver.run(default_tag: 'test') do
4173
4722
  driver.feed(sample_record)
4174
4723
  end
@@ -4178,6 +4727,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4178
4727
  def test_writes_to_speficied_port
4179
4728
  driver.configure("port 9201\n")
4180
4729
  elastic_request = stub_elastic("http://localhost:9201/_bulk")
4730
+ stub_elastic_info("http://localhost:9201")
4181
4731
  driver.run(default_tag: 'test') do
4182
4732
  driver.feed(sample_record)
4183
4733
  end
@@ -4193,6 +4743,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4193
4743
  hosts.each do |host_info|
4194
4744
  host, port = host_info
4195
4745
  stub_elastic_with_store_index_command_counts("http://#{host}:#{port}/_bulk")
4746
+ stub_elastic_info("http://#{host}:#{port}/")
4196
4747
  end
4197
4748
 
4198
4749
  driver.run(default_tag: 'test') do
@@ -4229,6 +4780,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4229
4780
  ]}
4230
4781
 
4231
4782
  stub_elastic
4783
+ stub_elastic_info
4232
4784
  driver.run(default_tag: 'test') do
4233
4785
  driver.feed(original_hash)
4234
4786
  end
@@ -4242,6 +4794,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4242
4794
  expected_output = {"foo" => {"bar" => "baz"}}
4243
4795
 
4244
4796
  stub_elastic
4797
+ stub_elastic_info
4245
4798
  driver.run(default_tag: 'test') do
4246
4799
  driver.feed(original_hash)
4247
4800
  end
@@ -4250,6 +4803,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4250
4803
 
4251
4804
  def test_makes_bulk_request
4252
4805
  stub_elastic
4806
+ stub_elastic_info
4253
4807
  driver.run(default_tag: 'test') do
4254
4808
  driver.feed(sample_record)
4255
4809
  driver.feed(sample_record.merge('age' => 27))
@@ -4257,8 +4811,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4257
4811
  assert_equal(4, index_cmds.count)
4258
4812
  end
4259
4813
 
4260
- def test_all_records_are_preserved_in_bulk
4814
+ def test_all_re
4261
4815
  stub_elastic
4816
+ stub_elastic_info
4262
4817
  driver.run(default_tag: 'test') do
4263
4818
  driver.feed(sample_record)
4264
4819
  driver.feed(sample_record.merge('age' => 27))
@@ -4274,6 +4829,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4274
4829
  dt = DateTime.new(2015, 6, 1, 0, 0, 1, "+01:00")
4275
4830
  logstash_index = "logstash-2015.05.31"
4276
4831
  stub_elastic
4832
+ stub_elastic_info
4277
4833
  driver.run(default_tag: 'test') do
4278
4834
  driver.feed(dt.to_time.to_i, sample_record)
4279
4835
  end
@@ -4288,6 +4844,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4288
4844
  time = Date.today.to_time
4289
4845
  index = "logstash-#{time.strftime("%Y.%m.%d")}"
4290
4846
  stub_elastic
4847
+ stub_elastic_info
4291
4848
  driver.run(default_tag: 'test') do
4292
4849
  driver.feed(time.to_i, sample_record)
4293
4850
  end
@@ -4300,6 +4857,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4300
4857
  time = Time.parse Date.today.iso8601
4301
4858
  logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m.%d")}"
4302
4859
  stub_elastic
4860
+ stub_elastic_info
4303
4861
  driver.run(default_tag: 'test') do
4304
4862
  driver.feed(time.to_i, sample_record)
4305
4863
  end
@@ -4314,6 +4872,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4314
4872
  time = Time.parse Date.today.iso8601
4315
4873
  logstash_index = "myprefix#{separator}#{time.getutc.strftime("%Y.%m.%d")}"
4316
4874
  stub_elastic
4875
+ stub_elastic_info
4317
4876
  driver.run(default_tag: 'test') do
4318
4877
  driver.feed(time.to_i, sample_record)
4319
4878
  end
@@ -4327,6 +4886,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4327
4886
  time = Time.parse Date.today.iso8601
4328
4887
  logstash_index = "myprefix-test-#{time.getutc.strftime("%Y.%m.%d")}"
4329
4888
  stub_elastic
4889
+ stub_elastic_info
4330
4890
  driver.run(default_tag: 'test') do
4331
4891
  driver.feed(time.to_i, sample_record)
4332
4892
  end
@@ -4349,6 +4909,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4349
4909
  time = Time.parse Date.today.iso8601
4350
4910
  logstash_index = "myprefix-#{time.getutc.strftime("%H")}-#{time.getutc.strftime("%Y.%m.%d")}"
4351
4911
  stub_elastic
4912
+ stub_elastic_info
4352
4913
  driver.run(default_tag: 'test') do
4353
4914
  driver.feed(time.to_i, sample_record)
4354
4915
  end
@@ -4369,6 +4930,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4369
4930
  pipeline_id = "mypipeline"
4370
4931
  logstash_index = "myprefix-#{pipeline_id}-#{time.getutc.strftime("%Y.%m.%d")}"
4371
4932
  stub_elastic
4933
+ stub_elastic_info
4372
4934
  driver.run(default_tag: 'test') do
4373
4935
  driver.feed(time.to_i, sample_record.merge({"pipeline_id" => pipeline_id}))
4374
4936
  end
@@ -4394,6 +4956,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4394
4956
  time = Time.parse Date.today.iso8601
4395
4957
  logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m.%d")}"
4396
4958
  stub_elastic
4959
+ stub_elastic_info
4397
4960
  driver.run(default_tag: 'test') do
4398
4961
  driver.feed(time.to_i, sample_record.merge('indexformat' => '%Y.%m.%d'))
4399
4962
  end
@@ -4417,6 +4980,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4417
4980
  time = Time.parse Date.today.iso8601
4418
4981
  logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m")}"
4419
4982
  stub_elastic
4983
+ stub_elastic_info
4420
4984
  driver.run(default_tag: 'test') do
4421
4985
  driver.feed(time.to_i, sample_record.merge('indexformat' => '%Y.%m'))
4422
4986
  end
@@ -4429,6 +4993,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4429
4993
  driver.configure("host ${tag}\n")
4430
4994
  time = Time.parse Date.today.iso8601
4431
4995
  elastic_request = stub_elastic("http://extracted-host:9200/_bulk")
4996
+ stub_elastic_info("http://extracted-host:9200/")
4432
4997
  driver.run(default_tag: 'extracted-host') do
4433
4998
  driver.feed(time.to_i, sample_record)
4434
4999
  end
@@ -4445,6 +5010,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4445
5010
  host, port = host_info
4446
5011
  host = "extracted-host" if host == '${tag}'
4447
5012
  stub_elastic_with_store_index_command_counts("http://#{host}:#{port}/_bulk")
5013
+ stub_elastic_info("http://#{host}:#{port}")
4448
5014
  end
4449
5015
 
4450
5016
  driver.run(default_tag: 'extracted-host') do
@@ -4479,8 +5045,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4479
5045
  ]
4480
5046
  ))
4481
5047
  stub_elastic
5048
+ stub_elastic_info
4482
5049
  time = Time.parse Date.today.iso8601
4483
5050
  elastic_request = stub_elastic("http://host-#{time.utc.strftime('%Y%m%d')}:9200/_bulk")
5051
+ stub_elastic_info("http://host-#{time.utc.strftime('%Y%m%d')}:9200/")
4484
5052
  driver.run(default_tag: 'test') do
4485
5053
  driver.feed(time.to_i, sample_record)
4486
5054
  end
@@ -4501,6 +5069,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4501
5069
  second_pipeline_id = "2"
4502
5070
  first_request = stub_elastic("http://myhost-1:9200/_bulk")
4503
5071
  second_request = stub_elastic("http://myhost-2:9200/_bulk")
5072
+ stub_elastic_info("http://myhost-1:9200/")
5073
+ stub_elastic_info("http://myhost-2:9200/")
4504
5074
  driver.run(default_tag: 'test') do
4505
5075
  driver.feed(time.to_i, sample_record.merge({"pipeline_id" => first_pipeline_id}))
4506
5076
  driver.feed(time.to_i, sample_record.merge({"pipeline_id" => second_pipeline_id}))
@@ -4521,6 +5091,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4521
5091
  time = Time.parse Date.today.iso8601
4522
5092
  pipeline_id = "1"
4523
5093
  request = stub_elastic_unavailable("http://myhost-1:9200/_bulk")
5094
+ stub_elastic_info("http://myhost-1:9200/")
4524
5095
  exception = assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
4525
5096
  driver.run(default_tag: 'test') do
4526
5097
  driver.feed(time.to_i, sample_record.merge({"pipeline_id" => pipeline_id}))
@@ -4536,6 +5107,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4536
5107
  time = Time.parse Date.today.iso8601
4537
5108
  logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m.%d")}"
4538
5109
  stub_elastic
5110
+ stub_elastic_info
4539
5111
  driver.run(default_tag: 'test') do
4540
5112
  driver.feed(time.to_i, sample_record)
4541
5113
  end
@@ -4550,6 +5122,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4550
5122
  time = Time.parse Date.today.iso8601
4551
5123
  logstash_index = "logstash-#{time.getutc.strftime("%Y.%m")}"
4552
5124
  stub_elastic
5125
+ stub_elastic_info
4553
5126
  driver.run(default_tag: 'test') do
4554
5127
  driver.feed(time.to_i, sample_record)
4555
5128
  end
@@ -4563,6 +5136,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4563
5136
  time = Time.parse Date.today.iso8601
4564
5137
  logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m")}"
4565
5138
  stub_elastic
5139
+ stub_elastic_info
4566
5140
  driver.run(default_tag: 'test') do
4567
5141
  driver.feed(time.to_i, sample_record)
4568
5142
  end
@@ -4589,6 +5163,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4589
5163
 
4590
5164
  def test_doesnt_add_logstash_timestamp_by_default
4591
5165
  stub_elastic
5166
+ stub_elastic_info
4592
5167
  driver.run(default_tag: 'test') do
4593
5168
  driver.feed(sample_record)
4594
5169
  end
@@ -4598,6 +5173,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4598
5173
  def test_adds_timestamp_when_logstash
4599
5174
  driver.configure("logstash_format true\n")
4600
5175
  stub_elastic
5176
+ stub_elastic_info
4601
5177
  ts = DateTime.now
4602
5178
  time = Fluent::EventTime.from_time(ts.to_time)
4603
5179
  driver.run(default_tag: 'test') do
@@ -4610,6 +5186,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4610
5186
  def test_adds_timestamp_when_include_timestamp
4611
5187
  driver.configure("include_timestamp true\n")
4612
5188
  stub_elastic
5189
+ stub_elastic_info
4613
5190
  ts = DateTime.now
4614
5191
  time = Fluent::EventTime.from_time(ts.to_time)
4615
5192
  driver.run(default_tag: 'test') do
@@ -4622,6 +5199,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4622
5199
  def test_uses_custom_timestamp_when_included_in_record
4623
5200
  driver.configure("logstash_format true\n")
4624
5201
  stub_elastic
5202
+ stub_elastic_info
4625
5203
  ts = DateTime.new(2001,2,3).iso8601
4626
5204
  driver.run(default_tag: 'test') do
4627
5205
  driver.feed(sample_record.merge!('@timestamp' => ts))
@@ -4633,6 +5211,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4633
5211
  def test_uses_custom_timestamp_when_included_in_record_without_logstash
4634
5212
  driver.configure("include_timestamp true\n")
4635
5213
  stub_elastic
5214
+ stub_elastic_info
4636
5215
  ts = DateTime.new(2001,2,3).iso8601
4637
5216
  driver.run(default_tag: 'test') do
4638
5217
  driver.feed(sample_record.merge!('@timestamp' => ts))
@@ -4645,6 +5224,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4645
5224
  driver.configure("logstash_format true
4646
5225
  time_key vtm\n")
4647
5226
  stub_elastic
5227
+ stub_elastic_info
4648
5228
  ts = DateTime.new(2001,2,3).iso8601(9)
4649
5229
  driver.run(default_tag: 'test') do
4650
5230
  driver.feed(sample_record.merge!('vtm' => ts))
@@ -4658,6 +5238,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4658
5238
  time_precision 3
4659
5239
  time_key vtm\n")
4660
5240
  stub_elastic
5241
+ stub_elastic_info
4661
5242
  time = Time.now
4662
5243
  float_time = time.to_f
4663
5244
  driver.run(default_tag: 'test') do
@@ -4672,6 +5253,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4672
5253
  time_key_format %Y-%m-%d %H:%M:%S.%N%z
4673
5254
  time_key vtm\n")
4674
5255
  stub_elastic
5256
+ stub_elastic_info
4675
5257
  ts = "2001-02-03 13:14:01.673+02:00"
4676
5258
  driver.run(default_tag: 'test') do
4677
5259
  driver.feed(sample_record.merge!('vtm' => ts))
@@ -4686,6 +5268,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4686
5268
  time_key_format %Y-%m-%d %H:%M:%S.%N%z
4687
5269
  time_key vtm\n")
4688
5270
  stub_elastic
5271
+ stub_elastic_info
4689
5272
  ts = "2001-02-03 13:14:01.673+02:00"
4690
5273
  time = Time.parse(ts)
4691
5274
  current_zone_offset = Time.new(2001, 02, 03).to_datetime.offset
@@ -4703,6 +5286,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4703
5286
  time_key_format %Y-%m-%d %H:%M:%S.%N%z
4704
5287
  time_key vtm\n")
4705
5288
  stub_elastic
5289
+ stub_elastic_info
4706
5290
  ts = "2001-02-03 13:14:01.673+02:00"
4707
5291
  driver.run(default_tag: 'test') do
4708
5292
  driver.feed(sample_record.merge!('vtm' => ts))
@@ -4717,6 +5301,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4717
5301
  time_key vtm
4718
5302
  time_key_exclude_timestamp true\n")
4719
5303
  stub_elastic
5304
+ stub_elastic_info
4720
5305
  ts = DateTime.new(2001,2,3).iso8601
4721
5306
  driver.run(default_tag: 'test') do
4722
5307
  driver.feed(sample_record.merge!('vtm' => ts))
@@ -4728,6 +5313,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4728
5313
  driver.configure("logstash_format true
4729
5314
  time_key_format %Y-%m-%dT%H:%M:%S.%N%z\n")
4730
5315
  stub_elastic
5316
+ stub_elastic_info
4731
5317
  ts = "2001-02-03T13:14:01.673+02:00"
4732
5318
  driver.run(default_tag: 'test') do
4733
5319
  driver.feed(sample_record.merge!('@timestamp' => ts))
@@ -4742,6 +5328,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4742
5328
  index_name test
4743
5329
  time_key_format %Y-%m-%dT%H:%M:%S.%N%z\n")
4744
5330
  stub_elastic
5331
+ stub_elastic_info
4745
5332
  ts = "2001-02-03T13:14:01.673+02:00"
4746
5333
  driver.run(default_tag: 'test') do
4747
5334
  driver.feed(sample_record.merge!('@timestamp' => ts))
@@ -4759,6 +5346,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4759
5346
  driver.configure("logstash_format true
4760
5347
  time_key_format %Y-%m-%dT%H:%M:%S.%N%z\n#{tag_config}\n")
4761
5348
  stub_elastic
5349
+ stub_elastic_info
4762
5350
 
4763
5351
  ts = "2001/02/03 13:14:01,673+02:00"
4764
5352
  index = "logstash-#{Time.now.getutc.strftime("%Y.%m.%d")}"
@@ -4779,6 +5367,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4779
5367
  driver.configure("logstash_format true
4780
5368
  time_key_format %a %b %d %H:%M:%S %Z %Y\n")
4781
5369
  stub_elastic
5370
+ stub_elastic_info
4782
5371
  ts = "Thu Nov 29 14:33:20 GMT 2001"
4783
5372
  driver.run(default_tag: 'test') do
4784
5373
  driver.feed(sample_record.merge!('@timestamp' => ts))
@@ -4791,6 +5380,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4791
5380
  def test_uses_nanosecond_precision_by_default
4792
5381
  driver.configure("logstash_format true\n")
4793
5382
  stub_elastic
5383
+ stub_elastic_info
4794
5384
  time = Fluent::EventTime.new(Time.now.to_i, 123456789)
4795
5385
  driver.run(default_tag: 'test') do
4796
5386
  driver.feed(time, sample_record)
@@ -4803,6 +5393,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4803
5393
  driver.configure("logstash_format true
4804
5394
  time_precision 3\n")
4805
5395
  stub_elastic
5396
+ stub_elastic_info
4806
5397
  time = Fluent::EventTime.new(Time.now.to_i, 123456789)
4807
5398
  driver.run(default_tag: 'test') do
4808
5399
  driver.feed(time, sample_record)
@@ -4813,6 +5404,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4813
5404
 
4814
5405
  def test_doesnt_add_tag_key_by_default
4815
5406
  stub_elastic
5407
+ stub_elastic_info
4816
5408
  driver.run(default_tag: 'test') do
4817
5409
  driver.feed(sample_record)
4818
5410
  end
@@ -4822,6 +5414,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4822
5414
  def test_adds_tag_key_when_configured
4823
5415
  driver.configure("include_tag_key true\n")
4824
5416
  stub_elastic
5417
+ stub_elastic_info
4825
5418
  driver.run(default_tag: 'mytag') do
4826
5419
  driver.feed(sample_record)
4827
5420
  end
@@ -4832,6 +5425,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4832
5425
  def test_adds_id_key_when_configured
4833
5426
  driver.configure("id_key request_id\n")
4834
5427
  stub_elastic
5428
+ stub_elastic_info
4835
5429
  driver.run(default_tag: 'test') do
4836
5430
  driver.feed(sample_record)
4837
5431
  end
@@ -4842,6 +5436,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4842
5436
  def test_adds_nested_id_key_with_dot
4843
5437
  driver.configure("id_key nested.request_id\n")
4844
5438
  stub_elastic
5439
+ stub_elastic_info
4845
5440
  driver.run(default_tag: 'test') do
4846
5441
  driver.feed(nested_sample_record)
4847
5442
  end
@@ -4851,6 +5446,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4851
5446
  def test_adds_nested_id_key_with_dollar_dot
4852
5447
  driver.configure("id_key $.nested.request_id\n")
4853
5448
  stub_elastic
5449
+ stub_elastic_info
4854
5450
  driver.run(default_tag: 'test') do
4855
5451
  driver.feed(nested_sample_record)
4856
5452
  end
@@ -4860,6 +5456,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4860
5456
  def test_adds_nested_id_key_with_bracket
4861
5457
  driver.configure("id_key $['nested']['request_id']\n")
4862
5458
  stub_elastic
5459
+ stub_elastic_info
4863
5460
  driver.run(default_tag: 'test') do
4864
5461
  driver.feed(nested_sample_record)
4865
5462
  end
@@ -4870,6 +5467,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4870
5467
  def test_doesnt_add_id_key_if_missing_when_configured
4871
5468
  driver.configure("id_key another_request_id\n")
4872
5469
  stub_elastic
5470
+ stub_elastic_info
4873
5471
  driver.run(default_tag: 'test') do
4874
5472
  driver.feed(sample_record)
4875
5473
  end
@@ -4878,6 +5476,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4878
5476
 
4879
5477
  def test_adds_id_key_when_not_configured
4880
5478
  stub_elastic
5479
+ stub_elastic_info
4881
5480
  driver.run(default_tag: 'test') do
4882
5481
  driver.feed(sample_record)
4883
5482
  end
@@ -4887,6 +5486,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4887
5486
  def test_adds_parent_key_when_configured
4888
5487
  driver.configure("parent_key parent_id\n")
4889
5488
  stub_elastic
5489
+ stub_elastic_info
4890
5490
  driver.run(default_tag: 'test') do
4891
5491
  driver.feed(sample_record)
4892
5492
  end
@@ -4897,6 +5497,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4897
5497
  def test_adds_nested_parent_key_with_dot
4898
5498
  driver.configure("parent_key nested.parent_id\n")
4899
5499
  stub_elastic
5500
+ stub_elastic_info
4900
5501
  driver.run(default_tag: 'test') do
4901
5502
  driver.feed(nested_sample_record)
4902
5503
  end
@@ -4906,6 +5507,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4906
5507
  def test_adds_nested_parent_key_with_dollar_dot
4907
5508
  driver.configure("parent_key $.nested.parent_id\n")
4908
5509
  stub_elastic
5510
+ stub_elastic_info
4909
5511
  driver.run(default_tag: 'test') do
4910
5512
  driver.feed(nested_sample_record)
4911
5513
  end
@@ -4915,6 +5517,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4915
5517
  def test_adds_nested_parent_key_with_bracket
4916
5518
  driver.configure("parent_key $['nested']['parent_id']\n")
4917
5519
  stub_elastic
5520
+ stub_elastic_info
4918
5521
  driver.run(default_tag: 'test') do
4919
5522
  driver.feed(nested_sample_record)
4920
5523
  end
@@ -4925,6 +5528,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4925
5528
  def test_doesnt_add_parent_key_if_missing_when_configured
4926
5529
  driver.configure("parent_key another_parent_id\n")
4927
5530
  stub_elastic
5531
+ stub_elastic_info
4928
5532
  driver.run(default_tag: 'test') do
4929
5533
  driver.feed(sample_record)
4930
5534
  end
@@ -4933,6 +5537,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4933
5537
 
4934
5538
  def test_adds_parent_key_when_not_configured
4935
5539
  stub_elastic
5540
+ stub_elastic_info
4936
5541
  driver.run(default_tag: 'test') do
4937
5542
  driver.feed(sample_record)
4938
5543
  end
@@ -4943,19 +5548,23 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4943
5548
  def test_es6
4944
5549
  driver("routing_key routing_id\n", 6)
4945
5550
  stub_elastic
5551
+ stub_elastic_info
4946
5552
  driver.run(default_tag: 'test') do
4947
5553
  driver.feed(sample_record)
4948
5554
  end
4949
- assert_equal('routing', index_cmds[0]['index']['_routing'])
5555
+ routing_key = driver.instance.instance_variable_get(:@routing_key_name)
5556
+ assert_equal('routing', index_cmds[0]['index'][routing_key])
4950
5557
  end
4951
5558
 
4952
5559
  def test_es7
4953
5560
  driver("routing_key routing_id\n", 7)
4954
5561
  stub_elastic
5562
+ stub_elastic_info
4955
5563
  driver.run(default_tag: 'test') do
4956
5564
  driver.feed(sample_record)
4957
5565
  end
4958
- assert_equal('routing', index_cmds[0]['index']['routing'])
5566
+ routing_key = driver.instance.instance_variable_get(:@routing_key_name)
5567
+ assert_equal('routing', index_cmds[0]['index'][routing_key])
4959
5568
  end
4960
5569
  end
4961
5570
 
@@ -4963,51 +5572,62 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
4963
5572
  def test_adds_nested_routing_key_with_dot
4964
5573
  driver.configure("routing_key nested.routing_id\n")
4965
5574
  stub_elastic
5575
+ stub_elastic_info
4966
5576
  driver.run(default_tag: 'test') do
4967
5577
  driver.feed(nested_sample_record)
4968
5578
  end
4969
- assert_equal('routing', index_cmds[0]['index']['_routing'])
5579
+ routing_key = driver.instance.instance_variable_get(:@routing_key_name)
5580
+ assert_equal('routing', index_cmds[0]['index'][routing_key])
4970
5581
  end
4971
5582
 
4972
5583
  def test_adds_nested_routing_key_with_dollar_dot
4973
5584
  driver.configure("routing_key $.nested.routing_id\n")
4974
5585
  stub_elastic
5586
+ stub_elastic_info
4975
5587
  driver.run(default_tag: 'test') do
4976
5588
  driver.feed(nested_sample_record)
4977
5589
  end
4978
- assert_equal('routing', index_cmds[0]['index']['_routing'])
5590
+ routing_key = driver.instance.instance_variable_get(:@routing_key_name)
5591
+ assert_equal('routing', index_cmds[0]['index'][routing_key])
4979
5592
  end
4980
5593
 
4981
5594
  def test_adds_nested_routing_key_with_bracket
4982
5595
  driver.configure("routing_key $['nested']['routing_id']\n")
4983
5596
  stub_elastic
5597
+ stub_elastic_info
4984
5598
  driver.run(default_tag: 'test') do
4985
5599
  driver.feed(nested_sample_record)
4986
5600
  end
4987
- assert_equal('routing', index_cmds[0]['index']['_routing'])
5601
+ routing_key = driver.instance.instance_variable_get(:@routing_key_name)
5602
+ assert_equal('routing', index_cmds[0]['index'][routing_key])
4988
5603
  end
4989
5604
  end
4990
5605
 
4991
5606
  def test_doesnt_add_routing_key_if_missing_when_configured
4992
5607
  driver.configure("routing_key another_routing_id\n")
4993
5608
  stub_elastic
5609
+ stub_elastic_info
4994
5610
  driver.run(default_tag: 'test') do
4995
5611
  driver.feed(sample_record)
4996
5612
  end
4997
- assert(!index_cmds[0]['index'].has_key?('_routing'))
5613
+ routing_key = driver.instance.instance_variable_get(:@routing_key_name)
5614
+ assert(!index_cmds[0]['index'].has_key?(routing_key))
4998
5615
  end
4999
5616
 
5000
5617
  def test_adds_routing_key_when_not_configured
5001
5618
  stub_elastic
5619
+ stub_elastic_info
5002
5620
  driver.run(default_tag: 'test') do
5003
5621
  driver.feed(sample_record)
5004
5622
  end
5005
- assert(!index_cmds[0]['index'].has_key?('_routing'))
5623
+ routing_key = driver.instance.instance_variable_get(:@routing_key_name)
5624
+ assert(!index_cmds[0]['index'].has_key?(routing_key))
5006
5625
  end
5007
5626
 
5008
5627
  def test_remove_one_key
5009
5628
  driver.configure("remove_keys key1\n")
5010
5629
  stub_elastic
5630
+ stub_elastic_info
5011
5631
  driver.run(default_tag: 'test') do
5012
5632
  driver.feed(sample_record.merge('key1' => 'v1', 'key2' => 'v2'))
5013
5633
  end
@@ -5018,6 +5638,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5018
5638
  def test_remove_multi_keys
5019
5639
  driver.configure("remove_keys key1, key2\n")
5020
5640
  stub_elastic
5641
+ stub_elastic_info
5021
5642
  driver.run(default_tag: 'test') do
5022
5643
  driver.feed(sample_record.merge('key1' => 'v1', 'key2' => 'v2'))
5023
5644
  end
@@ -5026,6 +5647,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5026
5647
  end
5027
5648
 
5028
5649
  def test_request_error
5650
+ stub_elastic_info
5029
5651
  stub_elastic_unavailable
5030
5652
  assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
5031
5653
  driver.run(default_tag: 'test', shutdown: false) do
@@ -5037,6 +5659,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5037
5659
  def test_request_forever
5038
5660
  omit("retry_forever test is unstable.") if ENV["CI"]
5039
5661
  stub_elastic
5662
+ stub_elastic_info
5040
5663
  driver.configure(Fluent::Config::Element.new(
5041
5664
  'ROOT', '', {
5042
5665
  '@type' => 'elasticsearch',
@@ -5061,6 +5684,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5061
5684
  connection_resets += 1
5062
5685
  raise Faraday::ConnectionFailed, "Test message"
5063
5686
  end
5687
+ stub_elastic_info
5064
5688
 
5065
5689
  assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
5066
5690
  driver.run(default_tag: 'test', shutdown: false) do
@@ -5077,6 +5701,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5077
5701
  connection_resets += 1
5078
5702
  raise ZeroDivisionError, "any not host_unreachable_exceptions exception"
5079
5703
  end
5704
+ stub_elastic_info
5080
5705
 
5081
5706
  driver.configure("reconnect_on_error true\n")
5082
5707
 
@@ -5103,6 +5728,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5103
5728
  connection_resets += 1
5104
5729
  raise ZeroDivisionError, "any not host_unreachable_exceptions exception"
5105
5730
  end
5731
+ stub_elastic_info
5106
5732
 
5107
5733
  driver.configure("reconnect_on_error false\n")
5108
5734
 
@@ -5146,6 +5772,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5146
5772
  })
5147
5773
  }
5148
5774
  end)
5775
+ stub_elastic_info
5149
5776
 
5150
5777
  driver.run(default_tag: 'test') do
5151
5778
  driver.feed(1, sample_record)
@@ -5217,6 +5844,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5217
5844
  })
5218
5845
  }
5219
5846
  end)
5847
+ stub_elastic_info
5220
5848
 
5221
5849
  # Check buffer fulfillment condition
5222
5850
  assert_raise(Fluent::Plugin::ElasticsearchOutput::RetryStreamEmitFailure) do
@@ -5263,6 +5891,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5263
5891
  })
5264
5892
  }
5265
5893
  end)
5894
+ stub_elastic_info
5895
+
5266
5896
  sample_record1 = sample_record('my_id' => 'abc')
5267
5897
  sample_record4 = sample_record('my_id' => 'xyz')
5268
5898
 
@@ -5312,6 +5942,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5312
5942
  })
5313
5943
  }
5314
5944
  end)
5945
+ stub_elastic_info
5946
+
5315
5947
  sample_record1 = sample_record('my_id' => 'abc')
5316
5948
  sample_record4 = sample_record('my_id' => 'xyz')
5317
5949
 
@@ -5382,6 +6014,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5382
6014
  })
5383
6015
  }
5384
6016
  end)
6017
+ stub_elastic_info
5385
6018
 
5386
6019
  driver.run(default_tag: 'test') do
5387
6020
  driver.feed(1, sample_record)
@@ -5398,6 +6031,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5398
6031
  def test_update_should_not_write_if_theres_no_id
5399
6032
  driver.configure("write_operation update\n")
5400
6033
  stub_elastic
6034
+ stub_elastic_info
5401
6035
  driver.run(default_tag: 'test') do
5402
6036
  driver.feed(sample_record)
5403
6037
  end
@@ -5407,6 +6041,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5407
6041
  def test_upsert_should_not_write_if_theres_no_id
5408
6042
  driver.configure("write_operation upsert\n")
5409
6043
  stub_elastic
6044
+ stub_elastic_info
5410
6045
  driver.run(default_tag: 'test') do
5411
6046
  driver.feed(sample_record)
5412
6047
  end
@@ -5416,6 +6051,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5416
6051
  def test_create_should_not_write_if_theres_no_id
5417
6052
  driver.configure("write_operation create\n")
5418
6053
  stub_elastic
6054
+ stub_elastic_info
5419
6055
  driver.run(default_tag: 'test') do
5420
6056
  driver.feed(sample_record)
5421
6057
  end
@@ -5426,6 +6062,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5426
6062
  driver.configure("write_operation update
5427
6063
  id_key request_id")
5428
6064
  stub_elastic
6065
+ stub_elastic_info
5429
6066
  driver.run(default_tag: 'test') do
5430
6067
  driver.feed(sample_record)
5431
6068
  end
@@ -5439,6 +6076,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5439
6076
  id_key request_id
5440
6077
  remove_keys_on_update parent_id")
5441
6078
  stub_elastic
6079
+ stub_elastic_info
5442
6080
  driver.run(default_tag: 'test') do
5443
6081
  driver.feed(sample_record)
5444
6082
  end
@@ -5450,6 +6088,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5450
6088
  driver.configure("write_operation upsert
5451
6089
  id_key request_id")
5452
6090
  stub_elastic
6091
+ stub_elastic_info
5453
6092
  driver.run(default_tag: 'test') do
5454
6093
  driver.feed(sample_record)
5455
6094
  end
@@ -5463,6 +6102,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5463
6102
  id_key request_id
5464
6103
  remove_keys_on_update parent_id")
5465
6104
  stub_elastic
6105
+ stub_elastic_info
5466
6106
  driver.run(default_tag: 'test') do
5467
6107
  driver.feed(sample_record)
5468
6108
  end
@@ -5477,6 +6117,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5477
6117
  id_key request_id
5478
6118
  remove_keys_on_update parent_id")
5479
6119
  stub_elastic
6120
+ stub_elastic_info
5480
6121
  driver.run(default_tag: 'test') do
5481
6122
  driver.feed(sample_record)
5482
6123
  end
@@ -5490,6 +6131,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5490
6131
  id_key id
5491
6132
  remove_keys_on_update foo,baz")
5492
6133
  stub_elastic
6134
+ stub_elastic_info
5493
6135
  driver.run(default_tag: 'test') do
5494
6136
  driver.feed("id" => 1, "foo" => "bar", "baz" => "quix", "zip" => "zam")
5495
6137
  end
@@ -5514,6 +6156,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5514
6156
  id_key id
5515
6157
  remove_keys_on_update_key keys_to_skip")
5516
6158
  stub_elastic
6159
+ stub_elastic_info
5517
6160
  driver.run(default_tag: 'test') do
5518
6161
  driver.feed("id" => 1, "foo" => "bar", "baz" => "quix", "keys_to_skip" => ["baz"])
5519
6162
  end
@@ -5538,6 +6181,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5538
6181
  remove_keys_on_update foo,bar
5539
6182
  remove_keys_on_update_key keys_to_skip")
5540
6183
  stub_elastic
6184
+ stub_elastic_info
5541
6185
  driver.run(default_tag: 'test') do
5542
6186
  driver.feed("id" => 1, "foo" => "bar", "baz" => "quix", "keys_to_skip" => ["baz"])
5543
6187
  end
@@ -5562,6 +6206,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5562
6206
  driver.configure("write_operation create
5563
6207
  id_key request_id")
5564
6208
  stub_elastic
6209
+ stub_elastic_info
5565
6210
  driver.run(default_tag: 'test') do
5566
6211
  driver.feed(sample_record)
5567
6212
  end
@@ -5570,6 +6215,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5570
6215
 
5571
6216
  def test_include_index_in_url
5572
6217
  stub_elastic('http://localhost:9200/logstash-2018.01.01/_bulk')
6218
+ stub_elastic_info('http://localhost:9200/')
5573
6219
 
5574
6220
  driver.configure("index_name logstash-2018.01.01
5575
6221
  include_index_in_url true")
@@ -5583,8 +6229,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5583
6229
 
5584
6230
  def test_use_simple_sniffer
5585
6231
  require 'fluent/plugin/elasticsearch_simple_sniffer'
5586
- stub_elastic_info
5587
6232
  stub_elastic
6233
+ stub_elastic_info
5588
6234
  config = %[
5589
6235
  sniffer_class_name Fluent::Plugin::ElasticsearchSimpleSniffer
5590
6236
  log_level debug
@@ -5608,6 +6254,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5608
6254
  remove_keys id
5609
6255
  suppress_doc_wrap true')
5610
6256
  stub_elastic
6257
+ stub_elastic_info
5611
6258
  doc_body = {'field' => 'value'}
5612
6259
  script_body = {'source' => 'ctx._source.counter += params.param1',
5613
6260
  'lang' => 'painless',
@@ -5634,6 +6281,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5634
6281
  remove_keys id
5635
6282
  suppress_doc_wrap true')
5636
6283
  stub_elastic
6284
+ stub_elastic_info
5637
6285
  doc_body = {'field' => 'value'}
5638
6286
  script_body = {'source' => 'ctx._source.counter += params.param1',
5639
6287
  'lang' => 'painless',
@@ -5658,8 +6306,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5658
6306
  end
5659
6307
 
5660
6308
  def test_ignore_exception
5661
- driver.configure('ignore_exceptions ["Elasticsearch::Transport::Transport::Errors::ServiceUnavailable"]')
6309
+ ignore_classes = if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
6310
+ ["Elastic::Transport::Transport::Errors::ServiceUnavailable"]
6311
+ else
6312
+ ["Elasticsearch::Transport::Transport::Errors::ServiceUnavailable"]
6313
+ end
6314
+ driver.configure("ignore_exceptions #{ignore_classes}")
5662
6315
  stub_elastic_unavailable
6316
+ stub_elastic_info
5663
6317
 
5664
6318
  driver.run(default_tag: 'test') do
5665
6319
  driver.feed(sample_record)
@@ -5667,8 +6321,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5667
6321
  end
5668
6322
 
5669
6323
  def test_ignore_exception_with_superclass
5670
- driver.configure('ignore_exceptions ["Elasticsearch::Transport::Transport::ServerError"]')
6324
+ ignore_classes = if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
6325
+ ["Elastic::Transport::Transport::Errors::ServiceUnavailable"]
6326
+ else
6327
+ ["Elasticsearch::Transport::Transport::Errors::ServiceUnavailable"]
6328
+ end
6329
+ driver.configure("ignore_exceptions #{ignore_classes}")
5671
6330
  stub_elastic_unavailable
6331
+ stub_elastic_info
5672
6332
 
5673
6333
  driver.run(default_tag: 'test') do
5674
6334
  driver.feed(sample_record)
@@ -5678,6 +6338,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
5678
6338
  def test_ignore_excetion_handles_appropriate_ones
5679
6339
  driver.configure('ignore_exceptions ["Faraday::ConnectionFailed"]')
5680
6340
  stub_elastic_unavailable
6341
+ stub_elastic_info
5681
6342
 
5682
6343
  assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
5683
6344
  driver.run(default_tag: 'test', shutdown: false) do