Skip to content

Commit ee5a41f

Browse files
przemekwiteksbourke
authored andcommitted
[ML] Make ml internal indices hidden (elastic#52423)
1 parent cb5635c commit ee5a41f

File tree

22 files changed

+78
-48
lines changed

22 files changed

+78
-48
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,13 @@ public Iterator<Setting<?>> settings() {
256256
Setting.Property.Dynamic,
257257
Setting.Property.IndexScope);
258258

259+
public static final String SETTING_INDEX_HIDDEN = "index.hidden";
259260
/**
260261
* Whether the index is considered hidden or not. A hidden index will not be resolved in
261262
* normal wildcard searches unless explicitly allowed
262263
*/
263264
public static final Setting<Boolean> INDEX_HIDDEN_SETTING =
264-
Setting.boolSetting("index.hidden", false, Property.IndexScope, Property.Final);
265+
Setting.boolSetting(SETTING_INDEX_HIDDEN, false, Property.IndexScope, Property.Final);
265266

266267
/**
267268
* an internal index format description, allowing us to find out if this index is upgraded or needs upgrading

server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java

-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ public class MetaDataCreateIndexService {
119119
*/
120120
private static final CharacterRunAutomaton DOT_INDICES_EXCLUSIONS = new CharacterRunAutomaton(Regex.simpleMatchToAutomaton(
121121
".watch-history-*",
122-
".ml-anomalies-*",
123-
".ml-notifications-*",
124-
".ml-annotations*",
125122
".data-frame-notifications-*",
126123
".transform-notifications-*"
127124
));

server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java

-3
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,6 @@ public void testIndexNameExclusionsList() {
618618
// this test case should be removed when DOT_INDICES_EXCLUSIONS is empty
619619
List<String> excludedNames = Arrays.asList(
620620
".watch-history-" + randomAlphaOfLength(5).toLowerCase(Locale.ROOT),
621-
".ml-anomalies-" + randomAlphaOfLength(5).toLowerCase(Locale.ROOT),
622-
".ml-notifications-" + randomAlphaOfLength(5).toLowerCase(Locale.ROOT),
623-
".ml-annotations-" + randomAlphaOfLength(5).toLowerCase(Locale.ROOT),
624621
".data-frame-notifications-" + randomAlphaOfLength(5).toLowerCase(Locale.ROOT),
625622
".transform-notifications-" + randomAlphaOfLength(5).toLowerCase(Locale.ROOT)
626623
);

test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
2323
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
2424
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
25+
import org.elasticsearch.action.support.IndicesOptions;
2526
import org.elasticsearch.client.Client;
2627
import org.elasticsearch.client.Requests;
2728
import org.elasticsearch.cluster.ClusterName;
@@ -124,13 +125,20 @@ public void setUp() throws Exception {
124125
public void tearDown() throws Exception {
125126
logger.trace("[{}#{}]: cleaning up after test", getTestClass().getSimpleName(), getTestName());
126127
super.tearDown();
127-
assertAcked(client().admin().indices().prepareDelete("*").get());
128+
assertAcked(
129+
client().admin().indices().prepareDelete("*")
130+
.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN)
131+
.get());
128132
MetaData metaData = client().admin().cluster().prepareState().get().getState().getMetaData();
129133
assertThat("test leaves persistent cluster metadata behind: " + metaData.persistentSettings().keySet(),
130134
metaData.persistentSettings().size(), equalTo(0));
131135
assertThat("test leaves transient cluster metadata behind: " + metaData.transientSettings().keySet(),
132136
metaData.transientSettings().size(), equalTo(0));
133-
GetIndexResponse indices = client().admin().indices().prepareGetIndex().addIndices("*").get();
137+
GetIndexResponse indices =
138+
client().admin().indices().prepareGetIndex()
139+
.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN)
140+
.addIndices("*")
141+
.get();
134142
assertThat("test leaves indices that were not deleted: " + Strings.arrayToCommaDelimitedString(indices.indices()),
135143
indices.indices(), equalTo(Strings.EMPTY_ARRAY));
136144
if (resetNodeAfterTest()) {

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,9 @@ private void wipeCluster() throws Exception {
572572
protected static void wipeAllIndices() throws IOException {
573573
boolean includeHidden = minimumNodeVersion().onOrAfter(Version.V_7_7_0);
574574
try {
575-
final Request deleteReq = new Request("DELETE", "*");
576-
deleteReq.addParameter("expand_wildcards", "open,closed" + (includeHidden ? ",hidden" : ""));
577-
final Response response = adminClient().performRequest(deleteReq);
575+
final Request deleteRequest = new Request("DELETE", "*");
576+
deleteRequest.addParameter("expand_wildcards", "open,closed" + (includeHidden ? ",hidden" : ""));
577+
final Response response = adminClient().performRequest(deleteRequest);
578578
try (InputStream is = response.getEntity().getContent()) {
579579
assertTrue((boolean) XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true).get("acknowledged"));
580580
}
@@ -706,6 +706,13 @@ private void wipeRollupJobs() throws IOException {
706706
}
707707
}
708708

709+
protected void refreshAllIndices() throws IOException {
710+
boolean includeHidden = minimumNodeVersion().onOrAfter(Version.V_7_7_0);
711+
Request refreshRequest = new Request("POST", "/_refresh");
712+
refreshRequest.addParameter("expand_wildcards", "open,closed" + (includeHidden ? ",hidden" : ""));
713+
client().performRequest(refreshRequest);
714+
}
715+
709716
private void waitForPendingRollupTasks() throws Exception {
710717
waitForPendingTasks(adminClient(), taskName -> taskName.startsWith("xpack/rollup/job") == false);
711718
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/annotations/AnnotationIndex.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ public static void createAnnotationsIndexIfNecessary(Settings settings, Client c
5959
// Create the annotations index if it doesn't exist already.
6060
if (mlLookup.containsKey(INDEX_NAME) == false) {
6161

62-
CreateIndexRequest createIndexRequest = new CreateIndexRequest(INDEX_NAME);
63-
createIndexRequest.mapping(annotationsMapping());
64-
createIndexRequest.settings(Settings.builder()
65-
.put(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, "0-1")
66-
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, "1"));
62+
CreateIndexRequest createIndexRequest =
63+
new CreateIndexRequest(INDEX_NAME)
64+
.mapping(annotationsMapping())
65+
.settings(Settings.builder()
66+
.put(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, "0-1")
67+
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, "1")
68+
.put(IndexMetaData.SETTING_INDEX_HIDDEN, true));
6769

6870
executeAsyncWithOrigin(client.threadPool().getThreadContext(), ML_ORIGIN, createIndexRequest,
6971
ActionListener.<CreateIndexResponse>wrap(

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/AnomalyDetectorsIndexFields.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ public final class AnomalyDetectorsIndexFields {
99

1010
public static final String CONFIG_INDEX = ".ml-config";
1111

12-
public static final String RESULTS_INDEX_PREFIX = ".ml-anomalies-";
13-
1412
public static final String STATE_INDEX_PREFIX = ".ml-state";
15-
public static final String STATE_INDEX_PATTERN = STATE_INDEX_PREFIX + "*";
1613

14+
public static final String RESULTS_INDEX_PREFIX = ".ml-anomalies-";
1715
public static final String RESULTS_INDEX_DEFAULT = "shared";
1816

1917
private AnomalyDetectorsIndexFields() {}

x-pack/plugin/core/src/main/resources/org/elasticsearch/xpack/core/ml/anomalydetection/results_index_template.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"auto_expand_replicas" : "0-1",
1313
"query" : {
1414
"default_field" : "all_field_values"
15-
}
15+
},
16+
"hidden": true
1617
}
1718
},
1819
"mappings": ${xpack.ml.anomalydetection.results.mappings}

x-pack/plugin/core/src/main/resources/org/elasticsearch/xpack/core/ml/anomalydetection/state_index_template.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
],
77
"settings" : {
88
"index" : {
9-
"auto_expand_replicas" : "0-1"
9+
"auto_expand_replicas" : "0-1",
10+
"hidden": true
1011
}
1112
},
1213
"mappings" : {

x-pack/plugin/core/src/main/resources/org/elasticsearch/xpack/core/ml/notifications_index_template.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"settings" : {
88
"index" : {
99
"number_of_shards" : "1",
10-
"auto_expand_replicas" : "0-1"
10+
"auto_expand_replicas" : "0-1",
11+
"hidden": true
1112
}
1213
},
1314
"mappings" : {

x-pack/plugin/ml/qa/basic-multi-node/src/test/java/org/elasticsearch/xpack/ml/integration/MlBasicMultiNodeIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void testMiniFarequoteWithDatafeeder() throws Exception {
127127
client().performRequest(airlineData2);
128128

129129
// Ensure all data is searchable
130-
client().performRequest(new Request("POST", "/_refresh"));
130+
refreshAllIndices();
131131

132132
String jobId = "mini-farequote-with-data-feeder-job";
133133
createFarequoteJob(jobId);

x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/CategorizationIT.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.elasticsearch.action.bulk.BulkRequestBuilder;
1010
import org.elasticsearch.action.bulk.BulkResponse;
1111
import org.elasticsearch.action.index.IndexRequest;
12+
import org.elasticsearch.action.support.IndicesOptions;
1213
import org.elasticsearch.action.support.WriteRequest;
1314
import org.elasticsearch.common.unit.TimeValue;
1415
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig;
@@ -79,7 +80,7 @@ public void setUpData() {
7980
public void tearDownData() {
8081
cleanUp();
8182
client().admin().indices().prepareDelete(DATA_INDEX).get();
82-
client().admin().indices().prepareRefresh("*").get();
83+
client().admin().indices().prepareRefresh("*").setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN).get();
8384
}
8485

8586
public void testBasicCategorization() throws Exception {

x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsRestIT.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ public void testLookbackWithoutPermissions() throws Exception {
747747
assertThat(jobStatsResponseAsString, containsString("\"processed_record_count\":0"));
748748

749749
// There should be a notification saying that there was a problem extracting data
750-
client().performRequest(new Request("POST", "/_refresh"));
750+
refreshAllIndices();
751751
Response notificationsResponse = client().performRequest(
752752
new Request("GET", NotificationsIndex.NOTIFICATIONS_INDEX + "/_search?size=1000&q=job_id:" + jobId));
753753
String notificationsResponseAsString = EntityUtils.toString(notificationsResponse.getEntity());
@@ -954,7 +954,7 @@ public void testLookbackWithoutPermissionsAndRollup() throws Exception {
954954
startDatafeedAndWaitUntilStopped(datafeedId, BASIC_AUTH_VALUE_ML_ADMIN_WITH_SOME_DATA_ACCESS);
955955
waitUntilJobIsClosed(jobId);
956956
// There should be a notification saying that there was a problem extracting data
957-
client().performRequest(new Request("POST", "/_refresh"));
957+
refreshAllIndices();
958958
Response notificationsResponse = client().performRequest(
959959
new Request("GET", NotificationsIndex.NOTIFICATIONS_INDEX + "/_search?size=1000&q=job_id:" + jobId));
960960
String notificationsResponseAsString = EntityUtils.toString(notificationsResponse.getEntity());

x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/DeleteExpiredDataIT.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.action.bulk.BulkResponse;
1111
import org.elasticsearch.action.index.IndexRequest;
1212
import org.elasticsearch.action.search.SearchResponse;
13+
import org.elasticsearch.action.support.IndicesOptions;
1314
import org.elasticsearch.action.support.WriteRequest;
1415
import org.elasticsearch.action.update.UpdateAction;
1516
import org.elasticsearch.action.update.UpdateRequest;
@@ -161,7 +162,7 @@ public void testDeleteExpiredData() throws Exception {
161162
}
162163

163164
// Refresh to ensure the snapshot timestamp updates are visible
164-
client().admin().indices().prepareRefresh("*").get();
165+
client().admin().indices().prepareRefresh("*").setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN).get();
165166

166167
// We need to wait a second to ensure the second time around model snapshots will have a different ID (it depends on epoch seconds)
167168
// FIXME it would be better to wait for something concrete instead of wait for time to elapse
@@ -292,6 +293,6 @@ private void retainAllSnapshots(String jobId) throws Exception {
292293
client().execute(UpdateModelSnapshotAction.INSTANCE, request).get();
293294
}
294295
// We need to refresh to ensure the updates are visible
295-
client().admin().indices().prepareRefresh("*").get();
296+
client().admin().indices().prepareRefresh("*").setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN).get();
296297
}
297298
}

x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public void testCreateJobsWithIndexNameOption() throws Exception {
231231
jobId1, "1236", 1));
232232
client().performRequest(createResultRequest);
233233

234-
client().performRequest(new Request("POST", "/_refresh"));
234+
refreshAllIndices();
235235

236236
responseAsString = EntityUtils.toString(client().performRequest(
237237
new Request("GET", MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId1 + "/results/buckets")).getEntity());
@@ -256,7 +256,7 @@ public void testCreateJobsWithIndexNameOption() throws Exception {
256256
jobId2, "1236", 1));
257257
client().performRequest(createResultRequest);
258258

259-
client().performRequest(new Request("POST", "/_refresh"));
259+
refreshAllIndices();
260260

261261
responseAsString = EntityUtils.toString(client().performRequest(
262262
new Request("GET", MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId2 + "/results/buckets")).getEntity());
@@ -278,7 +278,7 @@ public void testCreateJobsWithIndexNameOption() throws Exception {
278278
new Request("GET", "/_cat/indices/" + AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "*")).getEntity());
279279
assertThat(responseAsString, containsString(AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "custom-" + indexName));
280280

281-
client().performRequest(new Request("POST", "/_refresh"));
281+
refreshAllIndices();
282282

283283
responseAsString = EntityUtils.toString(client().performRequest(
284284
new Request("GET", AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "custom-" + indexName + "/_count")).getEntity());
@@ -289,7 +289,7 @@ public void testCreateJobsWithIndexNameOption() throws Exception {
289289
responseAsString = EntityUtils.toString(client().performRequest(new Request("GET", "/_aliases")).getEntity());
290290
assertThat(responseAsString, not(containsString(AnomalyDetectorsIndex.jobResultsAliasedName(jobId2))));
291291

292-
client().performRequest(new Request("POST", "/_refresh"));
292+
refreshAllIndices();
293293
responseAsString = EntityUtils.toString(client().performRequest(
294294
new Request("GET", "/_cat/indices/" + AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "*")).getEntity());
295295
assertThat(responseAsString, not(containsString(AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "custom-" + indexName)));
@@ -670,7 +670,7 @@ public void testMultiIndexDelete() throws Exception {
670670
createDoc3.setEntity(createDoc0.getEntity());
671671
client().performRequest(createDoc3);
672672

673-
client().performRequest(new Request("POST", "/_refresh"));
673+
refreshAllIndices();
674674

675675
// check for the documents
676676
assertThat(EntityUtils.toString(client().performRequest(new Request("GET", indexName+ "/_count")).getEntity()),
@@ -683,7 +683,7 @@ public void testMultiIndexDelete() throws Exception {
683683
// Delete
684684
client().performRequest(new Request("DELETE", MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId));
685685

686-
client().performRequest(new Request("POST", "/_refresh"));
686+
refreshAllIndices();
687687

688688
// check that the indices still exist but are empty
689689
String indicesAfterDelete = EntityUtils.toString(client().performRequest(

x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlNativeIntegTestCase.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.elasticsearch.xpack.ml.integration;
77

88
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
9+
import org.elasticsearch.action.support.IndicesOptions;
910
import org.elasticsearch.client.Client;
1011
import org.elasticsearch.cluster.ClusterModule;
1112
import org.elasticsearch.cluster.ClusterState;
@@ -148,7 +149,7 @@ protected DeleteExpiredDataAction.Response deleteExpiredData() throws Exception
148149
new DeleteExpiredDataAction.Request()).get();
149150

150151
// We need to refresh to ensure the deletion is visible
151-
client().admin().indices().prepareRefresh("*").get();
152+
client().admin().indices().prepareRefresh("*").setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN).get();
152153

153154
return response;
154155
}

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java

-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,6 @@ public List<NamedXContentRegistry.Entry> getNamedXContent() {
938938
public Collection<SystemIndexDescriptor> getSystemIndexDescriptors() {
939939
return List.of(
940940
new SystemIndexDescriptor(MlMetaIndex.INDEX_NAME, "Contains scheduling and anomaly tracking metadata"),
941-
new SystemIndexDescriptor(AnomalyDetectorsIndexFields.STATE_INDEX_PATTERN, "Contains ML model state"),
942941
new SystemIndexDescriptor(AnomalyDetectorsIndexFields.CONFIG_INDEX, "Contains ML configuration data"),
943942
new SystemIndexDescriptor(InferenceIndexConstants.INDEX_PATTERN, "Contains ML model configuration and statistics")
944943
);

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AnnotationIndexIT.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.elasticsearch.xpack.ml.integration;
77

88
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
9+
import org.elasticsearch.action.support.IndicesOptions;
910
import org.elasticsearch.cluster.metadata.AliasMetaData;
1011
import org.elasticsearch.common.collect.ImmutableOpenMap;
1112
import org.elasticsearch.common.settings.Settings;
@@ -73,7 +74,10 @@ private boolean annotationsIndexExists() {
7374
private int numberOfAnnotationsAliases() {
7475
int count = 0;
7576
ImmutableOpenMap<String, List<AliasMetaData>> aliases = client().admin().indices()
76-
.prepareGetAliases(AnnotationIndex.READ_ALIAS_NAME, AnnotationIndex.WRITE_ALIAS_NAME).get().getAliases();
77+
.prepareGetAliases(AnnotationIndex.READ_ALIAS_NAME, AnnotationIndex.WRITE_ALIAS_NAME)
78+
.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN)
79+
.get()
80+
.getAliases();
7781
if (aliases != null) {
7882
for (ObjectObjectCursor<String, List<AliasMetaData>> entry : aliases) {
7983
count += entry.value.size();

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/BasicDistributedJobsIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public void testJobAutoClose() throws Exception {
165165
indexRequest = new IndexRequest("data");
166166
indexRequest.source("time", 1407083600L);
167167
client().index(indexRequest).get();
168-
refresh();
168+
refresh("*", ".ml-*");
169169

170170
Job.Builder job = createScheduledJob("job_id");
171171
PutJobAction.Request putJobRequest = new PutJobAction.Request(job);

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.elasticsearch.action.ActionFuture;
99
import org.elasticsearch.action.search.SearchResponse;
10+
import org.elasticsearch.action.support.IndicesOptions;
1011
import org.elasticsearch.cluster.ClusterState;
1112
import org.elasticsearch.cluster.metadata.MetaData;
1213
import org.elasticsearch.cluster.node.DiscoveryNode;
@@ -495,6 +496,7 @@ private void run(String jobId, CheckedRunnable<Exception> disrupt) throws Except
495496
// are what we expect them to be:
496497
private static DataCounts getDataCountsFromIndex(String jobId) {
497498
SearchResponse searchResponse = client().prepareSearch()
499+
.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN)
498500
.setQuery(QueryBuilders.idsQuery().addIds(DataCounts.documentId(jobId)))
499501
.get();
500502
if (searchResponse.getHits().getTotalHits().value != 1) {

0 commit comments

Comments
 (0)