I am using VS2019, netcore 3.1 WebApi Project. I am trying to setup a custom health check for my DB. I see a weird behaviour . The /health uri that I configure shows me a 500 internal server when I browse the endpoint . However, /healthz endpoint gives me the status in json smoothly. My Question is what is happening with the /health endpoint that it returns me a 500 internal server error if I browse the endpoint ?
Image in the link Below on browsing https://localhost:44328/health
Image in the link Below on browsing https://localhost:44328/healthz
My Code for the configuring the endpoints:
public void Configure(
IApplicationBuilder app,
IApiVersionDescriptionProvider versionProvider)
{
app.UseChaos();
app.UseQuoteRequestCosmosDB();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseAuthorizationByPass();
app.UseEndpoints(endpoints =>
{
endpoints.MapHealthChecks("/health", new HealthCheckOptions()
{
Predicate = _ => true
});
endpoints.MapHealthChecks("/healthz", new HealthCheckOptions
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
endpoints.MapControllers();
});
app.UseSwagger(versionProvider);
}
Why is /health not working and /healthz working ?
The ConfigureServices Method:
public void ConfigureServices(IServiceCollection services)
{
ConfigureApplicationDependencies(services);
ConfigureApplicationServices(services);
ConfigureTestServices(services);
services.AddServiceBus(_configuration);
services.AddCorsPolicies();
services.AddUrlSegmentApiVersioning();
services.AddRouting(options =>
{
options.AppendTrailingSlash = true;
options.LowercaseUrls = true;
});
services.AddControllers()
.AddMetrics()
.AddChaos(_configuration)
.AddFluentValidation(config => config.RegisterValidatorsFromAssemblyContaining<Startup>());
services.AddHealthChecks()
.AddCheck<CosmosDBHealthCheck>(Constants.HealthChecks.CosmosDBHCName);
var authzOptions = services.AddAuth(_configuration);
services.AddSwagger(Constants.Swagger.ApiDescription, authzOptions);
services.AddHealthChecksUI().AddInMemoryStorage();
services.AddAppMetricsHealthPublishing();
services.AddApplicationInsightsTelemetry();
services.ConfigurePollyPolicies();
}
The appSettings.json file:
"HealthChecksUI": {
"HealthChecks": [
{
"Name": "Health Check - API",
"Uri": "/health"
}
],
"Webhooks": [],
"EvaluationTimeinSeconds": 10,
"MinimumSecondsBetweenFailureNotifications": 60
},