Skip to content

Commit 10cabbb

Browse files
authored
Transition Transforms to using hidden indices for notifcations index (elastic#53773)
This commit changes the Transforms notifications index to be hidden index, with a hidden alias. This commit also removes the temporary hack in MetaDataCreateIndexService that prevents deprecation warnings for known dot-prefixed index names which are not hidden/system indices, as this was the last index pattern to need that hack.
1 parent caa4e0d commit 10cabbb

File tree

5 files changed

+19
-54
lines changed

5 files changed

+19
-54
lines changed

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.apache.logging.log4j.LogManager;
2424
import org.apache.logging.log4j.Logger;
2525
import org.apache.logging.log4j.message.ParameterizedMessage;
26-
import org.apache.lucene.util.automaton.CharacterRunAutomaton;
2726
import org.elasticsearch.ElasticsearchException;
2827
import org.elasticsearch.ResourceAlreadyExistsException;
2928
import org.elasticsearch.Version;
@@ -55,7 +54,6 @@
5554
import org.elasticsearch.common.compress.CompressedXContent;
5655
import org.elasticsearch.common.io.PathUtils;
5756
import org.elasticsearch.common.logging.DeprecationLogger;
58-
import org.elasticsearch.common.regex.Regex;
5957
import org.elasticsearch.common.settings.IndexScopedSettings;
6058
import org.elasticsearch.common.settings.Setting;
6159
import org.elasticsearch.common.settings.Settings;
@@ -90,7 +88,6 @@
9088
import java.util.List;
9189
import java.util.Locale;
9290
import java.util.Map;
93-
import java.util.Objects;
9491
import java.util.Optional;
9592
import java.util.Set;
9693
import java.util.concurrent.atomic.AtomicInteger;
@@ -116,14 +113,6 @@ public class MetaDataCreateIndexService {
116113

117114
public static final int MAX_INDEX_NAME_BYTES = 255;
118115

119-
/**
120-
* These index patterns will be converted to hidden indices, at which point they should be removed from this list.
121-
*/
122-
private static final CharacterRunAutomaton DOT_INDICES_EXCLUSIONS = new CharacterRunAutomaton(Regex.simpleMatchToAutomaton(
123-
".data-frame-notifications-*",
124-
".transform-notifications-*"
125-
));
126-
127116
private final Settings settings;
128117
private final ClusterService clusterService;
129118
private final IndicesService indicesService;
@@ -194,11 +183,7 @@ public void validateDotIndex(String index, ClusterState state, @Nullable Boolean
194183
List<SystemIndexDescriptor> matchingDescriptors = systemIndexDescriptors.stream()
195184
.filter(descriptor -> descriptor.matchesIndexPattern(index))
196185
.collect(toList());
197-
if (DOT_INDICES_EXCLUSIONS.run(index)) {
198-
assert Objects.isNull(isHidden) || Boolean.FALSE.equals(isHidden) : "when converting a special-cased index to be a " +
199-
"hidden index, it must be removed from the exclusions list";
200-
logger.debug("not emitting deprecation warning about index [{}] because it is in the exclusions list", index);
201-
} else if (matchingDescriptors.isEmpty() && (isHidden == null || isHidden == Boolean.FALSE)) {
186+
if (matchingDescriptors.isEmpty() && (isHidden == null || isHidden == Boolean.FALSE)) {
202187
DEPRECATION_LOGGER.deprecated("index name [{}] starts with a dot '.', in the next major version, index names " +
203188
"starting with a dot are reserved for hidden indices and system indices", index);
204189
} else if (matchingDescriptors.size() > 1) {

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -638,41 +638,6 @@ public void testValidateDotIndex() {
638638
}
639639
}
640640

641-
public void testIndexNameExclusionsList() {
642-
// this test case should be removed when DOT_INDICES_EXCLUSIONS is empty
643-
List<String> excludedNames = Arrays.asList(
644-
".data-frame-notifications-" + randomAlphaOfLength(5).toLowerCase(Locale.ROOT),
645-
".transform-notifications-" + randomAlphaOfLength(5).toLowerCase(Locale.ROOT)
646-
);
647-
648-
ThreadPool testThreadPool = new TestThreadPool(getTestName());
649-
try {
650-
MetaDataCreateIndexService checkerService = new MetaDataCreateIndexService(
651-
Settings.EMPTY,
652-
ClusterServiceUtils.createClusterService(testThreadPool),
653-
null,
654-
null,
655-
null,
656-
null,
657-
null,
658-
testThreadPool,
659-
null,
660-
Collections.emptyList(),
661-
false
662-
);
663-
664-
excludedNames.forEach(name -> {
665-
checkerService.validateDotIndex(name, ClusterState.EMPTY_STATE, false);
666-
});
667-
668-
excludedNames.forEach(name -> {
669-
expectThrows(AssertionError.class, () -> checkerService.validateDotIndex(name, ClusterState.EMPTY_STATE, true));
670-
});
671-
} finally {
672-
testThreadPool.shutdown();
673-
}
674-
}
675-
676641
public void testParseMappingsAppliesDataFromTemplateAndRequest() throws Exception {
677642
IndexTemplateMetaData templateMetaData = addMatchingTemplate(templateBuilder -> {
678643
templateBuilder.putAlias(AliasMetaData.builder("alias1"));

x-pack/plugin/transform/qa/single-node-tests/src/test/java/org/elasticsearch/xpack/transform/integration/TransformAuditorIT.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
package org.elasticsearch.xpack.transform.integration;
88

99
import org.elasticsearch.client.Request;
10+
import org.elasticsearch.client.RequestOptions;
1011
import org.elasticsearch.cluster.metadata.IndexMetaData;
12+
import org.elasticsearch.common.Strings;
1113
import org.elasticsearch.common.settings.Settings;
1214
import org.elasticsearch.xpack.core.transform.transforms.persistence.TransformInternalIndexConstants;
1315
import org.junit.Before;
@@ -94,7 +96,16 @@ public void testAliasCreatedforBWCIndexes() throws Exception {
9496
.put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1)
9597
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0);
9698

97-
createIndex(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED, settings.build());
99+
// These indices should only exist if created in previous versions, ignore the deprecation warning for this test
100+
RequestOptions options = expectWarnings("index name [" + TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED + "] starts " +
101+
"with a dot '.', in the next major version, index names starting with a dot are reserved for hidden indices " +
102+
"and system indices");
103+
Request request = new Request("PUT", "/" + TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED);
104+
String entity = "{\"settings\": " + Strings.toString(settings.build()) + "}";
105+
request.setJsonEntity(entity);
106+
request.setOptions(options);
107+
client().performRequest(request);
108+
98109
assertBusy(() -> {
99110
assertTrue(aliasExists(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED,
100111
TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS));

x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformClusterStateListener.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ private static void createAuditAliasForDataFrameBWC(ClusterState state, Client c
7878
}
7979

8080
final IndicesAliasesRequest request = client.admin().indices().prepareAliases()
81-
.addAlias(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED, TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS)
81+
.addAliasAction(IndicesAliasesRequest.AliasActions.add()
82+
.index(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED)
83+
.alias(TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS)
84+
.isHidden(true))
8285
.request();
8386

8487
executeAsyncWithOrigin(client.threadPool().getThreadContext(), TRANSFORM_ORIGIN, request,

x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/persistence/TransformInternalIndex.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ public static IndexTemplateMetaData getAuditIndexTemplateMetaData() throws IOExc
105105
// the audits are expected to be small
106106
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
107107
.put(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, "0-1")
108+
.put(IndexMetaData.SETTING_INDEX_HIDDEN, true)
108109
)
109110
.putMapping(MapperService.SINGLE_MAPPING_NAME, Strings.toString(auditMappings()))
110-
.putAlias(AliasMetaData.builder(TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS))
111+
.putAlias(AliasMetaData.builder(TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS).isHidden(true))
111112
.build();
112113
return transformTemplate;
113114
}

0 commit comments

Comments
 (0)