feat(adminui): driver Controls status panel shows one entry per reporting node (#851)

DriverStatusPanel (the /hosts Controls dialog) showed one snapshot per driver - the most
recently published across both nodes of the redundant pair - so a driver Faulted on one node
and Healthy on its peer flipped on every publish. It now primes from the store's GetAll() and
keeps one entry per ReportingNodeId (DriverStatusByNode): per-node state chip in the header,
per-node last-success / 5-min errors / last error, per-node stale dimming. A snapshot with no
node id (pre-#847 publisher) renders unlabelled, sorted last. A primed copy older than a racing
live publish for the same node is dropped.
This commit is contained in:
Joseph Doherty
2026-11-11 06:16:06 -05:00
parent d1b6cad299
commit b40f08e187
3 changed files with 294 additions and 50 deletions
@@ -1,9 +1,11 @@
@* Live driver-status panel — subscribes to /hubs/driverstatus and shows state chip,
last-success age, 5-min error count, and last error message.
@* Live driver-status panel — reads the in-process driver-health snapshot store and shows, PER REPORTING NODE
(lmxopcua#851 — both nodes of a redundant pair run the driver), the state chip, last-success age, 5-min error
count and last error message. A snapshot from a node that predates ReportingNodeId (#847) renders unlabelled.
Enabled=false renders a static "Disabled" notice and never opens the hub.
DriverOperator-gated Reconnect/Restart buttons appear for authorised users. *@
@implements IAsyncDisposable
@using Microsoft.AspNetCore.Authorization
@using ZB.MOM.WW.OtOpcUa.AdminUI.Hosts
@using ZB.MOM.WW.OtOpcUa.AdminUI.Hubs
@using ZB.MOM.WW.OtOpcUa.Commons.Interfaces
@using ZB.MOM.WW.OtOpcUa.Commons.Messages.Admin
@@ -14,12 +16,18 @@
@inject IDriverStatusSnapshotStore StatusStore
@inject IDriverResilienceStatusStore ResilienceStore
<section class="panel rise mt-3" style="animation-delay:.04s; @(_stale ? "opacity:0.5;" : "")">
<div class="panel-head d-flex align-items-center gap-2">
@{ var nodes = _byNode?.Entries ?? []; var now = DateTime.UtcNow; }
<section class="panel rise mt-3" style="animation-delay:.04s">
<div class="panel-head d-flex align-items-center gap-2 flex-wrap">
<span>Driver status</span>
@if (_snapshot is not null)
@if (nodes.Count > 0)
{
<span class="chip @ChipClass(_snapshot.State)">@_snapshot.State</span>
@foreach (var n in nodes)
{
<span @key="@($"head-{n.Key}")" class="chip @ChipClass(n.Snapshot.State)"
style="@(n.IsStale(now, StaleAfter) ? "opacity:0.5;" : "")"
title="@(n.NodeId is null ? "Reported by a node that predates per-node health (#847)" : $"Reported by {n.NodeId}")">@(nodes.Count > 1 || n.NodeId is not null ? $"{n.Label}: " : "")@n.Snapshot.State</span>
}
}
else if (!Enabled)
{
@@ -40,37 +48,51 @@
{
<p class="mb-0" style="color:var(--bad)" title="@_error">SignalR error: @DisplayText.Abbreviate(_error, 60)</p>
}
else if (_snapshot is null)
else if (nodes.Count == 0)
{
<p class="mb-0" style="color:var(--ink-faint)">Awaiting first snapshot&hellip;</p>
}
else
{
<div class="d-flex flex-wrap gap-3 align-items-baseline">
<span style="color:var(--ink-soft)">
Last success:
@if (_snapshot.LastSuccessfulReadUtc is { } t)
{
<strong>@HumanizeAge(t) ago</strong>
}
else
{
<strong>never</strong>
}
</span>
@if (_snapshot.ErrorCount5Min > 0)
{
<span class="chip chip-bad">@_snapshot.ErrorCount5Min error@(_snapshot.ErrorCount5Min == 1 ? "" : "s") / 5 min</span>
}
</div>
@if (_snapshot.LastError is { Length: > 0 } lastError)
@foreach (var n in nodes)
{
<details class="mt-2" style="font-size:0.85rem">
<summary style="cursor:pointer; color:var(--ink-soft)">Last error</summary>
<pre class="mt-1 mb-0" style="white-space:pre-wrap; word-break:break-word; color:var(--bad); font-size:0.8rem">@lastError</pre>
</details>
var snap = n.Snapshot;
<div @key="@($"node-{n.Key}")" class="@(n == nodes[0] ? "" : "mt-3 pt-2 border-top")"
style="@(n.IsStale(now, StaleAfter) ? "opacity:0.5;" : "")">
<div class="d-flex flex-wrap gap-3 align-items-baseline">
<span class="mono" style="font-weight:600"
title="@(n.NodeId is null ? "Reported by a node that predates per-node health (#847)" : "Reporting node")">@n.Label</span>
<span class="chip @ChipClass(snap.State)">@snap.State</span>
<span style="color:var(--ink-soft)">
Last success:
@if (snap.LastSuccessfulReadUtc is { } t)
{
<strong>@HumanizeAge(t) ago</strong>
}
else
{
<strong>never</strong>
}
</span>
@if (snap.ErrorCount5Min > 0)
{
<span class="chip chip-bad">@snap.ErrorCount5Min error@(snap.ErrorCount5Min == 1 ? "" : "s") / 5 min</span>
}
@if (n.IsStale(now, StaleAfter))
{
<span class="chip chip-idle" title="No snapshot from this node for over @((int)StaleAfter.TotalSeconds) s">stale</span>
}
</div>
@if (snap.LastError is { Length: > 0 } lastError)
{
<details class="mt-2" style="font-size:0.85rem">
<summary style="cursor:pointer; color:var(--ink-soft)">Last error</summary>
<pre class="mt-1 mb-0" style="white-space:pre-wrap; word-break:break-word; color:var(--bad); font-size:0.8rem">@lastError</pre>
</details>
}
</div>
}
}
@@ -194,9 +216,10 @@
[Parameter] public string ClusterId { get; set; } = "";
[Parameter] public bool Enabled { get; set; } = true;
private DriverHealthChanged? _snapshot;
private DateTime _lastUpdateUtc = DateTime.MinValue;
private bool _stale;
// One entry per reporting node (lmxopcua#851). Created in OnInitializedAsync once DriverInstanceId is bound.
// Staleness is per node: a node that stops publishing dims on its own while its peer stays live.
private DriverStatusByNode? _byNode;
private static readonly TimeSpan StaleAfter = TimeSpan.FromSeconds(30);
// Per-host resilience snapshots for THIS instance, keyed by HostName. Fed by the
// driver-resilience-status DPS store (read in-process, same house pattern as the health store).
@@ -234,13 +257,11 @@
_connecting = true;
// Tick every 5 s to refresh the stale-dimming check and humanized ages.
_timer = new System.Threading.Timer(_ =>
{
_stale = _snapshot is not null &&
(DateTime.UtcNow - _lastUpdateUtc).TotalSeconds > 30;
InvokeAsync(StateHasChanged);
}, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5));
_byNode = new DriverStatusByNode(DriverInstanceId);
// Tick every 5 s to re-render the per-node stale dimming and humanized ages.
_timer = new System.Threading.Timer(_ => InvokeAsync(StateHasChanged),
null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5));
// Read live status straight from the in-process snapshot store rather than opening a
// self-targeted SignalR connection. This component runs server-side (Blazor
@@ -252,12 +273,12 @@
// this circuit.
try
{
// Subscribe BEFORE priming so a publish racing the read is not missed; a primed copy that lands after
// a newer racing live one is dropped by Upsert (it keeps the later PublishedUtc per node).
StatusStore.SnapshotChanged += OnSnapshotChanged;
if (StatusStore.TryGet(DriverInstanceId, out var snap))
{
_snapshot = snap;
_lastUpdateUtc = DateTime.UtcNow;
}
var primedUtc = DateTime.UtcNow;
foreach (var snap in StatusStore.GetAll())
_byNode.Upsert(snap, primedUtc);
// Prime + subscribe the resilience store (same in-process read pattern as the health store).
ResilienceStore.SnapshotChanged += OnResilienceChanged;
@@ -278,12 +299,9 @@
// ignore snapshots for other instances and marshal onto the render sync context.
private void OnSnapshotChanged(DriverHealthChanged snap)
{
if (!string.Equals(snap.DriverInstanceId, DriverInstanceId, StringComparison.Ordinal))
if (_byNode is null || !_byNode.Upsert(snap, DateTime.UtcNow))
return;
_snapshot = snap;
_lastUpdateUtc = DateTime.UtcNow;
_stale = false;
InvokeAsync(StateHasChanged);
}