Skip to content

Commit

Permalink
Fix trappy timeouts in GetAliasesRequest (#119817)
Browse files Browse the repository at this point in the history
Removes the use of the trappy default master node timeout and configures
a sensible default instead.
  • Loading branch information
nielsbauman authored Jan 9, 2025
1 parent 933da4e commit 48b9fae
Show file tree
Hide file tree
Showing 36 changed files with 394 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,11 @@ public void testResolvabilityOfDataStreamsInAPIs() throws Exception {
verifyResolvability(dataStreamName, indicesAdmin().prepareForceMerge(dataStreamName), false);
verifyResolvability(dataStreamName, indicesAdmin().prepareValidateQuery(dataStreamName), false);
verifyResolvability(dataStreamName, indicesAdmin().prepareRecoveries(dataStreamName), false);
verifyResolvability(dataStreamName, indicesAdmin().prepareGetAliases("dummy").setIndices(dataStreamName), false);
verifyResolvability(
dataStreamName,
indicesAdmin().prepareGetAliases(TEST_REQUEST_TIMEOUT, "dummy").setIndices(dataStreamName),
false
);
verifyResolvability(dataStreamName, indicesAdmin().prepareGetFieldMappings(dataStreamName), false);
verifyResolvability(dataStreamName, indicesAdmin().preparePutMapping(dataStreamName).setSource("""
{"_doc":{"properties": {"my_field":{"type":"keyword"}}}}""", XContentType.JSON), false);
Expand Down Expand Up @@ -635,7 +639,7 @@ public void testResolvabilityOfDataStreamsInAPIs() throws Exception {
verifyResolvability(wildcardExpression, indicesAdmin().prepareForceMerge(wildcardExpression), false);
verifyResolvability(wildcardExpression, indicesAdmin().prepareValidateQuery(wildcardExpression), false);
verifyResolvability(wildcardExpression, indicesAdmin().prepareRecoveries(wildcardExpression), false);
verifyResolvability(wildcardExpression, indicesAdmin().prepareGetAliases(wildcardExpression), false);
verifyResolvability(wildcardExpression, indicesAdmin().prepareGetAliases(TEST_REQUEST_TIMEOUT, wildcardExpression), false);
verifyResolvability(wildcardExpression, indicesAdmin().prepareGetFieldMappings(wildcardExpression), false);
verifyResolvability(wildcardExpression, indicesAdmin().preparePutMapping(wildcardExpression).setSource("""
{"_doc":{"properties": {"my_field":{"type":"keyword"}}}}""", XContentType.JSON), false);
Expand Down Expand Up @@ -738,7 +742,7 @@ public void testAliasActionsOnDataStreams() throws Exception {
IndicesAliasesRequest aliasesAddRequest = new IndicesAliasesRequest();
aliasesAddRequest.addAliasAction(addAction);
assertAcked(indicesAdmin().aliases(aliasesAddRequest).actionGet());
GetAliasesResponse response = indicesAdmin().getAliases(new GetAliasesRequest()).actionGet();
GetAliasesResponse response = indicesAdmin().getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT)).actionGet();
assertThat(
response.getDataStreamAliases(),
equalTo(Map.of("metrics-foo", List.of(new DataStreamAlias("foo", List.of("metrics-foo"), null, null))))
Expand All @@ -764,7 +768,7 @@ public void testDataSteamAliasWithFilter() throws Exception {
IndicesAliasesRequest aliasesAddRequest = new IndicesAliasesRequest();
aliasesAddRequest.addAliasAction(addAction);
assertAcked(indicesAdmin().aliases(aliasesAddRequest).actionGet());
GetAliasesResponse response = indicesAdmin().getAliases(new GetAliasesRequest()).actionGet();
GetAliasesResponse response = indicesAdmin().getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT)).actionGet();
assertThat(
response.getDataStreamAliases(),
equalTo(
Expand Down Expand Up @@ -794,7 +798,7 @@ public void testDataSteamAliasWithFilter() throws Exception {
aliasesAddRequest = new IndicesAliasesRequest();
aliasesAddRequest.addAliasAction(addAction);
assertAcked(indicesAdmin().aliases(aliasesAddRequest).actionGet());
response = indicesAdmin().getAliases(new GetAliasesRequest()).actionGet();
response = indicesAdmin().getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT)).actionGet();
assertThat(
response.getDataStreamAliases(),
equalTo(
Expand Down Expand Up @@ -840,7 +844,7 @@ public void testSearchFilteredAndUnfilteredAlias() throws Exception {
aliasesAddRequest.addAliasAction(addFilteredAliasAction);
aliasesAddRequest.addAliasAction(addUnfilteredAliasAction);
assertAcked(indicesAdmin().aliases(aliasesAddRequest).actionGet());
GetAliasesResponse response = indicesAdmin().getAliases(new GetAliasesRequest()).actionGet();
GetAliasesResponse response = indicesAdmin().getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT)).actionGet();
assertThat(response.getDataStreamAliases(), hasKey("logs-foobar"));
assertThat(
response.getDataStreamAliases().get("logs-foobar"),
Expand Down Expand Up @@ -884,7 +888,7 @@ public void testRandomDataSteamAliasesUpdate() throws Exception {
addAction = new AliasActions(AliasActions.Type.ADD).aliases(alias).indices(dataStreams[0]).filter(indexFilters).writeIndex(true);
assertAcked(indicesAdmin().aliases(new IndicesAliasesRequest().addAliasAction(addAction)).actionGet());

GetAliasesResponse response = indicesAdmin().getAliases(new GetAliasesRequest()).actionGet();
GetAliasesResponse response = indicesAdmin().getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT)).actionGet();
assertThat(response.getDataStreamAliases().size(), equalTo(dataStreams.length));
List<DataStreamAlias> result = response.getDataStreamAliases()
.values()
Expand Down Expand Up @@ -933,7 +937,7 @@ public void testDataSteamAliasWithMalformedFilter() throws Exception {
indicesAdmin().aliases(new IndicesAliasesRequest().addAliasAction(addAction))
);
assertThat(e.getMessage(), equalTo("failed to parse filter for alias [" + alias + "]"));
GetAliasesResponse response = indicesAdmin().getAliases(new GetAliasesRequest()).actionGet();
GetAliasesResponse response = indicesAdmin().getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT)).actionGet();
assertThat(response.getDataStreamAliases(), anEmptyMap());
}

Expand Down Expand Up @@ -998,7 +1002,7 @@ public void testRemoveDataStreamAliasesMixedExpression() throws Exception {
aliasesAddRequest.addAliasAction(new AliasActions(AliasActions.Type.ADD).index("metrics-foo").aliases("my-alias1"));
aliasesAddRequest.addAliasAction(new AliasActions(AliasActions.Type.ADD).index("metrics-myindex").aliases("my-alias2"));
assertAcked(indicesAdmin().aliases(aliasesAddRequest).actionGet());
GetAliasesResponse response = indicesAdmin().getAliases(new GetAliasesRequest()).actionGet();
GetAliasesResponse response = indicesAdmin().getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT)).actionGet();
assertThat(
response.getDataStreamAliases(),
equalTo(Map.of("metrics-foo", List.of(new DataStreamAlias("my-alias1", List.of("metrics-foo"), null, null))))
Expand All @@ -1013,7 +1017,7 @@ public void testRemoveDataStreamAliasesMixedExpression() throws Exception {
aliasesAddRequest.addAliasAction(new AliasActions(AliasActions.Type.REMOVE).index("_all").aliases("my-*"));
}
assertAcked(indicesAdmin().aliases(aliasesAddRequest).actionGet());
response = indicesAdmin().getAliases(new GetAliasesRequest()).actionGet();
response = indicesAdmin().getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT)).actionGet();
assertThat(response.getDataStreamAliases(), anEmptyMap());
assertThat(response.getAliases().get("metrics-myindex").size(), equalTo(0));
assertThat(response.getAliases().size(), equalTo(1));
Expand All @@ -1034,7 +1038,7 @@ public void testUpdateDataStreamsWithWildcards() throws Exception {
new AliasActions(AliasActions.Type.ADD).index("metrics-foo").aliases("my-alias1", "my-alias2")
);
assertAcked(indicesAdmin().aliases(aliasesAddRequest).actionGet());
GetAliasesResponse response = indicesAdmin().getAliases(new GetAliasesRequest()).actionGet();
GetAliasesResponse response = indicesAdmin().getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT)).actionGet();
assertThat(response.getDataStreamAliases().keySet(), containsInAnyOrder("metrics-foo"));
assertThat(
response.getDataStreamAliases().get("metrics-foo"),
Expand All @@ -1060,7 +1064,7 @@ public void testUpdateDataStreamsWithWildcards() throws Exception {
aliasesAddRequest.addAliasAction(new AliasActions(AliasActions.Type.REMOVE).index("_all").aliases("_all"));
}
assertAcked(indicesAdmin().aliases(aliasesAddRequest).actionGet());
GetAliasesResponse response = indicesAdmin().getAliases(new GetAliasesRequest()).actionGet();
GetAliasesResponse response = indicesAdmin().getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT)).actionGet();
assertThat(response.getDataStreamAliases(), anEmptyMap());
assertThat(response.getAliases().size(), equalTo(0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ public void testSnapshotAndRestore() throws Exception {
assertEquals(1, ds.get(0).getDataStream().getIndices().size());
assertEquals(dsBackingIndexName, ds.get(0).getDataStream().getIndices().get(0).getName());

GetAliasesResponse getAliasesResponse = client.admin().indices().getAliases(new GetAliasesRequest("my-alias")).actionGet();
GetAliasesResponse getAliasesResponse = client.admin()
.indices()
.getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT, "my-alias"))
.actionGet();
assertThat(getAliasesResponse.getDataStreamAliases().keySet(), containsInAnyOrder("ds", "other-ds"));
assertThat(getAliasesResponse.getDataStreamAliases().get("ds").size(), equalTo(1));
assertThat(getAliasesResponse.getDataStreamAliases().get("ds").get(0).getName(), equalTo("my-alias"));
Expand Down Expand Up @@ -462,7 +465,10 @@ public void testSnapshotAndRestoreAllIncludeSpecificDataStream() throws Exceptio
assertEquals(1, dataStreamInfos.get(0).getDataStream().getIndices().size());
assertEquals(backingIndexName, dataStreamInfos.get(0).getDataStream().getIndices().get(0).getName());

GetAliasesResponse getAliasesResponse = client.admin().indices().getAliases(new GetAliasesRequest("my-alias")).actionGet();
GetAliasesResponse getAliasesResponse = client.admin()
.indices()
.getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT, "my-alias"))
.actionGet();
assertThat(getAliasesResponse.getDataStreamAliases().keySet(), contains(dataStreamToSnapshot));
assertThat(
getAliasesResponse.getDataStreamAliases().get(dataStreamToSnapshot),
Expand Down Expand Up @@ -520,7 +526,10 @@ public void testSnapshotAndRestoreReplaceAll() throws Exception {
containsInAnyOrder("ds", "other-ds", "with-fs")
);

GetAliasesResponse getAliasesResponse = client.admin().indices().getAliases(new GetAliasesRequest("my-alias")).actionGet();
GetAliasesResponse getAliasesResponse = client.admin()
.indices()
.getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT, "my-alias"))
.actionGet();
assertThat(getAliasesResponse.getDataStreamAliases().keySet(), containsInAnyOrder("ds", "other-ds"));
assertThat(getAliasesResponse.getDataStreamAliases().get("ds").size(), equalTo(1));
assertThat(getAliasesResponse.getDataStreamAliases().get("ds").get(0).getName(), equalTo("my-alias"));
Expand Down Expand Up @@ -581,7 +590,10 @@ public void testSnapshotAndRestoreAll() throws Exception {
assertEquals(1, dataStreamInfos.get(2).getDataStream().getFailureIndices().getIndices().size());
assertEquals(fsFailureIndexName, dataStreamInfos.get(2).getDataStream().getFailureIndices().getIndices().get(0).getName());

GetAliasesResponse getAliasesResponse = client.admin().indices().getAliases(new GetAliasesRequest("my-alias")).actionGet();
GetAliasesResponse getAliasesResponse = client.admin()
.indices()
.getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT, "my-alias"))
.actionGet();
assertThat(getAliasesResponse.getDataStreamAliases().keySet(), containsInAnyOrder("ds", "other-ds"));

assertThat(getAliasesResponse.getDataStreamAliases().get("ds").size(), equalTo(1));
Expand Down Expand Up @@ -649,7 +661,10 @@ public void testSnapshotAndRestoreIncludeAliasesFalse() throws Exception {
assertEquals(1, dataStreamInfos.get(2).getDataStream().getIndices().size());
assertEquals(fsFailureIndexName, dataStreamInfos.get(2).getDataStream().getFailureIndices().getIndices().get(0).getName());

GetAliasesResponse getAliasesResponse = client.admin().indices().getAliases(new GetAliasesRequest("*")).actionGet();
GetAliasesResponse getAliasesResponse = client.admin()
.indices()
.getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT, "*"))
.actionGet();
assertThat(getAliasesResponse.getDataStreamAliases(), anEmptyMap());
assertAcked(
client().execute(
Expand Down Expand Up @@ -699,7 +714,10 @@ public void testRename() throws Exception {
);
assertEquals(DOCUMENT_SOURCE, client.prepareGet(ds2BackingIndexName, id).get().getSourceAsMap());

GetAliasesResponse getAliasesResponse = client.admin().indices().getAliases(new GetAliasesRequest("my-alias")).actionGet();
GetAliasesResponse getAliasesResponse = client.admin()
.indices()
.getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT, "my-alias"))
.actionGet();
assertThat(getAliasesResponse.getDataStreamAliases().keySet(), containsInAnyOrder("ds", "ds2", "other-ds"));
assertThat(getAliasesResponse.getDataStreamAliases().get("ds2").size(), equalTo(1));
assertThat(getAliasesResponse.getDataStreamAliases().get("ds2").get(0).getName(), equalTo("my-alias"));
Expand Down Expand Up @@ -749,7 +767,10 @@ public void testRenameWriteDataStream() throws Exception {
assertEquals(1, dataStreamInfos.get(0).getDataStream().getIndices().size());
assertEquals(otherDs2BackingIndexName, dataStreamInfos.get(0).getDataStream().getIndices().get(0).getName());

GetAliasesResponse getAliasesResponse = client.admin().indices().getAliases(new GetAliasesRequest("my-alias")).actionGet();
GetAliasesResponse getAliasesResponse = client.admin()
.indices()
.getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT, "my-alias"))
.actionGet();
assertThat(getAliasesResponse.getDataStreamAliases().keySet(), containsInAnyOrder("ds", "other-ds", "other-ds2"));
assertThat(getAliasesResponse.getDataStreamAliases().get("other-ds2").size(), equalTo(1));
assertThat(getAliasesResponse.getDataStreamAliases().get("other-ds2").get(0).getName(), equalTo("my-alias"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ public void testAllowed() {
final IndicesAliasesRequest request = new IndicesAliasesRequest().origin("allowed");
request.addAliasAction(IndicesAliasesRequest.AliasActions.add().index("index").alias("alias"));
assertAcked(client().admin().indices().aliases(request).actionGet());
final GetAliasesResponse response = client().admin().indices().getAliases(new GetAliasesRequest("alias")).actionGet();
final GetAliasesResponse response = client().admin()
.indices()
.getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT, "alias"))
.actionGet();
assertThat(response.getAliases().keySet().size(), equalTo(1));
assertThat(response.getAliases().keySet().iterator().next(), equalTo("index"));
final List<AliasMetadata> aliasMetadata = response.getAliases().get("index");
Expand Down Expand Up @@ -117,6 +120,8 @@ public void testSomeAllowed() {
final Exception e = expectThrows(IllegalStateException.class, client().admin().indices().aliases(request));
final String index = "foo_allowed".equals(origin) ? "bar" : "foo";
assertThat(e, hasToString(containsString("origin [" + origin + "] not allowed for index [" + index + "]")));
assertTrue(client().admin().indices().getAliases(new GetAliasesRequest("alias")).actionGet().getAliases().isEmpty());
assertTrue(
client().admin().indices().getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT, "alias")).actionGet().getAliases().isEmpty()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public void testAutoCreateSystemAliasViaComposableTemplateAllowsTemplates() thro
private void assertAliasesHidden(String nonPrimaryIndex, Set<String> aliasNames, int aliasCount) throws InterruptedException,
ExecutionException {
final GetAliasesResponse getAliasesResponse = indicesAdmin().getAliases(
new GetAliasesRequest().indicesOptions(IndicesOptions.strictExpandHidden())
new GetAliasesRequest(TEST_REQUEST_TIMEOUT).indicesOptions(IndicesOptions.strictExpandHidden())
).get();

assertThat(getAliasesResponse.getAliases().size(), equalTo(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void testNonPrimarySystemIndexIsAutoCreatedViaConcreteName() throws Excep

// Check that a non-primary system index is not assigned as the write index for the alias
final GetAliasesResponse getAliasesResponse = indicesAdmin().getAliases(
new GetAliasesRequest().indicesOptions(IndicesOptions.strictExpandHidden())
new GetAliasesRequest(TEST_REQUEST_TIMEOUT).indicesOptions(IndicesOptions.strictExpandHidden())
).actionGet();

assertThat(getAliasesResponse.getAliases().size(), equalTo(1));
Expand Down Expand Up @@ -322,7 +322,7 @@ public void onFailure(Exception e) {
*/
private void assertAliases(String concreteIndex) {
final GetAliasesResponse getAliasesResponse = indicesAdmin().getAliases(
new GetAliasesRequest().indicesOptions(IndicesOptions.strictExpandHidden())
new GetAliasesRequest(TEST_REQUEST_TIMEOUT).indicesOptions(IndicesOptions.strictExpandHidden())
).actionGet();

assertThat(getAliasesResponse.getAliases().size(), equalTo(1));
Expand All @@ -334,7 +334,7 @@ private void assertAliases(String concreteIndex) {
private void assertHasAliases(Set<String> aliasNames, String name, String primaryName, int aliasCount) throws InterruptedException,
java.util.concurrent.ExecutionException {
final GetAliasesResponse getAliasesResponse = indicesAdmin().getAliases(
new GetAliasesRequest().indicesOptions(IndicesOptions.strictExpandHidden())
new GetAliasesRequest(TEST_REQUEST_TIMEOUT).indicesOptions(IndicesOptions.strictExpandHidden())
).get();

assertThat(getAliasesResponse.getAliases().size(), equalTo(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ public void testRolloverConcurrently() throws Exception {

for (int i = 0; i < numOfThreads; i++) {
var aliasName = "test-" + i;
var response = indicesAdmin().getAliases(new GetAliasesRequest(aliasName)).get();
var response = indicesAdmin().getAliases(new GetAliasesRequest(TEST_REQUEST_TIMEOUT, aliasName)).get();
List<Map.Entry<String, List<AliasMetadata>>> actual = response.getAliases().entrySet().stream().toList();
List<Map.Entry<String, List<AliasMetadata>>> expected = new ArrayList<>(numberOfRolloversPerThread);
int numOfIndices = numberOfRolloversPerThread + 1;
Expand Down
Loading

0 comments on commit 48b9fae

Please sign in to comment.