From fa212fe60b1f047481377511c1e2614fcd6b209e Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Tue, 28 Jan 2020 15:36:29 +0100 Subject: [PATCH] Stricter checks of setup and teardown in docs tests (#51430) Adds extra checks due to 7.x backport --- docs/reference/cat/templates.asciidoc | 12 ++++++++++ .../ilm/getting-started-ilm.asciidoc | 10 ++++++++ .../ilm/ilm-with-existing-indices.asciidoc | 20 ++++++++++++++++ .../ilm/set-up-lifecycle-policy.asciidoc | 10 ++++++++ .../ilm/using-policies-rollover.asciidoc | 10 ++++++++ docs/reference/indices/templates.asciidoc | 4 +--- .../mapping/removal_of_types.asciidoc | 11 +++++++++ docs/reference/monitoring/indices.asciidoc | 10 ++++++++ .../smoketest/DocsClientYamlTestSuiteIT.java | 23 ++++++++++++++++++- .../test/rest/ESRestTestCase.java | 7 +++++- 10 files changed, 112 insertions(+), 5 deletions(-) diff --git a/docs/reference/cat/templates.asciidoc b/docs/reference/cat/templates.asciidoc index c0127296703..512ccaadde0 100644 --- a/docs/reference/cat/templates.asciidoc +++ b/docs/reference/cat/templates.asciidoc @@ -71,3 +71,15 @@ template1 [tea*] 1 template2 [teak*] 2 7 -------------------------------------------------- // TESTRESPONSE[s/\*/\\*/ s/\[/\\[/ s/\]/\\]/ non_json] + +////////////////////////// + +[source,console] +-------------------------------------------------- +DELETE /_template/template0 +DELETE /_template/template1 +DELETE /_template/template2 +-------------------------------------------------- +// TEST[continued] + +////////////////////////// diff --git a/docs/reference/ilm/getting-started-ilm.asciidoc b/docs/reference/ilm/getting-started-ilm.asciidoc index f7ca3f4d216..9aafb9a44fa 100644 --- a/docs/reference/ilm/getting-started-ilm.asciidoc +++ b/docs/reference/ilm/getting-started-ilm.asciidoc @@ -90,6 +90,16 @@ PUT _template/datastream_template ----------------------- // TEST[continued] +////////////////////////// + +[source,console] +-------------------------------------------------- +DELETE /_template/datastream_template +-------------------------------------------------- +// TEST[continued] + +////////////////////////// + <1> match all indices starting with "datastream-". These will include all newly created indices from actions like rollover <2> the name of the lifecycle policy managing the index diff --git a/docs/reference/ilm/ilm-with-existing-indices.asciidoc b/docs/reference/ilm/ilm-with-existing-indices.asciidoc index 96c1e4589de..8dfb122da8f 100644 --- a/docs/reference/ilm/ilm-with-existing-indices.asciidoc +++ b/docs/reference/ilm/ilm-with-existing-indices.asciidoc @@ -65,6 +65,16 @@ POST mylogs-pre-ilm-2019.06.25/_doc ----------------------- // TEST[continued] +////////////////////////// + +[source,console] +-------------------------------------------------- +DELETE _template/mylogs_template +-------------------------------------------------- +// TEST[continued] + +////////////////////////// + Now that we have these indices, we'll look at a few different ways of migrating these indices to ILM. @@ -316,6 +326,16 @@ PUT ilm-mylogs-000001 ----------------------- // TEST[continued] +////////////////////////// + +[source,console] +-------------------------------------------------- +DELETE /_template/mylogs_template +-------------------------------------------------- +// TEST[continued] + +////////////////////////// + All new documents should be indexed via the `mylogs` alias at this point. Adding new data to the old indices during the reindexing process can cause data to be added to the old indices, but not be reindexed into the new indices. diff --git a/docs/reference/ilm/set-up-lifecycle-policy.asciidoc b/docs/reference/ilm/set-up-lifecycle-policy.asciidoc index 83394de577c..60013951afd 100644 --- a/docs/reference/ilm/set-up-lifecycle-policy.asciidoc +++ b/docs/reference/ilm/set-up-lifecycle-policy.asciidoc @@ -68,6 +68,16 @@ PUT _template/my_template with `test-` <2> The template will set the policy to be used to `my_policy` +////////////////////////// + +[source,console] +-------------------------------------------------- +DELETE /_template/my_template +-------------------------------------------------- +// TEST[continued] + +////////////////////////// + Now that a policy exists and is used in an index template we can create an initial index which will be managed by our policy: diff --git a/docs/reference/ilm/using-policies-rollover.asciidoc b/docs/reference/ilm/using-policies-rollover.asciidoc index 04b084a0e8e..1670c8eaf1a 100644 --- a/docs/reference/ilm/using-policies-rollover.asciidoc +++ b/docs/reference/ilm/using-policies-rollover.asciidoc @@ -101,6 +101,16 @@ PUT _template/my_template <2> Associates my_policy with all indices created with this template <3> Rolls over the write alias test when the rollover action is triggered +////////////////////////// + +[source,console] +-------------------------------------------------- +DELETE /_template/my_template +-------------------------------------------------- +// TEST[continued] + +////////////////////////// + To be able to start using the policy for these `test-*` indexes we need to bootstrap the process by creating the first index. diff --git a/docs/reference/indices/templates.asciidoc b/docs/reference/indices/templates.asciidoc index cc89e3bdf47..a8f07649a34 100644 --- a/docs/reference/indices/templates.asciidoc +++ b/docs/reference/indices/templates.asciidoc @@ -36,7 +36,7 @@ PUT _template/template_1 [source,console] -------------------------------------------------- -DELETE _template/template_1 +DELETE _template/template_* -------------------------------------------------- // TEARDOWN @@ -156,7 +156,6 @@ PUT _template/template_1 } } -------------------------------------------------- -// TEST[s/^/DELETE _template\/template_1\n/] <1> the `{index}` placeholder in the alias name will be replaced with the actual index name that the template gets applied to, during index creation. @@ -197,7 +196,6 @@ PUT /_template/template_2 } } -------------------------------------------------- -// TEST[s/^/DELETE _template\/template_1\n/] The above will disable storing the `_source`, but for indices that start with `te*`, `_source` will still be enabled. diff --git a/docs/reference/mapping/removal_of_types.asciidoc b/docs/reference/mapping/removal_of_types.asciidoc index cee782565a4..db19a022a3b 100644 --- a/docs/reference/mapping/removal_of_types.asciidoc +++ b/docs/reference/mapping/removal_of_types.asciidoc @@ -702,6 +702,17 @@ PUT index-2-01 } -------------------------------------------------- +////////////////////////// + +[source,console] +-------------------------------------------------- +DELETE /_template/template1 +DELETE /_template/template2 +-------------------------------------------------- +// TEST[continued] + +////////////////////////// + In case of implicit index creation, because of documents that get indexed in an index that doesn't exist yet, the template is always honored. This is usually not a problem due to the fact that typeless index calls work on typed diff --git a/docs/reference/monitoring/indices.asciidoc b/docs/reference/monitoring/indices.asciidoc index c6432ea2e7f..2fabed309fe 100644 --- a/docs/reference/monitoring/indices.asciidoc +++ b/docs/reference/monitoring/indices.asciidoc @@ -38,6 +38,16 @@ PUT /_template/custom_monitoring } ---------------------------------- +////////////////////////// + +[source,console] +-------------------------------------------------- +DELETE /_template/custom_monitoring +-------------------------------------------------- +// TEST[continued] + +////////////////////////// + IMPORTANT: Only set the `number_of_shards` and `number_of_replicas` in the settings section. Overriding other monitoring template settings could cause your monitoring dashboards to stop working correctly. diff --git a/docs/src/test/java/org/elasticsearch/smoketest/DocsClientYamlTestSuiteIT.java b/docs/src/test/java/org/elasticsearch/smoketest/DocsClientYamlTestSuiteIT.java index 57041515759..0b9d16820f5 100644 --- a/docs/src/test/java/org/elasticsearch/smoketest/DocsClientYamlTestSuiteIT.java +++ b/docs/src/test/java/org/elasticsearch/smoketest/DocsClientYamlTestSuiteIT.java @@ -24,9 +24,11 @@ import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite; import org.apache.http.HttpHost; +import org.apache.http.util.EntityUtils; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.TimeUnits; import org.elasticsearch.Version; +import org.elasticsearch.client.Request; import org.elasticsearch.client.RestClient; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.xcontent.ConstructingObjectParser; @@ -105,6 +107,20 @@ public class DocsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { if (isMachineLearningTest() || isTransformTest()) { ESRestTestCase.waitForPendingTasks(adminClient()); } + + // check that there are no templates + Request request = new Request("GET", "_cat/templates"); + request.addParameter("h", "name"); + String templates = EntityUtils.toString(adminClient().performRequest(request).getEntity()); + if (false == "".equals(templates)) { + for (String template : templates.split("\n")) { + if (isXPackTemplate(template)) continue; + if ("".equals(template)) { + throw new IllegalStateException("empty template in templates list:\n" + templates); + } + throw new RuntimeException("Template " + template + " not cleared after test"); + } + } } @Override @@ -117,6 +133,9 @@ public class DocsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { return isILMTest() == false; } + /** + * Tests are themselves responsible for cleaning up templates, which speeds up build. + */ @Override protected boolean preserveTemplatesUponCompletion() { return true; @@ -124,7 +143,9 @@ public class DocsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { protected boolean isSLMTest() { String testName = getTestName(); - return testName != null && (testName.contains("/slm/") || testName.contains("\\slm\\")); + return testName != null && (testName.contains("/slm/") || testName.contains("\\slm\\") || + // TODO: Remove after backport of https://github.com/elastic/elasticsearch/pull/48705 which moves SLM docs to correct folder + testName.contains("/ilm/") || testName.contains("\\ilm\\")); } protected boolean isILMTest() { diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java index a3fc7209323..aae90b7c37d 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java @@ -80,6 +80,7 @@ import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -1108,7 +1109,7 @@ public abstract class ESRestTestCase extends ESTestCase { /** * Is this template one that is automatically created by xpack? */ - private static boolean isXPackTemplate(String name) { + protected static boolean isXPackTemplate(String name) { if (name.startsWith(".monitoring-")) { return true; } @@ -1121,10 +1122,14 @@ public abstract class ESRestTestCase extends ESTestCase { if (name.startsWith(".ml-")) { return true; } + if (name.startsWith(".transform-")) { + return true; + } switch (name) { case ".triggered_watches": case ".watches": case "logstash-index-template": + case ".logstash-management": case "security_audit_log": case ".slm-history": return true;