Skip to content

Commit a226293

Browse files
committed
Replace use of 'template' with 'index_patterns' when amending templates
1 parent 8fe2078 commit a226293

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

lib/logstash/outputs/elasticsearch/template_manager.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ def self.install(client, template_name, template, template_overwrite)
2424

2525
def self.add_ilm_settings_to_template(plugin, template)
2626
# Include ilm settings in template:
27-
plugin.logger.info("Overwriting template name and pattern as ILM is enabled.")
28-
template['template'] = "#{plugin.ilm_rollover_alias}-*"
27+
plugin.logger.info("Overwriting index patterns, as ILM is enabled.")
28+
# Overwrite any index patterns, and use the rollover alias. Use 'index_patterns' rather than 'template' for pattern
29+
# definition - remove any existing definition of 'template'
30+
template.delete('template') if template.include?('template')
31+
template['index_patterns'] = "#{plugin.ilm_rollover_alias}-*"
2932
if template['settings'] && (template['settings']['index.lifecycle.name'] || template['settings']['index.lifecycle.rollover_alias'])
3033
plugin.logger.info("Overwriting index lifecycle name and rollover alias as ILM is enabled.")
3134
end
3235
template['settings'].update({ 'index.lifecycle.name' => plugin.ilm_policy, 'index.lifecycle.rollover_alias' => plugin.ilm_rollover_alias})
3336
end
3437

35-
# TODO: Verify this is ok
3638
def self.template_name(plugin)
37-
plugin.ilm_enabled? ? plugin.ilm_rollover_alias : plugin.template_name
39+
(plugin.ilm_enabled? && !plugin.template_name) ? plugin.ilm_rollover_alias : plugin.template_name
3840
end
3941

4042
def self.default_template_path(es_major_version)

spec/fixtures/template-with-policy-es6x.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"template" : "custom-*",
2+
"template" : "overwrite-*",
33
"version" : 60001,
44
"settings" : {
55
"index.refresh_interval" : "1s",
66
"number_of_shards": 1,
7-
"index.lifecycle.name": "custom-policy",
8-
"index.lifecycle.rollover_alias": "custom"
7+
"index.lifecycle.name": "overwrite-policy",
8+
"index.lifecycle.rollover_alias": "overwrite"
99
},
1010
"mappings" : {
1111
"_default_" : {

spec/fixtures/template-with-policy-es7x.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"template" : "custom-*",
2+
"index_patterns" : "overwrite-*",
33
"version" : 60001,
44
"settings" : {
55
"index.refresh_interval" : "1s",

spec/integration/outputs/ilm_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,15 @@
396396
end
397397

398398
context 'with a custom template' do
399-
let (:ilm_rollover_alias) { "custom" }
399+
let (:ilm_rollover_alias) { "the_cat_in_the_hat" }
400400
let (:index) { ilm_rollover_alias }
401401
let(:expected_index) { index }
402+
let (:template_name) { "custom" }
402403
let (:settings) { super.merge("ilm_policy" => ilm_policy_name,
403404
"template" => template,
404405
"template_name" => template_name,
405406
"ilm_rollover_alias" => ilm_rollover_alias)}
406-
let (:template_name) { "custom" }
407+
407408

408409
if ESHelper.es_version_satisfies?(">= 7.0")
409410
let (:template) { "spec/fixtures/template-with-policy-es7x.json" }
@@ -441,6 +442,7 @@
441442
it 'should write the ILM settings into the template' do
442443
subject.register
443444
sleep(1)
445+
puts @es.indices.get_template(name: template_name)[template_name]
444446
expect(@es.indices.get_template(name: template_name)[template_name]["index_patterns"]).to eq(["#{ilm_rollover_alias}-*"])
445447
expect(@es.indices.get_template(name: template_name)[template_name]["settings"]['index']['lifecycle']['name']).to eq(ilm_policy_name)
446448
expect(@es.indices.get_template(name: template_name)[template_name]["settings"]['index']['lifecycle']['rollover_alias']).to eq(ilm_rollover_alias)

0 commit comments

Comments
 (0)