Create dedicated factory methods for data lifecycle (#126487)

The class `DataStreamLifecycle` is currently capturing the lifecycle
configuration that currently manages all data stream indices, but soon
enough it will be split into two variants, the data and the failures
lifecycle. 

Some pre-work has been done already but as we are progressing in our
POC, we see that it will be really useful if the `DataStreamLifecycle`
is "aware" of the target index component. This will allow us to
correctly apply global retention or to throw an error if a downsampling
configuration is provided to a failure lifecycle.

In this PR, we perform a small refactoring to reduce the noise in
https://github.com/elastic/elasticsearch/pull/125658. Here we introduce
the following:

- A factory method that creates a data lifecycle, for now it's trivial but it will be more useful soon.
- We rename the "empty" builder to explicitly mention the index component it refers to.
This commit is contained in:
Mary Gouseti 2025-04-23 13:00:25 +03:00 committed by GitHub
parent 1e7c6abaf6
commit b9917086e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 225 additions and 164 deletions

View file

@ -59,7 +59,7 @@ public class DataStreamLifecycleDownsampleDisruptionIT extends ESIntegTestCase {
ensureGreen();
final String dataStreamName = "metrics-foo";
DataStreamLifecycle.Template lifecycle = DataStreamLifecycle.builder()
DataStreamLifecycle.Template lifecycle = DataStreamLifecycle.dataLifecycleBuilder()
.downsampling(
List.of(
new DataStreamLifecycle.DownsamplingRound(

View file

@ -54,7 +54,7 @@ public class DataStreamLifecycleDownsampleIT extends ESIntegTestCase {
public void testDownsampling() throws Exception {
String dataStreamName = "metrics-foo";
DataStreamLifecycle.Template lifecycle = DataStreamLifecycle.builder()
DataStreamLifecycle.Template lifecycle = DataStreamLifecycle.dataLifecycleBuilder()
.downsampling(
List.of(
new DataStreamLifecycle.DownsamplingRound(
@ -127,7 +127,7 @@ public class DataStreamLifecycleDownsampleIT extends ESIntegTestCase {
public void testDownsamplingOnlyExecutesTheLastMatchingRound() throws Exception {
String dataStreamName = "metrics-bar";
DataStreamLifecycle.Template lifecycle = DataStreamLifecycle.builder()
DataStreamLifecycle.Template lifecycle = DataStreamLifecycle.dataLifecycleBuilder()
.downsampling(
List.of(
new DataStreamLifecycle.DownsamplingRound(
@ -195,7 +195,7 @@ public class DataStreamLifecycleDownsampleIT extends ESIntegTestCase {
// we expect the earlier round to be ignored
String dataStreamName = "metrics-baz";
DataStreamLifecycle.Template lifecycle = DataStreamLifecycle.builder()
DataStreamLifecycle.Template lifecycle = DataStreamLifecycle.dataLifecycleBuilder()
.downsampling(
List.of(
new DataStreamLifecycle.DownsamplingRound(
@ -259,7 +259,7 @@ public class DataStreamLifecycleDownsampleIT extends ESIntegTestCase {
// update the lifecycle so that it only has one round, for the same `after` parameter as before, but a different interval
// the different interval should yield a different downsample index name so we expect the data stream lifecycle to get the previous
// `10s` interval downsample index, downsample it to `30s` and replace it in the data stream instead of the `10s` one.
DataStreamLifecycle updatedLifecycle = DataStreamLifecycle.builder()
DataStreamLifecycle updatedLifecycle = DataStreamLifecycle.dataLifecycleBuilder()
.downsampling(
List.of(
new DataStreamLifecycle.DownsamplingRound(