1212import org .elasticsearch .ResourceNotFoundException ;
1313import org .elasticsearch .action .ActionListener ;
1414import org .elasticsearch .action .admin .indices .alias .Alias ;
15+ import org .elasticsearch .action .downsample .DownsampleConfig ;
1516import org .elasticsearch .action .support .ActionTestUtils ;
1617import org .elasticsearch .action .support .master .AcknowledgedResponse ;
1718import org .elasticsearch .cluster .metadata .MetadataIndexTemplateService .PutRequest ;
@@ -1109,6 +1110,15 @@ public void testResolveLifecycle() throws Exception {
11091110 .buildTemplate ();
11101111 String ct45d = "ct_45d" ;
11111112 project = addComponentTemplate (service , project , ct45d , lifecycle45d );
1113+ DataStreamLifecycle .Template lifecycle60d = DataStreamLifecycle .dataLifecycleBuilder ()
1114+ .dataRetention (TimeValue .timeValueDays (60 ))
1115+ .downsamplingRounds (
1116+ List .of (new DataStreamLifecycle .DownsamplingRound (TimeValue .timeValueDays (7 ), new DateHistogramInterval ("3h" )))
1117+ )
1118+ .downsamplingMethod (DownsampleConfig .SamplingMethod .LAST_VALUE )
1119+ .buildTemplate ();
1120+ String ct60d = "ct_60d" ;
1121+ project = addComponentTemplate (service , project , ct60d , lifecycle60d );
11121122
11131123 DataStreamLifecycle .Template lifecycleNullRetention = DataStreamLifecycle .createDataLifecycleTemplate (
11141124 true ,
@@ -1119,6 +1129,15 @@ public void testResolveLifecycle() throws Exception {
11191129 String ctNullRetention = "ct_null_retention" ;
11201130 project = addComponentTemplate (service , project , ctNullRetention , lifecycleNullRetention );
11211131
1132+ DataStreamLifecycle .Template lifecycleNullDownsampling = DataStreamLifecycle .createDataLifecycleTemplate (
1133+ true ,
1134+ ResettableValue .undefined (),
1135+ ResettableValue .reset (),
1136+ ResettableValue .reset ()
1137+ );
1138+ String ctNullDownsampling = "ct_null_downsampling" ;
1139+ project = addComponentTemplate (service , project , ctNullDownsampling , lifecycleNullDownsampling );
1140+
11221141 String ctEmptyLifecycle = "ct_empty_lifecycle" ;
11231142 project = addComponentTemplate (service , project , ctEmptyLifecycle , emptyLifecycle );
11241143
@@ -1220,6 +1239,72 @@ public void testResolveLifecycle() throws Exception {
12201239 // Composable Z: "lifecycle": {"retention": "45d", "downsampling": [{"after": "30d", "fixed_interval": "3h"}]}
12211240 // Result: "lifecycle": {"retention": "45d", "downsampling": [{"after": "30d", "fixed_interval": "3h"}]}
12221241 assertLifecycleResolution (service , project , List .of (ct30d , ctDisabledLifecycle ), lifecycle45d , lifecycle45d );
1242+
1243+ // Component A: "lifecycle": {
1244+ // "retention": "60d",
1245+ // "downsampling_method": "last_value",
1246+ // "downsampling": [{"after": "3d", "fixed_interval": "3h"}]
1247+ // }
1248+ // Composable Z: "lifecycle": {"retention": "45d", "downsampling": [{"after": "30d", "fixed_interval": "3h"}]}
1249+ // Result: "lifecycle": {
1250+ // "retention": "45d",
1251+ // "downsampling": [{"after": "30d", "fixed_interval": "3h"}],
1252+ // "downsampling_method": "last_value"
1253+ // }
1254+ assertLifecycleResolution (
1255+ service ,
1256+ project ,
1257+ List .of (ct60d ),
1258+ lifecycle45d ,
1259+ DataStreamLifecycle .dataLifecycleBuilder ()
1260+ .dataRetention (lifecycle45d .dataRetention ())
1261+ .downsamplingMethod (lifecycle60d .downsamplingMethod ())
1262+ .downsamplingRounds (lifecycle45d .downsamplingRounds ())
1263+ .buildTemplate ()
1264+ );
1265+
1266+ // Component A: "lifecycle": {
1267+ // "retention": "60d",
1268+ // "downsampling_method": "last_value",
1269+ // "downsampling": [{"after": "3d", "fixed_interval": "3h"}]
1270+ // }
1271+ // Component B: "lifecycle": {"retention": "45d", "downsampling": [{"after": "30d", "fixed_interval": "3h"}]}
1272+ // Composable Z: "lifecycle": {"downsampling": null, "downsampling_method": null}
1273+ // Result: "lifecycle": {"retention": "45d"}
1274+ assertLifecycleResolution (
1275+ service ,
1276+ project ,
1277+ List .of (ct60d , ct45d ),
1278+ lifecycleNullDownsampling ,
1279+ DataStreamLifecycle .dataLifecycleBuilder ().dataRetention (lifecycle45d .dataRetention ()).buildTemplate ()
1280+ );
1281+
1282+ // Component A: "lifecycle": {
1283+ // "retention": "60d",
1284+ // "downsampling_method": "last_value",
1285+ // "downsampling": [{"after": "3d", "fixed_interval": "3h"}]
1286+ // }
1287+ // Composable Z: "lifecycle": {"retention": "45d", "downsampling": [{"after": "30d", "fixed_interval": "3h"}]}
1288+ // Result: "lifecycle": {
1289+ // "retention": "45d",
1290+ // "downsampling": [{"after": "30d", "fixed_interval": "3h"}],
1291+ // "downsampling_method": "last_value"
1292+ // }
1293+ assertLifecycleResolution (
1294+ service ,
1295+ project ,
1296+ List .of (ct60d ),
1297+ DataStreamLifecycle .createDataLifecycleTemplate (
1298+ true ,
1299+ ResettableValue .undefined (),
1300+ ResettableValue .undefined (),
1301+ ResettableValue .reset ()
1302+ ),
1303+ DataStreamLifecycle .dataLifecycleBuilder ()
1304+ .dataRetention (lifecycle60d .dataRetention ())
1305+ .downsamplingRounds (lifecycle60d .downsamplingRounds ())
1306+ .buildTemplate ()
1307+ );
12231308 }
12241309
12251310 public void testResolveFailureStore () throws Exception {
0 commit comments