Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] More advanced post-test cleanup of ML indices #39049

Merged
merged 1 commit into from
Feb 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -15,11 +15,14 @@
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.ml.MachineLearningField;

import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;

/**
* An extension to {@link ESSingleNodeTestCase} that adds node settings specifically needed for ML test cases.
*/
@@ -46,6 +49,33 @@ protected Collection<Class<? extends Plugin>> getPlugins() {
return pluginList(LocalStateMachineLearning.class);
}

/**
* This cleanup is to fix the problem described in
* https://github.com/elastic/elasticsearch/issues/38952
*/
@Override
public void tearDown() throws Exception {
try {
logger.info("[{}#{}]: ML-specific after test cleanup", getTestClass().getSimpleName(), getTestName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for making this info level? I would like to see our test logs have less lines in them, not more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's info in the same place in ESSingleNodeTestCase, so I copied that. I'm happy to downgrade this one to trace though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I did not realize that we had an info line there in ESSingleNodeTestCase too. Thanks for pointing that out. Yes, I think that not only this one but both can be downgraded to trace. 🙏

String[] nonAnnotationMlIndices;
boolean mlAnnotationsIndexExists;
do {
String[] mlIndices = client().admin().indices().prepareGetIndex().addIndices(".ml-*").get().indices();
nonAnnotationMlIndices = Arrays.stream(mlIndices).filter(name -> name.startsWith(".ml-annotations") == false)
.toArray(String[]::new);
mlAnnotationsIndexExists = mlIndices.length > nonAnnotationMlIndices.length;
} while (nonAnnotationMlIndices.length > 0 && mlAnnotationsIndexExists == false);
if (nonAnnotationMlIndices.length > 0) {
// Delete the ML indices apart from the annotations index. The annotations index will be deleted by the
// base class cleanup. We want to delete all the others first so that the annotations index doesn't get
// automatically recreated.
assertAcked(client().admin().indices().prepareDelete(nonAnnotationMlIndices).get());
}
} finally {
super.tearDown();
}
}

protected void waitForMlTemplates() throws Exception {
// block until the templates are installed
assertBusy(() -> {