-
Notifications
You must be signed in to change notification settings - Fork 14
Closed
Labels
.NETPull requests that update .NET codePull requests that update .NET codeenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Description
Description
Introduce a standardized health check endpoint to expose the application’s health status for monitoring and orchestration purposes. This endpoint will:
- Report overall application health and availability.
- Validate critical subsystems (e.g., database connectivity).
- Support liveness and readiness probes.
- Provide a JSON payload with detailed health information.
- Optionally integrate with a UI dashboard for visual monitoring.
- Allow unauthenticated access for monitoring tools.
Suggested Approach
- Register health check services
InProgram.cs, add the health check services:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHealthChecks();- Map the health check endpoint
Configure the middleware pipeline to expose/health:
var app = builder.Build();
app.MapHealthChecks("/health");
app.Run();- Add dependency-specific checks
Chain additional checks for critical dependencies:
builder.Services.AddHealthChecks()
.AddSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"), name: "sql");- Customize JSON response
UseHealthCheckOptions.ResponseWriterto output a structured JSON payload:
app.MapHealthChecks("/health", new HealthCheckOptions
{
ResponseWriter = async (context, report) =>
await CustomJsonResponseWriter(context, report)
});- Enable anonymous access
Update endpoint routing or authorization policies to allow unauthenticated probes on/health(per Steve Gordon’s pattern):
app.MapHealthChecks("/health").AllowAnonymous();- (Optional) Integrate UI dashboard
Add the UI viewer package and configure its endpoint for real‑time health metrics:
builder.Services.AddHealthChecksUI();
app.MapHealthChecksUI();Acceptance Criteria
/healthresponds with HTTP 200 when all checks are Healthy, and HTTP 503 when any check is Degraded or Unhealthy.- Response includes structured JSON output with fields like
status,totalDuration, and individual check details. - At least one dependency (e.g., SQL Server) is checked and reflected in the health response.
- The
/healthendpoint is accessible without authentication. - Health check configuration is manageable via
appsettings.json. - Automated tests validate Healthy, Degraded, and Unhealthy responses.
References
Metadata
Metadata
Assignees
Labels
.NETPull requests that update .NET codePull requests that update .NET codeenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers