From 36f9230f01d92f694b64353f86235becc2791a8b Mon Sep 17 00:00:00 2001 From: rreich Date: Mon, 8 Aug 2022 10:35:15 +0200 Subject: [PATCH 1/2] Add path to DiskSpaceHealthIndicator's details and log message See gh-31998 --- .../boot/actuate/system/DiskSpaceHealthIndicator.java | 8 +++++--- .../actuate/system/DiskSpaceHealthIndicatorTests.java | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicator.java index bf3919a5e5..702dc76280 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicator.java @@ -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()); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicatorTests.java index b631c492bd..70a5f1756e 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicatorTests.java @@ -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); } From 25e6c533d9f6d50d658470deb659d18e0dc27cf0 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 5 Sep 2022 12:58:01 +0100 Subject: [PATCH 2/2] Polish "Add path to DiskSpaceHealthIndicator's details and log message" See gh-31998 --- .../boot/actuate/system/DiskSpaceHealthIndicator.java | 8 ++++---- .../actuate/system/DiskSpaceHealthIndicatorTests.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicator.java index 702dc76280..88dde19756 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicator.java @@ -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,9 +63,9 @@ public class DiskSpaceHealthIndicator extends AbstractHealthIndicator { builder.up(); } else { - logger.warn( - LogMessage.format("Free disk space below threshold. Available: %d bytes (path: %s, threshold: %s)", - diskFreeInBytes, this.path.getAbsolutePath(), 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) diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicatorTests.java index 70a5f1756e..d839a16215 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicatorTests.java @@ -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.