Merge pull request #31998 from rreich

* gh-31998:
  Polish "Add path to DiskSpaceHealthIndicator's details and log message"
  Add path to DiskSpaceHealthIndicator's details and log message

Closes gh-31998
pull/32235/head
Andy Wilkinson 2 years ago
commit 987b866383

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -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 at path '%s' below threshold. Available: %d bytes (threshold: %s)",
this.path.getAbsolutePath(), diskFreeInBytes, 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());
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -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);
}

Loading…
Cancel
Save