Skip to content

Commit

Permalink
adding a deprecation info check for search.remote properties (#76954)
Browse files Browse the repository at this point in the history
The search.remote.* properties have been removed in 8.0 and replaced with cluster.remote.* properties.
This adds a check for these properties in the deprecation info API.
Relates #42404 and #42381
  • Loading branch information
masseyke committed Sep 1, 2021
1 parent 4603a29 commit fc1749b
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private DeprecationChecks() {
NodeDeprecationChecks::checkSharedDataPathSetting,
NodeDeprecationChecks::checkSingleDataNodeWatermarkSetting,
NodeDeprecationChecks::checkImplicitlyDisabledSecurityOnBasicAndTrial,
NodeDeprecationChecks::checkSearchRemoteSettings,
NodeDeprecationChecks::checkMonitoringExporterPassword,
NodeDeprecationChecks::checkAcceptDefaultPasswordSetting,
NodeDeprecationChecks::checkAcceptRolesCacheMaxSizeSetting,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.threadpool.FixedExecutorBuilder;
import org.elasticsearch.transport.RemoteClusterService;
import org.elasticsearch.transport.SniffConnectionStrategy;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.security.SecurityField;
import org.elasticsearch.xpack.core.security.authc.RealmConfig;
Expand Down Expand Up @@ -593,6 +594,50 @@ static DeprecationIssue checkMonitoringExporterPassword(
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details, false, null);
}

static DeprecationIssue checkSearchRemoteSettings(
final Settings settings,
final PluginsAndModules pluginsAndModules,
ClusterState cs,
XPackLicenseState licenseState
) {
List<Setting<?>> remoteClusterSettings = new ArrayList<>();
remoteClusterSettings.addAll(SniffConnectionStrategy.SEARCH_REMOTE_CLUSTERS_SEEDS.getAllConcreteSettings(settings)
.sorted(Comparator.comparing(Setting::getKey)).collect(Collectors.toList()));
remoteClusterSettings.addAll(SniffConnectionStrategy.SEARCH_REMOTE_CLUSTERS_PROXY.getAllConcreteSettings(settings)
.sorted(Comparator.comparing(Setting::getKey)).collect(Collectors.toList()));
remoteClusterSettings.addAll(RemoteClusterService.SEARCH_REMOTE_CLUSTER_SKIP_UNAVAILABLE.getAllConcreteSettings(settings)
.sorted(Comparator.comparing(Setting::getKey)).collect(Collectors.toList()));
if (SniffConnectionStrategy.SEARCH_REMOTE_CONNECTIONS_PER_CLUSTER.exists(settings)) {
remoteClusterSettings.add(SniffConnectionStrategy.SEARCH_REMOTE_CONNECTIONS_PER_CLUSTER);
}
if (RemoteClusterService.SEARCH_REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING.exists(settings)) {
remoteClusterSettings.add(RemoteClusterService.SEARCH_REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING);
}
if (RemoteClusterService.SEARCH_REMOTE_NODE_ATTRIBUTE.exists(settings)) {
remoteClusterSettings.add(RemoteClusterService.SEARCH_REMOTE_NODE_ATTRIBUTE);
}
if (RemoteClusterService.SEARCH_ENABLE_REMOTE_CLUSTERS.exists(settings)) {
remoteClusterSettings.add(RemoteClusterService.SEARCH_ENABLE_REMOTE_CLUSTERS);
}
if (remoteClusterSettings.isEmpty()) {
return null;
}
final String remoteClusterSeedSettings = remoteClusterSettings.stream().map(Setting::getKey).collect(Collectors.joining(","));
final String message = String.format(
Locale.ROOT,
"search.remote settings [%s] are deprecated and will be removed in the next major version",
remoteClusterSeedSettings
);
final String details = String.format(
Locale.ROOT,
"replace search.remote settings [%s] with their secure 'cluster.remote' replacements",
remoteClusterSeedSettings
);
final String url =
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_settings_changes";
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details, false, null);
}

static DeprecationIssue checkClusterRoutingAllocationIncludeRelocationsSetting(final Settings settings,
final PluginsAndModules pluginsAndModules,
final ClusterState clusterState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,64 @@ public void testMonitoringExporterPassword() {
assertThat(issue, nullValue());
}

public void testCheckSearchRemoteSettings() {
// test for presence of deprecated exporter passwords
final int numClusters = randomIntBetween(1, 3);
final String[] clusterNames = new String[numClusters];
final Settings.Builder settingsBuilder = Settings.builder();
for (int k = 0; k < numClusters; k++) {
clusterNames[k] = randomAlphaOfLength(5);
settingsBuilder.put("search.remote." + clusterNames[k] + ".seeds", randomAlphaOfLength(5));
settingsBuilder.put("search.remote." + clusterNames[k] + ".proxy", randomAlphaOfLength(5));
settingsBuilder.put("search.remote." + clusterNames[k] + ".skip_unavailable", randomBoolean());
}
settingsBuilder.put("search.remote.connections_per_cluster", randomIntBetween(0, 100));
settingsBuilder.put("search.remote.initial_connect_timeout", randomIntBetween(30, 60));
settingsBuilder.put("search.remote.connect", randomBoolean());
final Settings settings = settingsBuilder.build();
final XPackLicenseState licenseState = new XPackLicenseState(Settings.EMPTY, () -> 0);
DeprecationIssue issue = NodeDeprecationChecks.checkSearchRemoteSettings(settings, null, null , licenseState);

final String expectedUrl =
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_settings_changes";
String joinedNames = Arrays
.stream(clusterNames)
.map(s -> "search.remote." + s + ".seeds")
.sorted()
.collect(Collectors.joining(","));
joinedNames += ",";
joinedNames += Arrays
.stream(clusterNames)
.map(s -> "search.remote." + s + ".proxy")
.sorted()
.collect(Collectors.joining(","));
joinedNames += ",";
joinedNames += Arrays
.stream(clusterNames)
.map(s -> "search.remote." + s + ".skip_unavailable")
.sorted()
.collect(Collectors.joining(","));
joinedNames += ",search.remote.connections_per_cluster,search.remote.initial_connect_timeout,search.remote.connect";

assertThat(issue, equalTo(new DeprecationIssue(
DeprecationIssue.Level.CRITICAL,
String.format(
Locale.ROOT,
"search.remote settings [%s] are deprecated and will be removed in the next major version",
joinedNames
),
expectedUrl,
String.format(
Locale.ROOT,
"replace search.remote settings [%s] with their secure 'cluster.remote' replacements",
joinedNames
), false, null)));

// test for absence of deprecated exporter passwords
issue = NodeDeprecationChecks.checkMonitoringExporterPassword(Settings.builder().build(), null, null, licenseState);
assertThat(issue, nullValue());
}

public void testClusterRoutingAllocationIncludeRelocationsSetting() {
boolean settingValue = randomBoolean();
String settingKey = CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING.getKey();
Expand Down

0 comments on commit fc1749b

Please sign in to comment.