Skip to content

Commit 72ccf3b

Browse files
committed
ClusterStats tests should allow for open file descriptors to be -1 (which they are on windows)
Also made some other small tweaks for that case.
1 parent 2535a40 commit 72ccf3b

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ public static class ProcessStats implements ToXContent, Streamable {
397397
int count;
398398
int cpuPercent;
399399
long totalOpenFileDescriptors;
400-
long minOpenFileDescriptors = Integer.MAX_VALUE;
401-
long maxOpenFileDescriptors = Integer.MIN_VALUE;
400+
long minOpenFileDescriptors = Long.MAX_VALUE;
401+
long maxOpenFileDescriptors = Long.MIN_VALUE;
402402

403403
public void addNodeStats(NodeStats nodeStats) {
404404
if (nodeStats.getProcess() == null) {
@@ -410,7 +410,11 @@ public void addNodeStats(NodeStats nodeStats) {
410410
cpuPercent += nodeStats.getProcess().cpu().getPercent();
411411
}
412412
long fd = nodeStats.getProcess().openFileDescriptors();
413-
totalOpenFileDescriptors += fd;
413+
if (fd > 0) {
414+
// fd can be -1 if not supported on platform
415+
totalOpenFileDescriptors += fd;
416+
}
417+
// we still do min max calc on -1, so we'll have an indication of it not being supported on one of the nodes.
414418
minOpenFileDescriptors = Math.min(minOpenFileDescriptors, fd);
415419
maxOpenFileDescriptors = Math.max(maxOpenFileDescriptors, fd);
416420
}

src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,12 @@ public void testValuesSmokeScreen() {
136136
assertThat(response.nodesStats.getVersions().contains(Version.CURRENT), Matchers.equalTo(true));
137137
assertThat(response.nodesStats.getPlugins().size(), Matchers.greaterThanOrEqualTo(0));
138138

139-
assertThat(response.nodesStats.getProcess().getAvgOpenFileDescriptors(), Matchers.greaterThan(0L));
140-
assertThat(response.nodesStats.getProcess().getMinOpenFileDescriptors(), Matchers.greaterThan(0L));
141-
assertThat(response.nodesStats.getProcess().getMaxOpenFileDescriptors(), Matchers.greaterThan(0L));
139+
assertThat(response.nodesStats.getProcess().count, Matchers.greaterThan(0));
140+
// 0 happens when not supported on platform
141+
assertThat(response.nodesStats.getProcess().getAvgOpenFileDescriptors(), Matchers.greaterThanOrEqualTo(0L));
142+
// these can be -1 if not supported on platform
143+
assertThat(response.nodesStats.getProcess().getMinOpenFileDescriptors(), Matchers.greaterThan(-1L));
144+
assertThat(response.nodesStats.getProcess().getMaxOpenFileDescriptors(), Matchers.greaterThan(-1L));
142145

143146
}
144147
}

0 commit comments

Comments
 (0)