Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.datastreams.CreateDataStreamAction;
import org.elasticsearch.action.datastreams.GetDataStreamAction;
import org.elasticsearch.action.datastreams.lifecycle.ExplainDataStreamLifecycleAction;
import org.elasticsearch.action.datastreams.lifecycle.ExplainIndexDataStreamLifecycle;
import org.elasticsearch.action.index.IndexRequest;
Expand All @@ -31,7 +30,6 @@
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.datastreams.DataStreamsPlugin;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestStatus;
Expand Down Expand Up @@ -99,29 +97,16 @@ public void testExplainLifecycle() throws Exception {

indexDocs(dataStreamName, 1);

assertBusy(() -> {
GetDataStreamAction.Request getDataStreamRequest = new GetDataStreamAction.Request(
TEST_REQUEST_TIMEOUT,
new String[] { dataStreamName }
);
GetDataStreamAction.Response getDataStreamResponse = client().execute(GetDataStreamAction.INSTANCE, getDataStreamRequest)
.actionGet();
assertThat(getDataStreamResponse.getDataStreams().size(), equalTo(1));
assertThat(getDataStreamResponse.getDataStreams().get(0).getDataStream().getName(), equalTo(dataStreamName));
List<Index> backingIndices = getDataStreamResponse.getDataStreams().get(0).getDataStream().getIndices();
assertThat(backingIndices.size(), equalTo(2));
String backingIndex = backingIndices.get(0).getName();
assertThat(backingIndex, backingIndexEqualTo(dataStreamName, 1));
String writeIndex = backingIndices.get(1).getName();
assertThat(writeIndex, backingIndexEqualTo(dataStreamName, 2));
});
List<String> backingIndices = waitForDataStreamBackingIndices(dataStreamName, 2);
String firstGenerationIndex = backingIndices.get(0);
assertThat(firstGenerationIndex, backingIndexEqualTo(dataStreamName, 1));
String secondGenerationIndex = backingIndices.get(1);
assertThat(secondGenerationIndex, backingIndexEqualTo(dataStreamName, 2));

{
ExplainDataStreamLifecycleAction.Request explainIndicesRequest = new ExplainDataStreamLifecycleAction.Request(
TEST_REQUEST_TIMEOUT,
new String[] {
DataStream.getDefaultBackingIndexName(dataStreamName, 1),
DataStream.getDefaultBackingIndexName(dataStreamName, 2) }
new String[] { firstGenerationIndex, secondGenerationIndex }
);
ExplainDataStreamLifecycleAction.Response response = client().execute(
ExplainDataStreamLifecycleAction.INSTANCE,
Expand All @@ -140,18 +125,16 @@ public void testExplainLifecycle() throws Exception {
assertThat(explainIndex.getError(), nullValue());
}

if (explainIndex.getIndex().equals(DataStream.getDefaultBackingIndexName(dataStreamName, 1))) {
if (explainIndex.getIndex().equals(firstGenerationIndex)) {
// first generation index was rolled over
assertThat(explainIndex.getIndex(), is(DataStream.getDefaultBackingIndexName(dataStreamName, 1)));
assertThat(explainIndex.getRolloverDate(), notNullValue());
assertThat(explainIndex.getTimeSinceRollover(System::currentTimeMillis), notNullValue());
assertThat(explainIndex.getGenerationTime(System::currentTimeMillis), notNullValue());
} else {
// the write index has not been rolled over yet
assertThat(explainIndex.getGenerationTime(System::currentTimeMillis), nullValue());
assertThat(explainIndex.getIndex(), is(DataStream.getDefaultBackingIndexName(dataStreamName, 2)));
assertThat(explainIndex.getRolloverDate(), nullValue());
assertThat(explainIndex.getTimeSinceRollover(System::currentTimeMillis), nullValue());
assertThat(explainIndex.getGenerationTime(System::currentTimeMillis), nullValue());
}
}
}
Expand All @@ -160,9 +143,7 @@ public void testExplainLifecycle() throws Exception {
// let's also explain with include_defaults=true
ExplainDataStreamLifecycleAction.Request explainIndicesRequest = new ExplainDataStreamLifecycleAction.Request(
TEST_REQUEST_TIMEOUT,
new String[] {
DataStream.getDefaultBackingIndexName(dataStreamName, 1),
DataStream.getDefaultBackingIndexName(dataStreamName, 2) },
new String[] { firstGenerationIndex, secondGenerationIndex },
true
);
ExplainDataStreamLifecycleAction.Response response = client().execute(
Expand Down Expand Up @@ -195,18 +176,16 @@ public void testExplainLifecycle() throws Exception {
assertThat(explainIndex.getLifecycle(), notNullValue());
assertThat(explainIndex.getLifecycle().dataRetention(), nullValue());

if (explainIndex.getIndex().equals(DataStream.getDefaultBackingIndexName(dataStreamName, 1))) {
if (explainIndex.getIndex().equals(firstGenerationIndex)) {
// first generation index was rolled over
assertThat(explainIndex.getIndex(), is(DataStream.getDefaultBackingIndexName(dataStreamName, 1)));
assertThat(explainIndex.getRolloverDate(), notNullValue());
assertThat(explainIndex.getTimeSinceRollover(System::currentTimeMillis), notNullValue());
assertThat(explainIndex.getGenerationTime(System::currentTimeMillis), notNullValue());
} else {
// the write index has not been rolled over yet
assertThat(explainIndex.getGenerationTime(System::currentTimeMillis), nullValue());
assertThat(explainIndex.getIndex(), is(DataStream.getDefaultBackingIndexName(dataStreamName, 2)));
assertThat(explainIndex.getRolloverDate(), nullValue());
assertThat(explainIndex.getTimeSinceRollover(System::currentTimeMillis), nullValue());
assertThat(explainIndex.getGenerationTime(System::currentTimeMillis), nullValue());
}
}
}
Expand All @@ -228,28 +207,15 @@ public void testSystemExplainLifecycle() throws Exception {

indexDocs(dataStreamName, 1);

assertBusy(() -> {
GetDataStreamAction.Request getDataStreamRequest = new GetDataStreamAction.Request(
TEST_REQUEST_TIMEOUT,
new String[] { dataStreamName }
);
GetDataStreamAction.Response getDataStreamResponse = client().execute(GetDataStreamAction.INSTANCE, getDataStreamRequest)
.actionGet();
assertThat(getDataStreamResponse.getDataStreams().size(), equalTo(1));
assertThat(getDataStreamResponse.getDataStreams().get(0).getDataStream().getName(), equalTo(dataStreamName));
List<Index> backingIndices = getDataStreamResponse.getDataStreams().get(0).getDataStream().getIndices();
assertThat(backingIndices.size(), equalTo(2));
String backingIndex = backingIndices.get(0).getName();
assertThat(backingIndex, backingIndexEqualTo(dataStreamName, 1));
String writeIndex = backingIndices.get(1).getName();
assertThat(writeIndex, backingIndexEqualTo(dataStreamName, 2));
});
List<String> backingIndices = waitForDataStreamBackingIndices(dataStreamName, 2);
String firstGenerationIndex = backingIndices.get(0);
assertThat(firstGenerationIndex, backingIndexEqualTo(dataStreamName, 1));
String secondGenerationIndex = backingIndices.get(1);
assertThat(secondGenerationIndex, backingIndexEqualTo(dataStreamName, 2));

ExplainDataStreamLifecycleAction.Request explainIndicesRequest = new ExplainDataStreamLifecycleAction.Request(
TEST_REQUEST_TIMEOUT,
new String[] {
DataStream.getDefaultBackingIndexName(dataStreamName, 1),
DataStream.getDefaultBackingIndexName(dataStreamName, 2) }
new String[] { firstGenerationIndex, secondGenerationIndex }
);
ExplainDataStreamLifecycleAction.Response response = client().execute(
ExplainDataStreamLifecycleAction.INSTANCE,
Expand Down Expand Up @@ -289,33 +255,21 @@ public void testExplainLifecycleForIndicesWithErrors() throws Exception {
indexDocs(dataStreamName, 1);

// let's allow one rollover to go through
assertBusy(() -> {
GetDataStreamAction.Request getDataStreamRequest = new GetDataStreamAction.Request(
TEST_REQUEST_TIMEOUT,
new String[] { dataStreamName }
);
GetDataStreamAction.Response getDataStreamResponse = client().execute(GetDataStreamAction.INSTANCE, getDataStreamRequest)
.actionGet();
assertThat(getDataStreamResponse.getDataStreams().size(), equalTo(1));
assertThat(getDataStreamResponse.getDataStreams().get(0).getDataStream().getName(), equalTo(dataStreamName));
List<Index> backingIndices = getDataStreamResponse.getDataStreams().get(0).getDataStream().getIndices();
assertThat(backingIndices.size(), equalTo(2));
String backingIndex = backingIndices.get(0).getName();
assertThat(backingIndex, backingIndexEqualTo(dataStreamName, 1));
String writeIndex = backingIndices.get(1).getName();
assertThat(writeIndex, backingIndexEqualTo(dataStreamName, 2));
});
List<String> backingIndices = waitForDataStreamBackingIndices(dataStreamName, 2);
String firstGenerationIndex = backingIndices.get(0);
assertThat(firstGenerationIndex, backingIndexEqualTo(dataStreamName, 1));
String secondGenerationIndex = backingIndices.get(1);
assertThat(secondGenerationIndex, backingIndexEqualTo(dataStreamName, 2));

// prevent new indices from being created (ie. future rollovers)
updateClusterSettings(Settings.builder().put(SETTING_CLUSTER_MAX_SHARDS_PER_NODE.getKey(), 1));

indexDocs(dataStreamName, 1);

String writeIndexName = DataStream.getDefaultBackingIndexName(dataStreamName, 2);
assertBusy(() -> {
ExplainDataStreamLifecycleAction.Request explainIndicesRequest = new ExplainDataStreamLifecycleAction.Request(
TEST_REQUEST_TIMEOUT,
new String[] { writeIndexName }
new String[] { secondGenerationIndex }
);
ExplainDataStreamLifecycleAction.Response response = client().execute(
ExplainDataStreamLifecycleAction.INSTANCE,
Expand All @@ -325,7 +279,7 @@ public void testExplainLifecycleForIndicesWithErrors() throws Exception {
// we requested the explain for indices with the default include_details=false
assertThat(response.getRolloverConfiguration(), nullValue());
for (ExplainIndexDataStreamLifecycle explainIndex : response.getIndices()) {
assertThat(explainIndex.getIndex(), is(writeIndexName));
assertThat(explainIndex.getIndex(), is(secondGenerationIndex));
assertThat(explainIndex.isManagedByLifecycle(), is(true));
assertThat(explainIndex.getIndexCreationDate(), notNullValue());
assertThat(explainIndex.getLifecycle(), notNullValue());
Expand All @@ -347,7 +301,7 @@ public void testExplainLifecycleForIndicesWithErrors() throws Exception {
assertBusy(() -> {
ExplainDataStreamLifecycleAction.Request explainIndicesRequest = new ExplainDataStreamLifecycleAction.Request(
TEST_REQUEST_TIMEOUT,
new String[] { writeIndexName }
new String[] { secondGenerationIndex }
);
ExplainDataStreamLifecycleAction.Response response = client().execute(
ExplainDataStreamLifecycleAction.INSTANCE,
Expand Down Expand Up @@ -385,11 +339,14 @@ public void testExplainDataStreamLifecycleForUnmanagedIndices() throws Exception

indexDocs(dataStreamName, 4);

String writeIndexName = DataStream.getDefaultBackingIndexName(dataStreamName, 1);
List<String> backingIndices = waitForDataStreamBackingIndices(dataStreamName, 1);
String firstGenerationIndex = backingIndices.get(0);
assertThat(firstGenerationIndex, backingIndexEqualTo(dataStreamName, 1));

assertBusy(() -> {
ExplainDataStreamLifecycleAction.Request explainIndicesRequest = new ExplainDataStreamLifecycleAction.Request(
TEST_REQUEST_TIMEOUT,
new String[] { writeIndexName }
new String[] { firstGenerationIndex }
);
ExplainDataStreamLifecycleAction.Response response = client().execute(
ExplainDataStreamLifecycleAction.INSTANCE,
Expand All @@ -399,7 +356,7 @@ public void testExplainDataStreamLifecycleForUnmanagedIndices() throws Exception
assertThat(response.getRolloverConfiguration(), nullValue());
for (ExplainIndexDataStreamLifecycle explainIndex : response.getIndices()) {
assertThat(explainIndex.isManagedByLifecycle(), is(false));
assertThat(explainIndex.getIndex(), is(writeIndexName));
assertThat(explainIndex.getIndex(), is(firstGenerationIndex));
assertThat(explainIndex.getIndexCreationDate(), nullValue());
assertThat(explainIndex.getLifecycle(), nullValue());
assertThat(explainIndex.getGenerationTime(System::currentTimeMillis), nullValue());
Expand Down
6 changes: 0 additions & 6 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,6 @@ tests:
- class: org.elasticsearch.xpack.ilm.DataStreamAndIndexLifecycleMixingTests
method: testUpdateIndexTemplateFromILMtoBothILMAndDataStreamLifecycle
issue: https://github.com/elastic/elasticsearch/issues/124850
- class: org.elasticsearch.datastreams.lifecycle.ExplainDataStreamLifecycleIT
method: testExplainLifecycle
issue: https://github.com/elastic/elasticsearch/issues/124882
- class: org.elasticsearch.datastreams.lifecycle.ExplainDataStreamLifecycleIT
method: testSystemExplainLifecycle
issue: https://github.com/elastic/elasticsearch/issues/124885
- class: org.elasticsearch.xpack.ilm.DataStreamAndIndexLifecycleMixingTests
method: testIndexTemplateSwapsILMForDataStreamLifecycle
issue: https://github.com/elastic/elasticsearch/issues/124886
Expand Down