8da60f57ac
LocalDbOplogBacklog was reported and Prometheus-exported with nothing consuming it: not sampled into KPI history, so a purge-burst spike could not be reviewed after the fact, and no threshold treatment anywhere. Both halves shipped. KPI SAMPLING. SiteHealthKpiSampleSource now emits localDbOplogBacklog and localDbReplicationConnected (0/1), and the backlog is charted on the Health dashboard's per-site trend panel. Charting is the point: a point-in-time tile can never answer 'did that spike drain?', which is the only thing separating an expected purge burst from a stalled peer. Both are CONDITIONALLY emitted rather than coerced with ?? 0 like the auditBacklogPending metric beside them. Both health-report fields are nullable and null means 'no reading' — replication not configured (rig site-b/site-c) or a failed poll — never zero. A fabricated 0 would render a pair that cannot read its own oplog, or one deliberately unreplicated, as perfectly healthy once a minute forever, burying the real series. So a site emits 12 metrics when unreplicated and 14 when replicated, and a GAP in these two series truthfully means 'not replicated / not reporting'. Note false and null differ for the connected flag: a configured link that is DOWN samples as 0; no link samples as nothing. Both fold as Gauge (summing an oplog depth, or a 0/1 flag, per hour is meaningless). THRESHOLD SEMANTICS — sustained, not instantaneous. This is the design, not a refinement. The site_events retention purge is CDC-captured like any other write, so the backlog jumps by the deleted batch and drains as the peer acks it; a bare 'backlog > threshold' badge would fire on every replicated site every day and be ignored within a week. Healthy is defined by the backlog RETURNING to ~0, which only a dwell can express. CentralHealthAggregator holds LocalDbBacklogAboveSince — the instant the backlog first rose above LocalDbBacklogThreshold (default 1000) — and the badge appears only after LocalDbBacklogSustainedFor (default 15 min). A report at or below the threshold clears the anchor; one above leaves the ORIGINAL instant intact, so the window is sustained rather than sliding. The null case is deliberately a third branch: a null backlog leaves the anchor UNCHANGED rather than clearing it. Null is evidence neither of a drain nor of a backlog, so a node going blind mid-climb must not silently reset its own dwell, and an unreplicated site (null forever) never accumulates an anchor and can never be badged. Validation rejects a non-positive threshold (0 would badge every replicated site permanently, since an idle backlog already sits at it) and a dwell shorter than one ReportInterval (satisfiable by a single sample, which collapses the check back into the bare threshold it replaces). DOC CORRECTION worth flagging: this row's premise was 'mirror the SiteAuditBacklog configurable threshold badge'. That badge does not exist — Component-HealthMonitoring.md described it in two places but no option, no comparison and no markup were ever implemented. The two stale claims are corrected here rather than left to send the next reader looking for it; the LocalDb badge is built fresh on the Metrics-stale badge's pattern, which is a real configurable-threshold badge. Tests: HealthMonitoring 115 (9 new aggregator tests incl. purge-burst-drains, unreplicated-never-anchors, null-mid-climb, exact-threshold, stale-report; 5 new validator tests; 4 new sampler tests incl. the null-semantics and false-vs-null cases); CentralUI 1042 (5 new badge/chart tests incl. the purge-burst negative control); Commons Kpi 93; KpiHistory 54.
64 lines
3.7 KiB
C#
64 lines
3.7 KiB
C#
namespace ZB.MOM.WW.ScadaBridge.HealthMonitoring;
|
|
|
|
public class HealthMonitoringOptions
|
|
{
|
|
/// <summary>Interval at which sites emit health reports to the central cluster.</summary>
|
|
public TimeSpan ReportInterval { get; set; } = TimeSpan.FromSeconds(30);
|
|
/// <summary>Duration of silence after which a site is classified as offline.</summary>
|
|
public TimeSpan OfflineTimeout { get; set; } = TimeSpan.FromMinutes(1);
|
|
|
|
/// <summary>
|
|
/// Offline timeout applied to the synthetic "central" site only. Real sites
|
|
/// emit frequent heartbeats that keep <c>LastHeartbeatAt</c> fresh, so the
|
|
/// normal <see cref="OfflineTimeout"/> only fires on genuine total loss. The
|
|
/// "central" self-report has no heartbeat source — its only signal is the
|
|
/// 30s <see cref="CentralHealthReportLoop"/>, so a single skipped/late
|
|
/// self-report (leader GC pause, brief stall, mid-failover before the new
|
|
/// leader's loop spins up) would flap it offline under the 60s site timeout.
|
|
/// A longer central grace gives the equivalent of "one missed report" that
|
|
/// the design doc grants real sites. Default: 3x the report interval.
|
|
/// </summary>
|
|
public TimeSpan CentralOfflineTimeout { get; set; } = TimeSpan.FromMinutes(3);
|
|
|
|
/// <summary>
|
|
/// Duration an online site may go without a full health <em>report</em>
|
|
/// (heartbeats notwithstanding) before it is flagged
|
|
/// <see cref="SiteHealthState.IsMetricsStale"/>. Distinct from
|
|
/// <see cref="OfflineTimeout"/>, which is heartbeat-based liveness: a site
|
|
/// whose HealthReportSender has died keeps heartbeating and stays "online",
|
|
/// but its metrics freeze — this window surfaces that. Must be positive and
|
|
/// no shorter than <see cref="ReportInterval"/> (a window shorter than one
|
|
/// report interval would flag every healthy site). Default: 2 minutes
|
|
/// (~4 missed 30s reports).
|
|
/// </summary>
|
|
public TimeSpan MetricsStaleTimeout { get; set; } = TimeSpan.FromMinutes(2);
|
|
|
|
/// <summary>
|
|
/// Unacked LocalDb replication oplog depth above which a site is considered backlogged
|
|
/// (register row 33). Crossing this alone shows nothing — the backlog must also stay
|
|
/// above it for <see cref="LocalDbBacklogSustainedFor"/> before the Health dashboard
|
|
/// badges the site. Must be positive. Default: <c>1000</c> entries.
|
|
/// </summary>
|
|
public long LocalDbBacklogThreshold { get; set; } = 1000;
|
|
|
|
/// <summary>
|
|
/// How long the oplog backlog must stay continuously above
|
|
/// <see cref="LocalDbBacklogThreshold"/> before the Health dashboard badges the site
|
|
/// (register row 33).
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// This dwell time is the whole point of the signal, not a refinement of it. A bare
|
|
/// threshold would fire every single day on a healthy replicated site: the `site_events`
|
|
/// retention purge and the storage-cap trim are CDC-captured like any other write, so the
|
|
/// backlog jumps by the deleted batch size and then drains as the peer acks it. That spike
|
|
/// is expected and documented (see <c>docs/deployment/topology-guide.md</c> → *Reading the
|
|
/// replication backlog*). Healthy means the backlog RETURNS TO ~0; unhealthy means it
|
|
/// stays up. Only a sustained window can tell those apart, so the default is set well
|
|
/// clear of a purge drain. Must be positive and no shorter than
|
|
/// <see cref="ReportInterval"/> — a window shorter than one report interval could be
|
|
/// satisfied by a single sample, which is exactly the bare threshold this exists to avoid.
|
|
/// Default: 15 minutes.
|
|
/// </remarks>
|
|
public TimeSpan LocalDbBacklogSustainedFor { get; set; } = TimeSpan.FromMinutes(15);
|
|
}
|