Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/128161.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 128161
summary: System data streams incorrectly show up in the list of template validation
problems
area: Data streams
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,12 @@ private static void validateDataStreamsStillReferenced(
String templateName,
ComposableIndexTemplate newTemplate
) {
final Set<String> dataStreams = project.dataStreams().keySet();
final Set<String> dataStreams = project.dataStreams()
.entrySet()
.stream()
.filter(entry -> entry.getValue().isSystem() == false)
.map(Map.Entry::getKey)
.collect(Collectors.toSet());

Function<ProjectMetadata, Set<String>> findUnreferencedDataStreams = meta -> {
final Set<String> unreferenced = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.Strings;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.env.Environment;
import org.elasticsearch.health.node.selection.HealthNodeTaskExecutor;
Expand Down Expand Up @@ -1718,6 +1719,76 @@ public void testInvalidNonDataStreamTemplateWithDataStreamOptions() throws Excep
);
}

public void testSystemDataStreamsIgnoredByValidateIndexTemplateV2() throws Exception {
/*
* This test makes sure that system data streams (which do not have named templates) do not appear in the list of data streams
* without named templates when validateIndexTemplateV2 fails due to another non-system data stream not having a named template.
*/
MetadataIndexTemplateService metadataIndexTemplateService = getMetadataIndexTemplateService();
final String dataStreamTemplateName = "data_stream_template";
final String indexTemplateName = "index_template";
final String systemDataStreamName = "system_ds";
final String ordinaryDataStreamName = "my_ds";
final String ordinaryDataStreamIndexPattern = "my_ds*";
ComposableIndexTemplate highPriorityDataStreamTemplate = ComposableIndexTemplate.builder()
.indexPatterns(List.of(ordinaryDataStreamIndexPattern))
.priority(275L)
.dataStreamTemplate(new ComposableIndexTemplate.DataStreamTemplate(randomBoolean(), randomBoolean()))
.build();
ComposableIndexTemplate highPriorityIndexTemplate = ComposableIndexTemplate.builder()
.indexPatterns(List.of(ordinaryDataStreamIndexPattern))
.priority(200L)
.build();
ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
.dataStreams(
Map.of(
systemDataStreamName,
DataStreamTestHelper.randomInstance(systemDataStreamName, System::currentTimeMillis, randomBoolean(), true),
ordinaryDataStreamName,
DataStreamTestHelper.randomInstance(ordinaryDataStreamName, System::currentTimeMillis, randomBoolean(), false)
),
Map.of()
)
.indexTemplates(Map.of(dataStreamTemplateName, highPriorityDataStreamTemplate, indexTemplateName, highPriorityIndexTemplate))
.build();
ComposableIndexTemplate lowPriorityDataStreamTemplate = ComposableIndexTemplate.builder()
.indexPatterns(List.of(ordinaryDataStreamIndexPattern))
.priority(1L)
.dataStreamTemplate(new ComposableIndexTemplate.DataStreamTemplate(randomBoolean(), randomBoolean()))
.build();
/*
* Here we attempt to change the priority of a template that matches an existing non-system data stream so that it is so low that
* the data stream matches the index (non data-stream) template instead. We expect an error, but that the error only mentions the
* non-system data stream.
*/
Exception exception = expectThrows(
Exception.class,
() -> metadataIndexTemplateService.validateIndexTemplateV2(project, dataStreamTemplateName, lowPriorityDataStreamTemplate)
);
assertThat(
exception.getMessage(),
containsString(
Strings.format(
"composable template [%s] with index patterns [%s], priority [1] would cause data streams [%s] to no longer "
+ "match a data stream template",
dataStreamTemplateName,
ordinaryDataStreamIndexPattern,
ordinaryDataStreamName
)
)
);
ComposableIndexTemplate mediumPriorityDataStreamTemplate = ComposableIndexTemplate.builder()
.indexPatterns(List.of(ordinaryDataStreamIndexPattern))
.priority(201L)
.dataStreamTemplate(new ComposableIndexTemplate.DataStreamTemplate(randomBoolean(), randomBoolean()))
.build();
/*
* We have now corrected the problem -- the priority of the new template is lower than the old data stream template but still higher
* than the non-data-stream index template. So we expect no validation errors.
*/
metadataIndexTemplateService.validateIndexTemplateV2(project, dataStreamTemplateName, mediumPriorityDataStreamTemplate);
}

private ProjectMetadata addComponentTemplate(
MetadataIndexTemplateService service,
ProjectMetadata project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ public static DataStream randomInstance(LongSupplier timeProvider, boolean failu
}

public static DataStream randomInstance(String dataStreamName, LongSupplier timeProvider, boolean failureStore) {
// Some tests don't work well with system data streams, since these data streams require special handling
return randomInstance(dataStreamName, timeProvider, failureStore, false);
}

public static DataStream randomInstance(String dataStreamName, LongSupplier timeProvider, boolean failureStore, boolean system) {
List<Index> indices = randomIndexInstances();
long generation = indices.size() + ESTestCase.randomLongBetween(1, 128);
indices.add(new Index(getDefaultBackingIndexName(dataStreamName, generation), UUIDs.randomBase64UUID(LuceneTestCase.random())));
Expand All @@ -360,9 +365,9 @@ public static DataStream randomInstance(String dataStreamName, LongSupplier time
generation,
metadata,
randomSettings(),
randomBoolean(),
system ? true : randomBoolean(),
replicated,
false, // Some tests don't work well with system data streams, since these data streams require special handling
system,
timeProvider,
randomBoolean(),
randomBoolean() ? IndexMode.STANDARD : null, // IndexMode.TIME_SERIES triggers validation that many unit tests doesn't pass
Expand Down
Loading