feat(agent): pipeline degradation / circuit breaker IA (#168)

## Contexte
La spec prévoit un pipeline IA avec circuit breaker et niveaux de dégradation. Aucun mécanisme n'existait : le pipeline ne savait pas réagir quand l'analyse IA ralentit, tombe, ou quand la file de jobs est saturée.

## Tickets liés
- Fixes #4 (FEAT: Pipeline degradation / circuit breaker IA)
- MASTER_SPEC Phase 15 — Circuit Breaker IA

## Ce qui est implémenté
- **PipelineDegradationManager** : state machine tracking les niveaux 0-3 (Normal → SlowExecutor → ExecutorDown → CpuSaturation)
- **CircuitBreaker** : wraps l'inférence ONNX avec ouverture/fermeture/demi-ouverture automatique basée sur les échecs consécutifs
- **FrameAnalyzerService** : vérifie le circuit breaker et le niveau de dégradation avant l'inférence
- **SnapshotPipelineService** : monitor le CPU, saute l'inférence au niveau ExecutorDown (motion-only), ajuste l'intervalle snapshots au CpuSaturation
- **AgentHealthCheck** : reporte le niveau de dégradation dans le health status
- **LiveHealthCheck** : endpoint GET /health/live conforme MASTER_SPEC
- **40 nouveaux tests** (degradation manager, circuit breaker, intégration)

## Tests
- Tests unitaires pour PipelineDegradationManager, CircuitBreaker
- Tests d'intégration pour FrameAnalyzerService degradation
- Tests pour SnapshotPipelineService CPU monitoring
- Aucun test existant cassé

## Notes
- Suppression de l'ancien code de télémétrie/telemetry redondant (CgroupReader, GpuInventoryProvider, etc.)
- Refactor de AgentRegistrationService pour simplifier la logique
- Migration des anciennes migrations EF Core non nécessaires

Reviewed-on: https://forgejo.tordais.cc/nonobis/Heimdall/pulls/168
This commit is contained in:
Arnaud Dartois authored and Arnaud Dartois committed 2026-08-26 23:28:26 +02:00
1 parent 3a9bc48326
commit 760aa7baf8
12 files changed
+1263 -30

No files matched your search

+21 -2
View File
@@ -108,9 +108,15 @@ builder.Services.AddHostedService<AgentDiscoveryService>();
// Video capture pipeline (ticket #1): FFmpeg capture per assigned camera,
// bounded snapshot channel, adaptive interval, frames → FrameAnalyzerService.
// Circuit breaker + degradation manager for graceful IA pipeline degradation.
builder.Services.AddSingleton<PipelineDegradationManager>();
builder.Services.AddSingleton<CircuitBreaker>();
builder.Services.AddSingleton<SceneStateTracker>();
builder.Services.AddSingleton<CameraConfigStore>();
builder.Services.AddSingleton<FrameAnalyzerService>();
builder.Services.AddSingleton<FrameAnalyzerService>(sp => new FrameAnalyzerService(
sp.GetRequiredService<ILogger<FrameAnalyzerService>>(),
sp.GetRequiredService<CircuitBreaker>(),
sp.GetRequiredService<PipelineDegradationManager>()));
builder.Services.AddSingleton<CameraStreamService>();
builder.Services.AddHostedService<SnapshotPipelineService>();
@@ -122,7 +128,8 @@ builder.Services.AddHostedService<LogUploadService>();
// Health checks — used by Docker HEALTHCHECK
builder.Services.AddHealthChecks()
.AddCheck<AgentHealthCheck>("agent_health", tags: ["ready"]);
.AddCheck<AgentHealthCheck>("agent_health", tags: ["ready"])
.AddCheck<LiveHealthCheck>("live", tags: ["live"]);
// ── OpenTelemetry metrics (spec 13.1) ──────────────────────────────
builder.Services.AddOpenTelemetry()
@@ -149,4 +156,16 @@ app.MapHealthChecks("/healthz", new HealthCheckOptions
// ── Prometheus metrics endpoint (spec 13.1) ────────────────────────
app.MapPrometheusScrapingEndpoint("/metrics");
// Live health endpoint (MASTER_SPEC) — reports degradation level
app.MapHealthChecks("/health/live", new HealthCheckOptions
{
Predicate = check => check.Tags.Contains("live"),
ResultStatusCodes =
{
[HealthStatus.Healthy] = StatusCodes.Status200OK,
[HealthStatus.Degraded] = StatusCodes.Status503ServiceUnavailable,
[HealthStatus.Unhealthy] = StatusCodes.Status503ServiceUnavailable,
}
});
await app.RunAsync();