From bb042ccdacb0028169e939a90076b9196cdbeada Mon Sep 17 00:00:00 2001 From: rbizos <58781501+rbizos@users.noreply.github.com> Date: Fri, 1 Apr 2022 21:41:22 +0200 Subject: [PATCH] Ilm disable template (#3610) * useILM will prevent index template creation The index template should be created by es-rollover. Without this, it was mandatory to use --es.create-index-templates=false with --es.use-ilm, otherwise it would override the index template with an empty lifecycle.name thus preventing the rollover to work Signed-off-by: Raphael Bizos * fixing ILM test Signed-off-by: Raphael Bizos * Adding a comment for ILM and index creation Signed-off-by: Raphael Bizos --- plugin/storage/es/factory.go | 4 +++- plugin/storage/es/factory_test.go | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plugin/storage/es/factory.go b/plugin/storage/es/factory.go index dea1ad6aff3..7878d022016 100644 --- a/plugin/storage/es/factory.go +++ b/plugin/storage/es/factory.go @@ -199,7 +199,9 @@ func createSpanWriter( Archive: archive, UseReadWriteAliases: cfg.GetUseReadWriteAliases(), }) - if cfg.IsCreateIndexTemplates() { + + // Creating a template here would conflict with the one created for ILM resulting to no index rollover + if cfg.IsCreateIndexTemplates() && !cfg.GetUseILM() { err := writer.CreateTemplates(spanMapping, serviceMapping, cfg.GetIndexPrefix()) if err != nil { return nil, err diff --git a/plugin/storage/es/factory_test.go b/plugin/storage/es/factory_test.go index 525dc9a29dc..a5d7b71d299 100644 --- a/plugin/storage/es/factory_test.go +++ b/plugin/storage/es/factory_test.go @@ -185,6 +185,16 @@ func TestCreateTemplateError(t *testing.T) { assert.Error(t, err, "template-error") } +func TestILMDisableTemplateCreation(t *testing.T) { + f := NewFactory() + f.primaryConfig = &mockClientBuilder{createTemplateError: errors.New("template-error"), Configuration: escfg.Configuration{Enabled: true, UseILM: true, UseReadWriteAliases: true, CreateIndexTemplates: true}} + f.archiveConfig = &mockClientBuilder{} + err := f.Initialize(metrics.NullFactory, zap.NewNop()) + require.NoError(t, err) + _, err = f.CreateSpanWriter() + assert.Nil(t, err) // as the createTemplate is not called, CreateSpanWriter should not return an error +} + func TestArchiveDisabled(t *testing.T) { f := NewFactory() f.archiveConfig = &mockClientBuilder{Configuration: escfg.Configuration{Enabled: false}}