Skip to content

Commit

Permalink
Remove trappy timeouts from GetIndexRequest (#120037)
Browse files Browse the repository at this point in the history
Relates #107984
  • Loading branch information
nielsbauman authored Jan 16, 2025
1 parent c0f54a9 commit 9f597a4
Show file tree
Hide file tree
Showing 65 changed files with 240 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,16 @@ public void testBasicScenario() throws Exception {

String backingIndex = barDataStream.getIndices().get(0).getName();
backingIndices.add(backingIndex);
GetIndexResponse getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest().indices(backingIndex)).actionGet();
GetIndexResponse getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices(backingIndex))
.actionGet();
assertThat(getIndexResponse.getSettings().get(backingIndex), notNullValue());
assertThat(getIndexResponse.getSettings().get(backingIndex).getAsBoolean("index.hidden", null), is(true));
Map<?, ?> mappings = getIndexResponse.getMappings().get(backingIndex).getSourceAsMap();
assertThat(ObjectPath.eval("[email protected]", mappings), is("date"));

backingIndex = fooDataStream.getIndices().get(0).getName();
backingIndices.add(backingIndex);
getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest().indices(backingIndex)).actionGet();
getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices(backingIndex)).actionGet();
assertThat(getIndexResponse.getSettings().get(backingIndex), notNullValue());
assertThat(getIndexResponse.getSettings().get(backingIndex).getAsBoolean("index.hidden", null), is(true));
mappings = getIndexResponse.getMappings().get(backingIndex).getSourceAsMap();
Expand All @@ -214,15 +215,15 @@ public void testBasicScenario() throws Exception {

backingIndex = fooRolloverResponse.getNewIndex();
backingIndices.add(backingIndex);
getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest().indices(backingIndex)).actionGet();
getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices(backingIndex)).actionGet();
assertThat(getIndexResponse.getSettings().get(backingIndex), notNullValue());
assertThat(getIndexResponse.getSettings().get(backingIndex).getAsBoolean("index.hidden", null), is(true));
mappings = getIndexResponse.getMappings().get(backingIndex).getSourceAsMap();
assertThat(ObjectPath.eval("[email protected]", mappings), is("date"));

backingIndex = barRolloverResponse.getNewIndex();
backingIndices.add(backingIndex);
getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest().indices(backingIndex)).actionGet();
getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices(backingIndex)).actionGet();
assertThat(getIndexResponse.getSettings().get(backingIndex), notNullValue());
assertThat(getIndexResponse.getSettings().get(backingIndex).getAsBoolean("index.hidden", null), is(true));
mappings = getIndexResponse.getMappings().get(backingIndex).getSourceAsMap();
Expand All @@ -245,7 +246,7 @@ public void testBasicScenario() throws Exception {
expectThrows(
IndexNotFoundException.class,
"Backing index '" + index + "' should have been deleted.",
() -> indicesAdmin().getIndex(new GetIndexRequest().indices(index)).actionGet()
() -> indicesAdmin().getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices(index)).actionGet()
);
}
}
Expand Down Expand Up @@ -479,7 +480,8 @@ public void testComposableTemplateOnlyMatchingWithDataStreamName() throws Except
String backingIndex = getDataStreamResponse.getDataStreams().get(0).getDataStream().getIndices().get(0).getName();
assertThat(backingIndex, backingIndexEqualTo(dataStreamName, 1));

GetIndexResponse getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest().indices(dataStreamName)).actionGet();
GetIndexResponse getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices(dataStreamName))
.actionGet();
assertThat(getIndexResponse.getSettings().get(backingIndex), notNullValue());
assertThat(getIndexResponse.getSettings().get(backingIndex).getAsBoolean("index.hidden", null), is(true));
assertThat(
Expand All @@ -492,7 +494,7 @@ public void testComposableTemplateOnlyMatchingWithDataStreamName() throws Except
assertThat(backingIndex, backingIndexEqualTo(dataStreamName, 2));
assertTrue(rolloverResponse.isRolledOver());

getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest().indices(backingIndex)).actionGet();
getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices(backingIndex)).actionGet();
assertThat(getIndexResponse.getSettings().get(backingIndex), notNullValue());
assertThat(getIndexResponse.getSettings().get(backingIndex).getAsBoolean("index.hidden", null), is(true));
assertThat(
Expand All @@ -518,7 +520,7 @@ public void testComposableTemplateOnlyMatchingWithDataStreamName() throws Except
expectThrows(
IndexNotFoundException.class,
"Backing index '" + index.getName() + "' should have been deleted.",
() -> indicesAdmin().getIndex(new GetIndexRequest().indices(index.getName())).actionGet()
() -> indicesAdmin().getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices(index.getName())).actionGet()
);
}
}
Expand Down Expand Up @@ -606,7 +608,7 @@ public void testResolvabilityOfDataStreamsInAPIs() throws Exception {
verifyResolvability(dataStreamName, clusterAdmin().prepareHealth(TEST_REQUEST_TIMEOUT, dataStreamName), false);
verifyResolvability(dataStreamName, clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).setIndices(dataStreamName), false);
verifyResolvability(dataStreamName, client().prepareFieldCaps(dataStreamName).setFields("*"), false);
verifyResolvability(dataStreamName, indicesAdmin().prepareGetIndex().addIndices(dataStreamName), false);
verifyResolvability(dataStreamName, indicesAdmin().prepareGetIndex(TEST_REQUEST_TIMEOUT).addIndices(dataStreamName), false);
verifyResolvability(dataStreamName, indicesAdmin().prepareOpen(dataStreamName), false);
verifyResolvability(dataStreamName, indicesAdmin().prepareClose(dataStreamName), true);
verifyResolvability(aliasToDataStream, indicesAdmin().prepareClose(aliasToDataStream), true);
Expand Down Expand Up @@ -653,7 +655,7 @@ public void testResolvabilityOfDataStreamsInAPIs() throws Exception {
verifyResolvability(wildcardExpression, clusterAdmin().prepareHealth(TEST_REQUEST_TIMEOUT, wildcardExpression), false);
verifyResolvability(wildcardExpression, clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).setIndices(wildcardExpression), false);
verifyResolvability(wildcardExpression, client().prepareFieldCaps(wildcardExpression).setFields("*"), false);
verifyResolvability(wildcardExpression, indicesAdmin().prepareGetIndex().addIndices(wildcardExpression), false);
verifyResolvability(wildcardExpression, indicesAdmin().prepareGetIndex(TEST_REQUEST_TIMEOUT).addIndices(wildcardExpression), false);
verifyResolvability(wildcardExpression, indicesAdmin().prepareOpen(wildcardExpression), false);
verifyResolvability(wildcardExpression, indicesAdmin().prepareClose(wildcardExpression), false);
verifyResolvability(
Expand Down Expand Up @@ -1401,7 +1403,8 @@ public void testGetDataStream() throws Exception {
}

private static void assertBackingIndex(String backingIndex, String timestampFieldPathInMapping, Map<?, ?> expectedMapping) {
GetIndexResponse getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest().indices(backingIndex)).actionGet();
GetIndexResponse getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices(backingIndex))
.actionGet();
assertThat(getIndexResponse.getSettings().get(backingIndex), notNullValue());
assertThat(getIndexResponse.getSettings().get(backingIndex).getAsBoolean("index.hidden", null), is(true));
Map<?, ?> mappings = getIndexResponse.getMappings().get(backingIndex).getSourceAsMap();
Expand Down Expand Up @@ -1488,7 +1491,8 @@ public void testMixedAutoCreate() throws Exception {
assertThat(getDataStreamsResponse.getDataStreams().get(2).getDataStream().getName(), equalTo("logs-foobaz2"));
assertThat(getDataStreamsResponse.getDataStreams().get(3).getDataStream().getName(), equalTo("logs-foobaz3"));

GetIndexResponse getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest().indices("logs-bar*")).actionGet();
GetIndexResponse getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices("logs-bar*"))
.actionGet();
assertThat(getIndexResponse.getIndices(), arrayWithSize(4));
assertThat(getIndexResponse.getIndices(), hasItemInArray("logs-barbaz"));
assertThat(getIndexResponse.getIndices(), hasItemInArray("logs-barfoo"));
Expand Down Expand Up @@ -1521,7 +1525,8 @@ public void testAutoCreateV1TemplateNoDataStream() {
.actionGet();
assertThat(getDataStreamsResponse.getDataStreams(), hasSize(0));

GetIndexResponse getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest().indices("logs-foobar")).actionGet();
GetIndexResponse getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices("logs-foobar"))
.actionGet();
assertThat(getIndexResponse.getIndices(), arrayWithSize(1));
assertThat(getIndexResponse.getIndices(), hasItemInArray("logs-foobar"));
assertThat(getIndexResponse.getSettings().get("logs-foobar").get(IndexMetadata.SETTING_NUMBER_OF_REPLICAS), equalTo("0"));
Expand Down Expand Up @@ -1657,7 +1662,7 @@ public void testMultiThreadedRollover() throws Exception {
.actionGet();
String newBackingIndexName = getDataStreamResponse.getDataStreams().get(0).getDataStream().getWriteIndex().getName();
assertThat(newBackingIndexName, backingIndexEqualTo("potato-biscuit", 2));
indicesAdmin().prepareGetIndex().addIndices(newBackingIndexName).get();
indicesAdmin().prepareGetIndex(TEST_REQUEST_TIMEOUT).addIndices(newBackingIndexName).get();
} catch (Exception e) {
logger.info("--> expecting second index to be created but it has not yet been created");
fail("expecting second index to exist");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ public void testRestoreSnapshotFully() throws Exception {
assertEquals(RestStatus.OK, restoreSnapshotResponse.status());

assertThat(getDataStreamInfo("*"), hasSize(3));
assertNotNull(client.admin().indices().prepareGetIndex().setIndices(indexName).get());
assertNotNull(client.admin().indices().prepareGetIndex(TEST_REQUEST_TIMEOUT).setIndices(indexName).get());
}

public void testRestoreDataStreamAliasWithConflictingDataStream() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void testDefaultDataStreamAllocateToHot() {
.setWaitForActiveShards(0)
.get()
.getIndex();
var idxSettings = indicesAdmin().prepareGetIndex().addIndices(index).get().getSettings().get(dsIndexName);
var idxSettings = indicesAdmin().prepareGetIndex(TEST_REQUEST_TIMEOUT).addIndices(index).get().getSettings().get(dsIndexName);
assertThat(DataTier.TIER_PREFERENCE_SETTING.get(idxSettings), equalTo(DataTier.DATA_HOT));

logger.info("--> waiting for {} to be yellow", index);
Expand All @@ -62,7 +62,7 @@ public void testDefaultDataStreamAllocateToHot() {
// new index name should have the rolled over name
assertNotEquals(dsIndexName, rolledOverIndexName);

idxSettings = indicesAdmin().prepareGetIndex().addIndices(index).get().getSettings().get(rolledOverIndexName);
idxSettings = indicesAdmin().prepareGetIndex(TEST_REQUEST_TIMEOUT).addIndices(index).get().getSettings().get(rolledOverIndexName);
assertThat(DataTier.TIER_PREFERENCE_SETTING.get(idxSettings), equalTo(DataTier.DATA_HOT));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,10 @@ private Map<String, Object> setupThreeClusters(boolean useAlias) throws IOExcept
DataStream fooDataStream = getDataStreamResponse.getDataStreams().get(0).getDataStream();
String backingIndex = fooDataStream.getIndices().get(0).getName();
backingIndices.add(backingIndex);
GetIndexResponse getIndexResponse = client.admin().indices().getIndex(new GetIndexRequest().indices(backingIndex)).actionGet();
GetIndexResponse getIndexResponse = client.admin()
.indices()
.getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices(backingIndex))
.actionGet();
assertThat(getIndexResponse.getSettings().get(backingIndex), notNullValue());
assertThat(getIndexResponse.getSettings().get(backingIndex).getAsBoolean("index.hidden", null), is(true));
Map<?, ?> mappings = getIndexResponse.getMappings().get(backingIndex).getSourceAsMap();
Expand Down Expand Up @@ -377,7 +380,10 @@ private Map<String, Object> setupThreeClusters(boolean useAlias) throws IOExcept
DataStream barDataStream = getDataStreamResponse.getDataStreams().get(0).getDataStream();
String backingIndex = barDataStream.getIndices().get(0).getName();
backingIndices.add(backingIndex);
GetIndexResponse getIndexResponse = client.admin().indices().getIndex(new GetIndexRequest().indices(backingIndex)).actionGet();
GetIndexResponse getIndexResponse = client.admin()
.indices()
.getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices(backingIndex))
.actionGet();
assertThat(getIndexResponse.getSettings().get(backingIndex), notNullValue());
assertThat(getIndexResponse.getSettings().get(backingIndex).getAsBoolean("index.hidden", null), is(true));
Map<?, ?> mappings = getIndexResponse.getMappings().get(backingIndex).getSourceAsMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void testSystemDataStreamInGlobalState() throws Exception {
}

{
GetIndexResponse indicesRemaining = indicesAdmin().prepareGetIndex().addIndices("_all").get();
GetIndexResponse indicesRemaining = indicesAdmin().prepareGetIndex(TEST_REQUEST_TIMEOUT).addIndices("_all").get();
assertThat(indicesRemaining.indices(), arrayWithSize(0));
assertSystemDataStreamDoesNotExist();
}
Expand Down Expand Up @@ -236,7 +236,7 @@ public void testSystemDataStreamInFeatureState() throws Exception {
assertAcked(indicesAdmin().prepareDelete("my-index"));

{
GetIndexResponse indicesRemaining = indicesAdmin().prepareGetIndex().addIndices("_all").get();
GetIndexResponse indicesRemaining = indicesAdmin().prepareGetIndex(TEST_REQUEST_TIMEOUT).addIndices("_all").get();
assertThat(indicesRemaining.indices(), arrayWithSize(0));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void testTimeRanges() throws Exception {
}

// fetch end time
var getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest().indices(backingIndexName)).actionGet();
var getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices(backingIndexName)).actionGet();
Instant endTime = IndexSettings.TIME_SERIES_END_TIME.get(getIndexResponse.getSettings().get(backingIndexName));

// index another doc and verify index
Expand Down Expand Up @@ -194,7 +194,7 @@ public void testTimeRanges() throws Exception {
var newBackingIndexName = rolloverResponse.getNewIndex();

// index and check target index is new
getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest().indices(newBackingIndexName)).actionGet();
getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices(newBackingIndexName)).actionGet();
Instant newStartTime = IndexSettings.TIME_SERIES_START_TIME.get(getIndexResponse.getSettings().get(newBackingIndexName));
Instant newEndTime = IndexSettings.TIME_SERIES_END_TIME.get(getIndexResponse.getSettings().get(newBackingIndexName));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void testIndexingGettingAndSearching() throws Exception {
}

// validate index:
var getIndexResponse = client().admin().indices().getIndex(new GetIndexRequest().indices(index)).actionGet();
var getIndexResponse = client().admin().indices().getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices(index)).actionGet();
assertThat(getIndexResponse.getSettings().get(index).get("index.routing_path"), equalTo("[attributes.*]"));
// validate mapping
var mapping = getIndexResponse.mappings().get(index).getSourceAsMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void testAutoCreatePrimaryIndex() throws Exception {
CreateIndexRequest request = new CreateIndexRequest(PRIMARY_INDEX_NAME);
client().execute(AutoCreateAction.INSTANCE, request).get();

GetIndexResponse response = indicesAdmin().prepareGetIndex().addIndices(PRIMARY_INDEX_NAME).get();
GetIndexResponse response = indicesAdmin().prepareGetIndex(TEST_REQUEST_TIMEOUT).addIndices(PRIMARY_INDEX_NAME).get();
assertThat(response.indices().length, is(1));
assertThat(response.aliases().size(), is(1));
assertThat(response.aliases().get(PRIMARY_INDEX_NAME).size(), is(1));
Expand All @@ -85,7 +85,7 @@ public void testAutoCreatePrimaryIndexFromAlias() throws Exception {
CreateIndexRequest request = new CreateIndexRequest(INDEX_NAME);
client().execute(AutoCreateAction.INSTANCE, request).get();

GetIndexResponse response = indicesAdmin().prepareGetIndex().addIndices(PRIMARY_INDEX_NAME).get();
GetIndexResponse response = indicesAdmin().prepareGetIndex(TEST_REQUEST_TIMEOUT).addIndices(PRIMARY_INDEX_NAME).get();
assertThat(response.indices().length, is(1));
assertThat(response.aliases().size(), is(1));
assertThat(response.aliases().get(PRIMARY_INDEX_NAME).size(), is(1));
Expand All @@ -99,7 +99,7 @@ public void testAutoCreateNonPrimaryIndex() throws Exception {
CreateIndexRequest request = new CreateIndexRequest(INDEX_NAME + "-2");
client().execute(AutoCreateAction.INSTANCE, request).get();

GetIndexResponse response = indicesAdmin().prepareGetIndex().addIndices(INDEX_NAME + "-2").get();
GetIndexResponse response = indicesAdmin().prepareGetIndex(TEST_REQUEST_TIMEOUT).addIndices(INDEX_NAME + "-2").get();
assertThat(response.indices().length, is(1));
assertThat(response.aliases().size(), is(1));
assertThat(response.aliases().get(INDEX_NAME + "-2").size(), is(1));
Expand Down Expand Up @@ -144,7 +144,9 @@ public void testSystemIndicesAutoCreatedAsHidden() throws Exception {
CreateIndexRequest request = new CreateIndexRequest(UnmanagedSystemIndexTestPlugin.SYSTEM_INDEX_NAME);
client().execute(AutoCreateAction.INSTANCE, request).get();

GetIndexResponse response = indicesAdmin().prepareGetIndex().addIndices(UnmanagedSystemIndexTestPlugin.SYSTEM_INDEX_NAME).get();
GetIndexResponse response = indicesAdmin().prepareGetIndex(TEST_REQUEST_TIMEOUT)
.addIndices(UnmanagedSystemIndexTestPlugin.SYSTEM_INDEX_NAME)
.get();
assertThat(response.indices().length, is(1));
Settings settings = response.settings().get(UnmanagedSystemIndexTestPlugin.SYSTEM_INDEX_NAME);
assertThat(settings, notNullValue());
Expand Down
Loading

0 comments on commit 9f597a4

Please sign in to comment.