refactor(kpi): K2/K6/K7 review fixups — empty-batch guard + sealed repo + uniform TryAddEnumerable + KPI-age doc fidelity + coverage
This commit is contained in:
@@ -20,9 +20,12 @@ namespace ZB.MOM.WW.ScadaBridge.SiteCallAudit.Kpi;
|
||||
/// The cutoffs are derived from <see cref="SiteCallAuditOptions"/> exactly as the
|
||||
/// live <c>SiteCallAuditActor</c> KPI handlers derive them
|
||||
/// (<c>stuckCutoff = capturedAtUtc - StuckAgeThreshold</c>,
|
||||
/// <c>intervalSince = capturedAtUtc - KpiInterval</c>) so a sampled value equals
|
||||
/// the live tile computed at the same instant. The recorder's
|
||||
/// <c>capturedAtUtc</c> is the single anchor for both cutoffs.
|
||||
/// <c>intervalSince = capturedAtUtc - KpiInterval</c>). The COUNT metrics
|
||||
/// (buffered, parked, failedLastInterval, deliveredLastInterval, stuck) equal the
|
||||
/// live tile at the same instant; the <c>oldestPendingAgeSeconds</c> metric is
|
||||
/// computed against the repository's internal clock and may differ from the live
|
||||
/// tile by the query-execution latency. The recorder's <c>capturedAtUtc</c> is
|
||||
/// the single anchor for both cutoffs.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Registered DI-scoped (next to the rest of the Site Call Audit composition) so
|
||||
@@ -33,12 +36,13 @@ namespace ZB.MOM.WW.ScadaBridge.SiteCallAudit.Kpi;
|
||||
public sealed class SiteCallAuditKpiSampleSource : IKpiSampleSource
|
||||
{
|
||||
// ── Metric catalog (the M6-agreed metric-name strings for this source) ──
|
||||
// Declaration order matches the emission order in AddSnapshot.
|
||||
private const string MetricBuffered = "buffered";
|
||||
private const string MetricParked = "parked";
|
||||
private const string MetricFailedLastInterval = "failedLastInterval";
|
||||
private const string MetricDeliveredLastInterval = "deliveredLastInterval";
|
||||
private const string MetricOldestPendingAgeSeconds = "oldestPendingAgeSeconds";
|
||||
private const string MetricStuck = "stuck";
|
||||
private const string MetricOldestPendingAgeSeconds = "oldestPendingAgeSeconds";
|
||||
|
||||
private readonly ISiteCallAuditRepository _repository;
|
||||
private readonly SiteCallAuditOptions _options;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Kpi;
|
||||
using ZB.MOM.WW.ScadaBridge.SiteCallAudit.Kpi;
|
||||
|
||||
@@ -44,7 +45,9 @@ public static class ServiceCollectionExtensions
|
||||
// KPIs (global + per-site + per-node) into the KpiSample history store.
|
||||
// Scoped so each pass resolves a fresh ISiteCallAuditRepository scope,
|
||||
// mirroring the actor's scope-per-message repository access.
|
||||
services.AddScoped<IKpiSampleSource, SiteCallAuditKpiSampleSource>();
|
||||
// TryAddEnumerable is idempotent — no double-registration if AddSiteCallAudit
|
||||
// is ever called more than once, matching the AuditLog (K8) idiom.
|
||||
services.TryAddEnumerable(ServiceDescriptor.Scoped<IKpiSampleSource, SiteCallAuditKpiSampleSource>());
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user