Skip to content

Commit 95a1931

Browse files
committed
[TEST] Work around _cat/indices bug with security enabled (#47160)
When the ML native multi-node tests use _cat/indices/_all and the request goes to a non-master node, _all is translated to a list of concrete indices by the authz layer on the coordinating node before the request is forwarded to the master node. Then it is possible for the master node to return an index_not_found_exception if one of the concrete indices that was expanded on the coordinating node has been deleted in the meantime. (#47159 has been opened to track the underlying problem.) It has been observed that the index that gets deleted when the problem affects the ML native multi-node tests is always the ML notifications index. The tests that fail are only interested in the presence or absense of ML results indices. Therefore the workaround is to only _cat indices that match the ML results index pattern. Fixes #45652
1 parent 1cb7896 commit 95a1931

File tree

1 file changed

+27
-13
lines changed
  • x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration

1 file changed

+27
-13
lines changed

x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ public void testCreateJobsWithIndexNameOption() throws Exception {
208208
}
209209
});
210210

211-
String responseAsString = EntityUtils.toString(client().performRequest(new Request("GET", "/_cat/indices")).getEntity());
211+
// Use _cat/indices/.ml-anomalies-* instead of _cat/indices/_all to workaround https://github.com/elastic/elasticsearch/issues/45652
212+
String responseAsString = EntityUtils.toString(client().performRequest(
213+
new Request("GET", "/_cat/indices/" + AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "*")).getEntity());
212214
assertThat(responseAsString,
213215
containsString(AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "custom-" + indexName));
214216
assertThat(responseAsString, not(containsString(AnomalyDetectorsIndex.jobResultsAliasedName(jobId1))));
@@ -272,7 +274,8 @@ public void testCreateJobsWithIndexNameOption() throws Exception {
272274
assertThat(responseAsString, not(containsString(AnomalyDetectorsIndex.jobResultsAliasedName(jobId1))));
273275
assertThat(responseAsString, containsString(AnomalyDetectorsIndex.jobResultsAliasedName(jobId2))); //job2 still exists
274276

275-
responseAsString = EntityUtils.toString(client().performRequest(new Request("GET", "/_cat/indices")).getEntity());
277+
responseAsString = EntityUtils.toString(client().performRequest(
278+
new Request("GET", "/_cat/indices/" + AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "*")).getEntity());
276279
assertThat(responseAsString, containsString(AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "custom-" + indexName));
277280

278281
client().performRequest(new Request("POST", "/_refresh"));
@@ -287,7 +290,8 @@ public void testCreateJobsWithIndexNameOption() throws Exception {
287290
assertThat(responseAsString, not(containsString(AnomalyDetectorsIndex.jobResultsAliasedName(jobId2))));
288291

289292
client().performRequest(new Request("POST", "/_refresh"));
290-
responseAsString = EntityUtils.toString(client().performRequest(new Request("GET", "/_cat/indices")).getEntity());
293+
responseAsString = EntityUtils.toString(client().performRequest(
294+
new Request("GET", "/_cat/indices/" + AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "*")).getEntity());
291295
assertThat(responseAsString, not(containsString(AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "custom-" + indexName)));
292296
}
293297

@@ -394,19 +398,21 @@ public void testCreateJob_WithClashingFieldMappingsFails() throws Exception {
394398
"avoid the clash by assigning a dedicated results index"));
395399
}
396400

397-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/45652")
398401
public void testDeleteJob() throws Exception {
399402
String jobId = "delete-job-job";
400403
String indexName = AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + AnomalyDetectorsIndexFields.RESULTS_INDEX_DEFAULT;
401404
createFarequoteJob(jobId);
402405

403-
String indicesBeforeDelete = EntityUtils.toString(client().performRequest(new Request("GET", "/_cat/indices")).getEntity());
406+
// Use _cat/indices/.ml-anomalies-* instead of _cat/indices/_all to workaround https://github.com/elastic/elasticsearch/issues/45652
407+
String indicesBeforeDelete = EntityUtils.toString(client().performRequest(
408+
new Request("GET", "/_cat/indices/" + AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "*")).getEntity());
404409
assertThat(indicesBeforeDelete, containsString(indexName));
405410

406411
client().performRequest(new Request("DELETE", MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId));
407412

408413
// check that the index still exists (it's shared by default)
409-
String indicesAfterDelete = EntityUtils.toString(client().performRequest(new Request("GET", "/_cat/indices")).getEntity());
414+
String indicesAfterDelete = EntityUtils.toString(client().performRequest(
415+
new Request("GET", "/_cat/indices/" + AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "*")).getEntity());
410416
assertThat(indicesAfterDelete, containsString(indexName));
411417

412418
waitUntilIndexIsEmpty(indexName);
@@ -465,13 +471,14 @@ public void testDeleteJob_TimingStatsDocumentIsDeleted() throws Exception {
465471
assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(404));
466472
}
467473

468-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/45652")
469474
public void testDeleteJobAsync() throws Exception {
470475
String jobId = "delete-job-async-job";
471476
String indexName = AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + AnomalyDetectorsIndexFields.RESULTS_INDEX_DEFAULT;
472477
createFarequoteJob(jobId);
473478

474-
String indicesBeforeDelete = EntityUtils.toString(client().performRequest(new Request("GET", "/_cat/indices")).getEntity());
479+
// Use _cat/indices/.ml-anomalies-* instead of _cat/indices/_all to workaround https://github.com/elastic/elasticsearch/issues/45652
480+
String indicesBeforeDelete = EntityUtils.toString(client().performRequest(
481+
new Request("GET", "/_cat/indices/" + AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "*")).getEntity());
475482
assertThat(indicesBeforeDelete, containsString(indexName));
476483

477484
Response response = client().performRequest(new Request("DELETE", MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId
@@ -483,7 +490,8 @@ public void testDeleteJobAsync() throws Exception {
483490
assertThat(EntityUtils.toString(taskResponse.getEntity()), containsString("\"acknowledged\":true"));
484491

485492
// check that the index still exists (it's shared by default)
486-
String indicesAfterDelete = EntityUtils.toString(client().performRequest(new Request("GET", "/_cat/indices")).getEntity());
493+
String indicesAfterDelete = EntityUtils.toString(client().performRequest(
494+
new Request("GET", "/_cat/indices/" + AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "*")).getEntity());
487495
assertThat(indicesAfterDelete, containsString(indexName));
488496

489497
waitUntilIndexIsEmpty(indexName);
@@ -518,7 +526,9 @@ public void testDeleteJobAfterMissingIndex() throws Exception {
518526
String indexName = AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + AnomalyDetectorsIndexFields.RESULTS_INDEX_DEFAULT;
519527
createFarequoteJob(jobId);
520528

521-
String indicesBeforeDelete = EntityUtils.toString(client().performRequest(new Request("GET", "/_cat/indices")).getEntity());
529+
// Use _cat/indices/.ml-anomalies-* instead of _cat/indices/_all to workaround https://github.com/elastic/elasticsearch/issues/45652
530+
String indicesBeforeDelete = EntityUtils.toString(client().performRequest(
531+
new Request("GET", "/_cat/indices/" + AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "*")).getEntity());
522532
assertThat(indicesBeforeDelete, containsString(indexName));
523533

524534
// Manually delete the index so that we can test that deletion proceeds
@@ -528,7 +538,8 @@ public void testDeleteJobAfterMissingIndex() throws Exception {
528538
client().performRequest(new Request("DELETE", MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId));
529539

530540
// check index was deleted
531-
String indicesAfterDelete = EntityUtils.toString(client().performRequest(new Request("GET", "/_cat/indices")).getEntity());
541+
String indicesAfterDelete = EntityUtils.toString(client().performRequest(
542+
new Request("GET", "/_cat/indices/" + AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "*")).getEntity());
532543
assertThat(indicesAfterDelete, not(containsString(aliasName)));
533544
assertThat(indicesAfterDelete, not(containsString(indexName)));
534545

@@ -598,7 +609,9 @@ public void testMultiIndexDelete() throws Exception {
598609
"}");
599610
client().performRequest(extraIndex2);
600611

601-
String indicesBeforeDelete = EntityUtils.toString(client().performRequest(new Request("GET", "/_cat/indices")).getEntity());
612+
// Use _cat/indices/.ml-anomalies-* instead of _cat/indices/_all to workaround https://github.com/elastic/elasticsearch/issues/45652
613+
String indicesBeforeDelete = EntityUtils.toString(client().performRequest(
614+
new Request("GET", "/_cat/indices/" + AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "*")).getEntity());
602615
assertThat(indicesBeforeDelete, containsString(indexName));
603616
assertThat(indicesBeforeDelete, containsString(indexName + "-001"));
604617
assertThat(indicesBeforeDelete, containsString(indexName + "-002"));
@@ -637,7 +650,8 @@ public void testMultiIndexDelete() throws Exception {
637650
client().performRequest(new Request("POST", "/_refresh"));
638651

639652
// check that the indices still exist but are empty
640-
String indicesAfterDelete = EntityUtils.toString(client().performRequest(new Request("GET", "/_cat/indices")).getEntity());
653+
String indicesAfterDelete = EntityUtils.toString(client().performRequest(
654+
new Request("GET", "/_cat/indices/" + AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "*")).getEntity());
641655
assertThat(indicesAfterDelete, containsString(indexName));
642656
assertThat(indicesAfterDelete, containsString(indexName + "-001"));
643657
assertThat(indicesAfterDelete, containsString(indexName + "-002"));

0 commit comments

Comments
 (0)