diff --git a/scripts/validation/grpc-data/unit-phases.json b/scripts/validation/grpc-data/unit-phases.json index 45f5d7b7b..ce9141e4f 100644 --- a/scripts/validation/grpc-data/unit-phases.json +++ b/scripts/validation/grpc-data/unit-phases.json @@ -925,7 +925,7 @@ "project": "tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/ZB.MOM.WW.OtOpcUa.Runtime.Tests.csproj", "filter": "(Feature=GrpcData&Phase=H4)|FullyQualifiedName~.GrpcDataProjectedHistoryCursorTests.|FullyQualifiedName~.GrpcDataOriginHistorySessionTests.", "new_classes": [ - "GrpcDataHistoryMetricsTests" + "GrpcDataHistoryMetricsTests", "GrpcDataDiagnosticsSerializationTests" ], "existing_classes": [ "GrpcDataConfiguredDiscoveryWireTests", 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 b19960bfb..21b6071f3 100644 --- a/src/Core/ZB.MOM.WW.OtOpcUa.Commons/Interfaces/DataConnectionDiagnosticsSnapshot.cs +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Commons/Interfaces/DataConnectionDiagnosticsSnapshot.cs @@ -57,9 +57,10 @@ 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). +/// +/// True 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. False once they run. Default false, so a payload without the +/// member (Akka's JSON serializer fills a missing constructor argument with the CLR default) never claims it. /// public sealed record OriginHistoryDiagnostics(bool Available, int Sessions, int OpenContinuations, long ReadsGood, - long ReadsUncertain, long ReadsBad, bool PeerServicesStarted = true); + long ReadsUncertain, long ReadsBad, bool NoPeerTrafficYet = false); 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 9bc071912..90ecb8155 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)@(origin.PeerServicesStarted ? "" : " · no peer has called since start") + · 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.NoPeerTrafficYet ? " · 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.Runtime/DataConnections/DataConnectionHistoryDiagnostics.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/DataConnectionHistoryDiagnostics.cs index 00754845f..dbcf5697d 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/DataConnectionHistoryDiagnostics.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/DataConnectionHistoryDiagnostics.cs @@ -156,7 +156,7 @@ public sealed class DataConnectionHistoryDiagnostics if (_originState is not { } state) { if (_provisionalAvailability is not { } provisional) return null; - try { return new(provisional(), 0, 0, 0, 0, 0, PeerServicesStarted: false); } + try { return new(provisional(), 0, 0, 0, 0, 0, NoPeerTrafficYet: true); } catch (Exception) { return null; } } (bool Available, int Sessions, int Open) now; diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataDiagnosticsSerializationTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataDiagnosticsSerializationTests.cs new file mode 100644 index 000000000..0cb3a34b2 --- /dev/null +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataDiagnosticsSerializationTests.cs @@ -0,0 +1,92 @@ +using System.Text; +using Akka.TestKit.Xunit; +using Newtonsoft.Json.Linq; +using Shouldly; +using Xunit; +using ZB.MOM.WW.OtOpcUa.Commons.Interfaces; +using ZB.MOM.WW.OtOpcUa.Commons.Types; +using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections; + +namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.DataConnections; + +/// +/// H4 review item 7: the fleet-diagnostics reply crosses Akka remoting (FleetDiagnosticsClient asks the node's +/// driver host) on the serializer Akka picks for it — round-trip the new members through THAT serializer, and decode an +/// old-shape payload (a pre-H4 sender) to show mixed-version tolerance. +/// +[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "H4")] +public sealed class GrpcDataDiagnosticsSerializationTests : TestKit +{ + private static readonly string[] H4ConnectionMembers = + ["NegotiatedFeatures", "HistoryVariants", "HistoryAggregateCount", "HistoryReadsGood", "HistoryReadsUncertain", "HistoryReadsBad", + "OpenRemoteContinuations"]; + + private static NodeDiagnosticsSnapshot Snapshot() => new( + // Arrays, as production builds them (CaptureDiagnostics .ToArray()s; RecordSelected builds string[]): a C# collection + // expression typed IReadOnlyList is a compiler-synthesized type Newtonsoft cannot construct. + NodeId.Parse("consumer-1:4053"), null, Array.Empty(), new DateTime(2026, 11, 24, 13, 0, 0, DateTimeKind.Utc), + DataConnections: new[] + { + new DataConnectionDiagnosticsSnapshot("link", 3, "ready", "https://source-2:4057", null, 0, 0, 7, "artifact-7", + new DateTime(2026, 11, 24, 13, 0, 0, DateTimeKind.Utc), DroppedUnknownOperations: DataOperations.None, + MappingsWithDroppedOperations: 0, NegotiatedFeatures: DataFeatures.History, HistoryVariants: new[] { "raw", "processed", "attime" }, + HistoryAggregateCount: 19, HistoryReadsGood: 34, HistoryReadsUncertain: 1, HistoryReadsBad: 3, OpenRemoteContinuations: 2), + }, + DroppedExportOperations: new Dictionary { ["export-a"] = (DataOperations)(1 << 20) }, + OriginHistory: new OriginHistoryDiagnostics(true, 1, 2, 7, 0, 2, NoPeerTrafficYet: true)); + + private (Akka.Serialization.Serializer Serializer, string Manifest) SerializerFor(object message) + { + var serializer = Sys.Serialization.FindSerializerFor(message); + return (serializer, Akka.Serialization.Serialization.ManifestFor(serializer, message)); + } + + [Fact] + public void A_snapshot_with_the_H4_members_round_trips_on_the_cluster_serializer() + { + var message = Snapshot(); + var (serializer, manifest) = SerializerFor(message); + var round = (NodeDiagnosticsSnapshot)Sys.Serialization.Deserialize(serializer.ToBinary(message), serializer.Identifier, manifest); + + round.OriginHistory.ShouldBe(message.OriginHistory); + round.DroppedExportOperations!["export-a"].ShouldBe((DataOperations)(1 << 20)); + var row = round.DataConnections.ShouldNotBeNull().ShouldHaveSingleItem(); + row.NegotiatedFeatures.ShouldBe(DataFeatures.History); + row.HistoryVariants.ShouldBe(["raw", "processed", "attime"]); + (row.HistoryAggregateCount, row.HistoryReadsGood, row.HistoryReadsUncertain, row.HistoryReadsBad, row.OpenRemoteContinuations) + .ShouldBe((19, 34L, 1L, 3L, 2)); + } + + [Fact] + public void An_old_shape_payload_without_the_H4_members_decodes_with_them_unavailable() + { + var message = Snapshot(); + var (serializer, manifest) = SerializerFor(message); + var json = JObject.Parse(Encoding.UTF8.GetString(serializer.ToBinary(message))); + json.Remove("OriginHistory").ShouldBeTrue("the H4 node member is on the wire"); + var removed = 0; + foreach (var row in json.Descendants().OfType().Where(o => o.ContainsKey("ConnectionId")).ToArray()) + foreach (var member in H4ConnectionMembers) + if (row.Remove(member)) removed++; + removed.ShouldBe(H4ConnectionMembers.Length, "every H4 connection member was on the wire and is now stripped"); + + var legacy = (NodeDiagnosticsSnapshot)Sys.Serialization.Deserialize(Encoding.UTF8.GetBytes(json.ToString(Newtonsoft.Json.Formatting.None)), + serializer.Identifier, manifest); + legacy.OriginHistory.ShouldBeNull("a pre-H4 node reports no origin evidence (rendered 'unavailable')"); + + // An origin record without the later NoPeerTrafficYet member decodes as live evidence, never "no peer traffic yet". + var withOrigin = JObject.Parse(Encoding.UTF8.GetString(serializer.ToBinary(message))); + ((JObject)withOrigin["OriginHistory"]!).Remove("NoPeerTrafficYet").ShouldBeTrue(); + var partial = (NodeDiagnosticsSnapshot)Sys.Serialization.Deserialize( + Encoding.UTF8.GetBytes(withOrigin.ToString(Newtonsoft.Json.Formatting.None)), serializer.Identifier, manifest); + partial.OriginHistory.ShouldNotBeNull().NoPeerTrafficYet.ShouldBeFalse(); + partial.OriginHistory.ReadsGood.ShouldBe(7); + var row0 = legacy.DataConnections.ShouldNotBeNull().ShouldHaveSingleItem(); + row0.ConnectionId.ShouldBe("link"); + row0.NegotiatedFeatures.ShouldBeNull(); + row0.HistoryVariants.ShouldBeNull(); + row0.HistoryReadsGood.ShouldBeNull(); + row0.OpenRemoteContinuations.ShouldBeNull(); + row0.DroppedUnknownOperations.ShouldBe(DataOperations.None, "X0 members are untouched"); + } +} 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 3a2a122c8..f0f7f9da2 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 @@ -118,12 +118,12 @@ public sealed class GrpcDataHistoryMetricsTests 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)); + NoPeerTrafficYet: true)); 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(); + diagnostics.CaptureOrigin()!.NoPeerTrafficYet.ShouldBeFalse(); } [Fact]