fix(adminui): lane D-b review r0 fixes (I1, M1, M2, M5-M9, N1-N3, N5, H3)
I1: /hosts eviction keyed off the AUTHORED DriverInstances, so a driver deleted in /raw but not yet deployed - still running, still publishing - vanished every tick. The stores' sweep is now EvictUnconfiguredStale(set, olderThanUtc): an entry goes only when unconfigured AND its PublishedUtc is older than 60 s. Tests cover unconfigured+fresh kept (positive control), unconfigured+stale evicted, configured+stale kept, and the deploy hand-off. M1: Test Connect falls back to the driver's documented ProbeTimeoutSeconds default (Galaxy 30, OpcUaClient 15, ...) when the key is absent. M2: the budget never undercuts the config's root timeoutMs (+1 s). M5: RawBrowseModal compares the open generation captured before the await, so a close-then-reopen mid-open closes the stale session. M6: /alarms-historian keeps a 30 s re-poll on 'not registered' (a driver node may still be starting) instead of stopping for good. M7: /scripts source fetch failure shows in the dialog, not the error boundary. M8: the export modal maps only its preview rows; the endpoint writes via Results.Text (no second byte[] copy). M9: /hosts config queries are ordered, so SequenceEqual change detection holds. N1 tooltip, N2 CRLF-safe regex, N3 throttled Warning for subscriber faults, N5 equipment-import help text now describes RFC 4180 quoting. H3: MonacoEditor documents that themes are page-global. Refs #745 Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
This commit is contained in:
@@ -28,15 +28,20 @@ public interface IDriverResilienceStatusStore
|
||||
IReadOnlyCollection<DriverResilienceStatusChanged> GetAll();
|
||||
|
||||
/// <summary>
|
||||
/// Evicts every snapshot whose driver instance is not in <paramref name="configuredInstanceIds"/>.
|
||||
/// The stores have no other removal path, so a deleted (or re-created under a new id) driver would
|
||||
/// otherwise keep its last snapshot until the process restarts. The <c>/hosts</c> page calls this
|
||||
/// after each successful config load; a failed load must never call it with an empty set.
|
||||
/// Evicts every snapshot whose driver instance is not in <paramref name="configuredInstanceIds"/>
|
||||
/// <b>and</b> whose last publish is older than <paramref name="olderThanUtc"/>. The stores have no other
|
||||
/// removal path, so a deleted (or re-created under a new id) driver would otherwise keep its last
|
||||
/// snapshot until the process restarts. Both conditions are required: the configured set comes from
|
||||
/// the AUTHORED (draft) table, so a driver deleted in <c>/raw</c> but not yet deployed is still
|
||||
/// running and still publishing — it must stay visible until a deploy actually stops it and its
|
||||
/// snapshot goes stale. The <c>/hosts</c> page calls this after each successful config load; a failed
|
||||
/// load must never call it.
|
||||
/// </summary>
|
||||
/// <param name="configuredInstanceIds">The configured driver-instance ids to keep. The set's own
|
||||
/// comparer decides matching.</param>
|
||||
/// <param name="olderThanUtc">Only an unconfigured entry published before this instant is evicted.</param>
|
||||
/// <returns>The number of entries removed.</returns>
|
||||
int RetainOnly(IReadOnlySet<string> configuredInstanceIds);
|
||||
int EvictUnconfiguredStale(IReadOnlySet<string> configuredInstanceIds, DateTime olderThanUtc);
|
||||
|
||||
/// <summary>
|
||||
/// Raised after every <see cref="Upsert"/> with the just-stored snapshot. Lets the Blazor Server
|
||||
|
||||
@@ -26,15 +26,20 @@ public interface IDriverStatusSnapshotStore
|
||||
IReadOnlyCollection<DriverHealthChanged> GetAll();
|
||||
|
||||
/// <summary>
|
||||
/// Evicts every snapshot whose driver instance is not in <paramref name="configuredInstanceIds"/>.
|
||||
/// The stores have no other removal path, so a deleted (or re-created under a new id) driver would
|
||||
/// otherwise keep its last snapshot until the process restarts. The <c>/hosts</c> page calls this
|
||||
/// after each successful config load; a failed load must never call it with an empty set.
|
||||
/// Evicts every snapshot whose driver instance is not in <paramref name="configuredInstanceIds"/>
|
||||
/// <b>and</b> whose last publish is older than <paramref name="olderThanUtc"/>. The stores have no other
|
||||
/// removal path, so a deleted (or re-created under a new id) driver would otherwise keep its last
|
||||
/// snapshot until the process restarts. Both conditions are required: the configured set comes from
|
||||
/// the AUTHORED (draft) table, so a driver deleted in <c>/raw</c> but not yet deployed is still
|
||||
/// running and still publishing — it must stay visible until a deploy actually stops it and its
|
||||
/// snapshot goes stale. The <c>/hosts</c> page calls this after each successful config load; a failed
|
||||
/// load must never call it.
|
||||
/// </summary>
|
||||
/// <param name="configuredInstanceIds">The configured driver-instance ids to keep. The set's own
|
||||
/// comparer decides matching.</param>
|
||||
/// <param name="olderThanUtc">Only an unconfigured entry published before this instant is evicted.</param>
|
||||
/// <returns>The number of entries removed.</returns>
|
||||
int RetainOnly(IReadOnlySet<string> configuredInstanceIds);
|
||||
int EvictUnconfiguredStale(IReadOnlySet<string> configuredInstanceIds, DateTime olderThanUtc);
|
||||
|
||||
/// <summary>
|
||||
/// Raised after every <see cref="Upsert"/> with the just-stored snapshot. Lets in-process
|
||||
|
||||
@@ -62,6 +62,7 @@ public sealed class InProcessBroadcaster<T> : IInProcessBroadcaster<T>
|
||||
private readonly object _connectionLock = new();
|
||||
private bool _isConnected;
|
||||
private readonly ILogger<InProcessBroadcaster<T>>? _logger;
|
||||
private readonly FailureLogThrottle _failureLog = new();
|
||||
|
||||
/// <summary>Creates the broadcaster.</summary>
|
||||
/// <param name="logger">Optional logger for a subscriber that throws during a raise.</param>
|
||||
@@ -77,7 +78,7 @@ public sealed class InProcessBroadcaster<T> : IInProcessBroadcaster<T>
|
||||
// Capture-then-invoke so a concurrent unsubscribe can't null the delegate mid-raise; one subscriber
|
||||
// at a time so a throwing one cannot starve the rest or escape onto the bridge actor.
|
||||
public void Publish(T item) =>
|
||||
SafeMulticast.Invoke(Received, item, ex => _logger?.LogDebug(ex, "In-process broadcast subscriber threw"));
|
||||
SafeMulticast.Invoke(Received, item, ex => _logger?.Log(_failureLog.NextLevel(), ex, "In-process broadcast subscriber threw"));
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsConnected
|
||||
@@ -109,6 +110,6 @@ public sealed class InProcessBroadcaster<T> : IInProcessBroadcaster<T>
|
||||
}
|
||||
|
||||
SafeMulticast.Invoke(handler, connected,
|
||||
ex => _logger?.LogDebug(ex, "In-process connection-state subscriber threw"));
|
||||
ex => _logger?.Log(_failureLog.NextLevel(), ex, "In-process connection-state subscriber threw"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ public sealed class InMemoryDriverResilienceStatusStore : IDriverResilienceStatu
|
||||
{
|
||||
private readonly ConcurrentDictionary<(string Instance, string Host), DriverResilienceStatusChanged> _byPair = new();
|
||||
private readonly ILogger<InMemoryDriverResilienceStatusStore>? _logger;
|
||||
private readonly FailureLogThrottle _failureLog = new();
|
||||
|
||||
/// <summary>Creates the store.</summary>
|
||||
/// <param name="logger">Optional logger for a subscriber that throws during a raise.</param>
|
||||
@@ -28,16 +29,18 @@ public sealed class InMemoryDriverResilienceStatusStore : IDriverResilienceStatu
|
||||
// Capture-then-invoke so a concurrent unsubscribe can't null the delegate mid-raise; one
|
||||
// subscriber at a time so a throwing one cannot starve the rest (or escape onto the bridge actor).
|
||||
SafeMulticast.Invoke(SnapshotChanged, snapshot,
|
||||
ex => _logger?.LogDebug(ex, "Driver resilience subscriber threw for {DriverInstanceId}", snapshot.DriverInstanceId));
|
||||
ex => _logger?.Log(_failureLog.NextLevel(), ex, "Driver resilience subscriber threw for {DriverInstanceId}", snapshot.DriverInstanceId));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int RetainOnly(IReadOnlySet<string> configuredInstanceIds)
|
||||
public int EvictUnconfiguredStale(IReadOnlySet<string> configuredInstanceIds, DateTime olderThanUtc)
|
||||
{
|
||||
var removed = 0;
|
||||
foreach (var key in _byPair.Keys)
|
||||
foreach (var (key, snapshot) in _byPair)
|
||||
{
|
||||
if (!configuredInstanceIds.Contains(key.Instance) && _byPair.TryRemove(key, out _)) removed++;
|
||||
if (configuredInstanceIds.Contains(key.Instance) || snapshot.PublishedUtc >= olderThanUtc) continue;
|
||||
// Remove only the exact snapshot inspected: a fresh publish that raced in is kept.
|
||||
if (_byPair.TryRemove(new KeyValuePair<(string Instance, string Host), DriverResilienceStatusChanged>(key, snapshot))) removed++;
|
||||
}
|
||||
|
||||
return removed;
|
||||
|
||||
@@ -12,6 +12,7 @@ public sealed class InMemoryDriverStatusSnapshotStore : IDriverStatusSnapshotSto
|
||||
{
|
||||
private readonly ConcurrentDictionary<string, DriverHealthChanged> _byInstance = new();
|
||||
private readonly ILogger<InMemoryDriverStatusSnapshotStore>? _logger;
|
||||
private readonly FailureLogThrottle _failureLog = new();
|
||||
|
||||
/// <summary>Creates the store.</summary>
|
||||
/// <param name="logger">Optional logger for a subscriber that throws during a raise.</param>
|
||||
@@ -28,16 +29,18 @@ public sealed class InMemoryDriverStatusSnapshotStore : IDriverStatusSnapshotSto
|
||||
// Capture-then-invoke so a concurrent unsubscribe can't null the delegate mid-raise; one
|
||||
// subscriber at a time so a throwing one cannot starve the rest (or escape onto the bridge actor).
|
||||
SafeMulticast.Invoke(SnapshotChanged, snapshot,
|
||||
ex => _logger?.LogDebug(ex, "Driver status subscriber threw for {DriverInstanceId}", snapshot.DriverInstanceId));
|
||||
ex => _logger?.Log(_failureLog.NextLevel(), ex, "Driver status subscriber threw for {DriverInstanceId}", snapshot.DriverInstanceId));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int RetainOnly(IReadOnlySet<string> configuredInstanceIds)
|
||||
public int EvictUnconfiguredStale(IReadOnlySet<string> configuredInstanceIds, DateTime olderThanUtc)
|
||||
{
|
||||
var removed = 0;
|
||||
foreach (var id in _byInstance.Keys)
|
||||
foreach (var (id, snapshot) in _byInstance)
|
||||
{
|
||||
if (!configuredInstanceIds.Contains(id) && _byInstance.TryRemove(id, out _)) removed++;
|
||||
if (configuredInstanceIds.Contains(id) || snapshot.PublishedUtc >= olderThanUtc) continue;
|
||||
// Remove only the exact snapshot inspected: a fresh publish that raced in is kept.
|
||||
if (_byInstance.TryRemove(new KeyValuePair<string, DriverHealthChanged>(id, snapshot))) removed++;
|
||||
}
|
||||
|
||||
return removed;
|
||||
|
||||
@@ -1,5 +1,34 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Hubs;
|
||||
|
||||
/// <summary>
|
||||
/// Logs a subscriber failure at Warning at most once per <see cref="Interval"/>, and at Debug otherwise,
|
||||
/// so a subscriber that throws on every publish is visible at the default level without flooding it.
|
||||
/// </summary>
|
||||
internal sealed class FailureLogThrottle
|
||||
{
|
||||
/// <summary>The minimum gap between Warning-level entries.</summary>
|
||||
public static readonly TimeSpan Interval = TimeSpan.FromMinutes(1);
|
||||
|
||||
private readonly Func<long> _nowMs;
|
||||
private long _lastWarnMs = long.MinValue;
|
||||
|
||||
/// <summary>Creates the throttle.</summary>
|
||||
/// <param name="nowMs">Monotonic milliseconds; <see cref="Environment.TickCount64"/> when null.</param>
|
||||
public FailureLogThrottle(Func<long>? nowMs = null) => _nowMs = nowMs ?? (() => Environment.TickCount64);
|
||||
|
||||
/// <summary>The level the next failure should log at; claims the Warning slot when it is free.</summary>
|
||||
/// <returns><see cref="LogLevel.Warning"/> at most once per interval, else <see cref="LogLevel.Debug"/>.</returns>
|
||||
public LogLevel NextLevel()
|
||||
{
|
||||
var now = _nowMs();
|
||||
var last = Interlocked.Read(ref _lastWarnMs);
|
||||
if (last != long.MinValue && now - last < (long)Interval.TotalMilliseconds) return LogLevel.Debug;
|
||||
return Interlocked.CompareExchange(ref _lastWarnMs, now, last) == last ? LogLevel.Warning : LogLevel.Debug;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises a multicast delegate one subscriber at a time, so a subscriber that throws cannot stop
|
||||
/// delivery to the subscribers after it. The in-process stores and broadcasters raise their events on
|
||||
|
||||
Reference in New Issue
Block a user