99
1010import org .elasticsearch .action .admin .indices .rollover .RolloverAction ;
1111import org .elasticsearch .action .admin .indices .rollover .RolloverRequest ;
12- import org .elasticsearch .action .datastreams .lifecycle .PutDataStreamLifecycleAction ;
1312import org .elasticsearch .action .downsample .DownsampleConfig ;
1413import org .elasticsearch .cluster .metadata .DataStreamLifecycle ;
1514import org .elasticsearch .common .settings .Settings ;
1615import org .elasticsearch .core .TimeValue ;
17- import org .elasticsearch .datastreams .DataStreamsPlugin ;
1816import org .elasticsearch .datastreams .lifecycle .DataStreamLifecycleService ;
19- import org .elasticsearch .plugins .Plugin ;
2017import org .elasticsearch .search .aggregations .bucket .histogram .DateHistogramInterval ;
21- import org .elasticsearch .test .ESIntegTestCase ;
2218import org .elasticsearch .test .junit .annotations .TestLogging ;
23- import org .elasticsearch .xpack .aggregatemetric .AggregateMetricMapperPlugin ;
24- import org .elasticsearch .xpack .core .LocalStateCompositeXPackPlugin ;
2519
26- import java .util .Collection ;
2720import java .util .HashSet ;
2821import java .util .List ;
2922import java .util .Set ;
3023import java .util .concurrent .TimeUnit ;
3124
3225import static org .elasticsearch .cluster .metadata .ClusterChangedEventUtils .indicesCreated ;
3326import static org .elasticsearch .cluster .metadata .DataStreamTestHelper .backingIndexEqualTo ;
34- import static org .elasticsearch .xpack .downsample .DataStreamLifecycleDriver .getBackingIndices ;
35- import static org .elasticsearch .xpack .downsample .DataStreamLifecycleDriver .putTSDBIndexTemplate ;
3627import static org .hamcrest .Matchers .is ;
3728
38- public class DataStreamLifecycleDownsampleIT extends ESIntegTestCase {
29+ public class DataStreamLifecycleDownsampleIT extends DownsamplingIntegTestCase {
3930 public static final int DOC_COUNT = 50_000 ;
4031
41- @ Override
42- protected Collection <Class <? extends Plugin >> nodePlugins () {
43- return List .of (DataStreamsPlugin .class , LocalStateCompositeXPackPlugin .class , Downsample .class , AggregateMetricMapperPlugin .class );
44- }
45-
4632 @ Override
4733 protected Settings nodeSettings (int nodeOrdinal , Settings otherSettings ) {
4834 Settings .Builder settings = Settings .builder ().put (super .nodeSettings (nodeOrdinal , otherSettings ));
@@ -69,8 +55,7 @@ public void testDownsampling() throws Exception {
6955 )
7056 .buildTemplate ();
7157
72- DataStreamLifecycleDriver .setupTSDBDataStreamAndIngestDocs (
73- client (),
58+ setupTSDBDataStreamAndIngestDocs (
7459 dataStreamName ,
7560 "1986-01-08T23:40:53.384Z" ,
7661 "2022-01-08T23:40:53.384Z" ,
@@ -79,7 +64,7 @@ public void testDownsampling() throws Exception {
7964 "1990-09-09T18:00:00"
8065 );
8166
82- List <String > backingIndices = getBackingIndices ( client (), dataStreamName );
67+ List <String > backingIndices = getDataStreamBackingIndexNames ( dataStreamName );
8368 String firstGenerationBackingIndex = backingIndices .get (0 );
8469 String oneSecondDownsampleIndex = "downsample-5m-" + firstGenerationBackingIndex ;
8570 String tenSecondsDownsampleIndex = "downsample-10m-" + firstGenerationBackingIndex ;
@@ -96,7 +81,7 @@ public void testDownsampling() throws Exception {
9681 });
9782 // before we rollover we update the index template to remove the start/end time boundaries (they're there just to ease with
9883 // testing so DSL doesn't have to wait for the end_time to lapse)
99- putTSDBIndexTemplate (client (), dataStreamName , null , null , lifecycle );
84+ putTSDBIndexTemplate (dataStreamName , null , null , lifecycle );
10085
10186 client ().execute (RolloverAction .INSTANCE , new RolloverRequest (dataStreamName , null )).actionGet ();
10287
@@ -112,7 +97,7 @@ public void testDownsampling() throws Exception {
11297 }, 30 , TimeUnit .SECONDS );
11398
11499 assertBusy (() -> {
115- List <String > dsBackingIndices = getBackingIndices ( client (), dataStreamName );
100+ List <String > dsBackingIndices = getDataStreamBackingIndexNames ( dataStreamName );
116101
117102 assertThat (dsBackingIndices .size (), is (2 ));
118103 String writeIndex = dsBackingIndices .get (1 );
@@ -143,8 +128,7 @@ public void testDownsamplingOnlyExecutesTheLastMatchingRound() throws Exception
143128 )
144129 )
145130 .buildTemplate ();
146- DataStreamLifecycleDriver .setupTSDBDataStreamAndIngestDocs (
147- client (),
131+ setupTSDBDataStreamAndIngestDocs (
148132 dataStreamName ,
149133 "1986-01-08T23:40:53.384Z" ,
150134 "2022-01-08T23:40:53.384Z" ,
@@ -153,7 +137,7 @@ public void testDownsamplingOnlyExecutesTheLastMatchingRound() throws Exception
153137 "1990-09-09T18:00:00"
154138 );
155139
156- List <String > backingIndices = getBackingIndices ( client (), dataStreamName );
140+ List <String > backingIndices = getDataStreamBackingIndexNames ( dataStreamName );
157141 String firstGenerationBackingIndex = backingIndices .get (0 );
158142 String oneSecondDownsampleIndex = "downsample-5m-" + firstGenerationBackingIndex ;
159143 String tenSecondsDownsampleIndex = "downsample-10m-" + firstGenerationBackingIndex ;
@@ -170,7 +154,7 @@ public void testDownsamplingOnlyExecutesTheLastMatchingRound() throws Exception
170154 });
171155 // before we rollover we update the index template to remove the start/end time boundaries (they're there just to ease with
172156 // testing so DSL doesn't have to wait for the end_time to lapse)
173- putTSDBIndexTemplate (client (), dataStreamName , null , null , lifecycle );
157+ putTSDBIndexTemplate (dataStreamName , null , null , lifecycle );
174158 client ().execute (RolloverAction .INSTANCE , new RolloverRequest (dataStreamName , null )).actionGet ();
175159
176160 assertBusy (() -> {
@@ -180,7 +164,7 @@ public void testDownsamplingOnlyExecutesTheLastMatchingRound() throws Exception
180164 }, 30 , TimeUnit .SECONDS );
181165
182166 assertBusy (() -> {
183- List <String > dsBackingIndices = getBackingIndices ( client (), dataStreamName );
167+ List <String > dsBackingIndices = getDataStreamBackingIndexNames ( dataStreamName );
184168
185169 assertThat (dsBackingIndices .size (), is (2 ));
186170 String writeIndex = dsBackingIndices .get (1 );
@@ -212,8 +196,7 @@ public void testUpdateDownsampleRound() throws Exception {
212196 )
213197 .buildTemplate ();
214198
215- DataStreamLifecycleDriver .setupTSDBDataStreamAndIngestDocs (
216- client (),
199+ setupTSDBDataStreamAndIngestDocs (
217200 dataStreamName ,
218201 "1986-01-08T23:40:53.384Z" ,
219202 "2022-01-08T23:40:53.384Z" ,
@@ -222,7 +205,7 @@ public void testUpdateDownsampleRound() throws Exception {
222205 "1990-09-09T18:00:00"
223206 );
224207
225- List <String > backingIndices = getBackingIndices ( client (), dataStreamName );
208+ List <String > backingIndices = getDataStreamBackingIndexNames ( dataStreamName );
226209 String firstGenerationBackingIndex = backingIndices .get (0 );
227210 String oneSecondDownsampleIndex = "downsample-5m-" + firstGenerationBackingIndex ;
228211 String tenSecondsDownsampleIndex = "downsample-10m-" + firstGenerationBackingIndex ;
@@ -239,8 +222,8 @@ public void testUpdateDownsampleRound() throws Exception {
239222 });
240223 // before we rollover we update the index template to remove the start/end time boundaries (they're there just to ease with
241224 // testing so DSL doesn't have to wait for the end_time to lapse)
242- putTSDBIndexTemplate (client (), dataStreamName , null , null , lifecycle );
243- client ().execute (RolloverAction .INSTANCE , new RolloverRequest (dataStreamName , null )). actionGet ( );
225+ putTSDBIndexTemplate (dataStreamName , null , null , lifecycle );
226+ safeGet ( client ().execute (RolloverAction .INSTANCE , new RolloverRequest (dataStreamName , null )));
244227
245228 assertBusy (() -> {
246229 assertThat (witnessedDownsamplingIndices .size (), is (1 ));
@@ -249,7 +232,7 @@ public void testUpdateDownsampleRound() throws Exception {
249232 }, 30 , TimeUnit .SECONDS );
250233
251234 assertBusy (() -> {
252- List <String > dsBackingIndices = getBackingIndices ( client (), dataStreamName );
235+ List <String > dsBackingIndices = getDataStreamBackingIndexNames ( dataStreamName );
253236 assertThat (dsBackingIndices .size (), is (2 ));
254237 String writeIndex = dsBackingIndices .get (1 );
255238 assertThat (writeIndex , backingIndexEqualTo (dataStreamName , 2 ));
@@ -258,34 +241,27 @@ public void testUpdateDownsampleRound() throws Exception {
258241
259242 // update the lifecycle so that it only has one round, for the same `after` parameter as before, but a different interval
260243 // the different interval should yield a different downsample index name so we expect the data stream lifecycle to get the previous
261- // `10s` interval downsample index, downsample it to `30s` and replace it in the data stream instead of the `10s` one.
262- DataStreamLifecycle updatedLifecycle = DataStreamLifecycle .dataLifecycleBuilder ()
263- .downsampling (
264- List .of (
265- new DataStreamLifecycle .DownsamplingRound (
266- TimeValue .timeValueMillis (10 ),
267- new DownsampleConfig (new DateHistogramInterval ("20m" ))
244+ // `10s` interval downsample index, downsample it to `20m` and replace it in the data stream instead of the `10s` one.
245+ updateDataLifecycle (
246+ dataStreamName ,
247+ DataStreamLifecycle .dataLifecycleBuilder ()
248+ .downsampling (
249+ List .of (
250+ new DataStreamLifecycle .DownsamplingRound (
251+ TimeValue .timeValueMillis (10 ),
252+ new DownsampleConfig (new DateHistogramInterval ("20m" ))
253+ )
268254 )
269255 )
270- )
271- .build ();
272-
273- client ().execute (
274- PutDataStreamLifecycleAction .INSTANCE ,
275- new PutDataStreamLifecycleAction .Request (
276- TEST_REQUEST_TIMEOUT ,
277- TEST_REQUEST_TIMEOUT ,
278- new String [] { dataStreamName },
279- updatedLifecycle
280- )
256+ .build ()
281257 );
282258
283259 String thirtySecondsDownsampleIndex = "downsample-20m-" + firstGenerationBackingIndex ;
284260
285261 assertBusy (() -> {
286262 assertThat (indexExists (tenSecondsDownsampleIndex ), is (false ));
287263
288- List <String > dsBackingIndices = getBackingIndices ( client (), dataStreamName );
264+ List <String > dsBackingIndices = getDataStreamBackingIndexNames ( dataStreamName );
289265 assertThat (dsBackingIndices .size (), is (2 ));
290266 String writeIndex = dsBackingIndices .get (1 );
291267 assertThat (writeIndex , backingIndexEqualTo (dataStreamName , 2 ));
0 commit comments