399
399
let ( :ilm_rollover_alias ) { "the_cat_in_the_hat" }
400
400
let ( :index ) { ilm_rollover_alias }
401
401
let ( :expected_index ) { index }
402
- let ( :template_name ) { "custom" }
403
402
let ( :settings ) { super . merge ( "ilm_policy" => ilm_policy_name ,
404
403
"template" => template ,
405
- "template_name" => template_name ,
406
404
"ilm_rollover_alias" => ilm_rollover_alias ) }
407
405
408
406
419
417
put_policy ( @es , ilm_policy_name , policy )
420
418
end
421
419
420
+ it_behaves_like 'an ILM enabled Logstash'
421
+
422
422
it 'should create the rollover alias' do
423
423
expect ( @es . indices . exists_alias ( index : ilm_rollover_alias ) ) . to be_falsey
424
424
subject . register
442
442
it 'should write the ILM settings into the template' do
443
443
subject . register
444
444
sleep ( 1 )
445
- expect ( @es . indices . get_template ( name : template_name ) [ template_name ] [ "index_patterns" ] ) . to eq ( [ "#{ ilm_rollover_alias } -*" ] )
446
- expect ( @es . indices . get_template ( name : template_name ) [ template_name ] [ "settings" ] [ 'index' ] [ 'lifecycle' ] [ 'name' ] ) . to eq ( ilm_policy_name )
447
- expect ( @es . indices . get_template ( name : template_name ) [ template_name ] [ "settings" ] [ 'index' ] [ 'lifecycle' ] [ 'rollover_alias' ] ) . to eq ( ilm_rollover_alias )
445
+ expect ( @es . indices . get_template ( name : ilm_rollover_alias ) [ ilm_rollover_alias ] [ "index_patterns" ] ) . to eq ( [ "#{ ilm_rollover_alias } -*" ] )
446
+ expect ( @es . indices . get_template ( name : ilm_rollover_alias ) [ ilm_rollover_alias ] [ "settings" ] [ 'index' ] [ 'lifecycle' ] [ 'name' ] ) . to eq ( ilm_policy_name )
447
+ expect ( @es . indices . get_template ( name : ilm_rollover_alias ) [ ilm_rollover_alias ] [ "settings" ] [ 'index' ] [ 'lifecycle' ] [ 'rollover_alias' ] ) . to eq ( ilm_rollover_alias )
448
+ end
449
+
450
+ context 'with a different template_name' do
451
+ let ( :template_name ) { "custom_template_name" }
452
+ let ( :settings ) { super . merge ( 'template_name' => template_name ) }
453
+
454
+ it_behaves_like 'an ILM enabled Logstash'
455
+
456
+ it 'should write the ILM settings into the template' do
457
+ subject . register
458
+ sleep ( 1 )
459
+ expect ( @es . indices . get_template ( name : template_name ) [ template_name ] [ "index_patterns" ] ) . to eq ( [ "#{ ilm_rollover_alias } -*" ] )
460
+ expect ( @es . indices . get_template ( name : template_name ) [ template_name ] [ "settings" ] [ 'index' ] [ 'lifecycle' ] [ 'name' ] ) . to eq ( ilm_policy_name )
461
+ expect ( @es . indices . get_template ( name : template_name ) [ template_name ] [ "settings" ] [ 'index' ] [ 'lifecycle' ] [ 'rollover_alias' ] ) . to eq ( ilm_rollover_alias )
462
+ end
448
463
end
449
464
450
- it_behaves_like 'an ILM enabled Logstash'
451
465
end
452
466
end
453
467
467
481
expect { get_policy ( @es , LogStash ::Outputs ::ElasticSearch ::DEFAULT_POLICY ) } . to raise_error ( Elasticsearch ::Transport ::Transport ::Errors ::NotFound )
468
482
end
469
483
470
- it 'should write the ILM settings into the template' do
484
+ it 'should not write the ILM settings into the template' do
471
485
subject . register
472
486
sleep ( 1 )
473
487
expect ( @es . indices . get_template ( name : "logstash" ) [ "logstash" ] [ "index_patterns" ] ) . to eq ( [ "logstash-*" ] )
474
488
expect ( @es . indices . get_template ( name : "logstash" ) [ "logstash" ] [ "settings" ] [ 'index' ] [ 'lifecycle' ] ) . to be_nil
475
-
476
489
end
477
490
478
-
479
491
context 'with an existing policy that will roll over' do
480
492
let ( :policy ) { small_max_doc_policy }
481
493
let ( :ilm_policy_name ) { "3_docs" }
482
494
let ( :settings ) { super . merge ( "ilm_policy" => ilm_policy_name ) }
483
495
484
- it 'should index documents normally' do
485
-
496
+ it 'should not roll over indices' do
486
497
subject . register
487
498
subject . multi_receive ( [
488
499
LogStash ::Event . new ( "message" => "sample message here" ) ,
513
524
expect ( indexes_written . values . first ) . to eq ( 6 )
514
525
end
515
526
end
527
+
528
+ context 'with a custom template name' do
529
+ let ( :template_name ) { "custom_template_name" }
530
+ let ( :settings ) { super . merge ( 'template_name' => template_name ) }
531
+
532
+ it 'should not write the ILM settings into the template' do
533
+ subject . register
534
+ sleep ( 1 )
535
+ expect ( @es . indices . get_template ( name : template_name ) [ template_name ] [ "index_patterns" ] ) . to eq ( [ "logstash-*" ] )
536
+ expect ( @es . indices . get_template ( name : template_name ) [ template_name ] [ "settings" ] [ 'index' ] [ 'lifecycle' ] ) . to be_nil
537
+ end
538
+ end
539
+
516
540
end
517
541
end
518
542
end
0 commit comments