Skip to content

Remove obsolete deprecation checks #37510

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
merged 6 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


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;
Expand Down Expand Up @@ -137,5 +138,10 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(level, message, url, details);
}

@Override
public String toString() {
return Strings.toString(this);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
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
Expand All @@ -37,11 +39,17 @@ private 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@


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;
Expand Down Expand Up @@ -79,119 +73,15 @@ private static List<String> findInPropertiesRecursively(String type, Map<String,
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) {
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
"Unrecognized match_mapping_type options not silently ignored",
"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) {
static DeprecationIssue oldIndicesCheck(IndexMetaData indexMetaData) {
Version createdWith = indexMetaData.getCreationVersion();
if (createdWith.before(Version.V_7_0_0)) {
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
"index.store.throttle settings are no longer recognized. these settings should be removed",
"Index created before 7.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me understand why indices created prior to 7.0 is a critical (or even an issue), and why are we linking to the 8.0 breaking changes.

The code looks fine, i think i am just missing something here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely: Our policy as listed in the docs is that each Elasticsearch version supports indices created in the previous major version, but any that are older than that can't be used. That is, 6.x can open indices created in 5.x, but not indices created in 2.x - those must be reindexed, either in 5.x before upgrading or using reindex-from-remote.

Due to that, the Deprecations API reports any indices which need to be reindexed before upgrading to the next major version: in 6.x, we'll flag indices which were created in 5.x and need to be reindexed before upgrading the cluster to 7.x.

With this PR, the Deprecations API on 7.x clusters will report any indices that will need to be reindexed before upgrading to the next major version (assumed to be 8.0). This lets us leave at least one check in place as an example, even though there aren't any breaking changes in 8.0 yet (because 8.0 doesn't exist yet).

We may want to switch out the link, as it is kind of making assumptions about the structure of documentation that doesn't exist yet - I could make it point to the page listing the policy about indices created in previous versions for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explains, that makes sense! I think guessing the 8.0 URL is a safe bet and plenty of time to fix it guessed wrong.

"https://www.elastic.co/guide/en/elasticsearch/reference/master/" +
"breaking_60_settings_changes.html#_store_throttling_settings", "present settings: " + foundSettings);
"breaking-changes-8.0.html",
"This index was created using version: " + createdWith);
}
}
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);

}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}