-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Validate that system indices aren't also hidden indices #72768
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
williamrandolph
merged 11 commits into
elastic:master
from
williamrandolph:system-indices-non-hidden
May 25, 2021
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
85728e4
Validate that system indices aren't also hidden inidices
williamrandolph c4b431f
Merge branch 'master' into system-indices-non-hidden
williamrandolph ba0bca7
Remove hidden from ingest geo system index
williamrandolph 5b04bcf
Add test coverage
williamrandolph 03fb374
Merge branch 'master' into system-indices-non-hidden
williamrandolph bf86c6c
Remove hidden setting if updating to become a system index
williamrandolph a87e2c2
Reject settings updates that try to hide system indices
williamrandolph c94e62c
Update javadoc
williamrandolph a0f7a00
Merge branch 'master' into system-indices-non-hidden
williamrandolph 064cdc8
Remove hidden setting from system index even if not upgrading
williamrandolph 4cbe16c
Merge branch 'master' into system-indices-non-hidden
williamrandolph 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
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
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
105 changes: 105 additions & 0 deletions
105
...g/elasticsearch/action/admin/indices/settings/put/TransportUpdateSettingsActionTests.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,105 @@ | ||
| /* | ||
| * 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 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| package org.elasticsearch.action.admin.indices.settings.put; | ||
|
|
||
| import org.elasticsearch.Version; | ||
| import org.elasticsearch.action.ActionListener; | ||
| import org.elasticsearch.action.support.ActionFilters; | ||
| import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
| import org.elasticsearch.cluster.ClusterName; | ||
| import org.elasticsearch.cluster.ClusterState; | ||
| import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
| import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
| import org.elasticsearch.cluster.metadata.Metadata; | ||
| import org.elasticsearch.cluster.metadata.MetadataUpdateSettingsService; | ||
| import org.elasticsearch.cluster.service.ClusterService; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.util.concurrent.ThreadContext; | ||
| import org.elasticsearch.indices.SystemIndexDescriptor; | ||
| import org.elasticsearch.indices.SystemIndices; | ||
| import org.elasticsearch.tasks.Task; | ||
| import org.elasticsearch.test.ESTestCase; | ||
| import org.elasticsearch.transport.TransportService; | ||
| import org.junit.Before; | ||
| import org.mockito.ArgumentCaptor; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.mockito.Matchers.any; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
|
|
||
| public class TransportUpdateSettingsActionTests extends ESTestCase { | ||
|
|
||
| private static final ClusterState CLUSTER_STATE = ClusterState.builder(new ClusterName("test")) | ||
| .metadata(Metadata.builder() | ||
| .put(IndexMetadata.builder(".my-system") | ||
| .system(true) | ||
| .settings(Settings.builder() | ||
| .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) | ||
| .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) | ||
| .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
| .build()) | ||
| .build(), true) | ||
| .build()) | ||
| .build(); | ||
|
|
||
| private static final String SYSTEM_INDEX_NAME = ".my-system"; | ||
| private static final SystemIndices SYSTEM_INDICES = new SystemIndices( | ||
| Map.of("test-feature", new SystemIndices.Feature( | ||
| "test-feature", | ||
| "a test feature", | ||
| List.of(new SystemIndexDescriptor(SYSTEM_INDEX_NAME, "test")) | ||
| )) | ||
| ); | ||
|
|
||
| private TransportUpdateSettingsAction action; | ||
|
|
||
| @Before | ||
| @Override | ||
| public void setUp() throws Exception { | ||
| super.setUp(); | ||
| ThreadContext threadContext = new ThreadContext(Settings.EMPTY); | ||
| IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext, SYSTEM_INDICES); | ||
| MetadataUpdateSettingsService metadataUpdateSettingsService = mock(MetadataUpdateSettingsService.class); | ||
| this.action = new TransportUpdateSettingsAction( | ||
| mock(TransportService.class), | ||
| mock(ClusterService.class), | ||
| null, | ||
| metadataUpdateSettingsService, | ||
| mock(ActionFilters.class), | ||
| indexNameExpressionResolver, | ||
| SYSTEM_INDICES | ||
| ); | ||
| } | ||
|
|
||
| public void testSystemIndicesCannotBeSetToHidden() { | ||
| UpdateSettingsRequest request = new UpdateSettingsRequest( | ||
| Settings.builder() | ||
| .put(IndexMetadata.SETTING_INDEX_HIDDEN, true) | ||
| .build() | ||
| ); | ||
| request.indices(SYSTEM_INDEX_NAME); | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| ActionListener<AcknowledgedResponse> mockListener = mock(ActionListener.class); | ||
|
|
||
| action.masterOperation(mock(Task.class), request, CLUSTER_STATE, mockListener); | ||
|
|
||
| ArgumentCaptor<Exception> exceptionArgumentCaptor = ArgumentCaptor.forClass(Exception.class); | ||
| verify(mockListener, times(0)).onResponse(any()); | ||
| verify(mockListener, times(1)).onFailure(exceptionArgumentCaptor.capture()); | ||
|
|
||
| Exception e = exceptionArgumentCaptor.getValue(); | ||
| assertThat(e.getMessage(), equalTo("Cannot set [index.hidden] to 'true' on system indices: [.my-system]")); | ||
| } | ||
| } |
101 changes: 101 additions & 0 deletions
101
.../test/java/org/elasticsearch/cluster/metadata/SystemIndexMetadataUpgradeServiceTests.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,101 @@ | ||
| /* | ||
| * 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 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| package org.elasticsearch.cluster.metadata; | ||
|
|
||
| import org.elasticsearch.Version; | ||
| import org.elasticsearch.cluster.ClusterName; | ||
| import org.elasticsearch.cluster.ClusterState; | ||
| import org.elasticsearch.cluster.service.ClusterService; | ||
| import org.elasticsearch.common.collect.ImmutableOpenMap; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.indices.SystemIndexDescriptor; | ||
| import org.elasticsearch.indices.SystemIndices; | ||
| import org.elasticsearch.test.ESTestCase; | ||
| import org.junit.Before; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| public class SystemIndexMetadataUpgradeServiceTests extends ESTestCase { | ||
|
|
||
| private static final String MAPPINGS = "{ \"_doc\": { \"_meta\": { \"version\": \"7.4.0\" } } }"; | ||
| private static final String SYSTEM_INDEX_NAME = ".myindex-1"; | ||
| private static final SystemIndexDescriptor DESCRIPTOR = SystemIndexDescriptor.builder() | ||
| .setIndexPattern(".myindex-*") | ||
| .setPrimaryIndex(SYSTEM_INDEX_NAME) | ||
| .setSettings(getSettingsBuilder().build()) | ||
| .setMappings(MAPPINGS) | ||
| .setVersionMetaKey("version") | ||
| .setOrigin("FAKE_ORIGIN") | ||
| .build(); | ||
|
|
||
| private SystemIndexMetadataUpgradeService service; | ||
|
|
||
| @Before | ||
| public void setUpTest() { | ||
| // set up a system index upgrade service | ||
| this.service = new SystemIndexMetadataUpgradeService( | ||
| new SystemIndices( | ||
| Map.of("MyIndex", new SystemIndices.Feature("foo", "a test feature", List.of(DESCRIPTOR)))), | ||
| mock(ClusterService.class) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * When we upgrade Elasticsearch versions, existing indices may be newly | ||
| * defined as system indices. If such indices are set to "hidden," we need | ||
| * to remove that setting. | ||
| */ | ||
| public void testUpgradeHiddenIndexToSystemIndex() throws Exception { | ||
| // create an initial cluster state with a hidden index that matches the system index descriptor | ||
| IndexMetadata.Builder hiddenIndexMetadata = IndexMetadata.builder(SYSTEM_INDEX_NAME) | ||
| .system(false) | ||
| .settings(getSettingsBuilder().put(IndexMetadata.SETTING_INDEX_HIDDEN, true)); | ||
|
|
||
| assertSystemUpgradeRemovesHiddenSetting(hiddenIndexMetadata); | ||
| } | ||
|
|
||
| /** | ||
| * If a system index erroneously is set to hidden, we should remedy that situation. | ||
| */ | ||
| public void testHiddenSettingRemovedFromSystemIndices() throws Exception { | ||
| // create an initial cluster state with a hidden index that matches the system index descriptor | ||
| IndexMetadata.Builder hiddenIndexMetadata = IndexMetadata.builder(SYSTEM_INDEX_NAME) | ||
| .system(true) | ||
| .settings(getSettingsBuilder().put(IndexMetadata.SETTING_INDEX_HIDDEN, true)); | ||
|
|
||
| assertSystemUpgradeRemovesHiddenSetting(hiddenIndexMetadata); | ||
| } | ||
|
|
||
| private void assertSystemUpgradeRemovesHiddenSetting(IndexMetadata.Builder hiddenIndexMetadata) throws Exception { | ||
| Metadata.Builder clusterMetadata = new Metadata.Builder(); | ||
| clusterMetadata.put(hiddenIndexMetadata); | ||
|
|
||
| ClusterState clusterState = ClusterState.builder(new ClusterName("system-index-metadata-upgrade-service-tests")) | ||
| .metadata(clusterMetadata.build()) | ||
| .customs(ImmutableOpenMap.of()).build(); | ||
|
|
||
| // Get a metadata upgrade task and execute it on the initial cluster state | ||
| ClusterState newState = service.getTask().execute(clusterState); | ||
|
|
||
| IndexMetadata result = newState.metadata().index(SYSTEM_INDEX_NAME); | ||
| assertThat(result.isSystem(), equalTo(true)); | ||
| assertThat(result.getSettings().get(IndexMetadata.SETTING_INDEX_HIDDEN), equalTo("false")); | ||
| } | ||
|
|
||
| private static Settings.Builder getSettingsBuilder() { | ||
| return Settings.builder() | ||
| .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) | ||
| .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) | ||
| .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1); | ||
| } | ||
| } |
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
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.