From 005720bd02bd1863e919559325142eb6cac29476 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 24 Nov 2026 08:37:38 -0500 Subject: [PATCH] =?UTF-8?q?fix(grpc-data):=20H4=20review=202=20=E2=80=94?= =?UTF-8?q?=20a=20fresh=20origin=20reports=20'no=20peer=20traffic=20yet',?= =?UTF-8?q?=20not=20'unavailable'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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'. --- docs/DataConnections.md | 4 +++- .../DataConnectionDiagnosticsSnapshot.cs | 6 +++++- .../Clusters/ClusterDataConnections.razor | 2 +- .../DataConnectionRegistration.cs | 10 +++++++++- .../DataConnectionHistoryDiagnostics.cs | 20 +++++++++++++++++-- .../GrpcDataHistoryMetricsTests.cs | 17 ++++++++++++++++ 6 files changed, 53 insertions(+), 6 deletions(-) diff --git a/docs/DataConnections.md b/docs/DataConnections.md index 09c92c498..ccb9d0ca3 100644 --- a/docs/DataConnections.md +++ b/docs/DataConnections.md @@ -286,7 +286,9 @@ history sessions, the **open origin continuations** (page cursors and chunk rema answered by status class, and its exports with dropped unknown operation bits. All counts are since process start and reset on restart. "Unavailable" means the node did not report the measure (built -before H4, or no data-connection services) — never zero activity. +before H4, or no data-connection services) — never zero activity. The origin's data services are created on the first peer call, +so until a peer has called, a node's origin line shows its backend availability with zero sessions, continuations and answers and +"no peer has called since start". Metrics, on the `ZB.MOM.WW.OtOpcUa` meter (exported on `/metrics` and OTLP like every OtOpcUa instrument), never carry a connection, node or principal id in a label: diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Commons/Interfaces/DataConnectionDiagnosticsSnapshot.cs b/src/Core/ZB.MOM.WW.OtOpcUa.Commons/Interfaces/DataConnectionDiagnosticsSnapshot.cs index 7dcc5f6c5..b19960bfb 100644 --- a/src/Core/ZB.MOM.WW.OtOpcUa.Commons/Interfaces/DataConnectionDiagnosticsSnapshot.cs +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Commons/Interfaces/DataConnectionDiagnosticsSnapshot.cs @@ -57,5 +57,9 @@ public sealed record DataConnectionDiagnosticsSnapshot( /// Remote history items answered Good since process start. /// Remote history items answered Uncertain since process start. /// Remote history items answered Bad (including refusals) since process start. +/// +/// False while no peer has called this node since start: the origin data services are created on the first peer call, so +/// the zeros are "no peer traffic yet", not missing evidence. True once they run (and from a sender that predates the flag). +/// public sealed record OriginHistoryDiagnostics(bool Available, int Sessions, int OpenContinuations, long ReadsGood, - long ReadsUncertain, long ReadsBad); + long ReadsUncertain, long ReadsBad, bool PeerServicesStarted = true); diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Clusters/ClusterDataConnections.razor b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Clusters/ClusterDataConnections.razor index e9cdb665f..9bc071912 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Clusters/ClusterDataConnections.razor +++ b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Clusters/ClusterDataConnections.razor @@ -53,7 +53,7 @@ else
@nodeId @if (node.OriginHistory is { } origin) { - · 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) + · 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") } else { · remote history evidence unavailable } @if (node.DroppedExportOperations is { } dropped) diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Host/Configuration/DataConnectionRegistration.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Host/Configuration/DataConnectionRegistration.cs index 2f574c943..1a6b07330 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.Host/Configuration/DataConnectionRegistration.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Host/Configuration/DataConnectionRegistration.cs @@ -120,7 +120,15 @@ public static class DataConnectionRegistration services.AddSingleton(sp => sp.GetRequiredService()); // 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(); + 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()); + 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(), sp.GetRequiredService(), diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/DataConnectionHistoryDiagnostics.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/DataConnectionHistoryDiagnostics.cs index 4fb7b961f..b0f533bc4 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/DataConnectionHistoryDiagnostics.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/DataConnectionHistoryDiagnostics.cs @@ -75,6 +75,7 @@ public sealed class DataConnectionHistoryDiagnostics private readonly ConcurrentDictionary _consumer = new(StringComparer.OrdinalIgnoreCase); private readonly Counts _origin = new(); private Func<(bool Available, int Sessions, int Open)>? _originState; + private Func? _provisionalAvailability; public DataConnectionHistoryDiagnostics() => Live.AddOrUpdate(this, new object()); @@ -129,6 +130,13 @@ public sealed class DataConnectionHistoryDiagnostics /// Connects the origin services whose live state (backend, sessions, open cursors) this reports. internal void AttachOrigin(Func<(bool Available, int Sessions, int Open)> state) => _originState = state; + /// + /// 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). + /// + public void AttachProvisionalOrigin(Func available) => _provisionalAvailability = available; + /// The consumer evidence for one connection; zeros when it has seen no history traffic. public ConsumerHistoryCounts CaptureConsumer(string connectionId) => _consumer.TryGetValue(connectionId, out var c) @@ -138,10 +146,18 @@ public sealed class DataConnectionHistoryDiagnostics /// Consumer continuations open across every connection. public int OpenConsumerContinuations => _consumer.Values.Sum(x => Math.Max(0, Volatile.Read(ref x.Open))); - /// The origin evidence; null until origin services are attached (no data-connection origin on this node yet). + /// + /// 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). + /// 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; } diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataHistoryMetricsTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataHistoryMetricsTests.cs index 3ffc620ac..3a2a122c8 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataHistoryMetricsTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataHistoryMetricsTests.cs @@ -109,6 +109,23 @@ public sealed class GrpcDataHistoryMetricsTests diagnostics.CaptureOrigin().ShouldBeNull(); } + [Fact] + public void Before_any_peer_call_a_provisional_origin_reports_no_peer_traffic_yet_not_unavailable() + { + // H4 review item 2: the origin services are composed on the first peer call; until then a fresh H4 origin must not + // read like a pre-H4 build (null). + var diagnostics = new DataConnectionHistoryDiagnostics(); + var backend = true; + diagnostics.AttachProvisionalOrigin(() => backend); + diagnostics.CaptureOrigin().ShouldBe(new ZB.MOM.WW.OtOpcUa.Commons.Interfaces.OriginHistoryDiagnostics(true, 0, 0, 0, 0, 0, + PeerServicesStarted: false)); + backend = false; + diagnostics.CaptureOrigin()!.Available.ShouldBeFalse("availability is probed live, not latched"); + diagnostics.AttachOrigin(() => (true, 2, 1)); + diagnostics.CaptureOrigin().ShouldBe(new ZB.MOM.WW.OtOpcUa.Commons.Interfaces.OriginHistoryDiagnostics(true, 2, 1, 0, 0, 0)); + diagnostics.CaptureOrigin()!.PeerServicesStarted.ShouldBeTrue(); + } + [Fact] public void The_plan_unknown_bit_counter_is_the_existing_X0_instrument_not_a_second_one() {