fix(grpc-data): H4 review 2 — a fresh origin reports 'no peer traffic yet', not 'unavailable'
The origin services are composed on the first peer call (they need the driver host actor), so CaptureOrigin returned null until then and a fresh H4 origin read like a pre-H4 build. The DI singleton now probes the same deferred history port for backend availability and reports zeros with PeerServicesStarted=false; the page says 'no peer has called since start'.
This commit is contained in:
+1
-1
@@ -53,7 +53,7 @@ else
|
||||
<div class="small mb-2 data-connection-origin"><strong>@nodeId</strong>
|
||||
@if (node.OriginHistory is { } origin)
|
||||
{
|
||||
<span> · remote history @(origin.Available ? "served" : "no historian backend") · peer history sessions @origin.Sessions · open origin continuations @origin.OpenContinuations · history items answered @DataConnectionDiagnostics.HistoryCounts(origin.ReadsGood, origin.ReadsUncertain, origin.ReadsBad)</span>
|
||||
<span> · remote history @(origin.Available ? "served" : "no historian backend") · peer history sessions @origin.Sessions · open origin continuations @origin.OpenContinuations · history items answered @DataConnectionDiagnostics.HistoryCounts(origin.ReadsGood, origin.ReadsUncertain, origin.ReadsBad)@(origin.PeerServicesStarted ? "" : " · no peer has called since start")</span>
|
||||
}
|
||||
else { <span> · remote history evidence unavailable</span> }
|
||||
@if (node.DroppedExportOperations is { } dropped)
|
||||
|
||||
@@ -120,7 +120,15 @@ public static class DataConnectionRegistration
|
||||
services.AddSingleton<IProjectedDataAccess>(sp => sp.GetRequiredService<ProjectedDataAccess>());
|
||||
// H4: one dependency-free history diagnostics instance shared by the origin services, the consumer gateway and the
|
||||
// diagnostics readers (it also backs the otopcua.dataconn.history.* metrics).
|
||||
services.AddSingleton<DataConnectionHistoryDiagnostics>();
|
||||
services.AddSingleton(sp =>
|
||||
{
|
||||
// Before the first peer call composes the origin services, report the backend's availability (and zeros) from a
|
||||
// probe of the same deferred history port, so a fresh H4 origin never reads like a pre-H4 build (H4 review 2).
|
||||
var diagnostics = new DataConnectionHistoryDiagnostics();
|
||||
var probe = new DeferredOriginHistoryPort(sp.GetRequiredService<DeferredAddressSpaceSink>());
|
||||
diagnostics.AttachProvisionalOrigin(() => probe.Serving is not null);
|
||||
return diagnostics;
|
||||
});
|
||||
// H3: OPC UA HistoryRead on projected variables, forwarded over the mapping's deployed connection.
|
||||
services.AddSingleton(sp => new ProjectedHistoryAccess(sp.GetRequiredService<ProjectedDataAccess>(),
|
||||
sp.GetRequiredService<IGrpcDataAdapterConnectionSource>(),
|
||||
|
||||
+18
-2
@@ -75,6 +75,7 @@ public sealed class DataConnectionHistoryDiagnostics
|
||||
private readonly ConcurrentDictionary<string, Counts> _consumer = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Counts _origin = new();
|
||||
private Func<(bool Available, int Sessions, int Open)>? _originState;
|
||||
private Func<bool>? _provisionalAvailability;
|
||||
|
||||
public DataConnectionHistoryDiagnostics() => Live.AddOrUpdate(this, new object());
|
||||
|
||||
@@ -129,6 +130,13 @@ public sealed class DataConnectionHistoryDiagnostics
|
||||
/// <summary>Connects the origin services whose live state (backend, sessions, open cursors) this reports.</summary>
|
||||
internal void AttachOrigin(Func<(bool Available, int Sessions, int Open)> state) => _originState = state;
|
||||
|
||||
/// <summary>
|
||||
/// H4 review: the origin's backend availability BEFORE its data services exist. They are composed on the first peer call
|
||||
/// (the composition needs the driver host actor), so until then the evidence is "available/not, no peer traffic yet" —
|
||||
/// zero sessions and continuations are facts, not unknowns — instead of null (which means a pre-H4 build).
|
||||
/// </summary>
|
||||
public void AttachProvisionalOrigin(Func<bool> available) => _provisionalAvailability = available;
|
||||
|
||||
/// <summary>The consumer evidence for one connection; zeros when it has seen no history traffic.</summary>
|
||||
public ConsumerHistoryCounts CaptureConsumer(string connectionId) =>
|
||||
_consumer.TryGetValue(connectionId, out var c)
|
||||
@@ -138,10 +146,18 @@ public sealed class DataConnectionHistoryDiagnostics
|
||||
/// <summary>Consumer continuations open across every connection.</summary>
|
||||
public int OpenConsumerContinuations => _consumer.Values.Sum(x => Math.Max(0, Volatile.Read(ref x.Open)));
|
||||
|
||||
/// <summary>The origin evidence; null until origin services are attached (no data-connection origin on this node yet).</summary>
|
||||
/// <summary>
|
||||
/// The origin evidence: live once the origin services are attached; before that the provisional "no peer traffic yet"
|
||||
/// state when one is attached; otherwise null (no data-connection origin on this node).
|
||||
/// </summary>
|
||||
public OriginHistoryDiagnostics? CaptureOrigin()
|
||||
{
|
||||
if (_originState is not { } state) return null;
|
||||
if (_originState is not { } state)
|
||||
{
|
||||
if (_provisionalAvailability is not { } provisional) return null;
|
||||
try { return new(provisional(), 0, 0, 0, 0, 0, PeerServicesStarted: false); }
|
||||
catch (Exception) { return null; }
|
||||
}
|
||||
(bool Available, int Sessions, int Open) now;
|
||||
try { now = state(); }
|
||||
catch (Exception) { return null; }
|
||||
|
||||
Reference in New Issue
Block a user