Skip to content

Commit 1123957

Browse files
committed
Indicate DOWN even if the threshold is zero
1 parent 8b70460 commit 1123957

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ public DiskSpaceHealthIndicator(File path, DataSize threshold) {
5959
@Override
6060
protected void doHealthCheck(Health.Builder builder) throws Exception {
6161
long diskFreeInBytes = this.path.getUsableSpace();
62-
if (diskFreeInBytes >= this.threshold.toBytes()) {
62+
// return value of 0L means "the abstract pathname does not name a
63+
// partition" which for our purposes means it's not usable i.e DOWN
64+
if (diskFreeInBytes >= this.threshold.toBytes() && diskFreeInBytes != 0L) {
6365
builder.up();
6466
}
6567
else {

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicatorPathTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class DiskSpaceHealthIndicatorPathTests {
4040

4141
private static final DataSize THRESHOLD = DataSize.ofKilobytes(1);
4242

43+
private static final DataSize ZERO_THRESHOLD = DataSize.ofBytes(0);
44+
4345
private static final DataSize TOTAL_SPACE = DataSize.ofKilobytes(10);
4446

4547
@Mock
@@ -70,6 +72,20 @@ void diskSpaceIsDown() {
7072
assertThat(health.getDetails().get("canExecute")).isEqualTo(false);
7173
}
7274

75+
@Test
76+
void diskSpaceIsDownWhenThresholdIsZero() {
77+
this.healthIndicator = new DiskSpaceHealthIndicator(this.fileMock, ZERO_THRESHOLD);
78+
Health health = this.healthIndicator.health();
79+
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
80+
assertThat(health.getDetails().get("threshold")).isEqualTo(ZERO_THRESHOLD.toBytes());
81+
assertThat(health.getDetails().get("free")).isEqualTo(0L);
82+
assertThat(health.getDetails().get("total")).isEqualTo(0L);
83+
assertThat(health.getDetails().get("exists")).isEqualTo(false);
84+
assertThat(health.getDetails().get("canRead")).isEqualTo(false);
85+
assertThat(health.getDetails().get("canWrite")).isEqualTo(false);
86+
assertThat(health.getDetails().get("canExecute")).isEqualTo(false);
87+
}
88+
7389
@Test
7490
void diskSpaceIsUpWhenPathOnlyExists() {
7591
long freeSpace = THRESHOLD.toBytes() + 10;

0 commit comments

Comments
 (0)