diff --git a/plugin/storage/es/factory.go b/plugin/storage/es/factory.go index 7bde808514f..205c9a216d7 100644 --- a/plugin/storage/es/factory.go +++ b/plugin/storage/es/factory.go @@ -138,6 +138,9 @@ func createSpanReader( cfg config.ClientBuilder, archive bool, ) (spanstore.Reader, error) { + if cfg.GetUseILM() && !cfg.GetUseReadWriteAliases() { + return nil, fmt.Errorf("--es.use-ilm must always be used in conjunction with --es.use-aliases to ensure ES writers and readers refer to the single index mapping") + } return esSpanStore.NewSpanReader(esSpanStore.SpanReaderParams{ Client: client, Logger: logger, @@ -161,6 +164,9 @@ func createSpanWriter( ) (spanstore.Writer, error) { var tags []string var err error + if cfg.GetUseILM() && !cfg.GetUseReadWriteAliases() { + return nil, fmt.Errorf("--es.use-ilm must always be used in conjunction with --es.use-aliases to ensure ES writers and readers refer to the single index mapping") + } if tags, err = cfg.TagKeysAsFields(); err != nil { logger.Error("failed to get tag keys", zap.Error(err)) return nil, err diff --git a/plugin/storage/es/factory_test.go b/plugin/storage/es/factory_test.go index 81f578eb385..885017e8966 100644 --- a/plugin/storage/es/factory_test.go +++ b/plugin/storage/es/factory_test.go @@ -105,6 +105,22 @@ func TestElasticsearchTagsFileDoNotExist(t *testing.T) { assert.Nil(t, r) } +func TestElasticsearchILMUsedWithoutReadWriteAliases(t *testing.T) { + f := NewFactory() + mockConf := &mockClientBuilder{} + mockConf.UseILM = true + f.primaryConfig = mockConf + f.archiveConfig = mockConf + assert.NoError(t, f.Initialize(metrics.NullFactory, zap.NewNop())) + w, err := f.CreateSpanWriter() + require.EqualError(t, err, "--es.use-ilm must always be used in conjunction with --es.use-aliases to ensure ES writers and readers refer to the single index mapping") + assert.Nil(t, w) + + r, err := f.CreateSpanReader() + require.EqualError(t, err, "--es.use-ilm must always be used in conjunction with --es.use-aliases to ensure ES writers and readers refer to the single index mapping") + assert.Nil(t, r) +} + func TestTagKeysAsFields(t *testing.T) { tests := []struct { path string