Add path to DiskSpaceHealthIndicator's details and log message

See gh-31998
This commit is contained in:
rreich 2022-08-08 10:35:15 +02:00 committed by Andy Wilkinson
parent 3dfe28c9f1
commit 36f9230f01
2 changed files with 9 additions and 3 deletions

View File

@ -63,12 +63,14 @@ public class DiskSpaceHealthIndicator extends AbstractHealthIndicator {
builder.up();
}
else {
logger.warn(LogMessage.format("Free disk space below threshold. Available: %d bytes (threshold: %s)",
diskFreeInBytes, this.threshold));
logger.warn(
LogMessage.format("Free disk space below threshold. Available: %d bytes (path: %s, threshold: %s)",
diskFreeInBytes, this.path.getAbsolutePath(), this.threshold));
builder.down();
}
builder.withDetail("total", this.path.getTotalSpace()).withDetail("free", diskFreeInBytes)
.withDetail("threshold", this.threshold.toBytes()).withDetail("exists", this.path.exists());
.withDetail("threshold", this.threshold.toBytes()).withDetail("path", this.path.getAbsolutePath())
.withDetail("exists", this.path.exists());
}
}

View File

@ -61,11 +61,13 @@ class DiskSpaceHealthIndicatorTests {
long freeSpace = THRESHOLD.toBytes() + 10;
given(this.fileMock.getUsableSpace()).willReturn(freeSpace);
given(this.fileMock.getTotalSpace()).willReturn(TOTAL_SPACE.toBytes());
given(this.fileMock.getAbsolutePath()).willReturn("/absolute-path");
Health health = this.healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("threshold")).isEqualTo(THRESHOLD.toBytes());
assertThat(health.getDetails().get("free")).isEqualTo(freeSpace);
assertThat(health.getDetails().get("total")).isEqualTo(TOTAL_SPACE.toBytes());
assertThat(health.getDetails().get("path")).isEqualTo("/absolute-path");
assertThat(health.getDetails().get("exists")).isEqualTo(true);
}
@ -75,11 +77,13 @@ class DiskSpaceHealthIndicatorTests {
long freeSpace = THRESHOLD.toBytes() - 10;
given(this.fileMock.getUsableSpace()).willReturn(freeSpace);
given(this.fileMock.getTotalSpace()).willReturn(TOTAL_SPACE.toBytes());
given(this.fileMock.getAbsolutePath()).willReturn("/absolute-path");
Health health = this.healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("threshold")).isEqualTo(THRESHOLD.toBytes());
assertThat(health.getDetails().get("free")).isEqualTo(freeSpace);
assertThat(health.getDetails().get("total")).isEqualTo(TOTAL_SPACE.toBytes());
assertThat(health.getDetails().get("path")).isEqualTo("/absolute-path");
assertThat(health.getDetails().get("exists")).isEqualTo(true);
}