Skip to content

Commit

Permalink
[Bug] Data stream stats fails when there is a concrete index in the c…
Browse files Browse the repository at this point in the history
…luster (#120901)
  • Loading branch information
gmarouli authored Jan 27, 2025
1 parent 04c53e2 commit 0fabaf7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ protected void shardOperation(
});
}

@Override
protected String[] resolveConcreteIndexNames(ClusterState clusterState, DataStreamsStatsAction.Request request) {
return DataStreamsActionUtil.resolveConcreteIndexNames(
indexNameExpressionResolver,
clusterState,
request.indices(),
request.indicesOptions()
).toArray(String[]::new);
}

@Override
protected DataStreamsStatsAction.DataStreamShardStats readShardResult(StreamInput in) throws IOException {
return new DataStreamsStatsAction.DataStreamShardStats(in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.elasticsearch.action.DocWriteRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
import org.elasticsearch.action.admin.indices.template.delete.TransportDeleteComposableIndexTemplateAction;
Expand Down Expand Up @@ -56,6 +58,7 @@ protected Collection<Class<? extends Plugin>> getPlugins() {
}

private final Set<String> createdDataStreams = new HashSet<>();
private final Set<String> createdStandAloneIndices = new HashSet<>();

@Override
@After
Expand All @@ -66,6 +69,12 @@ public void tearDown() throws Exception {
}
createdDataStreams.clear();
}
if (createdStandAloneIndices.isEmpty() == false) {
for (String indexName : createdStandAloneIndices) {
client().admin().indices().delete(new DeleteIndexRequest(indexName));
}
createdStandAloneIndices.clear();
}
super.tearDown();
}

Expand All @@ -80,6 +89,7 @@ public void testStatsNoDataStream() throws Exception {
}

public void testStatsEmptyDataStream() throws Exception {
maybeCreateCreatedStandAloneIndicesIndex();
String dataStreamName = createDataStream();

DataStreamsStatsAction.Response stats = getDataStreamsStats();
Expand All @@ -97,6 +107,7 @@ public void testStatsEmptyDataStream() throws Exception {
}

public void testStatsExistingDataStream() throws Exception {
maybeCreateCreatedStandAloneIndicesIndex();
String dataStreamName = createDataStream();
long timestamp = createDocument(dataStreamName);

Expand All @@ -115,6 +126,7 @@ public void testStatsExistingDataStream() throws Exception {
}

public void testStatsExistingDataStreamWithFailureStores() throws Exception {
maybeCreateCreatedStandAloneIndicesIndex();
String dataStreamName = createDataStream(false, true);
createFailedDocument(dataStreamName);

Expand All @@ -137,6 +149,7 @@ public void testStatsExistingDataStreamWithFailureStores() throws Exception {
}

public void testStatsExistingHiddenDataStream() throws Exception {
maybeCreateCreatedStandAloneIndicesIndex();
String dataStreamName = createDataStream(true, false);
long timestamp = createDocument(dataStreamName);

Expand All @@ -155,6 +168,7 @@ public void testStatsExistingHiddenDataStream() throws Exception {
}

public void testStatsClosedBackingIndexDataStream() throws Exception {
maybeCreateCreatedStandAloneIndicesIndex();
String dataStreamName = createDataStream();
createDocument(dataStreamName);
assertTrue(indicesAdmin().rolloverIndex(new RolloverRequest(dataStreamName, null)).get().isAcknowledged());
Expand Down Expand Up @@ -198,6 +212,7 @@ public void testStatsClosedBackingIndexDataStream() throws Exception {
}

public void testStatsRolledDataStream() throws Exception {
maybeCreateCreatedStandAloneIndicesIndex();
String dataStreamName = createDataStream();
long timestamp = createDocument(dataStreamName);
assertTrue(indicesAdmin().rolloverIndex(new RolloverRequest(dataStreamName, null)).get().isAcknowledged());
Expand All @@ -218,6 +233,7 @@ public void testStatsRolledDataStream() throws Exception {
}

public void testStatsMultipleDataStreams() throws Exception {
maybeCreateCreatedStandAloneIndicesIndex();
for (int dataStreamCount = 0; dataStreamCount < (2 + randomInt(3)); dataStreamCount++) {
createDataStream();
}
Expand Down Expand Up @@ -284,6 +300,14 @@ private String createDataStream(boolean hidden, boolean failureStore) throws Exc
return dataStreamName;
}

private void maybeCreateCreatedStandAloneIndicesIndex() {
if (randomBoolean()) {
String indexName = randomAlphaOfLength(10).toLowerCase(Locale.getDefault());
assertAcked(client().admin().indices().create(new CreateIndexRequest(indexName)));
createdStandAloneIndices.add(indexName);
}
}

private long createDocument(String dataStreamName) throws Exception {
// Get some randomized but reasonable timestamps on the data since not all of it is guaranteed to arrive in order.
long timeSeed = System.currentTimeMillis();
Expand Down

0 comments on commit 0fabaf7

Please sign in to comment.