fix(agent): report actual pipeline degradation level
Heimdall Gitea / Detect CI scope (pull_request) Successful in 5s
Heimdall Gitea / Build and tests (pull_request) Failing after 5m27s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Failing after 1s

This commit is contained in:
Arnaud Dartois committed 2026-10-25 13:47:41 +01:00
1 parent fea873ee97
commit 1143b0dfa4
5 files changed
+39 -9

No files matched your search

@@ -1,5 +1,6 @@
using System.Diagnostics;
using System.Threading;
using Heimdall.Application.Metrics;
using Microsoft.Extensions.Logging;
namespace Heimdall.Agent.Services;
@@ -265,6 +266,7 @@ public sealed class PipelineDegradationManager
// Caller must hold _lock
var oldLevel = _level;
_level = newLevel;
HeimdallMetrics.SetPipelineLevel((int)newLevel);
if (newLevel > _highestLevel)
_highestLevel = newLevel;
@@ -336,12 +336,6 @@ public sealed class SnapshotPipelineService : BackgroundService
_logger.LogWarning(ex, "Snapshot analysis failed for camera {CameraId}", snapshot.CameraId);
}
// Update pipeline degradation level (spec 13.1)
var failures = Interlocked.Read(ref _analysisFailures);
var processed = Interlocked.Read(ref _snapshotsProcessed);
var failureRate = processed > 0 ? (double)failures / processed : 0;
var pipelineLevel = failureRate > 0.5 ? 2 : failureRate > 0.1 ? 1 : 0;
HeimdallMetrics.SetPipelineLevel(pipelineLevel);
}
}
catch (OperationCanceledException)
@@ -102,14 +102,14 @@ public static class HeimdallMetrics
observeValue: () => new Measurement<int>(
Volatile.Read(ref _pipelineLevel),
tags: default),
description: "Niveau de dégradation actuel du pipeline IA (0=normal, 1=degraded, 2=critical)");
description: "Niveau de dégradation actuel du pipeline IA (0=normal, 1=slow, 2=down, 3=saturation CPU)");
private static int _pipelineLevel;
/// <summary>
/// Set the current pipeline degradation level.
/// </summary>
/// <param name="level">0=normal, 1=degraded, 2=critical</param>
/// <param name="level">0=normal, 1=slow, 2=down, 3=CPU saturation</param>
public static void SetPipelineLevel(int level) => Volatile.Write(ref _pipelineLevel, level);
private static readonly ObservableGauge<double> SnapshotIntervalGauge =