Skip to content

Commit 0ed5eab

Browse files
authored
Remove obsolete typed legacy index templates (#80937)
This removes a few legacy index templates that were superseded by equivalent component templates or updated index templates.
1 parent 2ce9cd3 commit 0ed5eab

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Logstash.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.elasticsearch.action.ActionResponse;
1212
import org.elasticsearch.cluster.metadata.IndexMetadata;
1313
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
14+
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
1415
import org.elasticsearch.cluster.node.DiscoveryNodes;
1516
import org.elasticsearch.common.settings.ClusterSettings;
1617
import org.elasticsearch.common.settings.IndexScopedSettings;
@@ -41,7 +42,9 @@
4142
import java.io.UncheckedIOException;
4243
import java.util.Collection;
4344
import java.util.List;
45+
import java.util.Map;
4446
import java.util.function.Supplier;
47+
import java.util.function.UnaryOperator;
4548

4649
import static org.elasticsearch.index.engine.EngineConfig.INDEX_CODEC_SETTING;
4750
import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME;
@@ -191,4 +194,13 @@ public String getFeatureName() {
191194
public String getFeatureDescription() {
192195
return "Enables Logstash Central Management pipeline storage";
193196
}
197+
198+
@Override
199+
public UnaryOperator<Map<String, IndexTemplateMetadata>> getIndexTemplateMetadataUpgrader() {
200+
return templates -> {
201+
// .logstash is a system index now. deleting the legacy template
202+
templates.remove("logstash-index-template");
203+
return templates;
204+
};
205+
}
194206
}

x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.action.ActionResponse;
1111
import org.elasticsearch.client.Client;
1212
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
13+
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
1314
import org.elasticsearch.cluster.node.DiscoveryNodes;
1415
import org.elasticsearch.cluster.service.ClusterService;
1516
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
@@ -72,6 +73,7 @@
7273
import java.util.Map;
7374
import java.util.Set;
7475
import java.util.function.Supplier;
76+
import java.util.function.UnaryOperator;
7577

7678
import static org.elasticsearch.common.settings.Setting.boolSetting;
7779

@@ -236,4 +238,17 @@ public void reload(Settings settings) throws Exception {
236238
exporters.setExportersSetting(settingsForChangedExporter);
237239
}
238240
}
241+
242+
@Override
243+
public UnaryOperator<Map<String, IndexTemplateMetadata>> getIndexTemplateMetadataUpgrader() {
244+
return map -> {
245+
// this template was not migrated to typeless due to the possibility of the old /_monitoring/bulk API being used
246+
// see {@link org.elasticsearch.xpack.core.monitoring.exporter.MonitoringTemplateUtils#OLD_TEMPLATE_VERSION}
247+
// however the bulk API is not typed (the type field is for the docs, a field inside the docs) so it's safe to remove this
248+
// old template and rely on the updated, typeless, .monitoring-alerts-7 template
249+
map.remove(".monitoring-alerts");
250+
return map;
251+
};
252+
253+
}
239254
}

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,8 @@ public UnaryOperator<Map<String, IndexTemplateMetadata>> getIndexTemplateMetadat
15311531
return templates -> {
15321532
// .security index is not managed by using templates anymore
15331533
templates.remove("security_audit_log");
1534+
// .security is a system index now. deleting another legacy template that's not used anymore
1535+
templates.remove("security-index-template");
15341536
return templates;
15351537
};
15361538
}

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,11 @@ public void onIndexModule(IndexModule module) {
716716
public UnaryOperator<Map<String, IndexTemplateMetadata>> getIndexTemplateMetadataUpgrader() {
717717
return map -> {
718718
map.keySet().removeIf(name -> name.startsWith("watch_history_"));
719+
// watcher migrated to using system indices so these legacy templates are not needed anymore
720+
map.remove(".watches");
721+
map.remove(".triggered_watches");
722+
// post 7.x we moved to typeless watch-history-10
723+
map.remove(".watch-history-9");
719724
return map;
720725
};
721726
}

x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/WatcherRestartIT.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
import org.apache.http.util.EntityUtils;
1010
import org.elasticsearch.client.Request;
1111
import org.elasticsearch.client.Response;
12+
import org.elasticsearch.client.ResponseException;
1213

1314
import java.nio.charset.StandardCharsets;
15+
import java.util.Map;
16+
import java.util.concurrent.TimeUnit;
1417

1518
import static org.hamcrest.Matchers.containsString;
19+
import static org.hamcrest.Matchers.is;
1620
import static org.hamcrest.Matchers.not;
1721

1822
public class WatcherRestartIT extends AbstractUpgradeTestCase {
@@ -25,6 +29,34 @@ public void testWatcherRestart() throws Exception {
2529
ensureWatcherStarted();
2630
}
2731

32+
public void testEnsureWatcherDeletesLegacyTemplates() throws Exception {
33+
client().performRequest(new Request("POST", "/_watcher/_start"));
34+
ensureWatcherStarted();
35+
36+
if (CLUSTER_TYPE.equals(ClusterType.UPGRADED)) {
37+
// legacy index template created in previous releases should not be present anymore
38+
assertBusy(() -> {
39+
Request request = new Request("GET", "/_template/*watch*");
40+
try {
41+
Response response = client().performRequest(request);
42+
Map<String, Object> responseLevel = entityAsMap(response);
43+
assertNotNull(responseLevel);
44+
45+
assertThat(responseLevel.containsKey(".watches"), is(false));
46+
assertThat(responseLevel.containsKey(".triggered_watches"), is(false));
47+
assertThat(responseLevel.containsKey(".watch-history-9"), is(false));
48+
} catch (ResponseException e) {
49+
// Not found is fine
50+
assertThat(
51+
"Unexpected failure getting templates: " + e.getResponse().getStatusLine(),
52+
e.getResponse().getStatusLine().getStatusCode(),
53+
is(404)
54+
);
55+
}
56+
}, 30, TimeUnit.SECONDS);
57+
}
58+
}
59+
2860
private void ensureWatcherStopped() throws Exception {
2961
assertBusy(() -> {
3062
Response stats = client().performRequest(new Request("GET", "_watcher/stats"));

0 commit comments

Comments
 (0)