Skip to content

Commit 77136ef

Browse files
committed
Add clear deprecation around legacy role settings
We've deprecated the legacy role settings. Individually, when you use such a setting, you will get an individual log message informing you that you've used a legacy role setting. What the deprecation does not tell you though, is the equivalent node.roles setting that you should be using to achieve identical functionality to what you have today. This creates a bad user experience. Suppose that you've configured a node (e.g., node.data: true, node.ingest: false, node.master: false, node.remote_cluster_client: false), but never explicitly set the legacy node.transform setting. In this case, we'll use the default value of true. You see the deprecation message informing you that node.data, node.ingest, node.master, and node.remote_cluster_client are deprecated. So you do some searching in the docs and discover the node.roles setting. So you dutifully set node.roles: [data] because this is the only legacy role setting that you've enabled. Well, now you're having a bad time because this will also disable the transform role, which was implicitly enabled. This commit provides a cleared deprecation message in this case: legacy role settings [node.data, node.ingest, node.remote_cluster_client, node.master] are deprecated, use [node.roles=[transform, data_frozen, data_hot, data_content, data_warm, data, data_cold] This should help users transition between the legacy role settings and the new role setting.
1 parent 1edc7c6 commit 77136ef

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,10 @@ public static DiscoveryNode createLocal(Settings settings, TransportAddress publ
206206

207207
/** extract node roles from the given settings */
208208
public static Set<DiscoveryNodeRole> getRolesFromSettings(final Settings settings) {
209-
if (NODE_ROLES_SETTING.exists(settings)) {
209+
// are any legacy settings in use?
210+
boolean usesLegacySettings =
211+
getPossibleRoles().stream().anyMatch(s -> s.legacySetting() != null && s.legacySetting().exists(settings));
212+
if (NODE_ROLES_SETTING.exists(settings) || usesLegacySettings == false) {
210213
validateLegacySettings(settings, roleMap);
211214
return Set.copyOf(NODE_ROLES_SETTING.get(settings));
212215
} else {

server/src/main/java/org/elasticsearch/node/Node.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.elasticsearch.cluster.service.ClusterService;
5353
import org.elasticsearch.common.StopWatch;
5454
import org.elasticsearch.common.breaker.CircuitBreaker;
55+
import org.elasticsearch.common.collect.Tuple;
5556
import org.elasticsearch.common.component.Lifecycle;
5657
import org.elasticsearch.common.component.LifecycleComponent;
5758
import org.elasticsearch.common.inject.Injector;
@@ -181,6 +182,7 @@
181182
import java.util.LinkedHashSet;
182183
import java.util.List;
183184
import java.util.Map;
185+
import java.util.Objects;
184186
import java.util.Optional;
185187
import java.util.Set;
186188
import java.util.concurrent.CountDownLatch;
@@ -338,11 +340,36 @@ protected Node(final Environment initialEnvironment,
338340
this.environment = new Environment(settings, initialEnvironment.configFile());
339341
Environment.assertEquivalent(initialEnvironment, this.environment);
340342
nodeEnvironment = new NodeEnvironment(tmpSettings, environment);
341-
logger.info("node name [{}], node ID [{}], cluster name [{}], roles {}",
342-
NODE_NAME_SETTING.get(tmpSettings), nodeEnvironment.nodeId(), ClusterName.CLUSTER_NAME_SETTING.get(tmpSettings).value(),
343-
DiscoveryNode.getRolesFromSettings(settings).stream()
344-
.map(DiscoveryNodeRole::roleName)
345-
.collect(Collectors.toCollection(LinkedHashSet::new)));
343+
final Set<String> roleNames = DiscoveryNode.getRolesFromSettings(settings).stream()
344+
.map(DiscoveryNodeRole::roleName)
345+
.collect(Collectors.toCollection(LinkedHashSet::new));
346+
logger.info(
347+
"node name [{}], node ID [{}], cluster name [{}], roles {}",
348+
NODE_NAME_SETTING.get(tmpSettings),
349+
nodeEnvironment.nodeId(),
350+
ClusterName.CLUSTER_NAME_SETTING.get(tmpSettings).value(),
351+
roleNames
352+
);
353+
{
354+
// are there any legacy settings in use?
355+
final List<Tuple<DiscoveryNodeRole, Setting<Boolean>>> maybeLegacyRoleSettings = DiscoveryNode.getPossibleRoles()
356+
.stream()
357+
.filter(s -> s.legacySetting() != null)
358+
.map(s -> Tuple.tuple(s, s.legacySetting()))
359+
.filter(t -> t.v2().exists(settings))
360+
.collect(Collectors.toUnmodifiableList());
361+
if (maybeLegacyRoleSettings.isEmpty() == false) {
362+
final String legacyRoleSettingNames =
363+
maybeLegacyRoleSettings.stream().map(Tuple::v2).map(Setting::getKey).collect(Collectors.joining(", "));
364+
deprecationLogger.deprecate(
365+
DeprecationCategory.SETTINGS,
366+
"legacy role settings",
367+
"legacy role settings [{}] are deprecated, use [node.roles={}]",
368+
legacyRoleSettingNames,
369+
roleNames
370+
);
371+
}
372+
}
346373
resourcesToClose.add(nodeEnvironment);
347374
localNodeFactory = new LocalNodeFactory(settings, nodeEnvironment.nodeId());
348375

0 commit comments

Comments
 (0)