-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Remove requirement for the disk space health indicator's path to exist when the app starts #20580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for the proposal. I like the idea of moving the checks out of the properties class as we generally try to limit those to being simple POJOs with little to no logic in them. I'm wondering if we should consider changing the current behaviour or allowing it to be configured. Instead of failing startup when the path does not exist (and causing the problem that you have observed) we could continue and allow the health indicator to report Flagging for team attention so that we can discuss our options. |
Yes, not failing startup at all would also be an acceptable option for my use case. I am however somewhat concerned that the application might report as unhealthy right after startup without an obvious cause. In development nobody might be monitoring the application health. Then an issue where the indicator can't become healthy would only just be caught in a staging or production environment. Maybe a warning could be logged instead? Or the behaviour could be made configurable? |
We discussed this today and we'd like to align |
@wilkinsona Thanks for the feedback. I'll give it a shot and report back here. |
By removing these checks the configuration can be successfully instantiated even if the the path for the health check does not exist (or is not readable) at that point. This is for example useful when the application intends to create the actual configured path itself during startup.
These new details are meant to provide pointers especially when the DiskSpaceHealthIndicator reports as DOWN.
@wilkinsona I've implemented the behavior you described:
Check is removed.
Responds with DOWN including the corner case where the threshold is zero.
Details added for exists & canRead/Write/Execute. It might be interesting to incorporate canRead/Write/Execute as well into the health check outcome. But I've left this out. Also I didn't test any of this on a non-linux system. Specifically, this means I didn't explicitly verify that |
Thanks very much for making your first contribution to Spring Boot, @poosha. I polished the proposed changes a little bit in f238812. This left the changes looking like this. I decided not to add |
Problem
When the path referenced by
management.health.diskspace.path
does not exist before a Spring Boot application with the actuator autoconfiguration is started, there is no possibility to create the path during application startup. This is sort of a chicken & egg problem. If I want to create the path during startup, I need to get it from the configuration. But to access the configuration the creation ofDiskSpaceHealthIndicatorProperties
must not fail. However, this is the case when that path does not exist (or is not readable) before application startup.Use Case
My application has a data directory and I want the autoconfigured DiskSpaceHealthIndicator to monitor that directory. Let's say the configuration is like that:
I do not want to tell every user (or developer) that he needs to create the
myapp/data/
directory first. So the application will create the directory itself when necessary. However, once I add the second line above this mechanism stops working and application startup fails until the directories are created outside the scope of the Spring Boot application and before its startup (e.g. manually).Proposed Solution
Do not check mutable aspects of the system environment when binding the configuration properties. That is, move the existence & readability assertions from
DiskSpaceHealthIndicatorProperties
toDiskSpaceHealthContributorAutoconfiguration
. This allows in my use case to access the configuration and to create the directories during startup before the autoconfiguration runs.I picked this solution because the behavior of
DiskSpaceHealthContributorAutoconfiguration
would remain largely unchanged as indicated by the test case I added. I did not move the assertions toDiskSpaceHealthIndicator
because that would affect users that directly use it and that might for some reason rely on being able to create it with a nonexistent or unreadable path.Please let me know if you would prefer a different approach.