feat(health): health checks complets /health/ready + /health/live (Fixes #13)
- Checks enregistrés : PostgreSQL (ready+live), Alarik S3 (ready), CodeProject.AI/Ollama (live) — optionnels → Healthy si non configurés - Routes : /health (alias /healthz), /health/ready (alias /readyz), /health/live → 503 + degradationLevel quand IA dégradée - Fix CI : dashboard Hangfire skip en Testing (Hangfire désactivé → crash au démarrage WebApplicationFactory) — IntegrationTests 125/125 verts
This commit is contained in:
1 parent
e3d14eec04
commit
381410510f
6 files changed
+159
-9
No files matched your search
@@ -9,14 +9,16 @@ public class HealthController : ControllerBase
|
||||
/// <summary>
|
||||
/// Liveness probe — always returns OK if the process is running.
|
||||
/// </summary>
|
||||
[HttpGet("/health")]
|
||||
[HttpGet("/healthz")]
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status200OK)]
|
||||
public IActionResult Health() => Ok(new { status = "healthy", timestamp = DateTime.UtcNow });
|
||||
|
||||
/// <summary>
|
||||
/// Readiness probe — checks if the database is reachable.
|
||||
/// Uses ASP.NET Core health checks infrastructure.
|
||||
/// Readiness probe — checks dependencies (PostgreSQL, Alarik S3).
|
||||
/// 503 when a required dependency is down.
|
||||
/// </summary>
|
||||
[HttpGet("/health/ready")]
|
||||
[HttpGet("/readyz")]
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status503ServiceUnavailable)]
|
||||
@@ -25,10 +27,40 @@ public class HealthController : ControllerBase
|
||||
CancellationToken ct)
|
||||
{
|
||||
var report = await healthCheckService.CheckHealthAsync(
|
||||
_ => true, ct);
|
||||
reg => reg.Tags.Contains("ready"), ct);
|
||||
|
||||
return report.Status == HealthStatus.Healthy
|
||||
? Ok(new { status = "healthy", timestamp = DateTime.UtcNow })
|
||||
: StatusCode(503, new { status = "unhealthy", errors = report.Entries });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Live probe — ready + no active AI degradation. 503 + degradationLevel
|
||||
/// when CodeProject.AI / Ollama is configured but unreachable.
|
||||
/// </summary>
|
||||
[HttpGet("/health/live")]
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status503ServiceUnavailable)]
|
||||
public async Task<IActionResult> Live(
|
||||
[FromServices] HealthCheckService healthCheckService,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var report = await healthCheckService.CheckHealthAsync(
|
||||
reg => reg.Tags.Contains("live"), ct);
|
||||
|
||||
if (report.Status == HealthStatus.Healthy)
|
||||
return Ok(new { status = "healthy", degradationLevel = 0, timestamp = DateTime.UtcNow });
|
||||
|
||||
// Dégradation IA : ready OK mais backends IA (live) down → 503.
|
||||
var degradedEntries = report.Entries
|
||||
.Where(e => e.Value.Status != HealthStatus.Healthy)
|
||||
.ToDictionary(e => e.Key, e => e.Value.Description ?? e.Value.Status.ToString());
|
||||
return StatusCode(503, new
|
||||
{
|
||||
status = "degraded",
|
||||
degradationLevel = 1,
|
||||
errors = degradedEntries,
|
||||
timestamp = DateTime.UtcNow,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user