Adding multiple health check endpoint for dotnet core application
Imagine the scenario when we need to expose one health check endpoint for checking application liveliness and another endpoint for checking application readiness.
Lets assume, liveliness endpoint is responsible to see if the application is healthy and ready to receive traffic. On the other hand, readiness endpoint is responsible to check if the application is responsive, if not - the application will be restarted by some way to fix that.
We can use the Health Checks provided by ASP.NET Core to achieve this with filtering by tags.
Lets assume that we have a "/ping" endpoint in our application that responses with "pong". We can add a health check to hit the ping endpoint to see if our application is responsive or not.
I am also assuming that the application relies on ElasticSearch for processing API requests. So, I am adding another health check for ElasticSearch.
Now we need to register those health checks:
And here is the implementation of the extension method for adding health check endpoints:
This will expose following endpoints for health checks:
- localhost:5000/health - this will check health status of underlying services
- localhost:5000/ready - this will check application responsiveness
HAPPY CODING 👌
Comments
Post a Comment