Skip to content
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

Deprecate creation of dot-prefixed index names except for hidden and system indices #49959

Merged
merged 45 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c731646
Deprecate creation of non-system dot-prefixed index names
gwbrown Dec 7, 2019
1efc133
Merge branch 'master' into sys-ind/basic-plugin
gwbrown Dec 19, 2019
01f4549
Convert validateIndexName to be non-static
gwbrown Dec 19, 2019
9ab1754
Switch to patterns instead of constant names
gwbrown Dec 24, 2019
e0223d5
Merge branch 'master' into sys-ind/basic-plugin
gwbrown Dec 24, 2019
89a3646
Merge branch 'master' into sys-ind/basic-plugin
gwbrown Jan 6, 2020
da43f63
Check for overlap in system index name patterns
gwbrown Jan 6, 2020
9bf2e96
Convert enrich to a system index plugin
gwbrown Jan 6, 2020
546d560
Register ML system indices
gwbrown Jan 6, 2020
0333a59
Register ``.watcher-history*` for now to prevent warnings
gwbrown Jan 6, 2020
635cac3
Register Logstash CM system index
gwbrown Jan 6, 2020
8de2c05
Register SLM history for now
gwbrown Jan 7, 2020
9d477b9
Line length
gwbrown Jan 7, 2020
4c23c02
Adjust ML test to avoid dot-prefixed index name
gwbrown Jan 7, 2020
f16dd57
Register Transform system indices
gwbrown Jan 7, 2020
98290f0
Merge branch 'master' into sys-ind/basic-plugin
gwbrown Jan 7, 2020
b099978
Use correct pattern for Transform indices
gwbrown Jan 7, 2020
08ca1f7
Merge branch 'master' into sys-ind/basic-plugin
gwbrown Jan 8, 2020
1a13224
Very basic tasks plugin
gwbrown Jan 13, 2020
ee2330d
Merge branch 'master' into sys-ind/basic-plugin
gwbrown Jan 13, 2020
6c12d1d
sourcePlugin->description, use constants for name patterns
gwbrown Jan 14, 2020
67bd20d
Fix comment
gwbrown Jan 14, 2020
ca459e4
Pass around source names differently in init checks
gwbrown Jan 14, 2020
f07c528
Merge branch 'master' into sys-ind/basic-plugin
gwbrown Jan 14, 2020
9714006
Add note to the docs
gwbrown Jan 14, 2020
9c99b69
Merge branch 'master' into sys-ind/basic-plugin
gwbrown Jan 14, 2020
7d425b2
Fix ml-annotations name pattern
gwbrown Jan 15, 2020
9257ff4
Remove unnecessary Watcher index pattern
gwbrown Jan 15, 2020
f014aa2
Add a dummy test for Tasks plugin
gwbrown Jan 15, 2020
1406564
Merge branch 'master' into sys-ind/basic-plugin
gwbrown Jan 15, 2020
0c7d11d
Make Tasks plugin even simpler to prevent test failures
gwbrown Jan 16, 2020
f397e91
Comments, TODOs, and general cleanup
gwbrown Jan 16, 2020
301c38e
Merge branch 'master' into sys-ind/basic-plugin
gwbrown Jan 16, 2020
61db4b4
Merge branch 'master' into sys-ind/basic-plugin
gwbrown Jan 17, 2020
9909be3
Merge branch 'master' into sys-ind/basic-plugin
gwbrown Jan 21, 2020
e9bdf1a
Docs changes per design update
gwbrown Jan 21, 2020
8e349f0
Rework overlapping pattern checks
gwbrown Jan 21, 2020
762471d
Merge branch 'master' into sys-ind/basic-plugin
gwbrown Jan 22, 2020
60dbf8b
Adjust comment about time complexity
gwbrown Jan 22, 2020
b130b05
Allow hidden indices to have dot prefixes
gwbrown Jan 23, 2020
832c4f8
Merge branch 'master' into sys-ind/basic-plugin
gwbrown Jan 23, 2020
ceb46fd
Collections tweaks per review
gwbrown Jan 23, 2020
3af1398
Merge branch 'master' into sys-ind/basic-plugin
gwbrown Jan 24, 2020
a0c68c1
Accept null `isHidden` in validateIndexName
gwbrown Jan 24, 2020
e9bada2
Merge branch 'master' into sys-ind/basic-plugin
gwbrown Jan 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference/index-modules.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ indices.
Indicates whether <<query-filter-context, cached filters>> are pre-loaded for
nested queries. Possible values are `true` (default) and `false`.

`index.hidden`::
[[index-hidden]] `index.hidden`::

Indicates whether the index should be hidden by default. Hidden indices are not
returned by default when using a wildcard expression. This behavior is controlled
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/indices/create-index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ PUT /twitter

[[indices-create-api-desc]]
==== {api-description-title}
You can use the create index API to add a new index to an {es} cluster. When
You can use the create index API to add a new index to an {es} cluster. When
creating an index, you can specify the following:

* Settings for the index
Expand All @@ -44,6 +44,7 @@ Index names must meet the following criteria:
- Cannot start with `-`, `_`, `+`
- Cannot be `.` or `..`
- Cannot be longer than 255 bytes (note it is bytes, so multi-byte characters will count towards the 255 limit faster)
- Names starting with `.` are deprecated, except for <<index-hidden,hidden indices>> and internal indices managed by plugins
// end::index-name-reqs[]
--

Expand Down
25 changes: 25 additions & 0 deletions modules/tasks/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

esplugin {
description 'Supports the Tasks API'
classname 'org.elasticsearch.tasksplugin.TasksPlugin'
}

integTest.enabled = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.tasksplugin;

import org.elasticsearch.indices.SystemIndexDescriptor;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.SystemIndexPlugin;

import java.util.Collection;
import java.util.Collections;

import static org.elasticsearch.tasks.TaskResultsService.TASK_INDEX;

/**
* This plugin currently only exists to register `.tasks` as a system index.
*/
public class TasksPlugin extends Plugin implements SystemIndexPlugin {

@Override
public Collection<SystemIndexDescriptor> getSystemIndexDescriptors() {
return Collections.singletonList(new SystemIndexDescriptor(TASK_INDEX, this.getClass().getSimpleName()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.tasksplugin;

import org.elasticsearch.test.ESTestCase;
import org.hamcrest.Matchers;

public class TasksPluginTests extends ESTestCase {

public void testDummy() {
// This is a dummy test case to satisfy the conventions
TasksPlugin plugin = new TasksPlugin();
assertThat(plugin.getSystemIndexDescriptors(), Matchers.hasSize(1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ protected void masterOperation(Task task, final RolloverRequest rolloverRequest,
? rolloverRequest.getNewIndexName()
: generateRolloverIndexName(sourceProvidedName, indexNameExpressionResolver);
final String rolloverIndexName = indexNameExpressionResolver.resolveDateMathExpression(unresolvedName);
MetaDataCreateIndexService.validateIndexName(rolloverIndexName, state); // will fail if the index already exists
final Boolean isHidden = IndexMetaData.INDEX_HIDDEN_SETTING.exists(rolloverRequest.getCreateIndexRequest().settings()) ?
IndexMetaData.INDEX_HIDDEN_SETTING.get(rolloverRequest.getCreateIndexRequest().settings()) : null;
createIndexService.validateIndexName(rolloverIndexName, state, isHidden); // fails if the index already exists
checkNoDuplicatedAliasInIndexTemplate(metaData, rolloverIndexName, rolloverRequest.getAlias(), isHidden);
IndicesStatsRequest statsRequest = new IndicesStatsRequest().indices(rolloverRequest.getAlias())
.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.elasticsearch.common.ValidationException;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
Expand All @@ -70,6 +71,7 @@
import org.elasticsearch.indices.IndexCreationException;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.InvalidIndexNameException;
import org.elasticsearch.indices.SystemIndexDescriptor;
import org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason;
import org.elasticsearch.threadpool.ThreadPool;

Expand All @@ -78,6 +80,7 @@
import java.nio.file.Path;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand All @@ -89,6 +92,7 @@
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static java.util.stream.Collectors.toList;
Expand All @@ -103,6 +107,7 @@
*/
public class MetaDataCreateIndexService {
private static final Logger logger = LogManager.getLogger(MetaDataCreateIndexService.class);
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(logger);

public static final int MAX_INDEX_NAME_BYTES = 255;

Expand All @@ -115,19 +120,21 @@ public class MetaDataCreateIndexService {
private final IndexScopedSettings indexScopedSettings;
private final ActiveShardsObserver activeShardsObserver;
private final NamedXContentRegistry xContentRegistry;
private final Collection<SystemIndexDescriptor> systemIndexDescriptors;
private final boolean forbidPrivateIndexSettings;

public MetaDataCreateIndexService(
final Settings settings,
final ClusterService clusterService,
final IndicesService indicesService,
final AllocationService allocationService,
final AliasValidator aliasValidator,
final Environment env,
final IndexScopedSettings indexScopedSettings,
final ThreadPool threadPool,
final NamedXContentRegistry xContentRegistry,
final boolean forbidPrivateIndexSettings) {
final Settings settings,
final ClusterService clusterService,
final IndicesService indicesService,
final AllocationService allocationService,
final AliasValidator aliasValidator,
final Environment env,
final IndexScopedSettings indexScopedSettings,
final ThreadPool threadPool,
final NamedXContentRegistry xContentRegistry,
final Collection<SystemIndexDescriptor> systemIndexDescriptors,
final boolean forbidPrivateIndexSettings) {
this.settings = settings;
this.clusterService = clusterService;
this.indicesService = indicesService;
Expand All @@ -137,17 +144,40 @@ public MetaDataCreateIndexService(
this.indexScopedSettings = indexScopedSettings;
this.activeShardsObserver = new ActiveShardsObserver(clusterService, threadPool);
this.xContentRegistry = xContentRegistry;
this.systemIndexDescriptors = systemIndexDescriptors;
this.forbidPrivateIndexSettings = forbidPrivateIndexSettings;
}

/**
* Validate the name for an index against some static rules and a cluster state.
*/
public static void validateIndexName(String index, ClusterState state) {
public void validateIndexName(String index, ClusterState state, @Nullable Boolean isHidden) {
validateIndexOrAliasName(index, InvalidIndexNameException::new);
if (!index.toLowerCase(Locale.ROOT).equals(index)) {
throw new InvalidIndexNameException(index, "must be lowercase");
}

if (index.charAt(0) == '.') {
List<SystemIndexDescriptor> matchingDescriptors = systemIndexDescriptors.stream()
.filter(descriptor -> descriptor.matchesIndexPattern(index))
.collect(toList());
if (matchingDescriptors.isEmpty() && (isHidden == null || isHidden == Boolean.FALSE)) {
deprecationLogger.deprecated("index name [{}] starts with a dot '.', in the next major version, index names " +
"starting with a dot are reserved for hidden indices and system indices", index);
} else if (matchingDescriptors.size() > 1) {
// This should be prevented by erroring on overlapping patterns at startup time, but is here just in case.
StringBuilder errorMessage = new StringBuilder()
.append("index name [")
.append(index)
.append("] is claimed as a system index by multiple system index patterns: [")
.append(matchingDescriptors.stream()
.map(descriptor -> "pattern: [" + descriptor.getIndexPattern() +
"], description: [" + descriptor.getDescription() + "]").collect(Collectors.joining("; ")));
// Throw AssertionError if assertions are enabled, or a regular exception otherwise:
assert false : errorMessage.toString();
throw new IllegalStateException(errorMessage.toString());
}
}
if (state.routingTable().hasIndex(index)) {
throw new ResourceAlreadyExistsException(state.routingTable().index(index).getIndex());
}
Expand Down Expand Up @@ -653,7 +683,8 @@ private static IndexService validateActiveShardCountAndCreateIndexService(String
}

private void validate(CreateIndexClusterStateUpdateRequest request, ClusterState state) {
validateIndexName(request.index(), state);
boolean isHidden = IndexMetaData.INDEX_HIDDEN_SETTING.get(request.settings());
validateIndexName(request.index(), state, isHidden);
validateIndexSettings(request.index(), request.settings(), forbidPrivateIndexSettings);
}

Expand Down
Loading