Skip to content
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

Ignore dynamic settings specified by deprecation.skip_deprecated_settings in node deprecation checks #82883

Merged
merged 5 commits into from
Jan 20, 2022
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 @@ -12,6 +12,7 @@
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.nodes.TransportNodesAction;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject;
Expand Down Expand Up @@ -107,10 +108,20 @@ NodesDeprecationCheckAction.NodeResponse nodeOperation(
XPackLicenseState,
DeprecationIssue>> nodeSettingsChecks
) {
Settings filteredSettings = settings.filter(setting -> Regex.simpleMatch(skipTheseDeprecations, setting) == false);
Settings filteredNodeSettings = settings.filter(setting -> Regex.simpleMatch(skipTheseDeprecations, setting) == false);

Metadata metadata = clusterService.state().metadata();
Settings transientSettings = metadata.transientSettings()
.filter(setting -> Regex.simpleMatch(skipTheseDeprecations, setting) == false);
Settings persistentSettings = metadata.persistentSettings()
.filter(setting -> Regex.simpleMatch(skipTheseDeprecations, setting) == false);
ClusterState filteredClusterState = ClusterState.builder(clusterService.state())
.metadata(Metadata.builder(metadata).transientSettings(transientSettings).persistentSettings(persistentSettings).build())
.build();

List<DeprecationIssue> issues = DeprecationInfoAction.filterChecks(
nodeSettingsChecks,
(c) -> c.apply(filteredSettings, pluginsService.info(), clusterService.state(), licenseState)
(c) -> c.apply(filteredNodeSettings, pluginsService.info(), filteredClusterState, licenseState)
);

return new NodesDeprecationCheckAction.NodeResponse(transportService.getLocalNode(), issues);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.node.DiscoveryNode;
Expand Down Expand Up @@ -38,25 +39,27 @@ public void testNodeOperation() {
settingsBuilder.putList("some.undeprecated.list.property", List.of("someValue4", "someValue5"));
settingsBuilder.putList(
DeprecationChecks.SKIP_DEPRECATIONS_SETTING.getKey(),
List.of("some.deprecated.property", "some.other.*.deprecated.property")
List.of("some.deprecated.property", "some.other.*.deprecated.property", "some.bad.dynamic.property")
);
Settings inputSettings = settingsBuilder.build();
Settings nodeSettings = settingsBuilder.build();
settingsBuilder = Settings.builder();
settingsBuilder.put("some.bad.dynamic.property", "someValue1");
Settings dynamicSettings = settingsBuilder.build();
ThreadPool threadPool = null;
final XPackLicenseState licenseState = null;
Metadata metadata = Mockito.mock(Metadata.class);
ClusterState clusterState = Mockito.mock(ClusterState.class);
Mockito.when(clusterState.metadata()).thenReturn(metadata);
Metadata metadata = Metadata.builder().transientSettings(dynamicSettings).build();
ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(metadata).build();
ClusterService clusterService = Mockito.mock(ClusterService.class);
Mockito.when(clusterService.state()).thenReturn(clusterState);
ClusterSettings clusterSettings = new ClusterSettings(inputSettings, Set.of(DeprecationChecks.SKIP_DEPRECATIONS_SETTING));
ClusterSettings clusterSettings = new ClusterSettings(nodeSettings, Set.of(DeprecationChecks.SKIP_DEPRECATIONS_SETTING));
Mockito.when((clusterService.getClusterSettings())).thenReturn(clusterSettings);
DiscoveryNode node = Mockito.mock(DiscoveryNode.class);
TransportService transportService = Mockito.mock(TransportService.class);
Mockito.when(transportService.getLocalNode()).thenReturn(node);
PluginsService pluginsService = Mockito.mock(PluginsService.class);
ActionFilters actionFilters = Mockito.mock(ActionFilters.class);
TransportNodeDeprecationCheckAction transportNodeDeprecationCheckAction = new TransportNodeDeprecationCheckAction(
inputSettings,
nodeSettings,
threadPool,
licenseState,
clusterService,
Expand All @@ -65,14 +68,16 @@ public void testNodeOperation() {
actionFilters
);
NodesDeprecationCheckAction.NodeRequest nodeRequest = null;
AtomicReference<Settings> visibleSettings = new AtomicReference<>();
AtomicReference<Settings> visibleNodeSettings = new AtomicReference<>();
AtomicReference<Settings> visibleClusterStateMetadataSettings = new AtomicReference<>();
DeprecationChecks.NodeDeprecationCheck<
Settings,
PluginsAndModules,
ClusterState,
XPackLicenseState,
DeprecationIssue> nodeSettingCheck = (settings, p, c, l) -> {
visibleSettings.set(settings);
DeprecationIssue> nodeSettingCheck = (settings, p, clusterState1, l) -> {
visibleNodeSettings.set(settings);
visibleClusterStateMetadataSettings.set(clusterState1.getMetadata().settings());
return null;
};
java.util.List<
Expand All @@ -88,11 +93,13 @@ public void testNodeOperation() {
settingsBuilder.putList("some.undeprecated.list.property", List.of("someValue4", "someValue5"));
settingsBuilder.putList(
DeprecationChecks.SKIP_DEPRECATIONS_SETTING.getKey(),
List.of("some.deprecated.property", "some.other.*.deprecated.property")
List.of("some.deprecated.property", "some.other.*.deprecated.property", "some.bad.dynamic.property")
);
Settings expectedSettings = settingsBuilder.build();
Assert.assertNotNull(visibleSettings.get());
Assert.assertEquals(expectedSettings, visibleSettings.get());
Assert.assertNotNull(visibleNodeSettings.get());
Assert.assertEquals(expectedSettings, visibleNodeSettings.get());
Assert.assertNotNull(visibleClusterStateMetadataSettings.get());
Assert.assertEquals(Settings.EMPTY, visibleClusterStateMetadataSettings.get());

// Testing that the setting is dynamically updatable:
Settings newSettings = Settings.builder()
Expand All @@ -107,10 +114,16 @@ public void testNodeOperation() {
// This is the node setting (since this is the node deprecation check), not the cluster setting:
settingsBuilder.putList(
DeprecationChecks.SKIP_DEPRECATIONS_SETTING.getKey(),
List.of("some.deprecated.property", "some.other.*.deprecated.property")
List.of("some.deprecated.property", "some.other.*.deprecated.property", "some.bad.dynamic.property")
);
expectedSettings = settingsBuilder.build();
Assert.assertNotNull(visibleSettings.get());
Assert.assertEquals(expectedSettings, visibleSettings.get());
Assert.assertNotNull(visibleNodeSettings.get());
Assert.assertEquals(expectedSettings, visibleNodeSettings.get());
Assert.assertNotNull(visibleClusterStateMetadataSettings.get());
Assert.assertEquals(
Settings.builder().put("some.bad.dynamic.property", "someValue1").build(),
visibleClusterStateMetadataSettings.get()
);
}

}