Bundle G of Audit Log #23 M2. Bridges the FallbackAuditWriter primary- failure counter into the Site Health Monitoring report payload so a sustained audit-write outage surfaces on /monitoring/health instead of disappearing into a NoOp sink. - SiteHealthReport: add SiteAuditWriteFailures (defaulted, additive). - ISiteHealthCollector + SiteHealthCollector: new IncrementSiteAuditWriteFailures() counter, per-interval reset semantics matching ScriptErrorCount / DeadLetterCount. - HealthMetricsAuditWriteFailureCounter: adapter forwarding IAuditWriteFailureCounter.Increment() to the collector. - AddAuditLogHealthMetricsBridge(): swaps the NoOp default registration for the real bridge; called from SiteServiceRegistration after AddSiteHealthMonitoring + AddAuditLog. - Existing host-wiring test updated: site composition now resolves HealthMetricsAuditWriteFailureCounter (not NoOp). Tests: HealthMonitoring 60 -> 63 (3 new), AuditLog 56 -> 59 (3 new), full solution green.
34 lines
1.4 KiB
C#
34 lines
1.4 KiB
C#
using ScadaLink.HealthMonitoring;
|
|
|
|
namespace ScadaLink.AuditLog.Site;
|
|
|
|
/// <summary>
|
|
/// Audit Log (#23) M2 Bundle G — bridges <see cref="IAuditWriteFailureCounter"/>
|
|
/// (incremented by <see cref="FallbackAuditWriter"/> every time the primary
|
|
/// SQLite writer throws) into <see cref="ISiteHealthCollector"/> so the count
|
|
/// surfaces in the site health report payload as
|
|
/// <c>SiteHealthReport.SiteAuditWriteFailures</c>.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Registered by <see cref="ServiceCollectionExtensions.AddAuditLogHealthMetricsBridge"/>;
|
|
/// callers must register <c>AddHealthMonitoring()</c> first so
|
|
/// <see cref="ISiteHealthCollector"/> resolves. The default <see cref="AddAuditLog"/>
|
|
/// registration keeps <see cref="NoOpAuditWriteFailureCounter"/> for nodes
|
|
/// where Site Health Monitoring is not wired (the silent-sink contract — audit
|
|
/// write failures must NEVER abort the user-facing action, alog.md §7).
|
|
/// </para>
|
|
/// </remarks>
|
|
public sealed class HealthMetricsAuditWriteFailureCounter : IAuditWriteFailureCounter
|
|
{
|
|
private readonly ISiteHealthCollector _collector;
|
|
|
|
public HealthMetricsAuditWriteFailureCounter(ISiteHealthCollector collector)
|
|
{
|
|
_collector = collector ?? throw new ArgumentNullException(nameof(collector));
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public void Increment() => _collector.IncrementSiteAuditWriteFailures();
|
|
}
|