99
1010package org .elasticsearch .datastreams ;
1111
12+ import org .elasticsearch .action .downsample .DownsampleConfig ;
1213import org .elasticsearch .cluster .metadata .ComponentTemplate ;
1314import org .elasticsearch .cluster .metadata .ComposableIndexTemplate ;
1415import org .elasticsearch .cluster .metadata .DataStreamGlobalRetentionSettings ;
@@ -146,20 +147,22 @@ public void testLifecycleComposition() {
146147 List <DataStreamLifecycle .Template > lifecycles = List .of ();
147148 assertThat (composeDataLifecycles (lifecycles ), nullValue ());
148149 }
149- // One lifecycle results to this lifecycle as the final
150+ // One lifecycle results in this lifecycle as the final
150151 {
152+ ResettableValue <List <DataStreamLifecycle .DownsamplingRound >> downsamplingRounds = randomDownsampling ();
151153 DataStreamLifecycle .Template lifecycle = DataStreamLifecycle .createDataLifecycleTemplate (
152154 true ,
153155 randomRetention (),
154- randomDownsampling () ,
155- ResettableValue . create ( DataStreamLifecycleFixtures . randomSamplingMethod () )
156+ downsamplingRounds ,
157+ randomSamplingMethod (downsamplingRounds )
156158 );
157159 List <DataStreamLifecycle .Template > lifecycles = List .of (lifecycle );
158160 DataStreamLifecycle result = composeDataLifecycles (lifecycles ).build ();
159161 // Defaults to true
160162 assertThat (result .enabled (), equalTo (true ));
161163 assertThat (result .dataRetention (), equalTo (lifecycle .dataRetention ().get ()));
162164 assertThat (result .downsamplingRounds (), equalTo (lifecycle .downsamplingRounds ().get ()));
165+ assertThat (result .downsamplingMethod (), equalTo (lifecycle .downsamplingMethod ().get ()));
163166 }
164167 // If the last lifecycle is missing a property (apart from enabled) we keep the latest from the previous ones
165168 // Enabled is always true unless it's explicitly set to false
@@ -175,26 +178,31 @@ public void testLifecycleComposition() {
175178 assertThat (result .enabled (), equalTo (true ));
176179 assertThat (result .dataRetention (), equalTo (lifecycle .dataRetention ().get ()));
177180 assertThat (result .downsamplingRounds (), equalTo (lifecycle .downsamplingRounds ().get ()));
181+ assertThat (result .downsamplingMethod (), equalTo (lifecycle .downsamplingMethod ().get ()));
178182 }
179- // If both lifecycle have all properties, then the latest one overwrites all the others
183+ // If both lifecycles have all properties, then the latest one overwrites all the others
180184 {
185+ DownsampleConfig .SamplingMethod downsamplingMethod1 = randomFrom (DownsampleConfig .SamplingMethod .LAST_VALUE );
181186 DataStreamLifecycle .Template lifecycle1 = DataStreamLifecycle .createDataLifecycleTemplate (
182187 false ,
183188 randomPositiveTimeValue (),
184189 randomRounds (),
185- DataStreamLifecycleFixtures . randomSamplingMethod ()
190+ downsamplingMethod1
186191 );
187192 DataStreamLifecycle .Template lifecycle2 = DataStreamLifecycle .createDataLifecycleTemplate (
188193 true ,
189194 randomPositiveTimeValue (),
190195 randomRounds (),
191- DataStreamLifecycleFixtures .randomSamplingMethod ()
196+ downsamplingMethod1 == DownsampleConfig .SamplingMethod .LAST_VALUE
197+ ? DownsampleConfig .SamplingMethod .AGGREGATE
198+ : DownsampleConfig .SamplingMethod .LAST_VALUE
192199 );
193200 List <DataStreamLifecycle .Template > lifecycles = List .of (lifecycle1 , lifecycle2 );
194201 DataStreamLifecycle result = composeDataLifecycles (lifecycles ).build ();
195202 assertThat (result .enabled (), equalTo (lifecycle2 .enabled ()));
196203 assertThat (result .dataRetention (), equalTo (lifecycle2 .dataRetention ().get ()));
197204 assertThat (result .downsamplingRounds (), equalTo (lifecycle2 .downsamplingRounds ().get ()));
205+ assertThat (result .downsamplingMethod (), equalTo (lifecycle2 .downsamplingMethod ().get ()));
198206 }
199207 }
200208
@@ -292,4 +300,18 @@ private static ResettableValue<List<DataStreamLifecycle.DownsamplingRound>> rand
292300 default -> throw new IllegalStateException ("Unknown randomisation path" );
293301 };
294302 }
303+
304+ private static ResettableValue <DownsampleConfig .SamplingMethod > randomSamplingMethod (
305+ ResettableValue <List <DataStreamLifecycle .DownsamplingRound >> rounds
306+ ) {
307+ if (rounds .get () == null ) {
308+ return randomBoolean () ? ResettableValue .undefined () : ResettableValue .reset ();
309+ } else {
310+ return randomBoolean () ? ResettableValue .create (DataStreamLifecycleFixtures .randomSamplingMethod ()) : ResettableValue .reset ();
311+ }
312+ }
313+
314+ private static DownsampleConfig .SamplingMethod randomSamplingMethod (List <DataStreamLifecycle .DownsamplingRound > rounds ) {
315+ return rounds == null ? null : DataStreamLifecycleFixtures .randomSamplingMethod ();
316+ }
295317}
0 commit comments