fix(kpi-history): backlogTotal trend records the real site-backlog aggregate instead of a hardwired zero
This commit is contained in:
@@ -3,6 +3,12 @@ using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Kpi;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Kpi;
|
||||
|
||||
// Task 10 (arch-review 04): the append-only repository leaves the snapshot's
|
||||
// BacklogTotal at zero; the real backlog is the cross-site health aggregate that
|
||||
// only the central node knows. An optional IAuditBacklogProvider supplies it so
|
||||
// the *history* sample stops recording a hardwired zero (the live tile already
|
||||
// filled this in). Sites/tests leave it unregistered → null → snapshot fallback.
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.AuditLog.Kpi;
|
||||
|
||||
/// <summary>
|
||||
@@ -44,18 +50,30 @@ public sealed class AuditLogKpiSampleSource : IKpiSampleSource
|
||||
private const string BacklogTotalMetric = KpiMetrics.AuditLog.BacklogTotal;
|
||||
|
||||
private readonly IAuditLogRepository _repository;
|
||||
private readonly IAuditBacklogProvider? _backlogProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AuditLogKpiSampleSource"/> class.
|
||||
/// </summary>
|
||||
/// <param name="repository">
|
||||
/// Append-only Audit Log repository — its <see cref="IAuditLogRepository.GetKpiSnapshotAsync"/>
|
||||
/// supplies the volume, error, and backlog counts snapshotted here.
|
||||
/// supplies the volume and error counts snapshotted here (its <c>BacklogTotal</c>
|
||||
/// is always zero — see <paramref name="backlogProvider"/>).
|
||||
/// </param>
|
||||
public AuditLogKpiSampleSource(IAuditLogRepository repository)
|
||||
/// <param name="backlogProvider">
|
||||
/// Optional cross-site backlog aggregate. When registered (central node), the
|
||||
/// <c>backlogTotal</c> sample records its value; when absent (sites / unit tests,
|
||||
/// where MS.DI resolves the default) the source falls back to the snapshot's own
|
||||
/// <c>BacklogTotal</c> — i.e. zero, the pre-Task-10 behavior. Injecting the seam
|
||||
/// keeps the append-only repo out of the in-memory health aggregator.
|
||||
/// </param>
|
||||
public AuditLogKpiSampleSource(
|
||||
IAuditLogRepository repository,
|
||||
IAuditBacklogProvider? backlogProvider = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(repository);
|
||||
_repository = repository;
|
||||
_backlogProvider = backlogProvider;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -78,11 +96,15 @@ public sealed class AuditLogKpiSampleSource : IKpiSampleSource
|
||||
return [];
|
||||
}
|
||||
|
||||
// Backlog: the provider's cross-site aggregate when registered (central),
|
||||
// otherwise the snapshot's own value (zero) as the site/test fallback.
|
||||
var backlogTotal = _backlogProvider?.GetPendingBacklogTotal() ?? snapshot.BacklogTotal;
|
||||
|
||||
return
|
||||
[
|
||||
Sample(TotalEventsLastHourMetric, snapshot.TotalEventsLastHour, capturedAtUtc),
|
||||
Sample(ErrorEventsLastHourMetric, snapshot.ErrorEventsLastHour, capturedAtUtc),
|
||||
Sample(BacklogTotalMetric, snapshot.BacklogTotal, capturedAtUtc),
|
||||
Sample(BacklogTotalMetric, backlogTotal, capturedAtUtc),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user