Remove obsolete deprecation checks (#37510)

* Remove obsolete deprecation checks

This also updates the old-indices check to be appropriate for the 7.x
series of releases, and leaves it as the only deprecation check in
place.

* Add toString to DeprecationIssue

* Bring filterChecks across from 6.x

* License headers
This commit is contained in:
Gordon Brown 2019-01-18 14:24:34 -07:00 committed by GitHub
parent 12cdf1cba4
commit 88b9810567
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 82 additions and 139 deletions

View File

@ -7,6 +7,7 @@ package org.elasticsearch.xpack.core.deprecation;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
@ -137,5 +138,10 @@ public class DeprecationIssue implements Writeable, ToXContentObject {
public int hashCode() {
return Objects.hash(level, message, url, details);
}
@Override
public String toString() {
return Strings.toString(this);
}
}

View File

@ -15,8 +15,10 @@ import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* Class containing all the cluster, node, and index deprecation checks that will be served
@ -37,11 +39,17 @@ public class DeprecationChecks {
static List<Function<IndexMetaData, DeprecationIssue>> INDEX_SETTINGS_CHECKS =
Collections.unmodifiableList(Arrays.asList(
IndexDeprecationChecks::baseSimilarityDefinedCheck,
IndexDeprecationChecks::dynamicTemplateWithMatchMappingTypeCheck,
IndexDeprecationChecks::indexSharedFileSystemCheck,
IndexDeprecationChecks::indexStoreTypeCheck,
IndexDeprecationChecks::storeThrottleSettingsCheck,
IndexDeprecationChecks::delimitedPayloadFilterCheck));
IndexDeprecationChecks::oldIndicesCheck));
/**
* helper utility function to reduce repeat of running a specific {@link List} of checks.
*
* @param checks The functional checks to execute using the mapper function
* @param mapper The function that executes the lambda check with the appropriate arguments
* @param <T> The signature of the check (BiFunction, Function, including the appropriate arguments)
* @return The list of {@link DeprecationIssue} that were found in the cluster
*/
static <T> List<DeprecationIssue> filterChecks(List<T> checks, Function<T, DeprecationIssue> mapper) {
return checks.stream().map(mapper).filter(Objects::nonNull).collect(Collectors.toList());
}
}

View File

@ -7,18 +7,12 @@ package org.elasticsearch.xpack.deprecation;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.analysis.AnalysisRegistry;
import org.elasticsearch.index.mapper.DynamicTemplate;
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
@ -79,118 +73,14 @@ public class IndexDeprecationChecks {
return issues;
}
static DeprecationIssue dynamicTemplateWithMatchMappingTypeCheck(IndexMetaData indexMetaData) {
if (indexMetaData.getCreationVersion().before(Version.V_6_0_0_alpha1)) {
List<String> issues = new ArrayList<>();
fieldLevelMappingIssue(indexMetaData, (mappingMetaData, sourceAsMap) -> {
List<?> dynamicTemplates = (List<?>) mappingMetaData
.getSourceAsMap().getOrDefault("dynamic_templates", Collections.emptyList());
for (Object template : dynamicTemplates) {
for (Map.Entry<?, ?> prop : ((Map<?, ?>) template).entrySet()) {
Map<?, ?> val = (Map<?, ?>) prop.getValue();
if (val.containsKey("match_mapping_type")) {
Object mappingMatchType = val.get("match_mapping_type");
boolean isValidMatchType = Arrays.stream(DynamicTemplate.XContentFieldType.values())
.anyMatch(v -> v.toString().equals(mappingMatchType));
if (isValidMatchType == false) {
issues.add("type: " + mappingMetaData.type() + ", dynamicFieldDefinition"
+ prop.getKey() + ", unknown match_mapping_type[" + mappingMatchType + "]");
}
}
}
}
});
if (issues.size() > 0) {
static DeprecationIssue oldIndicesCheck(IndexMetaData indexMetaData) {
Version createdWith = indexMetaData.getCreationVersion();
if (createdWith.before(Version.V_7_0_0)) {
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
"Unrecognized match_mapping_type options not silently ignored",
"Index created before 7.0",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/" +
"breaking_60_mappings_changes.html" +
"#_unrecognized_literal_match_mapping_type_literal_options_not_silently_ignored",
issues.toString());
}
}
return null;
}
static DeprecationIssue baseSimilarityDefinedCheck(IndexMetaData indexMetaData) {
if (indexMetaData.getCreationVersion().before(Version.V_6_0_0_alpha1)) {
Settings settings = indexMetaData.getSettings().getAsSettings("index.similarity.base");
if (settings.size() > 0) {
return new DeprecationIssue(DeprecationIssue.Level.WARNING,
"The base similarity is now ignored as coords and query normalization have been removed." +
"If provided, this setting will be ignored and issue a deprecation warning",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/" +
"breaking_60_settings_changes.html#_similarity_settings", null);
}
}
return null;
}
static DeprecationIssue delimitedPayloadFilterCheck(IndexMetaData indexMetaData) {
if (indexMetaData.getCreationVersion().before(Version.V_7_0_0)) {
List<String> issues = new ArrayList<>();
Map<String, Settings> filters = indexMetaData.getSettings().getGroups(AnalysisRegistry.INDEX_ANALYSIS_FILTER);
for (Map.Entry<String, Settings> entry : filters.entrySet()) {
if ("delimited_payload_filter".equals(entry.getValue().get("type"))) {
issues.add("The filter [" + entry.getKey() + "] is of deprecated 'delimited_payload_filter' type. "
+ "The filter type should be changed to 'delimited_payload'.");
}
}
if (issues.size() > 0) {
return new DeprecationIssue(DeprecationIssue.Level.WARNING,
"Use of 'delimited_payload_filter'.",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_70_analysis_changes.html",
issues.toString());
}
}
return null;
}
static DeprecationIssue indexStoreTypeCheck(IndexMetaData indexMetaData) {
if (indexMetaData.getCreationVersion().before(Version.V_6_0_0_alpha1) &&
indexMetaData.getSettings().get("index.store.type") != null) {
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
"The default index.store.type has been removed. If you were using it, " +
"we advise that you simply remove it from your index settings and Elasticsearch" +
"will use the best store implementation for your operating system.",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/" +
"breaking_60_settings_changes.html#_store_settings", null);
}
return null;
}
static DeprecationIssue storeThrottleSettingsCheck(IndexMetaData indexMetaData) {
if (indexMetaData.getCreationVersion().before(Version.V_6_0_0_alpha1)) {
Settings settings = indexMetaData.getSettings();
Settings throttleSettings = settings.getAsSettings("index.store.throttle");
ArrayList<String> foundSettings = new ArrayList<>();
if (throttleSettings.get("max_bytes_per_sec") != null) {
foundSettings.add("index.store.throttle.max_bytes_per_sec");
}
if (throttleSettings.get("type") != null) {
foundSettings.add("index.store.throttle.type");
}
if (foundSettings.isEmpty() == false) {
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
"index.store.throttle settings are no longer recognized. these settings should be removed",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/" +
"breaking_60_settings_changes.html#_store_throttling_settings", "present settings: " + foundSettings);
}
}
return null;
}
static DeprecationIssue indexSharedFileSystemCheck(IndexMetaData indexMetaData) {
if (indexMetaData.getCreationVersion().before(Version.V_6_0_0_alpha1) &&
indexMetaData.getSettings().get("index.shared_filesystem") != null) {
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
"[index.shared_filesystem] setting should be removed",
"https://www.elastic.co/guide/en/elasticsearch/reference/6.0/" +
"breaking_60_indices_changes.html#_shadow_replicas_have_been_removed", null);
"breaking-changes-8.0.html",
"This index was created using version: " + createdWith);
}
return null;
}

View File

@ -0,0 +1,41 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.deprecation;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.core.deprecation.DeprecationInfoAction;
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import static org.hamcrest.Matchers.equalTo;
public class DeprecationChecksTests extends ESTestCase {
public void testFilterChecks() {
DeprecationIssue issue = createRandomDeprecationIssue();
int numChecksPassed = randomIntBetween(0, 5);
int numChecksFailed = 10 - numChecksPassed;
List<Supplier<DeprecationIssue>> checks = new ArrayList<>();
for (int i = 0; i < numChecksFailed; i++) {
checks.add(() -> issue);
}
for (int i = 0; i < numChecksPassed; i++) {
checks.add(() -> null);
}
List<DeprecationIssue> filteredIssues = DeprecationInfoAction.filterChecks(checks, Supplier::get);
assertThat(filteredIssues.size(), equalTo(numChecksFailed));
}
private static DeprecationIssue createRandomDeprecationIssue() {
String details = randomBoolean() ? randomAlphaOfLength(10) : null;
return new DeprecationIssue(randomFrom(DeprecationIssue.Level.values()), randomAlphaOfLength(10),
randomAlphaOfLength(10), details);
}
}

View File

@ -3,37 +3,35 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.deprecation;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.xpack.core.deprecation.DeprecationInfoAction;
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
import java.io.IOException;
import java.util.List;
import static java.util.Collections.singletonList;
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.INDEX_SETTINGS_CHECKS;
public class IndexDeprecationChecksTests extends ESTestCase {
public void testDelimitedPayloadFilterCheck() throws IOException {
Settings settings = settings(
VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, VersionUtils.getPreviousVersion(Version.V_7_0_0)))
.put("index.analysis.filter.my_delimited_payload_filter.type", "delimited_payload_filter")
.put("index.analysis.filter.my_delimited_payload_filter.delimiter", "^")
.put("index.analysis.filter.my_delimited_payload_filter.encoding", "identity").build();
IndexMetaData indexMetaData = IndexMetaData.builder("test").settings(settings).numberOfShards(1).numberOfReplicas(0).build();
DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.WARNING, "Use of 'delimited_payload_filter'.",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_70_analysis_changes.html",
"[The filter [my_delimited_payload_filter] is of deprecated 'delimited_payload_filter' type. "
+ "The filter type should be changed to 'delimited_payload'.]");
List<DeprecationIssue> issues = DeprecationInfoAction.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetaData));
public void testOldIndicesCheck() {
Version createdWith = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0,
VersionUtils.getPreviousVersion(Version.V_7_0_0));
IndexMetaData indexMetaData = IndexMetaData.builder("test")
.settings(settings(createdWith))
.numberOfShards(1)
.numberOfReplicas(0)
.build();
DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
"Index created before 7.0",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/" +
"breaking-changes-8.0.html",
"This index was created using version: " + createdWith);
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetaData));
assertEquals(singletonList(expected), issues);
}
}