From e8ad8cbb36ea80de8f9b3aebcae77250ed6e99ba Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Tue, 9 Feb 2016 09:39:07 +0100 Subject: [PATCH] Watcher: Load versioned index template for watch history This loads an index template for the watch history to make sure, that field changes are taken into account. Also, the dynamic mapping for the watch history template has been changed from strict to false. This means that new fields can be included in a document, but they will not indexed and are not searchable. In addition the index names have been changed from .watch_history-$date to .watcher-history-$template-$date - using dashes to be more consistent. Closes elastic/elasticsearch#1299 Original commit: elastic/x-pack-elasticsearch@794f9822347011bd12a4d3e089d2da353581250d --- ...HistoryTemplateTransformMappingsTests.java | 2 +- .../watcher-with-shield-roles.yml | 6 +- .../watcher_mustache/20_array_access.yaml | 2 +- .../smoke-test-watcher-with-shield/roles.yml | 4 +- elasticsearch/x-pack/build.gradle | 3 + .../elasticsearch/watcher/WatcherModule.java | 27 +++++++- .../elasticsearch/watcher/WatcherPlugin.java | 69 +++++++++++-------- .../execution/WatchExecutionContext.java | 2 +- .../watcher/history/HistoryStore.java | 3 +- .../support/WatcherIndexTemplateRegistry.java | 14 +++- .../src/main/resources/watch_history.json | 8 ++- .../src/main/resources/watcher.properties | 1 + .../watcher/WatcherPluginTests.java | 4 +- .../watcher/history/HistoryStoreTests.java | 16 +++-- .../HistoryTemplateTimeMappingsTests.java | 2 +- ...HistoryTemplateTransformMappingsTests.java | 2 +- .../WatcherIndexTemplateRegistryTests.java | 1 - .../action/activate/ActivateWatchTests.java | 6 +- .../watcher/array_compare_watch/10_basic.yaml | 4 +- .../10_monitor_cluster_health.yaml | 4 +- 20 files changed, 118 insertions(+), 62 deletions(-) create mode 100644 elasticsearch/x-pack/watcher/src/main/resources/watcher.properties diff --git a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/HistoryTemplateTransformMappingsTests.java b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/HistoryTemplateTransformMappingsTests.java index 075bbc50e9a..ae8782a4d93 100644 --- a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/HistoryTemplateTransformMappingsTests.java +++ b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/HistoryTemplateTransformMappingsTests.java @@ -98,7 +98,7 @@ public class HistoryTemplateTransformMappingsTests extends AbstractWatcherIntegr assertThat(mappingsResponse, notNullValue()); assertThat(mappingsResponse.getMappings().isEmpty(), is(false)); for (ObjectObjectCursor> metadatas : mappingsResponse.getMappings()) { - if (!metadatas.key.startsWith(".watch_history")) { + if (!metadatas.key.startsWith(".watcher-history")) { continue; } MappingMetaData metadata = metadatas.value.get("watch_record"); diff --git a/elasticsearch/qa/smoke-test-found-license-with-shield-and-watcher/watcher-with-shield-roles.yml b/elasticsearch/qa/smoke-test-found-license-with-shield-and-watcher/watcher-with-shield-roles.yml index 8228084ac69..a0c1878f919 100644 --- a/elasticsearch/qa/smoke-test-found-license-with-shield-and-watcher/watcher-with-shield-roles.yml +++ b/elasticsearch/qa/smoke-test-found-license-with-shield-and-watcher/watcher-with-shield-roles.yml @@ -6,15 +6,15 @@ admin: watcher_manager: cluster: manage_watcher, cluster:monitor/nodes/info, cluster:monitor/health indices: - '.watch_history-*': all + '.watcher-history-*': all watcher_monitor: cluster: monitor_watcher indices: - '.watch_history-*': read + '.watcher-history-*': read crapy_role: cluster: - cluster:monitor/nodes/info - cluster:monitor/health - - cluster:monitor/nodes/liveness \ No newline at end of file + - cluster:monitor/nodes/liveness diff --git a/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/resources/rest-api-spec/test/watcher_mustache/20_array_access.yaml b/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/resources/rest-api-spec/test/watcher_mustache/20_array_access.yaml index d1a346e24b9..606d5c2baff 100644 --- a/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/resources/rest-api-spec/test/watcher_mustache/20_array_access.yaml +++ b/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/resources/rest-api-spec/test/watcher_mustache/20_array_access.yaml @@ -58,5 +58,5 @@ - do: search: - index: .watch_history-* + index: .watcher-history-* - match: { hits.hits.0._source.result.actions.0.logging.logged_text: "value1 value2" } diff --git a/elasticsearch/qa/smoke-test-watcher-with-shield/roles.yml b/elasticsearch/qa/smoke-test-watcher-with-shield/roles.yml index 8e695f84f9b..e5cbe14f6b5 100644 --- a/elasticsearch/qa/smoke-test-watcher-with-shield/roles.yml +++ b/elasticsearch/qa/smoke-test-watcher-with-shield/roles.yml @@ -6,13 +6,13 @@ admin: watcher_manager: cluster: manage_watcher, cluster:monitor/nodes/info, cluster:monitor/health indices: - '.watch_history-*': all + '.watcher-history-*': all run_as: powerless_user, watcher_manager watcher_monitor: cluster: monitor_watcher indices: - '.watch_history-*': read + '.watcher-history-*': read crappy_role: cluster: diff --git a/elasticsearch/x-pack/build.gradle b/elasticsearch/x-pack/build.gradle index 2af72067e18..4bfecdc4d86 100644 --- a/elasticsearch/x-pack/build.gradle +++ b/elasticsearch/x-pack/build.gradle @@ -74,6 +74,9 @@ ext.expansions = [ // Used in marvel index templates 'marvel.plugin.version': version, 'marvel.template.version': '1', + // Used in watcher index template + 'watcher.plugin.version': version, + 'watcher.template.version': '1', ] processResources { diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherModule.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherModule.java index d6d10f48ce3..7ab1f280fb5 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherModule.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherModule.java @@ -6,6 +6,7 @@ package org.elasticsearch.watcher; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.multibindings.Multibinder; import org.elasticsearch.common.settings.Setting; @@ -14,10 +15,17 @@ import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry; import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry.TemplateConfig; import org.elasticsearch.watcher.support.validation.WatcherSettingsValidation; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + public class WatcherModule extends AbstractModule { - public static final String HISTORY_TEMPLATE_NAME = "watch_history"; + static final String PROPERTIES_FILE = "/watcher.properties"; + static final String VERSION_FIELD = "watcher.template.version"; + + public static final String HISTORY_TEMPLATE_NAME = "watch_history_" + getHistoryIndexTemplateVersion(); public static final String TRIGGERED_TEMPLATE_NAME = "triggered_watches"; public static final String WATCHES_TEMPLATE_NAME = "watches"; public static final Setting HISTORY_TEMPLATE_SETTING = Setting.groupSetting("watcher.history.index.", true, @@ -30,7 +38,7 @@ public class WatcherModule extends AbstractModule { public final static TemplateConfig[] TEMPLATE_CONFIGS = new TemplateConfig[]{ new TemplateConfig(TRIGGERED_TEMPLATE_NAME, TRIGGERED_TEMPLATE_SETTING), - new TemplateConfig(HISTORY_TEMPLATE_NAME, HISTORY_TEMPLATE_SETTING), + new TemplateConfig(HISTORY_TEMPLATE_NAME, "watch_history", HISTORY_TEMPLATE_SETTING), new TemplateConfig(WATCHES_TEMPLATE_NAME, WATCHES_TEMPLATE_SETTING) }; @@ -53,4 +61,19 @@ public class WatcherModule extends AbstractModule { } } + public static final Integer getHistoryIndexTemplateVersion() { + try (InputStream is = WatcherModule.class.getResourceAsStream(PROPERTIES_FILE)) { + Properties properties = new Properties(); + properties.load(is); + String version = properties.getProperty(VERSION_FIELD); + if (Strings.hasLength(version)) { + return Integer.parseInt(version); + } + return null; + } catch (NumberFormatException e) { + throw new IllegalArgumentException("failed to parse watcher template version"); + } catch (IOException e) { + throw new IllegalArgumentException("failed to load watcher template version"); + } + } } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherPlugin.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherPlugin.java index 2a22b11785e..53da3a35380 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherPlugin.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherPlugin.java @@ -91,13 +91,19 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.function.Function; +import static org.elasticsearch.common.settings.Setting.Scope.CLUSTER; import static org.elasticsearch.common.settings.Settings.settingsBuilder; public class WatcherPlugin extends Plugin { public static final String NAME = "watcher"; public static final String ENABLED_SETTING = NAME + ".enabled"; + public static final Setting INDEX_WATCHER_VERSION_SETTING = + new Setting<>("index.watcher.plugin.version", "", Function.identity(), false, Setting.Scope.INDEX); + public static final Setting INDEX_WATCHER_TEMPLATE_VERSION_SETTING = + new Setting<>("index.watcher.template.version", "", Function.identity(), false, Setting.Scope.INDEX); private final static ESLogger logger = Loggers.getLogger(XPackPlugin.class); @@ -193,37 +199,40 @@ public class WatcherPlugin extends Plugin { module.registerSetting(InternalEmailService.EMAIL_ACCOUNT_SETTING); module.registerSetting(InternalHipChatService.HIPCHAT_ACCOUNT_SETTING); module.registerSetting(InternalPagerDutyService.PAGERDUTY_ACCOUNT_SETTING); - module.registerSetting(Setting.intSetting("watcher.execution.scroll.size", 0, false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.intSetting("watcher.watch.scroll.size", 0, false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.boolSetting("watcher.enabled", false, false, Setting.Scope.CLUSTER)); + module.registerSetting(INDEX_WATCHER_VERSION_SETTING); + module.registerSetting(INDEX_WATCHER_TEMPLATE_VERSION_SETTING); + module.registerSetting(Setting.intSetting("watcher.execution.scroll.size", 0, false, CLUSTER)); + module.registerSetting(Setting.intSetting("watcher.watch.scroll.size", 0, false, CLUSTER)); + module.registerSetting(Setting.boolSetting("watcher.enabled", false, false, CLUSTER)); module.registerSetting(ShieldSecretService.ENCRYPT_SENSITIVE_DATA_SETTING); // TODO add real settings for these - module.registerSetting(Setting.simpleString("resource.reload.interval", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.simpleString("resource.reload.enabled", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.simpleString("resource.reload.interval.low", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.simpleString("resource.reload.interval.medium", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.simpleString("watcher.internal.ops.search.default_timeout", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.simpleString("watcher.internal.ops.bulk.default_timeout", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.simpleString("watcher.internal.ops.index.default_timeout", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.simpleString("watcher.execution.default_throttle_period", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.simpleString("watcher.http.default_read_timeout", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.groupSetting("watcher.http.ssl.", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.groupSetting("watcher.http.proxy.", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.simpleString("watcher.actions.index.default_timeout", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.simpleString("watcher.index.rest.direct_access", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.simpleString("watcher.trigger.schedule.engine", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.simpleString("watcher.input.search.default_timeout", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.simpleString("watcher.transform.search.default_timeout", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.simpleString("watcher.trigger.schedule.ticker.tick_interval", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.simpleString("watcher.execution.scroll.timeout", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.simpleString("watcher.start_immediately", false, Setting.Scope.CLUSTER)); - module.registerSetting(Setting.simpleString("watcher.http.default_connection_timeout", false, Setting.Scope.CLUSTER)); + module.registerSetting(Setting.simpleString("resource.reload.interval", false, CLUSTER)); + module.registerSetting(Setting.simpleString("resource.reload.enabled", false, CLUSTER)); + module.registerSetting(Setting.simpleString("resource.reload.interval.low", false, CLUSTER)); + module.registerSetting(Setting.simpleString("resource.reload.interval.medium", false, CLUSTER)); + module.registerSetting(Setting.simpleString("watcher.internal.ops.search.default_timeout", false, CLUSTER)); + module.registerSetting(Setting.simpleString("watcher.internal.ops.bulk.default_timeout", false, CLUSTER)); + module.registerSetting(Setting.simpleString("watcher.internal.ops.index.default_timeout", false, CLUSTER)); + module.registerSetting(Setting.simpleString("watcher.execution.default_throttle_period", false, CLUSTER)); + module.registerSetting(Setting.simpleString("watcher.http.default_read_timeout", false, CLUSTER)); + module.registerSetting(Setting.groupSetting("watcher.http.ssl.", false, CLUSTER)); + module.registerSetting(Setting.groupSetting("watcher.http.proxy.", false, CLUSTER)); + module.registerSetting(Setting.simpleString("watcher.actions.index.default_timeout", false, CLUSTER)); + module.registerSetting(Setting.simpleString("watcher.index.rest.direct_access", false, CLUSTER)); + module.registerSetting(Setting.simpleString("watcher.trigger.schedule.engine", false, CLUSTER)); + module.registerSetting(Setting.simpleString("watcher.input.search.default_timeout", false, CLUSTER)); + module.registerSetting(Setting.simpleString("watcher.transform.search.default_timeout", false, CLUSTER)); + module.registerSetting(Setting.simpleString("watcher.trigger.schedule.ticker.tick_interval", false, CLUSTER)); + module.registerSetting(Setting.simpleString("watcher.execution.scroll.timeout", false, CLUSTER)); + module.registerSetting(Setting.simpleString("watcher.start_immediately", false, CLUSTER)); + module.registerSetting(Setting.simpleString("watcher.http.default_connection_timeout", false, CLUSTER)); module.registerSettingsFilter("watcher.actions.email.service.account.*.smtp.password"); module.registerSettingsFilter("watcher.actions.slack.service.account.*.url"); module.registerSettingsFilter("watcher.actions.pagerduty.service.account.*.url"); module.registerSettingsFilter("watcher.actions.pagerduty.service." + PagerDutyAccount.SERVICE_KEY_SETTING); - module.registerSettingsFilter("watcher.actions.pagerduty.service.account.*." + PagerDutyAccount.SERVICE_KEY_SETTING); + module.registerSettingsFilter("watcher.actions.pagerduty.service.account.*." + + PagerDutyAccount.SERVICE_KEY_SETTING); module.registerSettingsFilter("watcher.actions.hipchat.service.account.*.auth_token"); } @@ -265,8 +274,9 @@ public class WatcherPlugin extends Plugin { return; } - String errorMessage = LoggerMessageFormat.format("the [action.auto_create_index] setting value [{}] is too restrictive. disable " + - "[action.auto_create_index] or set it to [.watches,.triggered_watches,.watch_history*]", (Object) settings); + String errorMessage = LoggerMessageFormat.format("the [action.auto_create_index] setting value [{}] is too" + + " restrictive. disable [action.auto_create_index] or set it to " + + "[.watches,.triggered_watches,.watcher-history*]", (Object) settings); if (Booleans.isExplicitFalse(value)) { throw new IllegalArgumentException(errorMessage); } @@ -312,9 +322,10 @@ public class WatcherPlugin extends Plugin { throw new IllegalArgumentException(errorMessage); } } - logger.warn("the [action.auto_create_index] setting is configured to be restrictive [{}]. for the next 6 months daily history " + - "indices are allowed to be created, but please make sure that any future history indices after 6 months with the pattern " + - "[.watch_history-YYYY.MM.dd] are allowed to be created", value); + logger.warn("the [action.auto_create_index] setting is configured to be restrictive [{}]. " + + " for the next 6 months daily history indices are allowed to be created, but please make sure" + + " that any future history indices after 6 months with the pattern " + + "[.watcher-history-YYYY.MM.dd] are allowed to be created", value); } } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionContext.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionContext.java index cb47bb486eb..b6cf607c728 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionContext.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionContext.java @@ -70,7 +70,7 @@ public abstract class WatchExecutionContext { public abstract boolean skipThrottling(String actionId); /** - * @return true if this execution should be recorded in the .watch_history index + * @return true if this execution should be recorded in the .watcher-history index */ public abstract boolean recordExecution(); diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/history/HistoryStore.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/history/HistoryStore.java index d3cbe477f5b..08c6b272860 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/history/HistoryStore.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/history/HistoryStore.java @@ -12,6 +12,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.engine.VersionConflictEngineException; +import org.elasticsearch.watcher.WatcherModule; import org.elasticsearch.watcher.execution.ExecutionState; import org.elasticsearch.watcher.support.init.proxy.ClientProxy; import org.joda.time.DateTime; @@ -30,7 +31,7 @@ import static org.elasticsearch.watcher.support.Exceptions.ioException; */ public class HistoryStore extends AbstractComponent { - public static final String INDEX_PREFIX = ".watch_history-"; + public static final String INDEX_PREFIX = ".watcher-history-" + WatcherModule.getHistoryIndexTemplateVersion() + "-"; public static final String DOC_TYPE = "watch_record"; static final DateTimeFormatter indexTimeFormat = DateTimeFormat.forPattern("YYYY.MM.dd"); diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherIndexTemplateRegistry.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherIndexTemplateRegistry.java index 7d4858ffdc0..b8264d00a7c 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherIndexTemplateRegistry.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherIndexTemplateRegistry.java @@ -153,9 +153,9 @@ public class WatcherIndexTemplateRegistry extends AbstractComponent implements C executor.execute(new Runnable() { @Override public void run() { - try (InputStream is = WatchStore.class.getResourceAsStream("/" + config.getTemplateName() + ".json")) { + try (InputStream is = WatchStore.class.getResourceAsStream("/" + config.getFileName()+ ".json")) { if (is == null) { - logger.error("Resource [/" + config.getTemplateName() + ".json] not found in classpath"); + logger.error("Resource [/" + config.getFileName() + ".json] not found in classpath"); return; } final byte[] template; @@ -184,13 +184,23 @@ public class WatcherIndexTemplateRegistry extends AbstractComponent implements C public static class TemplateConfig { private final String templateName; + private String fileName; private final Setting setting; public TemplateConfig(String templateName, Setting setting) { + this(templateName, templateName, setting); + } + + public TemplateConfig(String templateName, String fileName, Setting setting) { this.templateName = templateName; + this.fileName = fileName; this.setting = setting; } + public String getFileName() { + return fileName; + } + public String getTemplateName() { return templateName; } diff --git a/elasticsearch/x-pack/watcher/src/main/resources/watch_history.json b/elasticsearch/x-pack/watcher/src/main/resources/watch_history.json index 4c9e6fb8eeb..57470bb9afc 100644 --- a/elasticsearch/x-pack/watcher/src/main/resources/watch_history.json +++ b/elasticsearch/x-pack/watcher/src/main/resources/watch_history.json @@ -1,7 +1,9 @@ { - "template": ".watch_history*", + "template": ".watcher-history-${watcher.template.version}*", "order": 2147483647, "settings": { + "watcher.plugin.version": "${watcher.plugin.version}", + "watcher.template.version": "${watcher.template.version}", "index.number_of_shards": 1, "index.mapper.dynamic": false }, @@ -29,7 +31,7 @@ } } ], - "dynamic": "strict", + "dynamic": false, "_all": { "enabled": false }, @@ -544,4 +546,4 @@ } } } -} +} \ No newline at end of file diff --git a/elasticsearch/x-pack/watcher/src/main/resources/watcher.properties b/elasticsearch/x-pack/watcher/src/main/resources/watcher.properties new file mode 100644 index 00000000000..bf7c8605062 --- /dev/null +++ b/elasticsearch/x-pack/watcher/src/main/resources/watcher.properties @@ -0,0 +1 @@ +watcher.template.version=${watcher.template.version} diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/WatcherPluginTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/WatcherPluginTests.java index d0a78749f3a..31efd271688 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/WatcherPluginTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/WatcherPluginTests.java @@ -19,7 +19,7 @@ public class WatcherPluginTests extends ESTestCase { } catch (IllegalArgumentException e) { } WatcherPlugin.validAutoCreateIndex(Settings.builder().put("action.auto_create_index", - ".watches,.triggered_watches,.watch_history*").build()); + ".watches,.triggered_watches,.watcher-history*").build()); WatcherPlugin.validAutoCreateIndex(Settings.builder().put("action.auto_create_index", "*w*").build()); WatcherPlugin.validAutoCreateIndex(Settings.builder().put("action.auto_create_index", ".w*,.t*").build()); try { @@ -33,7 +33,7 @@ public class WatcherPluginTests extends ESTestCase { } catch (IllegalArgumentException e) { } try { - WatcherPlugin.validAutoCreateIndex(Settings.builder().put("action.auto_create_index", ".watch_history*").build()); + WatcherPlugin.validAutoCreateIndex(Settings.builder().put("action.auto_create_index", ".watcher-history*").build()); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryStoreTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryStoreTests.java index 07ca4469ec0..d659a11c6ef 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryStoreTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryStoreTests.java @@ -10,6 +10,7 @@ import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.watcher.WatcherModule; import org.elasticsearch.watcher.execution.ExecutionState; import org.elasticsearch.watcher.execution.Wid; import org.elasticsearch.watcher.support.init.proxy.ClientProxy; @@ -45,7 +46,7 @@ public class HistoryStoreTests extends ESTestCase { WatchRecord watchRecord = new WatchRecord(wid, event, ExecutionState.EXECUTED, null); IndexResponse indexResponse = mock(IndexResponse.class); - IndexRequest indexRequest = indexRequest(".watch_history-1970.01.01", HistoryStore.DOC_TYPE, wid.value() + IndexRequest indexRequest = indexRequest(".watcher-history-1970.01.01", HistoryStore.DOC_TYPE, wid.value() , IndexRequest.OpType.CREATE); when(clientProxy.index(indexRequest, Matchers.any())).thenReturn(indexResponse); historyStore.put(watchRecord); @@ -69,9 +70,14 @@ public class HistoryStoreTests extends ESTestCase { } public void testIndexNameGeneration() { - assertThat(HistoryStore.getHistoryIndexNameForTime(new DateTime(0, UTC)), equalTo(".watch_history-1970.01.01")); - assertThat(HistoryStore.getHistoryIndexNameForTime(new DateTime(100000000000L, UTC)), equalTo(".watch_history-1973.03.03")); - assertThat(HistoryStore.getHistoryIndexNameForTime(new DateTime(1416582852000L, UTC)), equalTo(".watch_history-2014.11.21")); - assertThat(HistoryStore.getHistoryIndexNameForTime(new DateTime(2833165811000L, UTC)), equalTo(".watch_history-2059.10.12")); + Integer indexTemplateVersion = WatcherModule.getHistoryIndexTemplateVersion(); + assertThat(HistoryStore.getHistoryIndexNameForTime(new DateTime(0, UTC)), + equalTo(".watcher-history-"+ indexTemplateVersion +"-1970.01.01")); + assertThat(HistoryStore.getHistoryIndexNameForTime(new DateTime(100000000000L, UTC)), + equalTo(".watcher-history-" + indexTemplateVersion + "-1973.03.03")); + assertThat(HistoryStore.getHistoryIndexNameForTime(new DateTime(1416582852000L, UTC)), + equalTo(".watcher-history-" + indexTemplateVersion + "-2014.11.21")); + assertThat(HistoryStore.getHistoryIndexNameForTime(new DateTime(2833165811000L, UTC)), + equalTo(".watcher-history-" + indexTemplateVersion + "-2059.10.12")); } } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryTemplateTimeMappingsTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryTemplateTimeMappingsTests.java index dda571511c1..ae30a15c72c 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryTemplateTimeMappingsTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryTemplateTimeMappingsTests.java @@ -63,7 +63,7 @@ public class HistoryTemplateTimeMappingsTests extends AbstractWatcherIntegration assertThat(mappingsResponse, notNullValue()); assertThat(mappingsResponse.getMappings().isEmpty(), is(false)); for (ObjectObjectCursor> metadatas : mappingsResponse.getMappings()) { - if (!metadatas.key.startsWith(".watch_history")) { + if (!metadatas.key.startsWith(".watcher-history")) { continue; } MappingMetaData metadata = metadatas.value.get("watch_record"); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryTemplateTransformMappingsTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryTemplateTransformMappingsTests.java index 5164d69b464..17b886a0c3c 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryTemplateTransformMappingsTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryTemplateTransformMappingsTests.java @@ -89,7 +89,7 @@ public class HistoryTemplateTransformMappingsTests extends AbstractWatcherIntegr assertThat(mappingsResponse, notNullValue()); assertThat(mappingsResponse.getMappings().isEmpty(), is(false)); for (ObjectObjectCursor> metadatas : mappingsResponse.getMappings()) { - if (!metadatas.key.startsWith(".watch_history")) { + if (!metadatas.key.startsWith(".watcher-history")) { continue; } MappingMetaData metadata = metadatas.value.get("watch_record"); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/WatcherIndexTemplateRegistryTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/WatcherIndexTemplateRegistryTests.java index 190b3834920..acc00f2ab37 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/WatcherIndexTemplateRegistryTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/WatcherIndexTemplateRegistryTests.java @@ -6,7 +6,6 @@ package org.elasticsearch.watcher.support; import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/transport/action/activate/ActivateWatchTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/transport/action/activate/ActivateWatchTests.java index 2ec3e49c710..1859f292fd5 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/transport/action/activate/ActivateWatchTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/transport/action/activate/ActivateWatchTests.java @@ -75,13 +75,13 @@ public class ActivateWatchTests extends AbstractWatcherIntegrationTestCase { flush(); refresh(); - long count1 = docCount(".watch_history*", "watch_record", matchAllQuery()); + long count1 = docCount(".watcher-history*", "watch_record", matchAllQuery()); Thread.sleep(10000); flush(); refresh(); - long count2 = docCount(".watch_history*", "watch_record", matchAllQuery()); + long count2 = docCount(".watcher-history*", "watch_record", matchAllQuery()); assertThat(count2, is(count1)); @@ -96,7 +96,7 @@ public class ActivateWatchTests extends AbstractWatcherIntegrationTestCase { assertThat(getWatchResponse.getStatus().state().isActive(), is(true)); Thread.sleep(10000); - long count3 = docCount(".watch_history*", "watch_record", matchAllQuery()); + long count3 = docCount(".watcher-history*", "watch_record", matchAllQuery()); assertThat(count3, greaterThan(count1)); } diff --git a/elasticsearch/x-pack/watcher/src/test/resources/rest-api-spec/test/watcher/array_compare_watch/10_basic.yaml b/elasticsearch/x-pack/watcher/src/test/resources/rest-api-spec/test/watcher/array_compare_watch/10_basic.yaml index 5a2b6734c52..104b15037db 100644 --- a/elasticsearch/x-pack/watcher/src/test/resources/rest-api-spec/test/watcher/array_compare_watch/10_basic.yaml +++ b/elasticsearch/x-pack/watcher/src/test/resources/rest-api-spec/test/watcher/array_compare_watch/10_basic.yaml @@ -106,11 +106,11 @@ - do: indices.refresh: - index: .watch_history-* + index: .watcher-history-* - do: search: - index: .watch_history-* + index: .watcher-history-* body: > { "query": { diff --git a/elasticsearch/x-pack/watcher/src/test/resources/rest-api-spec/test/watcher/getting_started/10_monitor_cluster_health.yaml b/elasticsearch/x-pack/watcher/src/test/resources/rest-api-spec/test/watcher/getting_started/10_monitor_cluster_health.yaml index 95190135d12..01431cee5c4 100644 --- a/elasticsearch/x-pack/watcher/src/test/resources/rest-api-spec/test/watcher/getting_started/10_monitor_cluster_health.yaml +++ b/elasticsearch/x-pack/watcher/src/test/resources/rest-api-spec/test/watcher/getting_started/10_monitor_cluster_health.yaml @@ -65,11 +65,11 @@ - do: indices.refresh: - index: .watch_history-* + index: .watcher-history-* - do: search: - index: .watch_history-* + index: .watcher-history-* body: > { "query": {