Skip to content

Commit a692aed

Browse files
authored
Include component templates in retention validaiton (#109779)
We shouldn't disregard a component template's lifecycle configuration if the index template has one during retention validation.
1 parent 4eaaf9c commit a692aed

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

docs/changelog/109779.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 109779
2+
summary: Include component templates in retention validaiton
3+
area: Data streams
4+
type: bug
5+
issues: []

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -805,9 +805,7 @@ static void validateLifecycle(
805805
ComposableIndexTemplate template,
806806
@Nullable DataStreamGlobalRetention globalRetention
807807
) {
808-
DataStreamLifecycle lifecycle = template.template() != null && template.template().lifecycle() != null
809-
? template.template().lifecycle()
810-
: resolveLifecycle(template, metadata.componentTemplates());
808+
DataStreamLifecycle lifecycle = resolveLifecycle(template, metadata.componentTemplates());
811809
if (lifecycle != null) {
812810
if (template.getDataStreamTemplate() == null) {
813811
throw new IllegalArgumentException(

server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamLifecycleWithRetentionWarningsTests.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,48 @@ public void testValidateLifecycleIndexTemplateWithWarning() {
191191
);
192192
}
193193

194+
/**
195+
* Make sure we still take into account component templates during validation (and not just the index template).
196+
*/
197+
public void testValidateLifecycleComponentTemplateWithWarning() {
198+
ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
199+
HeaderWarning.setThreadContext(threadContext);
200+
TimeValue defaultRetention = randomTimeValue(2, 100, TimeUnit.DAYS);
201+
MetadataIndexTemplateService.validateLifecycle(
202+
Metadata.builder()
203+
.componentTemplates(
204+
Map.of(
205+
"component-template",
206+
new ComponentTemplate(
207+
new Template(
208+
null,
209+
null,
210+
null,
211+
new DataStreamLifecycle(
212+
new DataStreamLifecycle.Retention(randomTimeValue(2, 100, TimeUnit.DAYS)),
213+
null,
214+
null
215+
)
216+
),
217+
null,
218+
null
219+
)
220+
)
221+
)
222+
.build(),
223+
randomAlphaOfLength(10),
224+
ComposableIndexTemplate.builder()
225+
.template(new Template(null, null, null, DataStreamLifecycle.DEFAULT))
226+
.dataStreamTemplate(new ComposableIndexTemplate.DataStreamTemplate())
227+
.indexPatterns(List.of(randomAlphaOfLength(10)))
228+
.componentTemplates(List.of("component-template"))
229+
.build(),
230+
new DataStreamGlobalRetention(defaultRetention, null)
231+
);
232+
Map<String, List<String>> responseHeaders = threadContext.getResponseHeaders();
233+
assertThat(responseHeaders.size(), is(0));
234+
}
235+
194236
public void testValidateLifecycleInComponentTemplate() throws Exception {
195237
IndicesService indicesService = mock(IndicesService.class);
196238
IndexService indexService = mock(IndexService.class);

0 commit comments

Comments
 (0)