Skip to content

Commit

Permalink
Add clear deprecation around legacy role settings (#71143)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jasontedor authored Apr 1, 2021
1 parent d3a152e commit 3d784f8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ public static DiscoveryNode createLocal(Settings settings, TransportAddress publ

/** extract node roles from the given settings */
public static Set<DiscoveryNodeRole> getRolesFromSettings(final Settings settings) {
if (NODE_ROLES_SETTING.exists(settings)) {
// are any legacy settings in use?
boolean usesLegacySettings =
getPossibleRoles().stream().anyMatch(s -> s.legacySetting() != null && s.legacySetting().exists(settings));
if (NODE_ROLES_SETTING.exists(settings) || usesLegacySettings == false) {
validateLegacySettings(settings, roleMap);
return Set.copyOf(NODE_ROLES_SETTING.get(settings));
} else {
Expand Down
37 changes: 31 additions & 6 deletions server/src/main/java/org/elasticsearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
import org.elasticsearch.cluster.NodeConnectionsService;
import org.elasticsearch.cluster.action.index.MappingUpdatedAction;
import org.elasticsearch.cluster.metadata.AliasValidator;
import org.elasticsearch.cluster.metadata.IndexMetadataVerifier;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.metadata.MetadataCreateDataStreamService;
import org.elasticsearch.cluster.metadata.MetadataCreateIndexService;
import org.elasticsearch.cluster.metadata.IndexMetadataVerifier;
import org.elasticsearch.cluster.metadata.SystemIndexMetadataUpgradeService;
import org.elasticsearch.cluster.metadata.TemplateUpgradeService;
import org.elasticsearch.cluster.node.DiscoveryNode;
Expand Down Expand Up @@ -338,11 +338,36 @@ protected Node(final Environment initialEnvironment,
this.environment = new Environment(settings, initialEnvironment.configFile());
Environment.assertEquivalent(initialEnvironment, this.environment);
nodeEnvironment = new NodeEnvironment(tmpSettings, environment);
logger.info("node name [{}], node ID [{}], cluster name [{}], roles {}",
NODE_NAME_SETTING.get(tmpSettings), nodeEnvironment.nodeId(), ClusterName.CLUSTER_NAME_SETTING.get(tmpSettings).value(),
DiscoveryNode.getRolesFromSettings(settings).stream()
.map(DiscoveryNodeRole::roleName)
.collect(Collectors.toCollection(LinkedHashSet::new)));
final Set<String> roleNames = DiscoveryNode.getRolesFromSettings(settings).stream()
.map(DiscoveryNodeRole::roleName)
.collect(Collectors.toCollection(LinkedHashSet::new));
logger.info(
"node name [{}], node ID [{}], cluster name [{}], roles {}",
NODE_NAME_SETTING.get(tmpSettings),
nodeEnvironment.nodeId(),
ClusterName.CLUSTER_NAME_SETTING.get(tmpSettings).value(),
roleNames
);
{
// are there any legacy settings in use?
final List<Setting<Boolean>> maybeLegacyRoleSettings = DiscoveryNode.getPossibleRoles()
.stream()
.filter(s -> s.legacySetting() != null)
.map(DiscoveryNodeRole::legacySetting)
.filter(s -> s.exists(settings))
.collect(Collectors.toUnmodifiableList());
if (maybeLegacyRoleSettings.isEmpty() == false) {
final String legacyRoleSettingNames =
maybeLegacyRoleSettings.stream().map(Setting::getKey).collect(Collectors.joining(", "));
deprecationLogger.deprecate(
DeprecationCategory.SETTINGS,
"legacy role settings",
"legacy role settings [{}] are deprecated, use [node.roles={}]",
legacyRoleSettingNames,
roleNames
);
}
}
resourcesToClose.add(nodeEnvironment);
localNodeFactory = new LocalNodeFactory(settings, nodeEnvironment.nodeId());

Expand Down

0 comments on commit 3d784f8

Please sign in to comment.