Closed alecor191 closed 5 years ago
Thanks for contacting us, @alecor191. @rynowak, can you please handle this? Thanks!
Hi @alecor191 - this is an intentional change - we want the application developer to be able to configure the status reported by a health check. This is essential if the health check is supplied by a library that you didn't write.
For your use case, I a few options:
You can include these details in the data
returns by your health check https://github.com/aspnet/Diagnostics/blob/release/2.2/samples/HealthChecksSample/GCInfoHealthCheck.cs#L60 and then configure a custom writer to include information in the response https://github.com/aspnet/Diagnostics/blob/release/2.2/samples/HealthChecksSample/CustomWriterStartup.cs
Or you could just register two health checks. Write a check that accepts 'days remaining' as a parameter, and register the same code twice, once with 30 days remaining and once with 0 days. Then, configure one of them to report degraded when it fails.
I hope this helps.
Thanks @rynowak!
Those two approaches should work fine for me. I just found the previous approach a bit more convenient/simple in my setup. However, I understand that there are other scenarios where a more generic approach is required.
I noticed that in Preview3
IHealthCheck
can only return whether it passed or not (through booleanHealthCheckResult.Result
property). When registering the health check, I can specify whatfalse
means, i.e. whetherHealthStatus.Unhealthy
orHealthStatus.Degraded
should be returned. Essentially I have to pick one of the two states for a given health check implementation and can't have the health check decide what to return.In Preview2 a
IHealthCheck
implementation was able to provide more granular state. I.e. it was able to return any of theHealthStatus
values.This limitation in Preview3 is now an issue in a couple of my scenarios. Here an example: I have a health check that looks at the expiration date of the HTTPS certificate used in my ASP.NET Core services.
Healthy
Degraded
(essentially "warning" state that some action is needed, but the service will still work)Unhealthy
(certificate is invalid, hence browsers will reject connecting to the service)Is there still a way to achieve this in Preview3?