Skip to content

Commit 9a358ee

Browse files
committed
Log the situation when resolving the ILM template settings.
1 parent 974d030 commit 9a358ee

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

lib/logstash/outputs/elasticsearch/template_manager.rb

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,27 @@ def self.add_ilm_settings_to_template(plugin, template)
5454
end
5555

5656
def self.resolve_template_settings(plugin, template)
57-
return composable_index_template_settings(template) if template.key?('template')
58-
return legacy_index_template_settings(template) if template.key?('settings')
59-
return template_endpoint(plugin) == INDEX_TEMPLATE_ENDPOINT ?
60-
composable_index_template_settings(template) :
61-
legacy_index_template_settings(template)
57+
if template.key?('template')
58+
plugin.logger.trace("Resolving ILM template settings: under 'template' key", :template => template, :template_api => plugin.template_api, :es_version => plugin.maximum_seen_major_version)
59+
composable_index_template_settings(template)
60+
elsif template.key?('settings')
61+
plugin.logger.trace("Resolving ILM template settings: under 'settings' key", :template => template, :template_api => plugin.template_api, :es_version => plugin.maximum_seen_major_version)
62+
legacy_index_template_settings(template)
63+
else
64+
template_endpoint = template_endpoint(plugin)
65+
plugin.logger.trace("Resolving ILM template settings: template doesn't have 'settings' or 'template' fields, falling back to auto detection", :template => template, :template_api => plugin.template_api, :es_version => plugin.maximum_seen_major_version, :template_endpoint => template_endpoint)
66+
template_endpoint == INDEX_TEMPLATE_ENDPOINT ?
67+
composable_index_template_settings(template) :
68+
legacy_index_template_settings(template)
69+
end
6270
end
6371

64-
# Returns (if exists) or creates _template API compatible template settings
72+
# Sets ['settings'] field to be compatible with _template API structure
6573
def self.legacy_index_template_settings(template)
6674
template['settings'] ||= {}
6775
end
6876

69-
# Returns (if exists) or creates _index_template API compatible template settings
77+
# Sets the ['template']['settings'] fields if not exist to be compatible with _index_template API structure
7078
def self.composable_index_template_settings(template)
7179
template['template'] ||= {}
7280
template['template']['settings'] ||= {}

spec/unit/outputs/elasticsearch/template_manager_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
let(:template_api) { "composable" }
7474

7575
it 'resolves composable index template API compatible setting' do
76+
expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(8) # required to log
7677
template = {}
7778
described_class.resolve_template_settings(plugin, template)
7879
expect(template["template"]["settings"]).not_to eq(nil)
@@ -83,6 +84,7 @@
8384
let(:template_api) { "legacy" }
8485

8586
it 'resolves legacy index template API compatible setting' do
87+
expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(7) # required to log
8688
template = {}
8789
described_class.resolve_template_settings(plugin, template)
8890
expect(template["settings"]).not_to eq(nil)

0 commit comments

Comments
 (0)