Hi Team,
As my project outcome, I have 2 HealthCheck Status -
1 - Healthy
2 - UnHealthy
If I see Unhealthy, my overall status should be degraded. Is it possible to implement ? If so, how ? Please help.
My Current Code ::
Predicate = check => check.Tags.Contains("SQL Connection") || check.Tags.Contains("rate check") || check.Tags.Contains("live check"),
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
If any is unhealthy I should the overall status as Degraded but now it is getting displayed as UnHealthy
Sample ::
app
-> Rollout (degraded)
-> ReplicaSet A (healthy)
-> Pod 1 (healthy)
-> ReplicaSet B [canary] (unhealthy)
-> Pod 2 (unhealthy)
Jithu ThomasPosted Jun 5, 2024, 7:02 AM
if so, Here's the revised implementation:
Revised Custom Response Writer
Also please ensure your health check middleware is configured correctly:
Please accept the answer if you find it useful.
HemapriyaPosted Jun 5, 2024, 9:08 AM
Awesome! It works!
HemapriyaPosted Jun 5, 2024, 6:58 AM
Thanks!
Overall Status "Degraded": Only if the "live check" is unhealthy.
Overall Status "UnHealthy": If any other check is unhealthy and the "live check" is not unhealthy. this should be your output right.
Yes, That's correct.
Jithu ThomasPosted Jun 5, 2024, 6:43 AM
i strongly guess....Overall Status "Degraded": Only if the "live check" is unhealthy. Overall Status "UnHealthy": If any other check is unhealthy and the "live check" is not unhealthy. this should be your output right.
Please confirm if not please explain
HemapriyaPosted Jun 5, 2024, 6:36 AM
Excellent, It works! Thanks!
Only if check.Tags.Contains("live check") is UnHealthy it should display as Degraded so for other checks it should display as UnHealthy only. Is this possible ?
Now from the below code, If it's UnHealthy for all the 3 checks it displays 'Degraded'
Can you help me please.
Jithu ThomasPosted Jun 5, 2024, 5:53 AM
Here's a step-by-step approach to implement this in ASP.NET Core:
Define Custom Health Statuses: Ensure you have custom health statuses like "Degraded" defined. ASP.NET Core by default supports "Healthy," "Degraded," and "Unhealthy."
Create a Custom Response Writer: Implement a custom response writer that checks the health status of individual components and sets the overall status to "Degraded" if any are "Unhealthy."
Register the Health Checks: Ensure the health checks are registered in the
Startup.csfile with the custom response writer.Here's an example implementation:
Step 1: Define Custom Health Statuses
Step 2: Create a Custom Response Writer
Step 3: Register the Health Checks
Modify your
Startup.csto register the health checks and use the custom response writer.Also note that,
WriteResponsethat formats the health check report and sets the overall status to "Degraded" if any individual check is "Unhealthy."With this setup, the health check endpoint will return a JSON response indicating "Degraded" status if any health check is "Unhealthy," while still listing the individual statuses of all checks.