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
@@ -16,7 +16,15 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
16
16
  @driver = nil
17
17
  end
18
18
 
19
- def driver(conf='', es_version=5)
19
+ def elasticsearch_version
20
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.14.0")
21
+ TRANSPORT_CLASS::VERSION
22
+ else
23
+ '6.4.2'.freeze
24
+ end
25
+ end
26
+
27
+ def driver(conf='', es_version=elasticsearch_version.to_i)
20
28
  # For request stub to detect compatibility.
21
29
  @es_version ||= es_version
22
30
  Fluent::Plugin::ElasticsearchOutputDynamic.module_eval(<<-CODE)
@@ -34,6 +42,14 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
34
42
  }.configure(conf)
35
43
  end
36
44
 
45
+ def elasticsearch_transport_layer_decoupling?
46
+ Gem::Version.create(::TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.14.0")
47
+ end
48
+
49
+ def elastic_transport_layer?
50
+ Gem::Version.create(::TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
51
+ end
52
+
37
53
  def default_type_name
38
54
  Fluent::Plugin::ElasticsearchOutput::DEFAULT_TYPE_NAME
39
55
  end
@@ -54,6 +70,11 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
54
70
  end
55
71
  end
56
72
 
73
+ def stub_elastic_info(url="http://localhost:9200/", version=elasticsearch_version)
74
+ body ="{\"version\":{\"number\":\"#{version}\", \"build_flavor\":\"default\"},\"tagline\" : \"You Know, for Search\"}"
75
+ stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json', 'x-elastic-product' => 'Elasticsearch' } })
76
+ end
77
+
57
78
  def stub_elastic_unavailable(url="http://localhost:9200/_bulk")
58
79
  stub_request(:post, url).to_return(:status => [503, "Service Unavailable"])
59
80
  end
@@ -123,7 +144,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
123
144
  end
124
145
 
125
146
  test 'configure compression' do
126
- omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.2.0")
147
+ omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.2.0")
127
148
 
128
149
  config = %{
129
150
  compression_level best_compression
@@ -134,7 +155,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
134
155
  end
135
156
 
136
157
  test 'check compression strategy' do
137
- omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.2.0")
158
+ omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.2.0")
138
159
 
139
160
  config = %{
140
161
  compression_level best_speed
@@ -145,43 +166,69 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
145
166
  end
146
167
 
147
168
  test 'check content-encoding header with compression' do
148
- omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.2.0")
169
+ omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.2.0")
149
170
 
150
171
  config = %{
151
172
  compression_level best_compression
152
173
  }
153
174
  instance = driver(config).instance
154
175
 
155
- assert_equal nil, instance.client.transport.options[:transport_options][:headers]["Content-Encoding"]
176
+ if elastic_transport_layer?
177
+ assert_equal nil, instance.client.transport.options[:transport_options][:headers]["Content-Encoding"]
178
+ elsif elasticsearch_transport_layer_decoupling?
179
+ assert_equal nil, instance.client.transport.transport.options[:transport_options][:headers]["Content-Encoding"]
180
+ else
181
+ assert_equal nil, instance.client.transport.options[:transport_options][:headers]["Content-Encoding"]
182
+ end
156
183
 
157
184
  stub_request(:post, "http://localhost:9200/_bulk").
158
185
  to_return(status: 200, body: "", headers: {})
186
+ stub_elastic_info
159
187
  driver.run(default_tag: 'test') do
160
188
  driver.feed(sample_record)
161
189
  end
162
190
  compressable = instance.compressable_connection
163
191
 
164
- assert_equal "gzip", instance.client(nil, compressable).transport.options[:transport_options][:headers]["Content-Encoding"]
192
+ if elastic_transport_layer?
193
+ assert_equal "gzip", instance.client(nil, compressable).transport.options[:transport_options][:headers]["Content-Encoding"]
194
+ elsif elasticsearch_transport_layer_decoupling?
195
+ assert_equal "gzip", instance.client(nil, compressable).transport.transport.options[:transport_options][:headers]["Content-Encoding"]
196
+ else
197
+ assert_equal "gzip", instance.client(nil, compressable).transport.options[:transport_options][:headers]["Content-Encoding"]
198
+ end
165
199
  end
166
200
 
167
201
  test 'check compression option is passed to transport' do
168
- omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.2.0")
202
+ omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.2.0")
169
203
 
170
204
  config = %{
171
205
  compression_level best_compression
172
206
  }
173
207
  instance = driver(config).instance
174
208
 
175
- assert_equal false, instance.client.transport.options[:compression]
209
+ if elastic_transport_layer?
210
+ assert_equal false, instance.client.transport.options[:compression]
211
+ elsif elasticsearch_transport_layer_decoupling?
212
+ assert_equal false, instance.client.transport.transport.options[:compression]
213
+ else
214
+ assert_equal false, instance.client.transport.options[:compression]
215
+ end
176
216
 
177
217
  stub_request(:post, "http://localhost:9200/_bulk").
178
218
  to_return(status: 200, body: "", headers: {})
219
+ stub_elastic_info
179
220
  driver.run(default_tag: 'test') do
180
221
  driver.feed(sample_record)
181
222
  end
182
223
  compressable = instance.compressable_connection
183
224
 
184
- assert_equal true, instance.client(nil, compressable).transport.options[:compression]
225
+ if elastic_transport_layer?
226
+ assert_equal true, instance.client(nil, compressable).transport.options[:compression]
227
+ elsif elasticsearch_transport_layer_decoupling?
228
+ assert_equal true, instance.client(nil, compressable).transport.transport.options[:compression]
229
+ else
230
+ assert_equal true, instance.client(nil, compressable).transport.options[:compression]
231
+ end
185
232
  end
186
233
 
187
234
  test 'configure Content-Type' do
@@ -348,6 +395,8 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
348
395
  elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
349
396
  with(headers: { "Content-Type" => "application/json" })
350
397
  end
398
+ stub_elastic_info('http://localhost:9200')
399
+
351
400
  driver.run(default_tag: 'test') do
352
401
  driver.feed(sample_record)
353
402
  end
@@ -356,6 +405,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
356
405
 
357
406
  def test_writes_to_default_index
358
407
  stub_elastic
408
+ stub_elastic_info
359
409
  driver.run(default_tag: 'test') do
360
410
  driver.feed(sample_record)
361
411
  end
@@ -372,7 +422,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
372
422
  end
373
423
 
374
424
  def test_writes_to_default_index_with_compression
375
- omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.2.0")
425
+ omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.2.0")
376
426
 
377
427
  config = %[
378
428
  compression_level default_compression
@@ -395,6 +445,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
395
445
 
396
446
  elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
397
447
  to_return(:status => 200, :headers => {'Content-Type' => 'Application/json'}, :body => compressed_body)
448
+ stub_elastic_info
398
449
 
399
450
  driver(config)
400
451
  driver.run(default_tag: 'test') do
@@ -406,15 +457,23 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
406
457
 
407
458
  def test_writes_to_default_type
408
459
  stub_elastic
460
+ stub_elastic_info
409
461
  driver.run(default_tag: 'test') do
410
462
  driver.feed(sample_record)
411
463
  end
412
- assert_equal(default_type_name, index_cmds.first['index']['_type'])
464
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
465
+ assert_nil(index_cmds.first['index']['_type'])
466
+ elsif Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.0.0")
467
+ assert_equal("_doc", index_cmds.first['index']['_type'])
468
+ else
469
+ assert_equal("fluentd", index_cmds.first['index']['_type'])
470
+ end
413
471
  end
414
472
 
415
473
  def test_writes_to_specified_index
416
474
  driver.configure("index_name myindex\n")
417
475
  stub_elastic
476
+ stub_elastic_info
418
477
  driver.run(default_tag: 'test') do
419
478
  driver.feed(sample_record)
420
479
  end
@@ -424,6 +483,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
424
483
  def test_writes_to_specified_index_uppercase
425
484
  driver.configure("index_name MyIndex\n")
426
485
  stub_elastic
486
+ stub_elastic_info
427
487
  driver.run(default_tag: 'test') do
428
488
  driver.feed(sample_record)
429
489
  end
@@ -433,15 +493,23 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
433
493
  def test_writes_to_specified_type
434
494
  driver.configure("type_name mytype\n")
435
495
  stub_elastic
496
+ stub_elastic_info
436
497
  driver.run(default_tag: 'test') do
437
498
  driver.feed(sample_record)
438
499
  end
439
- assert_equal('mytype', index_cmds.first['index']['_type'])
500
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
501
+ assert_nil(index_cmds.first['index']['_type'])
502
+ elsif Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.0.0")
503
+ assert_equal("_doc", index_cmds.first['index']['_type'])
504
+ else
505
+ assert_equal("mytype", index_cmds.first['index']['_type'])
506
+ end
440
507
  end
441
508
 
442
509
  def test_writes_to_specified_host
443
510
  driver.configure("host 192.168.33.50\n")
444
511
  elastic_request = stub_elastic("http://192.168.33.50:9200/_bulk")
512
+ stub_elastic_info("http://192.168.33.50:9200/")
445
513
  driver.run(default_tag: 'test') do
446
514
  driver.feed(sample_record)
447
515
  end
@@ -451,6 +519,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
451
519
  def test_writes_to_specified_port
452
520
  driver.configure("port 9201\n")
453
521
  elastic_request = stub_elastic("http://localhost:9201/_bulk")
522
+ stub_elastic_info("http://localhost:9201/")
454
523
  driver.run(default_tag: 'test') do
455
524
  driver.feed(sample_record)
456
525
  end
@@ -466,6 +535,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
466
535
  hosts.each do |host_info|
467
536
  host, port = host_info
468
537
  stub_elastic_with_store_index_command_counts("http://#{host}:#{port}/_bulk")
538
+ stub_elastic_info("http://#{host}:#{port}/")
469
539
  end
470
540
 
471
541
  driver.run(default_tag: 'test') do
@@ -501,6 +571,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
501
571
  ]}
502
572
 
503
573
  stub_elastic
574
+ stub_elastic_info
504
575
  driver.run(default_tag: 'test') do
505
576
  driver.feed(original_hash)
506
577
  end
@@ -514,6 +585,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
514
585
  expected_output = {"foo" => {"bar" => "baz"}}
515
586
 
516
587
  stub_elastic
588
+ stub_elastic_info
517
589
  driver.run(default_tag: 'test') do
518
590
  driver.feed(original_hash)
519
591
  end
@@ -522,6 +594,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
522
594
 
523
595
  def test_makes_bulk_request
524
596
  stub_elastic
597
+ stub_elastic_info
525
598
  driver.run(default_tag: 'test') do
526
599
  driver.feed(sample_record)
527
600
  driver.feed(sample_record.merge('age' => 27))
@@ -531,6 +604,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
531
604
 
532
605
  def test_all_records_are_preserved_in_bulk
533
606
  stub_elastic
607
+ stub_elastic_info
534
608
  driver.run(default_tag: 'test') do
535
609
  driver.feed(sample_record)
536
610
  driver.feed(sample_record.merge('age' => 27))
@@ -544,6 +618,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
544
618
  time = Time.parse Date.today.iso8601
545
619
  logstash_index = "logstash-#{time.getutc.strftime("%Y.%m.%d")}"
546
620
  stub_elastic
621
+ stub_elastic_info
547
622
  driver.run(default_tag: 'test') do
548
623
  driver.feed(time.to_i, sample_record)
549
624
  end
@@ -556,6 +631,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
556
631
  time = Time.parse Date.today.iso8601
557
632
  utc_index = "logstash-#{time.strftime("%Y.%m.%d")}"
558
633
  stub_elastic
634
+ stub_elastic_info
559
635
  driver.run(default_tag: 'test') do
560
636
  driver.feed(time.to_i, sample_record)
561
637
  end
@@ -568,6 +644,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
568
644
  time = Time.parse Date.today.iso8601
569
645
  logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m.%d")}"
570
646
  stub_elastic
647
+ stub_elastic_info
571
648
  driver.run(default_tag: 'test') do
572
649
  driver.feed(time.to_i, sample_record)
573
650
  end
@@ -582,6 +659,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
582
659
  time = Time.parse Date.today.iso8601
583
660
  logstash_index = "myprefix#{separator}#{time.getutc.strftime("%Y.%m.%d")}"
584
661
  stub_elastic
662
+ stub_elastic_info
585
663
  driver.run(default_tag: 'test') do
586
664
  driver.feed(time.to_i, sample_record)
587
665
  end
@@ -594,18 +672,20 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
594
672
  time = Time.parse Date.today.iso8601
595
673
  logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m.%d")}"
596
674
  stub_elastic
675
+ stub_elastic_info
597
676
  driver.run(default_tag: 'test') do
598
677
  driver.feed(time.to_i, sample_record)
599
678
  end
600
679
  assert_equal(logstash_index, index_cmds.first['index']['_index'])
601
680
  end
602
681
 
603
- def test_writes_to_logstash_index_with_specified_dateformat
682
+ def test_writes_to_logstash_index_with_specified_dateformat
604
683
  driver.configure("logstash_format true
605
684
  logstash_dateformat %Y.%m")
606
685
  time = Time.parse Date.today.iso8601
607
686
  logstash_index = "logstash-#{time.getutc.strftime("%Y.%m")}"
608
687
  stub_elastic
688
+ stub_elastic_info
609
689
  driver.run(default_tag: 'test') do
610
690
  driver.feed(time.to_i, sample_record)
611
691
  end
@@ -619,6 +699,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
619
699
  time = Time.parse Date.today.iso8601
620
700
  logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m")}"
621
701
  stub_elastic
702
+ stub_elastic_info
622
703
  driver.run(default_tag: 'test') do
623
704
  driver.feed(time.to_i, sample_record)
624
705
  end
@@ -627,6 +708,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
627
708
 
628
709
  def test_doesnt_add_logstash_timestamp_by_default
629
710
  stub_elastic
711
+ stub_elastic_info
630
712
  driver.run(default_tag: 'test') do
631
713
  driver.feed(sample_record)
632
714
  end
@@ -636,6 +718,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
636
718
  def test_adds_logstash_timestamp_when_configured
637
719
  driver.configure("logstash_format true\n")
638
720
  stub_elastic
721
+ stub_elastic_info
639
722
  time = Fluent::EventTime.new(Time.now.to_i, 123456789)
640
723
  driver.run(default_tag: 'test') do
641
724
  driver.feed(time, sample_record)
@@ -648,6 +731,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
648
731
  driver.configure("logstash_format true
649
732
  time_precision 3\n")
650
733
  stub_elastic
734
+ stub_elastic_info
651
735
  time = Fluent::EventTime.new(Time.now.to_i, 123456789)
652
736
  driver.run(default_tag: 'test') do
653
737
  driver.feed(time, sample_record)
@@ -659,6 +743,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
659
743
  def test_uses_custom_timestamp_when_included_in_record
660
744
  driver.configure("include_timestamp true\n")
661
745
  stub_elastic
746
+ stub_elastic_info
662
747
  ts = DateTime.new(2001,2,3).iso8601
663
748
  driver.run(default_tag: 'test') do
664
749
  driver.feed(sample_record.merge!('@timestamp' => ts))
@@ -670,6 +755,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
670
755
  def test_uses_custom_timestamp_when_included_in_record_logstash
671
756
  driver.configure("logstash_format true\n")
672
757
  stub_elastic
758
+ stub_elastic_info
673
759
  ts = DateTime.new(2001,2,3).iso8601
674
760
  driver.run(default_tag: 'test') do
675
761
  driver.feed(sample_record.merge!('@timestamp' => ts))
@@ -682,6 +768,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
682
768
  driver.configure("logstash_format true
683
769
  time_key vtm\n")
684
770
  stub_elastic
771
+ stub_elastic_info
685
772
  ts = DateTime.new(2001,2,3).iso8601
686
773
  driver.run(default_tag: 'test') do
687
774
  driver.feed(sample_record.merge!('vtm' => ts))
@@ -694,6 +781,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
694
781
  driver.configure("include_timestamp true
695
782
  time_key vtm\n")
696
783
  stub_elastic
784
+ stub_elastic_info
697
785
  ts = DateTime.new(2001,2,3).iso8601
698
786
  driver.run(default_tag: 'test') do
699
787
  driver.feed(sample_record.merge!('vtm' => ts))
@@ -707,6 +795,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
707
795
  index_name test
708
796
  time_key vtm\n")
709
797
  stub_elastic
798
+ stub_elastic_info
710
799
  ts = DateTime.new(2001,2,3).iso8601
711
800
  driver.run(default_tag: 'test') do
712
801
  driver.feed(sample_record.merge!('vtm' => ts))
@@ -721,6 +810,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
721
810
  time_key vtm
722
811
  time_key_exclude_timestamp true\n")
723
812
  stub_elastic
813
+ stub_elastic_info
724
814
  ts = DateTime.new(2001,2,3).iso8601
725
815
  driver.run(default_tag: 'test') do
726
816
  driver.feed(sample_record.merge!('vtm' => ts))
@@ -733,6 +823,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
733
823
  time_key vtm
734
824
  time_key_exclude_timestamp true\n")
735
825
  stub_elastic
826
+ stub_elastic_info
736
827
  ts = DateTime.new(2001,2,3).iso8601
737
828
  driver.run(default_tag: 'test') do
738
829
  driver.feed(sample_record.merge!('vtm' => ts))
@@ -742,6 +833,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
742
833
 
743
834
  def test_doesnt_add_tag_key_by_default
744
835
  stub_elastic
836
+ stub_elastic_info
745
837
  driver.run(default_tag: 'test') do
746
838
  driver.feed(sample_record)
747
839
  end
@@ -751,6 +843,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
751
843
  def test_adds_tag_key_when_configured
752
844
  driver.configure("include_tag_key true\n")
753
845
  stub_elastic
846
+ stub_elastic_info
754
847
  driver.run(default_tag: 'mytag') do
755
848
  driver.feed(sample_record)
756
849
  end
@@ -761,6 +854,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
761
854
  def test_adds_id_key_when_configured
762
855
  driver.configure("id_key request_id\n")
763
856
  stub_elastic
857
+ stub_elastic_info
764
858
  driver.run(default_tag: 'test') do
765
859
  driver.feed(sample_record)
766
860
  end
@@ -771,6 +865,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
771
865
  def test_adds_nested_id_key_with_dot
772
866
  driver.configure("id_key nested.request_id\n")
773
867
  stub_elastic
868
+ stub_elastic_info
774
869
  driver.run(default_tag: 'test') do
775
870
  driver.feed(nested_sample_record)
776
871
  end
@@ -780,6 +875,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
780
875
  def test_adds_nested_id_key_with_dollar_dot
781
876
  driver.configure("id_key $.nested.request_id\n")
782
877
  stub_elastic
878
+ stub_elastic_info
783
879
  driver.run(default_tag: 'test') do
784
880
  driver.feed(nested_sample_record)
785
881
  end
@@ -789,6 +885,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
789
885
  def test_adds_nested_id_key_with_bracket
790
886
  driver.configure("id_key $['nested']['request_id']\n")
791
887
  stub_elastic
888
+ stub_elastic_info
792
889
  driver.run(default_tag: 'test') do
793
890
  driver.feed(nested_sample_record)
794
891
  end
@@ -799,6 +896,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
799
896
  def test_doesnt_add_id_key_if_missing_when_configured
800
897
  driver.configure("id_key another_request_id\n")
801
898
  stub_elastic
899
+ stub_elastic_info
802
900
  driver.run(default_tag: 'test') do
803
901
  driver.feed(sample_record)
804
902
  end
@@ -807,6 +905,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
807
905
 
808
906
  def test_adds_id_key_when_not_configured
809
907
  stub_elastic
908
+ stub_elastic_info
810
909
  driver.run(default_tag: 'test') do
811
910
  driver.feed(sample_record)
812
911
  end
@@ -816,6 +915,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
816
915
  def test_adds_parent_key_when_configured
817
916
  driver.configure("parent_key parent_id\n")
818
917
  stub_elastic
918
+ stub_elastic_info
819
919
  driver.run(default_tag: 'test') do
820
920
  driver.feed(sample_record)
821
921
  end
@@ -826,6 +926,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
826
926
  def test_adds_nested_parent_key_with_dot
827
927
  driver.configure("parent_key nested.parent_id\n")
828
928
  stub_elastic
929
+ stub_elastic_info
829
930
  driver.run(default_tag: 'test') do
830
931
  driver.feed(nested_sample_record)
831
932
  end
@@ -835,6 +936,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
835
936
  def test_adds_nested_parent_key_with_dollar_dot
836
937
  driver.configure("parent_key $.nested.parent_id\n")
837
938
  stub_elastic
939
+ stub_elastic_info
838
940
  driver.run(default_tag: 'test') do
839
941
  driver.feed(nested_sample_record)
840
942
  end
@@ -844,6 +946,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
844
946
  def test_adds_nested_parent_key_with_bracket
845
947
  driver.configure("parent_key $['nested']['parent_id']\n")
846
948
  stub_elastic
949
+ stub_elastic_info
847
950
  driver.run(default_tag: 'test') do
848
951
  driver.feed(nested_sample_record)
849
952
  end
@@ -854,6 +957,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
854
957
  def test_doesnt_add_parent_key_if_missing_when_configured
855
958
  driver.configure("parent_key another_parent_id\n")
856
959
  stub_elastic
960
+ stub_elastic_info
857
961
  driver.run(default_tag: 'test') do
858
962
  driver.feed(sample_record)
859
963
  end
@@ -862,6 +966,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
862
966
 
863
967
  def test_adds_parent_key_when_not_configured
864
968
  stub_elastic
969
+ stub_elastic_info
865
970
  driver.run(default_tag: 'test') do
866
971
  driver.feed(sample_record)
867
972
  end
@@ -872,6 +977,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
872
977
  def test_es6
873
978
  driver("routing_key routing_id\n", 6)
874
979
  stub_elastic
980
+ stub_elastic_info
875
981
  driver.run(default_tag: 'test') do
876
982
  driver.feed(sample_record)
877
983
  end
@@ -881,6 +987,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
881
987
  def test_es7
882
988
  driver("routing_key routing_id\n", 7)
883
989
  stub_elastic
990
+ stub_elastic_info
884
991
  driver.run(default_tag: 'test') do
885
992
  driver.feed(sample_record)
886
993
  end
@@ -892,51 +999,62 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
892
999
  def test_adds_nested_routing_key_with_dot
893
1000
  driver.configure("routing_key nested.routing_id\n")
894
1001
  stub_elastic
1002
+ stub_elastic_info
895
1003
  driver.run(default_tag: 'test') do
896
1004
  driver.feed(nested_sample_record)
897
1005
  end
898
- assert_equal('routing', index_cmds[0]['index']['_routing'])
1006
+ routing_key = driver.instance.instance_variable_get(:@routing_key_name)
1007
+ assert_equal('routing', index_cmds[0]['index'][routing_key])
899
1008
  end
900
1009
 
901
1010
  def test_adds_nested_routing_key_with_dollar_dot
902
1011
  driver.configure("routing_key $.nested.routing_id\n")
903
1012
  stub_elastic
1013
+ stub_elastic_info
904
1014
  driver.run(default_tag: 'test') do
905
1015
  driver.feed(nested_sample_record)
906
1016
  end
907
- assert_equal('routing', index_cmds[0]['index']['_routing'])
1017
+ routing_key = driver.instance.instance_variable_get(:@routing_key_name)
1018
+ assert_equal('routing', index_cmds[0]['index'][routing_key])
908
1019
  end
909
1020
 
910
1021
  def test_adds_nested_routing_key_with_bracket
911
1022
  driver.configure("routing_key $['nested']['routing_id']\n")
912
1023
  stub_elastic
1024
+ stub_elastic_info
913
1025
  driver.run(default_tag: 'test') do
914
1026
  driver.feed(nested_sample_record)
915
1027
  end
916
- assert_equal('routing', index_cmds[0]['index']['_routing'])
1028
+ routing_key = driver.instance.instance_variable_get(:@routing_key_name)
1029
+ assert_equal('routing', index_cmds[0]['index'][routing_key])
917
1030
  end
918
1031
  end
919
1032
 
920
1033
  def test_doesnt_add_routing_key_if_missing_when_configured
921
1034
  driver.configure("routing_key another_routing_id\n")
922
1035
  stub_elastic
1036
+ stub_elastic_info
923
1037
  driver.run(default_tag: 'test') do
924
1038
  driver.feed(sample_record)
925
1039
  end
926
- assert(!index_cmds[0]['index'].has_key?('_routing'))
1040
+ routing_key = driver.instance.instance_variable_get(:@routing_key_name)
1041
+ assert(!index_cmds[0]['index'].has_key?(routing_key))
927
1042
  end
928
1043
 
929
1044
  def test_adds_routing_key_when_not_configured
930
1045
  stub_elastic
1046
+ stub_elastic_info
931
1047
  driver.run(default_tag: 'test') do
932
1048
  driver.feed(sample_record)
933
1049
  end
934
- assert(!index_cmds[0]['index'].has_key?('_routing'))
1050
+ routing_key = driver.instance.instance_variable_get(:@routing_key_name)
1051
+ assert(!index_cmds[0]['index'].has_key?(routing_key))
935
1052
  end
936
1053
 
937
1054
  def test_remove_one_key
938
1055
  driver.configure("remove_keys key1\n")
939
1056
  stub_elastic
1057
+ stub_elastic_info
940
1058
  driver.run(default_tag: 'test') do
941
1059
  driver.feed(sample_record.merge('key1' => 'v1', 'key2' => 'v2'))
942
1060
  end
@@ -947,6 +1065,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
947
1065
  def test_remove_multi_keys
948
1066
  driver.configure("remove_keys key1, key2\n")
949
1067
  stub_elastic
1068
+ stub_elastic_info
950
1069
  driver.run(default_tag: 'test') do
951
1070
  driver.feed(sample_record.merge('key1' => 'v1', 'key2' => 'v2'))
952
1071
  end
@@ -956,6 +1075,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
956
1075
 
957
1076
  def test_request_error
958
1077
  stub_elastic_unavailable
1078
+ stub_elastic_info
959
1079
  assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
960
1080
  driver.run(default_tag: 'test', shutdown: false) do
961
1081
  driver.feed(sample_record)
@@ -967,6 +1087,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
967
1087
  omit("retry_forever test is unstable.") if ENV["CI"]
968
1088
 
969
1089
  stub_elastic
1090
+ stub_elastic_info
970
1091
  driver.configure(Fluent::Config::Element.new(
971
1092
  'ROOT', '', {
972
1093
  '@type' => 'elasticsearch',
@@ -986,6 +1107,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
986
1107
 
987
1108
  def test_tag_parts_index_error_event
988
1109
  stub_elastic
1110
+ stub_elastic_info
989
1111
  driver.configure("logstash_prefix ${tag_parts[1]}\n")
990
1112
  flexmock(driver.instance.router).should_receive(:emit_error_event)
991
1113
  .with('test', Fluent::EventTime, Hash, TypeError).once
@@ -1001,6 +1123,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
1001
1123
  connection_resets += 1
1002
1124
  raise Faraday::ConnectionFailed, "Test message"
1003
1125
  end
1126
+ stub_elastic_info
1004
1127
 
1005
1128
  assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
1006
1129
  driver.run(default_tag: 'test', shutdown: false) do
@@ -1017,6 +1140,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
1017
1140
  connection_resets += 1
1018
1141
  raise ZeroDivisionError, "any not host_unreachable_exceptions exception"
1019
1142
  end
1143
+ stub_elastic_info
1020
1144
 
1021
1145
  driver.configure("reconnect_on_error true\n")
1022
1146
 
@@ -1043,6 +1167,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
1043
1167
  connection_resets += 1
1044
1168
  raise ZeroDivisionError, "any not host_unreachable_exceptions exception"
1045
1169
  end
1170
+ stub_elastic_info
1046
1171
 
1047
1172
  driver.configure("reconnect_on_error false\n")
1048
1173
 
@@ -1063,6 +1188,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
1063
1188
  def test_update_should_not_write_if_theres_no_id
1064
1189
  driver.configure("write_operation update\n")
1065
1190
  stub_elastic
1191
+ stub_elastic_info
1066
1192
  driver.run(default_tag: 'test') do
1067
1193
  driver.feed(sample_record)
1068
1194
  end
@@ -1072,6 +1198,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
1072
1198
  def test_upsert_should_not_write_if_theres_no_id
1073
1199
  driver.configure("write_operation upsert\n")
1074
1200
  stub_elastic
1201
+ stub_elastic_info
1075
1202
  driver.run(default_tag: 'test') do
1076
1203
  driver.feed(sample_record)
1077
1204
  end
@@ -1081,6 +1208,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
1081
1208
  def test_create_should_not_write_if_theres_no_id
1082
1209
  driver.configure("write_operation create\n")
1083
1210
  stub_elastic
1211
+ stub_elastic_info
1084
1212
  driver.run(default_tag: 'test') do
1085
1213
  driver.feed(sample_record)
1086
1214
  end
@@ -1091,6 +1219,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
1091
1219
  driver.configure("write_operation update
1092
1220
  id_key request_id")
1093
1221
  stub_elastic
1222
+ stub_elastic_info
1094
1223
  driver.run(default_tag: 'test') do
1095
1224
  driver.feed(sample_record)
1096
1225
  end
@@ -1102,6 +1231,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
1102
1231
  driver.configure("write_operation upsert
1103
1232
  id_key request_id")
1104
1233
  stub_elastic
1234
+ stub_elastic_info
1105
1235
  driver.run(default_tag: 'test') do
1106
1236
  driver.feed(sample_record)
1107
1237
  end
@@ -1113,6 +1243,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
1113
1243
  driver.configure("write_operation create
1114
1244
  id_key request_id")
1115
1245
  stub_elastic
1246
+ stub_elastic_info
1116
1247
  driver.run(default_tag: 'test') do
1117
1248
  driver.feed(sample_record)
1118
1249
  end
@@ -1121,6 +1252,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
1121
1252
 
1122
1253
  def test_include_index_in_url
1123
1254
  stub_elastic('http://localhost:9200/logstash-2018.01.01/_bulk')
1255
+ stub_elastic_info('http://localhost:9200/')
1124
1256
 
1125
1257
  driver.configure("index_name logstash-2018.01.01
1126
1258
  include_index_in_url true")