-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[ML] Make ML indices hidden when the node becomes master #77416
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
Merged
przemekwitek
merged 18 commits into
elastic:master
from
przemekwitek:make_indices_hidden
Oct 11, 2021
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0f425e0
Make ML indices hidden when the node becomes master
przemekwitek 0843fc1
Revert the unnecessary change
przemekwitek 01e276a
Fix integration test
przemekwitek b42085b
Add full cluster restart test
przemekwitek 6bb53ea
Apply review comments
przemekwitek 6cfe8b2
Make ML aliases hidden
przemekwitek 17e72e9
Expect warnings related to system indices
przemekwitek 461fdac
Fix style
przemekwitek 60edef7
Fix integration and BWC tests
przemekwitek 61b881c
Remove assertion which may not be true if many tests are running at o…
przemekwitek e2b672e
Extract common code to a method
przemekwitek bee3040
Adjust log messages
przemekwitek 4596f60
Restore warning expectation
przemekwitek 36d5069
Do not require warning in the mixed-version environment
przemekwitek 0840625
Ignore REST warnings
przemekwitek fe9c776
Apply review comments
przemekwitek 428a22b
Make MlInitializationServiceIT test wait for the code making indices …
przemekwitek b11436a
Take into account that .ml-state-write alias may be attached to .ml-s…
przemekwitek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
...c/javaRestTest/java/org/elasticsearch/xpack/ml/integration/MlInitializationServiceIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
| package org.elasticsearch.xpack.ml.integration; | ||
|
|
||
| import org.elasticsearch.ResourceAlreadyExistsException; | ||
| import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; | ||
| import org.elasticsearch.action.support.IndicesOptions; | ||
| import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
| import org.elasticsearch.cluster.service.ClusterService; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.util.concurrent.EsExecutors; | ||
| import org.elasticsearch.threadpool.ThreadPool; | ||
| import org.elasticsearch.xpack.ml.MachineLearning; | ||
| import org.elasticsearch.xpack.ml.MlDailyMaintenanceService; | ||
| import org.elasticsearch.xpack.ml.MlInitializationService; | ||
| import org.junit.Before; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_INDEX_HIDDEN; | ||
| import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.hamcrest.Matchers.is; | ||
| import static org.hamcrest.Matchers.notNullValue; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| public class MlInitializationServiceIT extends MlNativeAutodetectIntegTestCase { | ||
|
|
||
| private ThreadPool threadPool; | ||
| private MlInitializationService mlInitializationService; | ||
|
|
||
| @Before | ||
| public void setUpMocks() { | ||
| threadPool = mock(ThreadPool.class); | ||
| when(threadPool.executor(ThreadPool.Names.SAME)).thenReturn(EsExecutors.DIRECT_EXECUTOR_SERVICE); | ||
| when(threadPool.executor(MachineLearning.UTILITY_THREAD_POOL_NAME)).thenReturn(EsExecutors.DIRECT_EXECUTOR_SERVICE); | ||
| MlDailyMaintenanceService mlDailyMaintenanceService = mock(MlDailyMaintenanceService.class); | ||
| ClusterService clusterService = mock(ClusterService.class); | ||
| mlInitializationService = new MlInitializationService(client(), threadPool, mlDailyMaintenanceService, clusterService); | ||
| } | ||
|
|
||
| public void testThatMlIndicesBecomeHiddenWhenTheNodeBecomesMaster() throws Exception { | ||
| String[] mlHiddenIndexNames = { | ||
| ".ml-anomalies-7", | ||
| ".ml-state-000001", | ||
| ".ml-stats-000001", | ||
| ".ml-notifications-000002", | ||
| ".ml-annotations-6" | ||
| }; | ||
| String[] otherIndexNames = { "some-index-1", "some-other-index-2" }; | ||
| String[] allIndexNames = Stream.concat(Arrays.stream(mlHiddenIndexNames), Arrays.stream(otherIndexNames)).toArray(String[]::new); | ||
|
|
||
| for (String indexName : mlHiddenIndexNames) { | ||
| try { | ||
| assertAcked(prepareCreate(indexName).setSettings(Collections.singletonMap(SETTING_INDEX_HIDDEN, randomBoolean()))); | ||
| } catch (ResourceAlreadyExistsException e) { | ||
| logger.info("Index " + indexName + "already exists: {}", e.getDetailedMessage()); | ||
| } | ||
| } | ||
| createIndex(otherIndexNames); | ||
|
|
||
| GetSettingsResponse settingsResponse = | ||
| client().admin().indices().prepareGetSettings(allIndexNames) | ||
| .setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN) | ||
| .get(); | ||
| assertThat(settingsResponse, is(notNullValue())); | ||
| for (String indexName : mlHiddenIndexNames) { | ||
| Settings settings = settingsResponse.getIndexToSettings().get(indexName); | ||
| assertThat(settings, is(notNullValue())); | ||
| } | ||
| for (String indexName : otherIndexNames) { | ||
| Settings settings = settingsResponse.getIndexToSettings().get(indexName); | ||
| assertThat(settings, is(notNullValue())); | ||
| assertThat( | ||
| "Index " + indexName + " expected not to be hidden but was", | ||
| settings.getAsBoolean(SETTING_INDEX_HIDDEN, false), is(equalTo(false))); | ||
| } | ||
|
|
||
| mlInitializationService.onMaster(); | ||
| assertBusy(() -> assertTrue(mlInitializationService.areMlInternalIndicesHidden())); | ||
|
|
||
| settingsResponse = | ||
| client().admin().indices().prepareGetSettings(allIndexNames) | ||
| .setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN) | ||
| .get(); | ||
| assertThat(settingsResponse, is(notNullValue())); | ||
| for (String indexName : mlHiddenIndexNames) { | ||
| Settings settings = settingsResponse.getIndexToSettings().get(indexName); | ||
| assertThat(settings, is(notNullValue())); | ||
| assertThat( | ||
| "Index " + indexName + " expected to be hidden but wasn't, settings = " + settings, | ||
| settings.getAsBoolean(SETTING_INDEX_HIDDEN, false), is(equalTo(true))); | ||
| } | ||
| for (String indexName : otherIndexNames) { | ||
| Settings settings = settingsResponse.getIndexToSettings().get(indexName); | ||
| assertThat(settings, is(notNullValue())); | ||
| assertThat( | ||
| "Index " + indexName + " expected not to be hidden but was, settings = " + settings, | ||
| settings.getAsBoolean(SETTING_INDEX_HIDDEN, false), is(equalTo(false))); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Settings indexSettings() { | ||
| return Settings.builder().put(super.indexSettings()) | ||
| .put(IndexMetadata.SETTING_DATA_PATH, (String) null) | ||
| .build(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.