-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
) * Validate that system indices aren't also hidden indices (#72768) * Validate that system indices aren't also hidden inidices * Remove hidden from ingest geo system index * Add test coverage * Remove hidden setting from system index even if not upgrading * Fix compilation for backport
- Loading branch information
1 parent
addeb9f
commit ce362d7
Showing
6 changed files
with
288 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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
103 changes: 103 additions & 0 deletions
103
...g/elasticsearch/action/admin/indices/settings/put/TransportUpdateSettingsActionTests.java
This file contains 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,103 @@ | ||
/* | ||
* 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.collect.List; | ||
import org.elasticsearch.common.collect.Map; | ||
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.test.ESTestCase; | ||
import org.elasticsearch.transport.TransportService; | ||
import org.junit.Before; | ||
import org.mockito.ArgumentCaptor; | ||
|
||
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(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]")); | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
.../test/java/org/elasticsearch/cluster/metadata/SystemIndexMetadataUpgradeServiceTests.java
This file contains 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,100 @@ | ||
/* | ||
* 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.collect.List; | ||
import org.elasticsearch.common.collect.Map; | ||
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 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 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