Skip to content

Commit 582a744

Browse files
committed
Polishing
1 parent 0016bbc commit 582a744

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed

x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/DataStreamLifecycleDownsampleIT.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import org.elasticsearch.action.admin.indices.rollover.RolloverAction;
1111
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
12+
import org.elasticsearch.action.datastreams.lifecycle.PutDataStreamLifecycleAction;
1213
import org.elasticsearch.action.downsample.DownsampleConfig;
1314
import org.elasticsearch.cluster.metadata.DataStreamLifecycle;
1415
import org.elasticsearch.common.settings.Settings;
@@ -24,6 +25,7 @@
2425

2526
import static org.elasticsearch.cluster.metadata.ClusterChangedEventUtils.indicesCreated;
2627
import static org.elasticsearch.cluster.metadata.DataStreamTestHelper.backingIndexEqualTo;
28+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
2729
import static org.hamcrest.Matchers.is;
2830

2931
public class DataStreamLifecycleDownsampleIT extends DownsamplingIntegTestCase {
@@ -242,18 +244,26 @@ public void testUpdateDownsampleRound() throws Exception {
242244
// update the lifecycle so that it only has one round, for the same `after` parameter as before, but a different interval
243245
// the different interval should yield a different downsample index name so we expect the data stream lifecycle to get the previous
244246
// `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-
)
247+
DataStreamLifecycle lifecycle1 = DataStreamLifecycle.dataLifecycleBuilder()
248+
.downsampling(
249+
List.of(
250+
new DataStreamLifecycle.DownsamplingRound(
251+
TimeValue.timeValueMillis(10),
252+
new DownsampleConfig(new DateHistogramInterval("20m"))
254253
)
255254
)
256-
.build()
255+
)
256+
.build();
257+
assertAcked(
258+
client().execute(
259+
PutDataStreamLifecycleAction.INSTANCE,
260+
new PutDataStreamLifecycleAction.Request(
261+
TEST_REQUEST_TIMEOUT,
262+
TEST_REQUEST_TIMEOUT,
263+
new String[] { dataStreamName },
264+
lifecycle1
265+
)
266+
)
257267
);
258268

259269
String thirtySecondsDownsampleIndex = "downsample-20m-" + firstGenerationBackingIndex;

x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/DownsampleIT.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class DownsampleIT extends DownsamplingIntegTestCase {
3030

3131
public void testDownsamplingPassthroughDimensions() throws Exception {
3232
String dataStreamName = "metrics-foo";
33-
33+
// Set up template
3434
putTSDBIndexTemplate("my-template", List.of("metrics-foo"), null, """
3535
{
3636
"properties": {
@@ -47,6 +47,7 @@ public void testDownsamplingPassthroughDimensions() throws Exception {
4747
}
4848
""", null, null);
4949

50+
// Create data stream by indexing documents
5051
final Instant now = Instant.now();
5152
Supplier<XContentBuilder> sourceSupplier = () -> {
5253
String ts = randomDateForRange(now.minusSeconds(60 * 60).toEpochMilli(), now.plusSeconds(60 * 29).toEpochMilli());
@@ -62,8 +63,8 @@ public void testDownsamplingPassthroughDimensions() throws Exception {
6263
}
6364
};
6465
bulkIndex(dataStreamName, sourceSupplier, 100);
66+
// Rollover to ensure the index we will downsample is not the write index
6567
assertAcked(client().admin().indices().rolloverIndex(new RolloverRequest(dataStreamName, null)));
66-
6768
List<String> backingIndices = waitForDataStreamBackingIndices(dataStreamName, 2);
6869
String sourceIndex = backingIndices.get(0);
6970
String interval = "5m";
@@ -82,6 +83,7 @@ public void testDownsamplingPassthroughDimensions() throws Exception {
8283
)
8384
);
8485

86+
// Wait for downsampling to complete
8587
SubscribableListener<Void> listener = ClusterServiceUtils.addMasterTemporaryStateListener(clusterState -> {
8688
final var indexMetadata = clusterState.metadata().getProject().index(targetIndex);
8789
if (indexMetadata == null) {

x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/DownsamplingIntegTestCase.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.elasticsearch.action.bulk.BulkItemResponse;
1818
import org.elasticsearch.action.bulk.BulkRequestBuilder;
1919
import org.elasticsearch.action.bulk.BulkResponse;
20-
import org.elasticsearch.action.datastreams.lifecycle.PutDataStreamLifecycleAction;
2120
import org.elasticsearch.action.downsample.DownsampleConfig;
2221
import org.elasticsearch.action.index.IndexRequest;
2322
import org.elasticsearch.action.support.WriteRequest;
@@ -175,20 +174,6 @@ void putTSDBIndexTemplate(
175174
assertAcked(client().execute(TransportPutComposableIndexTemplateAction.TYPE, request));
176175
}
177176

178-
void updateDataLifecycle(String dataStreamName, DataStreamLifecycle lifecycle) throws IOException {
179-
assertAcked(
180-
client().execute(
181-
PutDataStreamLifecycleAction.INSTANCE,
182-
new PutDataStreamLifecycleAction.Request(
183-
TEST_REQUEST_TIMEOUT,
184-
TEST_REQUEST_TIMEOUT,
185-
new String[] { dataStreamName },
186-
lifecycle
187-
)
188-
)
189-
);
190-
}
191-
192177
/**
193178
* Creates and indexes the specified number of documents using the docSource supplier.
194179
* @return the count of indexed documents

0 commit comments

Comments
 (0)