/
test_out_forward.rb
1358 lines (1175 loc) · 39.5 KB
/
test_out_forward.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
require_relative '../helper'
require 'fluent/test/driver/output'
require 'fluent/plugin/out_forward'
require 'flexmock/test_unit'
require 'fluent/test/driver/input'
require 'fluent/plugin/in_forward'
class ForwardOutputTest < Test::Unit::TestCase
def setup
Fluent::Test.setup
FileUtils.rm_rf(TMP_DIR)
FileUtils.mkdir_p(TMP_DIR)
@d = nil
@target_port = unused_port
end
def teardown
@d.instance_shutdown if @d
@port = nil
end
TMP_DIR = File.join(__dir__, "../tmp/out_forward#{ENV['TEST_ENV_NUMBER']}")
TARGET_HOST = '127.0.0.1'
def config
%[
send_timeout 51
heartbeat_type udp
<server>
name test
host #{TARGET_HOST}
port #{@target_port}
</server>
]
end
def target_config
%[
port #{@target_port}
bind #{TARGET_HOST}
]
end
def create_driver(conf=config)
Fluent::Test::Driver::Output.new(Fluent::Plugin::ForwardOutput) {
attr_reader :sent_chunk_ids, :ack_handler, :discovery_manager
def initialize
super
@sent_chunk_ids = []
end
def try_write(chunk)
retval = super
@sent_chunk_ids << chunk.unique_id
retval
end
}.configure(conf)
end
test 'configure' do
@d = d = create_driver(%[
self_hostname localhost
<server>
name test
host #{TARGET_HOST}
port #{@target_port}
</server>
])
nodes = d.instance.nodes
assert_equal 60, d.instance.send_timeout
assert_equal :transport, d.instance.heartbeat_type
assert_equal 1, nodes.length
assert_nil d.instance.connect_timeout
node = nodes.first
assert_equal "test", node.name
assert_equal '127.0.0.1', node.host
assert_equal @target_port, node.port
end
test 'configure_traditional' do
@d = d = create_driver(<<EOL)
self_hostname localhost
<server>
name test
host #{TARGET_HOST}
port #{@target_port}
</server>
buffer_chunk_limit 10m
EOL
instance = d.instance
assert instance.chunk_key_tag
assert !instance.chunk_key_time
assert_equal [], instance.chunk_keys
assert{ instance.buffer.is_a?(Fluent::Plugin::MemoryBuffer) }
assert_equal( 10*1024*1024, instance.buffer.chunk_limit_size )
end
test 'configure timeouts' do
@d = d = create_driver(%[
send_timeout 30
connect_timeout 10
hard_timeout 15
ack_response_timeout 20
<server>
host #{TARGET_HOST}
port #{@target_port}
</server>
])
assert_equal 30, d.instance.send_timeout
assert_equal 10, d.instance.connect_timeout
assert_equal 15, d.instance.hard_timeout
assert_equal 20, d.instance.ack_response_timeout
end
test 'configure_udp_heartbeat' do
@d = d = create_driver(config + "\nheartbeat_type udp")
assert_equal :udp, d.instance.heartbeat_type
end
test 'configure_none_heartbeat' do
@d = d = create_driver(config + "\nheartbeat_type none")
assert_equal :none, d.instance.heartbeat_type
end
test 'configure_expire_dns_cache' do
@d = d = create_driver(config + "\nexpire_dns_cache 5")
assert_equal 5, d.instance.expire_dns_cache
end
test 'configure_dns_round_robin udp' do
assert_raise(Fluent::ConfigError) do
create_driver(config + "\nheartbeat_type udp\ndns_round_robin true")
end
end
test 'configure_dns_round_robin transport' do
@d = d = create_driver(config + "\nheartbeat_type transport\ndns_round_robin true")
assert_equal true, d.instance.dns_round_robin
end
test 'configure_dns_round_robin none' do
@d = d = create_driver(config + "\nheartbeat_type none\ndns_round_robin true")
assert_equal true, d.instance.dns_round_robin
end
test 'configure_no_server' do
assert_raise(Fluent::ConfigError, 'forward output plugin requires at least one <server> is required') do
create_driver('')
end
end
test 'configure with ignore_network_errors_at_startup' do
normal_conf = config_element('match', '**', {}, [
config_element('server', '', {'name' => 'test', 'host' => 'unexisting.yaaaaaaaaaaaaaay.host.example.com'})
])
assert_raise SocketError do
create_driver(normal_conf)
end
conf = config_element('match', '**', {'ignore_network_errors_at_startup' => 'true'}, [
config_element('server', '', {'name' => 'test', 'host' => 'unexisting.yaaaaaaaaaaaaaay.host.example.com'})
])
@d = d = create_driver(conf)
expected_log = "failed to resolve node name when configured"
expected_detail = 'server="test" error_class=SocketError'
logs = d.logs
assert{ logs.any?{|log| log.include?(expected_log) && log.include?(expected_detail) } }
end
data('CA cert' => 'tls_ca_cert_path',
'non CA cert' => 'tls_cert_path')
test 'configure tls_cert_path/tls_ca_cert_path' do |param|
dummy_cert_path = File.join(TMP_DIR, "dummy_cert.pem")
FileUtils.touch(dummy_cert_path)
conf = %[
send_timeout 5
transport tls
tls_insecure_mode true
#{param} #{dummy_cert_path}
<server>
host #{TARGET_HOST}
port #{@target_port}
</server>
]
@d = d = create_driver(conf)
# In the plugin, tls_ca_cert_path is used for both cases
assert_equal([dummy_cert_path], d.instance.tls_ca_cert_path)
end
sub_test_case "certstore loading parameters for Windows" do
test 'certstore related config parameters' do
omit "certstore related values raise error on not Windows" if Fluent.windows?
conf = %[
send_timeout 5
transport tls
tls_cert_logical_store_name Root
tls_cert_thumbprint a909502dd82ae41433e6f83886b00d4277a32a7b
<server>
host #{TARGET_HOST}
port #{@target_port}
</server>
]
assert_raise(Fluent::ConfigError) do
create_driver(conf)
end
end
test 'cert_logical_store_name and tls_cert_thumbprint default values' do
conf = %[
send_timeout 5
transport tls
<server>
host #{TARGET_HOST}
port #{@target_port}
</server>
]
@d = d = create_driver(conf)
assert_nil d.instance.tls_cert_logical_store_name
assert_nil d.instance.tls_cert_thumbprint
end
data('CA cert' => 'tls_ca_cert_path',
'non CA cert' => 'tls_cert_path')
test 'specify tls_cert_logical_store_name and tls_cert_path should raise error' do |param|
omit "Loading CertStore feature works only Windows" unless Fluent.windows?
dummy_cert_path = File.join(TMP_DIR, "dummy_cert.pem")
FileUtils.touch(dummy_cert_path)
conf = %[
send_timeout 5
transport tls
#{param} #{dummy_cert_path}
tls_cert_logical_store_name Root
<server>
host #{TARGET_HOST}
port #{@target_port}
</server>
]
assert_raise(Fluent::ConfigError) do
create_driver(conf)
end
end
test 'configure cert_logical_store_name and tls_cert_thumbprint' do
omit "Loading CertStore feature works only Windows" unless Fluent.windows?
conf = %[
send_timeout 5
transport tls
tls_cert_logical_store_name Root
tls_cert_thumbprint a909502dd82ae41433e6f83886b00d4277a32a7b
<server>
host #{TARGET_HOST}
port #{@target_port}
</server>
]
@d = d = create_driver(conf)
assert_equal "Root", d.instance.tls_cert_logical_store_name
assert_equal "a909502dd82ae41433e6f83886b00d4277a32a7b", d.instance.tls_cert_thumbprint
end
end
test 'server is an abbreviation of static type of service_discovery' do
@d = d = create_driver(%[
<server>
host 127.0.0.1
port 1234
</server>
<service_discovery>
@type static
<service>
host 127.0.0.1
port 1235
</service>
</service_discovery>
])
assert_equal(
[
{ host: '127.0.0.1', port: 1234 },
{ host: '127.0.0.1', port: 1235 },
],
d.instance.discovery_manager.services.collect do |service|
{ host: service.host, port: service.port }
end
)
end
test 'pass username and password as empty string to HandshakeProtocol' do
config_path = File.join(TMP_DIR, "sd_file.conf")
File.open(config_path, 'w') do |file|
file.write(%[
- 'host': 127.0.0.1
'port': 1234
'weight': 1
])
end
mock(Fluent::Plugin::ForwardOutput::HandshakeProtocol).new(log: anything, hostname: nil, shared_key: anything, password: '', username: '')
@d = d = create_driver(%[
<service_discovery>
@type file
path #{config_path}
</service_discovery>
])
assert_equal 1, d.instance.discovery_manager.services.size
assert_equal '127.0.0.1', d.instance.discovery_manager.services[0].host
assert_equal 1234, d.instance.discovery_manager.services[0].port
end
test 'compress_default_value' do
@d = d = create_driver
assert_equal :text, d.instance.compress
node = d.instance.nodes.first
assert_equal :text, node.instance_variable_get(:@compress)
end
test 'set_compress_is_gzip' do
@d = d = create_driver(config + %[compress gzip])
assert_equal :gzip, d.instance.compress
assert_equal :gzip, d.instance.buffer.compress
node = d.instance.nodes.first
assert_equal :gzip, node.instance_variable_get(:@compress)
end
test 'set_compress_is_gzip_in_buffer_section' do
mock = flexmock($log)
mock.should_receive(:log).with("buffer is compressed. If you also want to save the bandwidth of a network, Add `compress` configuration in <match>")
@d = d = create_driver(config + %[
<buffer>
type memory
compress gzip
</buffer>
])
assert_equal :text, d.instance.compress
assert_equal :gzip, d.instance.buffer.compress
node = d.instance.nodes.first
assert_equal :text, node.instance_variable_get(:@compress)
end
test 'phi_failure_detector disabled' do
@d = d = create_driver(config + %[phi_failure_detector false \n phi_threshold 0])
node = d.instance.nodes.first
stub(node.failure).phi { raise 'Should not be called' }
node.tick
assert_true node.available?
end
test 'phi_failure_detector enabled' do
@d = d = create_driver(config + %[phi_failure_detector true \n phi_threshold 0])
node = d.instance.nodes.first
node.tick
assert_false node.available?
end
test 'require_ack_response is disabled in default' do
@d = d = create_driver(config)
assert_equal false, d.instance.require_ack_response
assert_equal 190, d.instance.ack_response_timeout
end
test 'require_ack_response can be enabled' do
@d = d = create_driver(config + %[
require_ack_response true
ack_response_timeout 2s
])
d.instance_start
assert d.instance.require_ack_response
assert_equal 2, d.instance.ack_response_timeout
end
test 'suspend_flush is disable before before_shutdown' do
@d = d = create_driver(config + %[
require_ack_response true
ack_response_timeout 2s
])
d.instance_start
assert_false d.instance.instance_variable_get(:@suspend_flush)
end
test 'suspend_flush should be enabled and try_flush returns nil after before_shutdown' do
@d = d = create_driver(config + %[
require_ack_response true
ack_response_timeout 2s
])
d.instance_start
d.instance.before_shutdown
assert_true d.instance.instance_variable_get(:@suspend_flush)
assert_nil d.instance.try_flush
end
test 'verify_connection_at_startup is disabled in default' do
@d = d = create_driver(config)
assert_false d.instance.verify_connection_at_startup
end
test 'verify_connection_at_startup can be enabled' do
@d = d = create_driver(config + %[
verify_connection_at_startup true
])
assert_true d.instance.verify_connection_at_startup
end
test 'send tags in str (utf-8 strings)' do
target_input_driver = create_target_input_driver
@d = d = create_driver(config + %[flush_interval 1s])
time = event_time("2011-01-02 13:14:15 UTC")
tag_in_utf8 = "test.utf8".encode("utf-8")
tag_in_ascii = "test.ascii".encode("ascii-8bit")
emit_events = [
[tag_in_utf8, time, {"a" => 1}],
[tag_in_ascii, time, {"a" => 2}],
]
stub(d.instance.ack_handler).read_ack_from_sock(anything).never
assert_rr do
target_input_driver.run(expect_records: 2) do
d.run do
emit_events.each do |tag, t, record|
d.feed(tag, t, record)
end
end
end
end
events = target_input_driver.events
assert_equal_event_time(time, events[0][1])
assert_equal ['test.utf8', time, emit_events[0][2]], events[0]
assert_equal Encoding::UTF_8, events[0][0].encoding
assert_equal_event_time(time, events[1][1])
assert_equal ['test.ascii', time, emit_events[1][2]], events[1]
assert_equal Encoding::UTF_8, events[1][0].encoding
end
test 'send_with_time_as_integer' do
target_input_driver = create_target_input_driver
@d = d = create_driver(config + %[flush_interval 1s])
time = event_time("2011-01-02 13:14:15 UTC")
records = [
{"a" => 1},
{"a" => 2}
]
stub(d.instance.ack_handler).read_ack_from_sock(anything).never
assert_rr do
target_input_driver.run(expect_records: 2) do
d.run(default_tag: 'test') do
records.each do |record|
d.feed(time, record)
end
end
end
end
events = target_input_driver.events
assert_equal_event_time(time, events[0][1])
assert_equal ['test', time, records[0]], events[0]
assert_equal_event_time(time, events[1][1])
assert_equal ['test', time, records[1]], events[1]
end
test 'send_without_time_as_integer' do
target_input_driver = create_target_input_driver
@d = d = create_driver(config + %[
flush_interval 1s
time_as_integer false
])
time = event_time("2011-01-02 13:14:15 UTC")
records = [
{"a" => 1},
{"a" => 2}
]
stub(d.instance.ack_handler).read_ack_from_sock(anything).never
assert_rr do
target_input_driver.run(expect_records: 2) do
d.run(default_tag: 'test') do
records.each do |record|
d.feed(time, record)
end
end
end
end
events = target_input_driver.events
assert_equal_event_time(time, events[0][1])
assert_equal ['test', time, records[0]], events[0]
assert_equal_event_time(time, events[1][1])
assert_equal ['test', time, records[1]], events[1]
end
test 'send_comprssed_message_pack_stream_if_compress_is_gzip' do
target_input_driver = create_target_input_driver
@d = d = create_driver(config + %[
flush_interval 1s
compress gzip
])
time = event_time('2011-01-02 13:14:15 UTC')
records = [
{"a" => 1},
{"a" => 2}
]
target_input_driver.run(expect_records: 2) do
d.run(default_tag: 'test') do
records.each do |record|
d.feed(time, record)
end
end
end
event_streams = target_input_driver.event_streams
assert_true event_streams[0][1].is_a?(Fluent::CompressedMessagePackEventStream)
events = target_input_driver.events
assert_equal ['test', time, records[0]], events[0]
assert_equal ['test', time, records[1]], events[1]
end
test 'send_to_a_node_supporting_responses' do
target_input_driver = create_target_input_driver
@d = d = create_driver(config + %[flush_interval 1s])
time = event_time("2011-01-02 13:14:15 UTC")
records = [
{"a" => 1},
{"a" => 2}
]
# not attempt to receive responses
stub(d.instance.ack_handler).read_ack_from_sock(anything).never
assert_rr do
target_input_driver.run(expect_records: 2) do
d.run(default_tag: 'test') do
records.each do |record|
d.feed(time, record)
end
end
end
end
events = target_input_driver.events
assert_equal ['test', time, records[0]], events[0]
assert_equal ['test', time, records[1]], events[1]
end
test 'send_to_a_node_not_supporting_responses' do
target_input_driver = create_target_input_driver
@d = d = create_driver(config + %[flush_interval 1s])
time = event_time("2011-01-02 13:14:15 UTC")
records = [
{"a" => 1},
{"a" => 2}
]
# not attempt to receive responses
stub(d.instance.ack_handler).read_ack_from_sock(anything).never
assert_rr do
target_input_driver.run(expect_records: 2) do
d.run(default_tag: 'test') do
records.each do |record|
d.feed(time, record)
end
end
end
end
events = target_input_driver.events
assert_equal ['test', time, records[0]], events[0]
assert_equal ['test', time, records[1]], events[1]
end
test 'a node supporting responses' do
target_input_driver = create_target_input_driver
@d = d = create_driver(config + %[
require_ack_response true
ack_response_timeout 1s
<buffer tag>
flush_mode immediate
retry_type periodic
retry_wait 30s
flush_at_shutdown true
</buffer>
])
time = event_time("2011-01-02 13:14:15 UTC")
acked_chunk_ids = []
nacked = false
mock.proxy(d.instance.ack_handler).read_ack_from_sock(anything) do |info, success|
if success
acked_chunk_ids << info.chunk_id
else
nacked = true
end
[info, success]
end
records = [
{"a" => 1},
{"a" => 2}
]
target_input_driver.run(expect_records: 2, timeout: 5) do
d.end_if { acked_chunk_ids.size > 0 || nacked }
d.run(default_tag: 'test', wait_flush_completion: false, shutdown: false) do
d.feed([[time, records[0]], [time,records[1]]])
end
end
assert(!nacked, d.instance.log.logs.join)
events = target_input_driver.events
assert_equal ['test', time, records[0]], events[0]
assert_equal ['test', time, records[1]], events[1]
assert_equal 1, acked_chunk_ids.size
assert_equal d.instance.sent_chunk_ids.first, acked_chunk_ids.first
end
test 'a node supporting responses after stop' do
target_input_driver = create_target_input_driver
@d = d = create_driver(config + %[
require_ack_response true
ack_response_timeout 10s
<buffer tag>
flush_mode immediate
retry_type periodic
retry_wait 30s
flush_at_shutdown true
</buffer>
])
time = event_time("2011-01-02 13:14:15 UTC")
acked_chunk_ids = []
nacked = false
mock.proxy(d.instance.ack_handler).read_ack_from_sock(anything) do |info, success|
if success
acked_chunk_ids << info.chunk_id
else
nacked = true
end
[info, success]
end
records = [
{"a" => 1},
{"a" => 2}
]
target_input_driver.run(expect_records: 2, timeout: 5) do
d.end_if { acked_chunk_ids.size > 0 || nacked }
d.run(default_tag: 'test', wait_flush_completion: false, shutdown: false) do
d.instance.stop
d.feed([[time, records[0]], [time,records[1]]])
d.instance.before_shutdown
d.instance.shutdown
d.instance.after_shutdown
end
end
assert(!nacked, d.instance.log.logs.join)
events = target_input_driver.events
assert_equal ['test', time, records[0]], events[0]
assert_equal ['test', time, records[1]], events[1]
assert_equal 1, acked_chunk_ids.size
assert_equal d.instance.sent_chunk_ids.first, acked_chunk_ids.first
end
data('ack true' => true,
'ack false' => false)
test 'TLS transport and ack parameter combination' do |ack|
omit "TLS and 'ack false' always fails on AppVeyor. Need to debug" if Fluent.windows? && !ack
input_conf = target_config + %[
<transport tls>
insecure true
</transport>
]
target_input_driver = create_target_input_driver(conf: input_conf)
output_conf = %[
send_timeout 5
require_ack_response #{ack}
transport tls
tls_insecure_mode true
<server>
host #{TARGET_HOST}
port #{@target_port}
</server>
<buffer>
#flush_mode immediate
flush_interval 0s
flush_at_shutdown false # suppress errors in d.instance_shutdown
</buffer>
]
@d = d = create_driver(output_conf)
time = event_time("2011-01-02 13:14:15 UTC")
records = [{"a" => 1}, {"a" => 2}]
target_input_driver.run(expect_records: 2, timeout: 3) do
d.run(default_tag: 'test', wait_flush_completion: false, shutdown: false) do
records.each do |record|
d.feed(time, record)
end
end
end
events = target_input_driver.events
assert{ events != [] }
assert_equal(['test', time, records[0]], events[0])
assert_equal(['test', time, records[1]], events[1])
end
test 'a destination node not supporting responses by just ignoring' do
target_input_driver = create_target_input_driver(response_stub: ->(_option) { nil }, disconnect: false)
@d = d = create_driver(config + %[
require_ack_response true
ack_response_timeout 1s
<buffer tag>
flush_mode immediate
retry_type periodic
retry_wait 30s
flush_at_shutdown false # suppress errors in d.instance_shutdown
flush_thread_interval 30s
</buffer>
])
node = d.instance.nodes.first
delayed_commit_timeout_value = nil
time = event_time("2011-01-02 13:14:15 UTC")
records = [
{"a" => 1},
{"a" => 2}
]
target_input_driver.end_if{ d.instance.rollback_count > 0 }
target_input_driver.end_if{ !node.available? }
target_input_driver.run(expect_records: 2, timeout: 25) do
d.run(default_tag: 'test', timeout: 20, wait_flush_completion: false, shutdown: false, flush: false) do
delayed_commit_timeout_value = d.instance.delayed_commit_timeout
d.feed([[time, records[0]], [time,records[1]]])
end
end
assert_equal (1 + 2), delayed_commit_timeout_value
events = target_input_driver.events
assert_equal ['test', time, records[0]], events[0]
assert_equal ['test', time, records[1]], events[1]
assert{ d.instance.rollback_count > 0 }
logs = d.instance.log.logs
assert{ logs.any?{|log| log.include?("no response from node. regard it as unavailable.") } }
end
test 'a destination node not supporting responses by disconnection' do
target_input_driver = create_target_input_driver(response_stub: ->(_option) { nil }, disconnect: true)
@d = d = create_driver(config + %[
require_ack_response true
ack_response_timeout 1s
<buffer tag>
flush_mode immediate
retry_type periodic
retry_wait 30s
flush_at_shutdown false # suppress errors in d.instance_shutdown
flush_thread_interval 30s
</buffer>
])
node = d.instance.nodes.first
delayed_commit_timeout_value = nil
time = event_time("2011-01-02 13:14:15 UTC")
records = [
{"a" => 1},
{"a" => 2}
]
target_input_driver.end_if{ d.instance.rollback_count > 0 }
target_input_driver.end_if{ !node.available? }
target_input_driver.run(expect_records: 2, timeout: 25) do
d.run(default_tag: 'test', timeout: 20, wait_flush_completion: false, shutdown: false, flush: false) do
delayed_commit_timeout_value = d.instance.delayed_commit_timeout
d.feed([[time, records[0]], [time,records[1]]])
end
end
assert_equal (1 + 2), delayed_commit_timeout_value
events = target_input_driver.events
assert_equal ['test', time, records[0]], events[0]
assert_equal ['test', time, records[1]], events[1]
assert{ d.instance.rollback_count > 0 }
logs = d.instance.log.logs
assert{ logs.any?{|log| log.include?("no response from node. regard it as unavailable.") } }
end
test 'authentication_with_shared_key' do
input_conf = target_config + %[
<security>
self_hostname in.localhost
shared_key fluentd-sharedkey
<client>
host 127.0.0.1
</client>
</security>
]
target_input_driver = create_target_input_driver(conf: input_conf)
output_conf = %[
send_timeout 51
<security>
self_hostname localhost
shared_key fluentd-sharedkey
</security>
<server>
name test
host #{TARGET_HOST}
port #{@target_port}
shared_key fluentd-sharedkey
</server>
]
@d = d = create_driver(output_conf)
time = event_time("2011-01-02 13:14:15 UTC")
records = [
{"a" => 1},
{"a" => 2}
]
target_input_driver.run(expect_records: 2, timeout: 15) do
d.run(default_tag: 'test') do
records.each do |record|
d.feed(time, record)
end
end
end
events = target_input_driver.events
assert{ events != [] }
assert_equal(['test', time, records[0]], events[0])
assert_equal(['test', time, records[1]], events[1])
end
test 'keepalive + shared_key' do
input_conf = target_config + %[
<security>
self_hostname in.localhost
shared_key fluentd-sharedkey
</security>
]
target_input_driver = create_target_input_driver(conf: input_conf)
output_conf = %[
send_timeout 51
keepalive true
<security>
self_hostname localhost
shared_key fluentd-sharedkey
</security>
<server>
name test
host #{TARGET_HOST}
port #{@target_port}
</server>
]
@d = d = create_driver(output_conf)
time = event_time('2011-01-02 13:14:15 UTC')
records = [{ 'a' => 1 }, { 'a' => 2 }]
records2 = [{ 'b' => 1}, { 'b' => 2}]
target_input_driver.run(expect_records: 4, timeout: 15) do
d.run(default_tag: 'test') do
records.each do |record|
d.feed(time, record)
end
d.flush # emit buffer to reuse same socket later
records2.each do |record|
d.feed(time, record)
end
end
end
events = target_input_driver.events
assert{ events != [] }
assert_equal(['test', time, records[0]], events[0])
assert_equal(['test', time, records[1]], events[1])
assert_equal(['test', time, records2[0]], events[2])
assert_equal(['test', time, records2[1]], events[3])
end
test 'authentication_with_user_auth' do
input_conf = target_config + %[
<security>
self_hostname in.localhost
shared_key fluentd-sharedkey
user_auth true
<user>
username fluentd
password fluentd
</user>
<client>
host 127.0.0.1
</client>
</security>
]
target_input_driver = create_target_input_driver(conf: input_conf)
output_conf = %[
send_timeout 51
<security>
self_hostname localhost
shared_key fluentd-sharedkey
</security>
<server>
name test
host #{TARGET_HOST}
port #{@target_port}
shared_key fluentd-sharedkey
username fluentd
password fluentd
</server>
]
@d = d = create_driver(output_conf)
time = event_time("2011-01-02 13:14:15 UTC")
records = [
{"a" => 1},
{"a" => 2}
]
target_input_driver.run(expect_records: 2, timeout: 15) do
d.run(default_tag: 'test') do
records.each do |record|
d.feed(time, record)
end
end
end
events = target_input_driver.events
assert{ events != [] }
assert_equal(['test', time, records[0]], events[0])
assert_equal(['test', time, records[1]], events[1])
end
# This test is not 100% but test failed with previous Node implementation which has race condition
test 'Node with security is thread-safe on multi threads' do
input_conf = target_config + %[
<security>
self_hostname in.localhost
shared_key fluentd-sharedkey
<client>
host 127.0.0.1
</client>
</security>
]
target_input_driver = create_target_input_driver(conf: input_conf)
output_conf = %[
send_timeout 51
<security>
self_hostname localhost