Skip to content

Commit

Permalink
Make MlDeprecationIT delete system indices before generic cleanup
Browse files Browse the repository at this point in the history
The generic post test cleanup code causes deprecation warnings
when deleting system indices. This is particularly problematic
for deprecation plugin integration tests.

This change makes the ML test in the deprecation plugin integration
tests clean up the ML system indices before the generic post test
cleanup runs.

Fixes elastic#79058
  • Loading branch information
droberts195 committed Oct 13, 2021
1 parent 6dd55f2 commit 8a0e5d3
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.WarningsHandler;
import org.elasticsearch.client.feature.ResetFeaturesRequest;
import org.elasticsearch.client.feature.ResetFeaturesResponse;
import org.elasticsearch.client.migration.DeprecationInfoRequest;
import org.elasticsearch.client.migration.DeprecationInfoResponse;
import org.elasticsearch.client.ml.PutJobRequest;
Expand All @@ -25,9 +27,11 @@
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentType;
import org.junit.After;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static org.hamcrest.Matchers.containsString;
Expand Down Expand Up @@ -57,6 +61,29 @@ protected boolean enableWarningsCheck() {
return false;
}

/**
* Currently the generic test cleanup code that runs in between tests is causing deprecation warnings
* when it deletes system indices like .ml-config. This causes particular problems within this test
* suite that's specifically testing for deprecations. Therefore, before the generic cleanup code runs,
* ensure that all ML system indices are already deleted.
*
* TODO: delete this method once the generic cleanup code deletes system indices without generating
* deprecation warnings.
*/
@After
public void resetFeatures() throws Exception {
HLRC adminHlrc = new HLRC(adminClient());
List<ResetFeaturesResponse.ResetFeatureStateStatus> statuses = adminHlrc.features()
.resetFeatures(new ResetFeaturesRequest(), RequestOptions.DEFAULT)
.getFeatureResetStatuses();
for (ResetFeaturesResponse.ResetFeatureStateStatus status : statuses) {
if ("machine_learning".equals(status.getFeatureName()) && status.getException() != null) {
throw status.getException();
}
}
// It's deliberate not to close the admin client
}

public void testMlDeprecationChecks() throws Exception {
HLRC hlrc = new HLRC(client());
String jobId = "deprecation_check_job";
Expand Down Expand Up @@ -99,5 +126,4 @@ public void testMlDeprecationChecks() throws Exception {
assertThat(response.getMlSettingsIssues().get(0).getMeta(), equalTo(Map.of("job_id", jobId, "snapshot_id", "1")));
hlrc.close();
}

}

0 comments on commit 8a0e5d3

Please sign in to comment.