fluent-plugin-elasticsearch 2.12.5 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +5 -0
- data/README.md +25 -0
- data/fluent-plugin-elasticsearch.gemspec +1 -1
- data/lib/fluent/plugin/elasticsearch_index_template.rb +5 -2
- data/lib/fluent/plugin/out_elasticsearch.rb +10 -26
- data/lib/fluent/plugin/out_elasticsearch_dynamic.rb +4 -23
- data/test/plugin/test_out_elasticsearch.rb +46 -135
- data/test/plugin/test_out_elasticsearch_dynamic.rb +47 -87
- metadata +2 -2
@@ -48,10 +48,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
48
48
|
}
|
49
49
|
end
|
50
50
|
|
51
|
-
def stub_elastic_ping(url="http://localhost:9200")
|
52
|
-
stub_request(:head, url).to_return(:status => 200, :body => "", :headers => {})
|
53
|
-
end
|
54
|
-
|
55
51
|
def stub_elastic(url="http://localhost:9200/_bulk")
|
56
52
|
stub_request(:post, url).with do |req|
|
57
53
|
@index_cmds = req.body.split("\n").map {|r| JSON.parse(r) }
|
@@ -78,6 +74,11 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
78
74
|
end
|
79
75
|
end
|
80
76
|
|
77
|
+
def assert_logs_include(logs, msg, exp_matches=1)
|
78
|
+
matches = logs.grep /#{msg}/
|
79
|
+
assert_equal(exp_matches, matches.length, "Logs do not contain '#{msg}' '#{logs}'")
|
80
|
+
end
|
81
|
+
|
81
82
|
def test_configure
|
82
83
|
config = %{
|
83
84
|
host logs.google.com
|
@@ -130,6 +131,27 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
130
131
|
assert_equal '_doc', instance.type_name
|
131
132
|
end
|
132
133
|
|
134
|
+
sub_test_case 'connection exceptions' do
|
135
|
+
test 'default connection exception' do
|
136
|
+
driver(Fluent::Config::Element.new(
|
137
|
+
'ROOT', '', {
|
138
|
+
'@type' => 'elasticsearch',
|
139
|
+
'host' => 'log.google.com',
|
140
|
+
'port' => 777,
|
141
|
+
'scheme' => 'https',
|
142
|
+
'path' => '/es/',
|
143
|
+
'user' => 'john',
|
144
|
+
'pasword' => 'doe',
|
145
|
+
}, [
|
146
|
+
Fluent::Config::Element.new('buffer', 'tag', {
|
147
|
+
}, [])
|
148
|
+
]
|
149
|
+
))
|
150
|
+
logs = driver.logs
|
151
|
+
assert_logs_include(logs, /you should specify 2 or more 'flush_thread_count'/, 1)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
133
155
|
def test_defaults
|
134
156
|
config = %{
|
135
157
|
host logs.google.com
|
@@ -276,7 +298,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
276
298
|
end
|
277
299
|
|
278
300
|
def test_writes_to_default_index
|
279
|
-
stub_elastic_ping
|
280
301
|
stub_elastic
|
281
302
|
driver.run(default_tag: 'test') do
|
282
303
|
driver.feed(sample_record)
|
@@ -285,7 +306,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
285
306
|
end
|
286
307
|
|
287
308
|
def test_writes_to_default_type
|
288
|
-
stub_elastic_ping
|
289
309
|
stub_elastic
|
290
310
|
driver.run(default_tag: 'test') do
|
291
311
|
driver.feed(sample_record)
|
@@ -295,7 +315,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
295
315
|
|
296
316
|
def test_writes_to_specified_index
|
297
317
|
driver.configure("index_name myindex\n")
|
298
|
-
stub_elastic_ping
|
299
318
|
stub_elastic
|
300
319
|
driver.run(default_tag: 'test') do
|
301
320
|
driver.feed(sample_record)
|
@@ -305,7 +324,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
305
324
|
|
306
325
|
def test_writes_to_specified_index_uppercase
|
307
326
|
driver.configure("index_name MyIndex\n")
|
308
|
-
stub_elastic_ping
|
309
327
|
stub_elastic
|
310
328
|
driver.run(default_tag: 'test') do
|
311
329
|
driver.feed(sample_record)
|
@@ -315,7 +333,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
315
333
|
|
316
334
|
def test_writes_to_specified_type
|
317
335
|
driver.configure("type_name mytype\n")
|
318
|
-
stub_elastic_ping
|
319
336
|
stub_elastic
|
320
337
|
driver.run(default_tag: 'test') do
|
321
338
|
driver.feed(sample_record)
|
@@ -325,7 +342,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
325
342
|
|
326
343
|
def test_writes_to_specified_host
|
327
344
|
driver.configure("host 192.168.33.50\n")
|
328
|
-
stub_elastic_ping("http://192.168.33.50:9200")
|
329
345
|
elastic_request = stub_elastic("http://192.168.33.50:9200/_bulk")
|
330
346
|
driver.run(default_tag: 'test') do
|
331
347
|
driver.feed(sample_record)
|
@@ -335,7 +351,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
335
351
|
|
336
352
|
def test_writes_to_specified_port
|
337
353
|
driver.configure("port 9201\n")
|
338
|
-
stub_elastic_ping("http://localhost:9201")
|
339
354
|
elastic_request = stub_elastic("http://localhost:9201/_bulk")
|
340
355
|
driver.run(default_tag: 'test') do
|
341
356
|
driver.feed(sample_record)
|
@@ -351,7 +366,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
351
366
|
|
352
367
|
hosts.each do |host_info|
|
353
368
|
host, port = host_info
|
354
|
-
stub_elastic_ping("http://#{host}:#{port}")
|
355
369
|
stub_elastic_with_store_index_command_counts("http://#{host}:#{port}/_bulk")
|
356
370
|
end
|
357
371
|
|
@@ -374,7 +388,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
374
388
|
end
|
375
389
|
|
376
390
|
def test_makes_bulk_request
|
377
|
-
stub_elastic_ping
|
378
391
|
stub_elastic
|
379
392
|
driver.run(default_tag: 'test') do
|
380
393
|
driver.feed(sample_record)
|
@@ -384,7 +397,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
384
397
|
end
|
385
398
|
|
386
399
|
def test_all_records_are_preserved_in_bulk
|
387
|
-
stub_elastic_ping
|
388
400
|
stub_elastic
|
389
401
|
driver.run(default_tag: 'test') do
|
390
402
|
driver.feed(sample_record)
|
@@ -398,7 +410,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
398
410
|
driver.configure("logstash_format true\n")
|
399
411
|
time = Time.parse Date.today.iso8601
|
400
412
|
logstash_index = "logstash-#{time.getutc.strftime("%Y.%m.%d")}"
|
401
|
-
stub_elastic_ping
|
402
413
|
stub_elastic
|
403
414
|
driver.run(default_tag: 'test') do
|
404
415
|
driver.feed(time.to_i, sample_record)
|
@@ -411,7 +422,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
411
422
|
utc_index false")
|
412
423
|
time = Time.parse Date.today.iso8601
|
413
424
|
utc_index = "logstash-#{time.strftime("%Y.%m.%d")}"
|
414
|
-
stub_elastic_ping
|
415
425
|
stub_elastic
|
416
426
|
driver.run(default_tag: 'test') do
|
417
427
|
driver.feed(time.to_i, sample_record)
|
@@ -424,7 +434,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
424
434
|
logstash_prefix myprefix")
|
425
435
|
time = Time.parse Date.today.iso8601
|
426
436
|
logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m.%d")}"
|
427
|
-
stub_elastic_ping
|
428
437
|
stub_elastic
|
429
438
|
driver.run(default_tag: 'test') do
|
430
439
|
driver.feed(time.to_i, sample_record)
|
@@ -439,7 +448,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
439
448
|
logstash_prefix myprefix")
|
440
449
|
time = Time.parse Date.today.iso8601
|
441
450
|
logstash_index = "myprefix#{separator}#{time.getutc.strftime("%Y.%m.%d")}"
|
442
|
-
stub_elastic_ping
|
443
451
|
stub_elastic
|
444
452
|
driver.run(default_tag: 'test') do
|
445
453
|
driver.feed(time.to_i, sample_record)
|
@@ -452,7 +460,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
452
460
|
logstash_prefix MyPrefix")
|
453
461
|
time = Time.parse Date.today.iso8601
|
454
462
|
logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m.%d")}"
|
455
|
-
stub_elastic_ping
|
456
463
|
stub_elastic
|
457
464
|
driver.run(default_tag: 'test') do
|
458
465
|
driver.feed(time.to_i, sample_record)
|
@@ -465,7 +472,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
465
472
|
logstash_dateformat %Y.%m")
|
466
473
|
time = Time.parse Date.today.iso8601
|
467
474
|
logstash_index = "logstash-#{time.getutc.strftime("%Y.%m")}"
|
468
|
-
stub_elastic_ping
|
469
475
|
stub_elastic
|
470
476
|
driver.run(default_tag: 'test') do
|
471
477
|
driver.feed(time.to_i, sample_record)
|
@@ -479,7 +485,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
479
485
|
logstash_dateformat %Y.%m")
|
480
486
|
time = Time.parse Date.today.iso8601
|
481
487
|
logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m")}"
|
482
|
-
stub_elastic_ping
|
483
488
|
stub_elastic
|
484
489
|
driver.run(default_tag: 'test') do
|
485
490
|
driver.feed(time.to_i, sample_record)
|
@@ -488,7 +493,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
488
493
|
end
|
489
494
|
|
490
495
|
def test_doesnt_add_logstash_timestamp_by_default
|
491
|
-
stub_elastic_ping
|
492
496
|
stub_elastic
|
493
497
|
driver.run(default_tag: 'test') do
|
494
498
|
driver.feed(sample_record)
|
@@ -498,7 +502,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
498
502
|
|
499
503
|
def test_adds_logstash_timestamp_when_configured
|
500
504
|
driver.configure("logstash_format true\n")
|
501
|
-
stub_elastic_ping
|
502
505
|
stub_elastic
|
503
506
|
time = Fluent::EventTime.new(Time.now.to_i, 123456789)
|
504
507
|
driver.run(default_tag: 'test') do
|
@@ -511,7 +514,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
511
514
|
def test_uses_subsecond_precision_when_configured
|
512
515
|
driver.configure("logstash_format true
|
513
516
|
time_precision 3\n")
|
514
|
-
stub_elastic_ping
|
515
517
|
stub_elastic
|
516
518
|
time = Fluent::EventTime.new(Time.now.to_i, 123456789)
|
517
519
|
driver.run(default_tag: 'test') do
|
@@ -523,7 +525,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
523
525
|
|
524
526
|
def test_uses_custom_timestamp_when_included_in_record
|
525
527
|
driver.configure("include_timestamp true\n")
|
526
|
-
stub_elastic_ping
|
527
528
|
stub_elastic
|
528
529
|
ts = DateTime.new(2001,2,3).iso8601
|
529
530
|
driver.run(default_tag: 'test') do
|
@@ -535,7 +536,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
535
536
|
|
536
537
|
def test_uses_custom_timestamp_when_included_in_record_logstash
|
537
538
|
driver.configure("logstash_format true\n")
|
538
|
-
stub_elastic_ping
|
539
539
|
stub_elastic
|
540
540
|
ts = DateTime.new(2001,2,3).iso8601
|
541
541
|
driver.run(default_tag: 'test') do
|
@@ -548,7 +548,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
548
548
|
def test_uses_custom_time_key_logstash
|
549
549
|
driver.configure("logstash_format true
|
550
550
|
time_key vtm\n")
|
551
|
-
stub_elastic_ping
|
552
551
|
stub_elastic
|
553
552
|
ts = DateTime.new(2001,2,3).iso8601
|
554
553
|
driver.run(default_tag: 'test') do
|
@@ -561,7 +560,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
561
560
|
def test_uses_custom_time_key_timestamp
|
562
561
|
driver.configure("include_timestamp true
|
563
562
|
time_key vtm\n")
|
564
|
-
stub_elastic_ping
|
565
563
|
stub_elastic
|
566
564
|
ts = DateTime.new(2001,2,3).iso8601
|
567
565
|
driver.run(default_tag: 'test') do
|
@@ -575,7 +573,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
575
573
|
driver.configure("include_timestamp true
|
576
574
|
index_name test
|
577
575
|
time_key vtm\n")
|
578
|
-
stub_elastic_ping
|
579
576
|
stub_elastic
|
580
577
|
ts = DateTime.new(2001,2,3).iso8601
|
581
578
|
driver.run(default_tag: 'test') do
|
@@ -590,7 +587,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
590
587
|
driver.configure("include_timestamp true
|
591
588
|
time_key vtm
|
592
589
|
time_key_exclude_timestamp true\n")
|
593
|
-
stub_elastic_ping
|
594
590
|
stub_elastic
|
595
591
|
ts = DateTime.new(2001,2,3).iso8601
|
596
592
|
driver.run(default_tag: 'test') do
|
@@ -603,7 +599,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
603
599
|
driver.configure("logstash_format true
|
604
600
|
time_key vtm
|
605
601
|
time_key_exclude_timestamp true\n")
|
606
|
-
stub_elastic_ping
|
607
602
|
stub_elastic
|
608
603
|
ts = DateTime.new(2001,2,3).iso8601
|
609
604
|
driver.run(default_tag: 'test') do
|
@@ -613,7 +608,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
613
608
|
end
|
614
609
|
|
615
610
|
def test_doesnt_add_tag_key_by_default
|
616
|
-
stub_elastic_ping
|
617
611
|
stub_elastic
|
618
612
|
driver.run(default_tag: 'test') do
|
619
613
|
driver.feed(sample_record)
|
@@ -623,7 +617,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
623
617
|
|
624
618
|
def test_adds_tag_key_when_configured
|
625
619
|
driver.configure("include_tag_key true\n")
|
626
|
-
stub_elastic_ping
|
627
620
|
stub_elastic
|
628
621
|
driver.run(default_tag: 'mytag') do
|
629
622
|
driver.feed(sample_record)
|
@@ -634,7 +627,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
634
627
|
|
635
628
|
def test_adds_id_key_when_configured
|
636
629
|
driver.configure("id_key request_id\n")
|
637
|
-
stub_elastic_ping
|
638
630
|
stub_elastic
|
639
631
|
driver.run(default_tag: 'test') do
|
640
632
|
driver.feed(sample_record)
|
@@ -645,7 +637,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
645
637
|
class NestedIdKeyTest < self
|
646
638
|
def test_adds_nested_id_key_with_dot
|
647
639
|
driver.configure("id_key nested.request_id\n")
|
648
|
-
stub_elastic_ping
|
649
640
|
stub_elastic
|
650
641
|
driver.run(default_tag: 'test') do
|
651
642
|
driver.feed(nested_sample_record)
|
@@ -655,7 +646,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
655
646
|
|
656
647
|
def test_adds_nested_id_key_with_dollar_dot
|
657
648
|
driver.configure("id_key $.nested.request_id\n")
|
658
|
-
stub_elastic_ping
|
659
649
|
stub_elastic
|
660
650
|
driver.run(default_tag: 'test') do
|
661
651
|
driver.feed(nested_sample_record)
|
@@ -665,7 +655,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
665
655
|
|
666
656
|
def test_adds_nested_id_key_with_bracket
|
667
657
|
driver.configure("id_key $['nested']['request_id']\n")
|
668
|
-
stub_elastic_ping
|
669
658
|
stub_elastic
|
670
659
|
driver.run(default_tag: 'test') do
|
671
660
|
driver.feed(nested_sample_record)
|
@@ -676,7 +665,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
676
665
|
|
677
666
|
def test_doesnt_add_id_key_if_missing_when_configured
|
678
667
|
driver.configure("id_key another_request_id\n")
|
679
|
-
stub_elastic_ping
|
680
668
|
stub_elastic
|
681
669
|
driver.run(default_tag: 'test') do
|
682
670
|
driver.feed(sample_record)
|
@@ -685,7 +673,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
685
673
|
end
|
686
674
|
|
687
675
|
def test_adds_id_key_when_not_configured
|
688
|
-
stub_elastic_ping
|
689
676
|
stub_elastic
|
690
677
|
driver.run(default_tag: 'test') do
|
691
678
|
driver.feed(sample_record)
|
@@ -695,7 +682,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
695
682
|
|
696
683
|
def test_adds_parent_key_when_configured
|
697
684
|
driver.configure("parent_key parent_id\n")
|
698
|
-
stub_elastic_ping
|
699
685
|
stub_elastic
|
700
686
|
driver.run(default_tag: 'test') do
|
701
687
|
driver.feed(sample_record)
|
@@ -706,7 +692,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
706
692
|
class NestedParentKeyTest < self
|
707
693
|
def test_adds_nested_parent_key_with_dot
|
708
694
|
driver.configure("parent_key nested.parent_id\n")
|
709
|
-
stub_elastic_ping
|
710
695
|
stub_elastic
|
711
696
|
driver.run(default_tag: 'test') do
|
712
697
|
driver.feed(nested_sample_record)
|
@@ -716,7 +701,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
716
701
|
|
717
702
|
def test_adds_nested_parent_key_with_dollar_dot
|
718
703
|
driver.configure("parent_key $.nested.parent_id\n")
|
719
|
-
stub_elastic_ping
|
720
704
|
stub_elastic
|
721
705
|
driver.run(default_tag: 'test') do
|
722
706
|
driver.feed(nested_sample_record)
|
@@ -726,7 +710,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
726
710
|
|
727
711
|
def test_adds_nested_parent_key_with_bracket
|
728
712
|
driver.configure("parent_key $['nested']['parent_id']\n")
|
729
|
-
stub_elastic_ping
|
730
713
|
stub_elastic
|
731
714
|
driver.run(default_tag: 'test') do
|
732
715
|
driver.feed(nested_sample_record)
|
@@ -737,7 +720,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
737
720
|
|
738
721
|
def test_doesnt_add_parent_key_if_missing_when_configured
|
739
722
|
driver.configure("parent_key another_parent_id\n")
|
740
|
-
stub_elastic_ping
|
741
723
|
stub_elastic
|
742
724
|
driver.run(default_tag: 'test') do
|
743
725
|
driver.feed(sample_record)
|
@@ -746,7 +728,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
746
728
|
end
|
747
729
|
|
748
730
|
def test_adds_parent_key_when_not_configured
|
749
|
-
stub_elastic_ping
|
750
731
|
stub_elastic
|
751
732
|
driver.run(default_tag: 'test') do
|
752
733
|
driver.feed(sample_record)
|
@@ -756,7 +737,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
756
737
|
|
757
738
|
def test_adds_routing_key_when_configured
|
758
739
|
driver.configure("routing_key routing_id\n")
|
759
|
-
stub_elastic_ping
|
760
740
|
stub_elastic
|
761
741
|
driver.run(default_tag: 'test') do
|
762
742
|
driver.feed(sample_record)
|
@@ -767,7 +747,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
767
747
|
class NestedRoutingKeyTest < self
|
768
748
|
def test_adds_nested_routing_key_with_dot
|
769
749
|
driver.configure("routing_key nested.routing_id\n")
|
770
|
-
stub_elastic_ping
|
771
750
|
stub_elastic
|
772
751
|
driver.run(default_tag: 'test') do
|
773
752
|
driver.feed(nested_sample_record)
|
@@ -777,7 +756,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
777
756
|
|
778
757
|
def test_adds_nested_routing_key_with_dollar_dot
|
779
758
|
driver.configure("routing_key $.nested.routing_id\n")
|
780
|
-
stub_elastic_ping
|
781
759
|
stub_elastic
|
782
760
|
driver.run(default_tag: 'test') do
|
783
761
|
driver.feed(nested_sample_record)
|
@@ -787,7 +765,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
787
765
|
|
788
766
|
def test_adds_nested_routing_key_with_bracket
|
789
767
|
driver.configure("routing_key $['nested']['routing_id']\n")
|
790
|
-
stub_elastic_ping
|
791
768
|
stub_elastic
|
792
769
|
driver.run(default_tag: 'test') do
|
793
770
|
driver.feed(nested_sample_record)
|
@@ -798,7 +775,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
798
775
|
|
799
776
|
def test_doesnt_add_routing_key_if_missing_when_configured
|
800
777
|
driver.configure("routing_key another_routing_id\n")
|
801
|
-
stub_elastic_ping
|
802
778
|
stub_elastic
|
803
779
|
driver.run(default_tag: 'test') do
|
804
780
|
driver.feed(sample_record)
|
@@ -807,7 +783,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
807
783
|
end
|
808
784
|
|
809
785
|
def test_adds_routing_key_when_not_configured
|
810
|
-
stub_elastic_ping
|
811
786
|
stub_elastic
|
812
787
|
driver.run(default_tag: 'test') do
|
813
788
|
driver.feed(sample_record)
|
@@ -817,7 +792,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
817
792
|
|
818
793
|
def test_remove_one_key
|
819
794
|
driver.configure("remove_keys key1\n")
|
820
|
-
stub_elastic_ping
|
821
795
|
stub_elastic
|
822
796
|
driver.run(default_tag: 'test') do
|
823
797
|
driver.feed(sample_record.merge('key1' => 'v1', 'key2' => 'v2'))
|
@@ -828,7 +802,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
828
802
|
|
829
803
|
def test_remove_multi_keys
|
830
804
|
driver.configure("remove_keys key1, key2\n")
|
831
|
-
stub_elastic_ping
|
832
805
|
stub_elastic
|
833
806
|
driver.run(default_tag: 'test') do
|
834
807
|
driver.feed(sample_record.merge('key1' => 'v1', 'key2' => 'v2'))
|
@@ -838,17 +811,17 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
838
811
|
end
|
839
812
|
|
840
813
|
def test_request_error
|
841
|
-
stub_elastic_ping
|
842
814
|
stub_elastic_unavailable
|
843
|
-
assert_raise(
|
844
|
-
driver.run(default_tag: 'test') do
|
815
|
+
assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
|
816
|
+
driver.run(default_tag: 'test', shutdown: false) do
|
845
817
|
driver.feed(sample_record)
|
846
818
|
end
|
847
819
|
}
|
848
820
|
end
|
849
821
|
|
850
822
|
def test_request_forever
|
851
|
-
|
823
|
+
omit("retry_forever test is unstable.") if ENV["CI"]
|
824
|
+
|
852
825
|
stub_elastic
|
853
826
|
driver.configure(Fluent::Config::Element.new(
|
854
827
|
'ROOT', '', {
|
@@ -860,13 +833,14 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
860
833
|
]
|
861
834
|
))
|
862
835
|
stub_elastic_timeout
|
863
|
-
|
864
|
-
driver.
|
865
|
-
|
836
|
+
assert_raise(Timeout::Error) {
|
837
|
+
driver.run(default_tag: 'test', timeout: 10, force_flush_retry: true) do
|
838
|
+
driver.feed(sample_record)
|
839
|
+
end
|
840
|
+
}
|
866
841
|
end
|
867
842
|
|
868
843
|
def test_tag_parts_index_error_event
|
869
|
-
stub_elastic_ping
|
870
844
|
stub_elastic
|
871
845
|
driver.configure("logstash_prefix ${tag_parts[1]}\n")
|
872
846
|
flexmock(driver.instance.router).should_receive(:emit_error_event)
|
@@ -876,37 +850,33 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
876
850
|
end
|
877
851
|
end
|
878
852
|
|
879
|
-
def
|
853
|
+
def test_connection_failed
|
880
854
|
connection_resets = 0
|
881
855
|
|
882
|
-
stub_elastic_ping(url="http://localhost:9200").with do |req|
|
883
|
-
connection_resets += 1
|
884
|
-
end
|
885
|
-
|
886
856
|
stub_request(:post, "http://localhost:9200/_bulk").with do |req|
|
857
|
+
connection_resets += 1
|
887
858
|
raise Faraday::ConnectionFailed, "Test message"
|
888
859
|
end
|
889
860
|
|
890
|
-
|
891
|
-
driver.
|
892
|
-
|
893
|
-
|
861
|
+
assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
|
862
|
+
driver.run(default_tag: 'test', shutdown: false) do
|
863
|
+
driver.feed(sample_record)
|
864
|
+
end
|
865
|
+
}
|
866
|
+
assert_equal(connection_resets, 1)
|
894
867
|
end
|
895
868
|
|
896
869
|
def test_reconnect_on_error_enabled
|
897
870
|
connection_resets = 0
|
898
871
|
|
899
|
-
stub_elastic_ping(url="http://localhost:9200").with do |req|
|
900
|
-
connection_resets += 1
|
901
|
-
end
|
902
|
-
|
903
872
|
stub_request(:post, "http://localhost:9200/_bulk").with do |req|
|
873
|
+
connection_resets += 1
|
904
874
|
raise ZeroDivisionError, "any not host_unreachable_exceptions exception"
|
905
875
|
end
|
906
876
|
|
907
877
|
driver.configure("reconnect_on_error true\n")
|
908
878
|
|
909
|
-
assert_raise(
|
879
|
+
assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
|
910
880
|
driver.run(default_tag: 'test', shutdown: false) do
|
911
881
|
driver.feed(sample_record)
|
912
882
|
end
|
@@ -925,17 +895,14 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
925
895
|
def test_reconnect_on_error_disabled
|
926
896
|
connection_resets = 0
|
927
897
|
|
928
|
-
stub_elastic_ping(url="http://localhost:9200").with do |req|
|
929
|
-
connection_resets += 1
|
930
|
-
end
|
931
|
-
|
932
898
|
stub_request(:post, "http://localhost:9200/_bulk").with do |req|
|
899
|
+
connection_resets += 1
|
933
900
|
raise ZeroDivisionError, "any not host_unreachable_exceptions exception"
|
934
901
|
end
|
935
902
|
|
936
903
|
driver.configure("reconnect_on_error false\n")
|
937
904
|
|
938
|
-
assert_raise(
|
905
|
+
assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
|
939
906
|
driver.run(default_tag: 'test', shutdown: false) do
|
940
907
|
driver.feed(sample_record)
|
941
908
|
end
|
@@ -951,7 +918,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
951
918
|
|
952
919
|
def test_update_should_not_write_if_theres_no_id
|
953
920
|
driver.configure("write_operation update\n")
|
954
|
-
stub_elastic_ping
|
955
921
|
stub_elastic
|
956
922
|
driver.run(default_tag: 'test') do
|
957
923
|
driver.feed(sample_record)
|
@@ -961,7 +927,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
961
927
|
|
962
928
|
def test_upsert_should_not_write_if_theres_no_id
|
963
929
|
driver.configure("write_operation upsert\n")
|
964
|
-
stub_elastic_ping
|
965
930
|
stub_elastic
|
966
931
|
driver.run(default_tag: 'test') do
|
967
932
|
driver.feed(sample_record)
|
@@ -971,7 +936,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
971
936
|
|
972
937
|
def test_create_should_not_write_if_theres_no_id
|
973
938
|
driver.configure("write_operation create\n")
|
974
|
-
stub_elastic_ping
|
975
939
|
stub_elastic
|
976
940
|
driver.run(default_tag: 'test') do
|
977
941
|
driver.feed(sample_record)
|
@@ -982,7 +946,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
982
946
|
def test_update_should_write_update_op_and_doc_as_upsert_is_false
|
983
947
|
driver.configure("write_operation update
|
984
948
|
id_key request_id")
|
985
|
-
stub_elastic_ping
|
986
949
|
stub_elastic
|
987
950
|
driver.run(default_tag: 'test') do
|
988
951
|
driver.feed(sample_record)
|
@@ -994,7 +957,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
994
957
|
def test_upsert_should_write_update_op_and_doc_as_upsert_is_true
|
995
958
|
driver.configure("write_operation upsert
|
996
959
|
id_key request_id")
|
997
|
-
stub_elastic_ping
|
998
960
|
stub_elastic
|
999
961
|
driver.run(default_tag: 'test') do
|
1000
962
|
driver.feed(sample_record)
|
@@ -1006,7 +968,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
1006
968
|
def test_create_should_write_create_op
|
1007
969
|
driver.configure("write_operation create
|
1008
970
|
id_key request_id")
|
1009
|
-
stub_elastic_ping
|
1010
971
|
stub_elastic
|
1011
972
|
driver.run(default_tag: 'test') do
|
1012
973
|
driver.feed(sample_record)
|
@@ -1015,7 +976,6 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
|
|
1015
976
|
end
|
1016
977
|
|
1017
978
|
def test_include_index_in_url
|
1018
|
-
stub_elastic_ping
|
1019
979
|
stub_elastic('http://localhost:9200/logstash-2018.01.01/_bulk')
|
1020
980
|
|
1021
981
|
driver.configure("index_name logstash-2018.01.01
|