I started using Health checks from Asp.net Core, I love them but I could not find an easy way to wire it up with tenant based routing, for example supporting:
- /health [generic non tenant specific checks]
- /{tenant}/health [tenant specific check]
If I succeeded with this approach I could have used tags to filter which health check to use, but unfortunately I failed to configure the routing for the request.
app.UseEndpointRouting();
app.UseHealthChecks("/{tenant}/health", new HealthCheckOptions
{
ResponseWriter = WriteCustomHealthResponse,
AllowCachingResponses = false,
Predicate = _ => _.Tags.Contains("tenant-specific")
});
The above code is not routing correctly. I explored the possibility to use something like the below:
app.MapWhen(context =>
context.Request.Method == HttpMethod.Get.Method &&
context.Request.?ROUTEDATA?.SOMECHECK("/{tenant}/HealthCheck"),
builder => builder.UseHealthChecks());
But in this case I don't have a way to check if the routing is correct.