Skip to content

Commit 5eb536e

Browse files
Fix for GET /_migration/deprecations doesn't report node deprecations if low watermark exceeded and GET /_migration/deprecations doesn't report node-level failures properly (#137964)
Fix for GET /_migration/deprecations doesn't report node deprecations if low watermark exceeded and GET /_migration/deprecations doesn't report node-level failures properly Closes #137010 Closes #137004
1 parent 0051df8 commit 5eb536e

File tree

4 files changed

+126
-12
lines changed

4 files changed

+126
-12
lines changed

docs/changelog/137964.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pr: 137964
2+
summary: Fix for GET /_migration/deprecations doesn't report node deprecations if
3+
low watermark exceeded and GET /_migration/deprecations doesn't report node-level
4+
failures properly
5+
area: Infra/Core
6+
type: bug
7+
issues:
8+
- 137010
9+
- 137004

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void check(Client client, ActionListener<List<DeprecationIssue>> listener
5252
.collect(Collectors.toList());
5353
logger.warn("nodes failed to run deprecation checks: {}", failedNodeIds);
5454
for (FailedNodeException failure : response.failures()) {
55-
logger.debug("node {} failed to run deprecation checks: {}", failure.nodeId(), failure);
55+
logger.atWarn().withThrowable(failure).log("node {} failed to run deprecation checks", failure.nodeId());
5656
}
5757
}
5858
l.onResponse(reduceToDeprecationIssues(response));

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportNodeDeprecationCheckAction.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
3434

3535
import java.io.IOException;
36+
import java.util.ArrayList;
3637
import java.util.Collections;
3738
import java.util.List;
3839
import java.util.Locale;
39-
import java.util.Objects;
4040

4141
import static org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING;
4242

@@ -107,11 +107,10 @@ protected NodesDeprecationCheckAction.NodeResponse newNodeResponse(StreamInput i
107107

108108
@Override
109109
protected NodesDeprecationCheckAction.NodeResponse nodeOperation(NodesDeprecationCheckAction.NodeRequest request, Task task) {
110-
return nodeOperation(request, NodeDeprecationChecks.SINGLE_NODE_CHECKS);
110+
return nodeOperation(NodeDeprecationChecks.SINGLE_NODE_CHECKS);
111111
}
112112

113113
NodesDeprecationCheckAction.NodeResponse nodeOperation(
114-
NodesDeprecationCheckAction.NodeRequest request,
115114
List<
116115
NodeDeprecationChecks.NodeDeprecationCheck<
117116
Settings,
@@ -131,10 +130,18 @@ NodesDeprecationCheckAction.NodeResponse nodeOperation(
131130
.metadata(Metadata.builder(metadata).transientSettings(transientSettings).persistentSettings(persistentSettings).build())
132131
.build();
133132

134-
List<DeprecationIssue> issues = nodeSettingsChecks.stream()
135-
.map(c -> c.apply(filteredNodeSettings, pluginsService.info(), filteredClusterState, licenseState))
136-
.filter(Objects::nonNull)
137-
.toList();
133+
List<DeprecationIssue> issues = new ArrayList<>();
134+
for (NodeDeprecationChecks.NodeDeprecationCheck<
135+
Settings,
136+
PluginsAndModules,
137+
ClusterState,
138+
XPackLicenseState,
139+
DeprecationIssue> c : nodeSettingsChecks) {
140+
DeprecationIssue deprecationIssue = c.apply(filteredNodeSettings, pluginsService.info(), filteredClusterState, licenseState);
141+
if (deprecationIssue != null) {
142+
issues.add(deprecationIssue);
143+
}
144+
}
138145
DeprecationIssue watermarkIssue = checkDiskLowWatermark(
139146
filteredNodeSettings,
140147
filteredClusterState.metadata().settings(),

x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TransportNodeDeprecationCheckActionTests.java

Lines changed: 102 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,37 @@
1616
import org.elasticsearch.cluster.DiskUsage;
1717
import org.elasticsearch.cluster.metadata.Metadata;
1818
import org.elasticsearch.cluster.node.DiscoveryNode;
19+
import org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings;
1920
import org.elasticsearch.cluster.service.ClusterService;
2021
import org.elasticsearch.common.settings.ClusterSettings;
2122
import org.elasticsearch.common.settings.Settings;
23+
import org.elasticsearch.common.util.CollectionUtils;
2224
import org.elasticsearch.license.XPackLicenseState;
2325
import org.elasticsearch.plugins.PluginsService;
2426
import org.elasticsearch.test.ESTestCase;
2527
import org.elasticsearch.threadpool.TestThreadPool;
2628
import org.elasticsearch.threadpool.ThreadPool;
2729
import org.elasticsearch.transport.TransportService;
2830
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
31+
import org.hamcrest.BaseMatcher;
32+
import org.hamcrest.Description;
33+
import org.hamcrest.Matcher;
2934
import org.junit.After;
3035
import org.junit.Assert;
3136
import org.junit.Before;
3237
import org.mockito.Mockito;
3338

39+
import java.util.Collections;
3440
import java.util.List;
3541
import java.util.Map;
3642
import java.util.Set;
3743
import java.util.concurrent.TimeUnit;
3844
import java.util.concurrent.atomic.AtomicReference;
3945

46+
import static org.elasticsearch.common.settings.ClusterSettings.BUILT_IN_CLUSTER_SETTINGS;
47+
import static org.hamcrest.Matchers.equalTo;
48+
import static org.hamcrest.Matchers.hasItem;
49+
import static org.hamcrest.Matchers.hasSize;
4050
import static org.mockito.Mockito.when;
4151

4252
public class TransportNodeDeprecationCheckActionTests extends ESTestCase {
@@ -98,7 +108,6 @@ public void testNodeOperation() {
98108
actionFilters,
99109
clusterInfoService
100110
);
101-
NodesDeprecationCheckAction.NodeRequest nodeRequest = null;
102111
AtomicReference<Settings> visibleNodeSettings = new AtomicReference<>();
103112
AtomicReference<Settings> visibleClusterStateMetadataSettings = new AtomicReference<>();
104113
NodeDeprecationChecks.NodeDeprecationCheck<
@@ -118,7 +127,7 @@ public void testNodeOperation() {
118127
ClusterState,
119128
XPackLicenseState,
120129
DeprecationIssue>> nodeSettingsChecks = List.of(nodeSettingCheck);
121-
transportNodeDeprecationCheckAction.nodeOperation(nodeRequest, nodeSettingsChecks);
130+
transportNodeDeprecationCheckAction.nodeOperation(nodeSettingsChecks);
122131
settingsBuilder = Settings.builder();
123132
settingsBuilder.put("some.undeprecated.property", "someValue3");
124133
settingsBuilder.putList("some.undeprecated.list.property", List.of("someValue4", "someValue5"));
@@ -137,7 +146,7 @@ public void testNodeOperation() {
137146
.putList(TransportDeprecationInfoAction.SKIP_DEPRECATIONS_SETTING.getKey(), List.of("some.undeprecated.property"))
138147
.build();
139148
clusterSettings.applySettings(newSettings);
140-
transportNodeDeprecationCheckAction.nodeOperation(nodeRequest, nodeSettingsChecks);
149+
transportNodeDeprecationCheckAction.nodeOperation(nodeSettingsChecks);
141150
settingsBuilder = Settings.builder();
142151
settingsBuilder.put("some.deprecated.property", "someValue1");
143152
settingsBuilder.put("some.other.bad.deprecated.property", "someValue2");
@@ -163,7 +172,7 @@ public void testCheckDiskLowWatermark() {
163172
settingsBuilder.put("cluster.routing.allocation.disk.watermark.low", "10%");
164173
Settings settingsWithLowWatermark = settingsBuilder.build();
165174
Settings dynamicSettings = settingsWithLowWatermark;
166-
ClusterSettings clusterSettings = new ClusterSettings(nodeSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
175+
ClusterSettings clusterSettings = new ClusterSettings(nodeSettings, BUILT_IN_CLUSTER_SETTINGS);
167176
String nodeId = "123";
168177
long totalBytesOnMachine = 100;
169178
long totalBytesFree = 70;
@@ -203,4 +212,93 @@ public void testCheckDiskLowWatermark() {
203212
assertNotNull(issue);
204213
assertEquals("Disk usage exceeds low watermark", issue.getMessage());
205214
}
215+
216+
public void testDiskLowWatermarkIsIncludedInDeprecationWarnings() {
217+
Settings.Builder settingsBuilder = Settings.builder();
218+
String deprecatedSettingKey = "some.deprecated.property";
219+
settingsBuilder.put(deprecatedSettingKey, "someValue1");
220+
settingsBuilder.put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "10%");
221+
Settings nodeSettings = settingsBuilder.build();
222+
final XPackLicenseState licenseState = null;
223+
ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(Metadata.builder().build()).build();
224+
ClusterService clusterService = Mockito.mock(ClusterService.class);
225+
when(clusterService.state()).thenReturn(clusterState);
226+
ClusterSettings clusterSettings = new ClusterSettings(
227+
nodeSettings,
228+
Set.copyOf(CollectionUtils.appendToCopy(BUILT_IN_CLUSTER_SETTINGS, TransportDeprecationInfoAction.SKIP_DEPRECATIONS_SETTING))
229+
);
230+
when((clusterService.getClusterSettings())).thenReturn(clusterSettings);
231+
DiscoveryNode node = Mockito.mock(DiscoveryNode.class);
232+
String nodeId = "123";
233+
when(node.getId()).thenReturn(nodeId);
234+
TransportService transportService = Mockito.mock(TransportService.class);
235+
when(transportService.getThreadPool()).thenReturn(threadPool);
236+
when(transportService.getLocalNode()).thenReturn(node);
237+
PluginsService pluginsService = Mockito.mock(PluginsService.class);
238+
ActionFilters actionFilters = Mockito.mock(ActionFilters.class);
239+
ClusterInfoService clusterInfoService = Mockito.mock(ClusterInfoService.class);
240+
long totalBytesOnMachine = 100;
241+
long totalBytesFree = 70;
242+
ClusterInfo clusterInfo = ClusterInfo.builder()
243+
.mostAvailableSpaceUsage(Map.of(nodeId, new DiskUsage(nodeId, "", "", totalBytesOnMachine, totalBytesFree)))
244+
.build();
245+
when(clusterInfoService.getClusterInfo()).thenReturn(clusterInfo);
246+
TransportNodeDeprecationCheckAction transportNodeDeprecationCheckAction = new TransportNodeDeprecationCheckAction(
247+
nodeSettings,
248+
threadPool,
249+
licenseState,
250+
clusterService,
251+
transportService,
252+
pluginsService,
253+
actionFilters,
254+
clusterInfoService
255+
);
256+
257+
NodeDeprecationChecks.NodeDeprecationCheck<
258+
Settings,
259+
PluginsAndModules,
260+
ClusterState,
261+
XPackLicenseState,
262+
DeprecationIssue> deprecationCheck = (first, second, third, fourth) -> {
263+
if (first.keySet().contains(deprecatedSettingKey)) {
264+
return new DeprecationIssue(DeprecationIssue.Level.WARNING, "Deprecated setting", null, null, false, null);
265+
}
266+
return null;
267+
};
268+
NodesDeprecationCheckAction.NodeResponse nodeResponse = transportNodeDeprecationCheckAction.nodeOperation(
269+
Collections.singletonList(deprecationCheck)
270+
);
271+
List<DeprecationIssue> deprecationIssues = nodeResponse.getDeprecationIssues();
272+
assertThat(deprecationIssues, hasSize(2));
273+
assertThat(deprecationIssues, hasItem(new DeprecationIssueMatcher(DeprecationIssue.Level.WARNING, equalTo("Deprecated setting"))));
274+
assertThat(
275+
deprecationIssues,
276+
hasItem(new DeprecationIssueMatcher(DeprecationIssue.Level.CRITICAL, equalTo("Disk usage exceeds low watermark")))
277+
);
278+
}
279+
280+
private static class DeprecationIssueMatcher extends BaseMatcher<DeprecationIssue> {
281+
private final DeprecationIssue.Level level;
282+
private final Matcher<String> messageMatcher;
283+
284+
private DeprecationIssueMatcher(DeprecationIssue.Level level, Matcher<String> messageMatcher) {
285+
this.level = level;
286+
this.messageMatcher = messageMatcher;
287+
}
288+
289+
@Override
290+
public boolean matches(Object actual) {
291+
if (actual instanceof DeprecationIssue == false) {
292+
return false;
293+
}
294+
DeprecationIssue actualDeprecationIssue = (DeprecationIssue) actual;
295+
return level.equals(actualDeprecationIssue.getLevel()) && messageMatcher.matches(actualDeprecationIssue.getMessage());
296+
}
297+
298+
@Override
299+
public void describeTo(Description description) {
300+
description.appendText("deprecation issue with level: ").appendValue(level).appendText(" and message: ");
301+
messageMatcher.describeTo(description);
302+
}
303+
}
206304
}

0 commit comments

Comments
 (0)