feat(grpc-data): H4 remote-history diagnostics and metrics

Consumer and origin history evidence for data connections (plan §6):
- DataConnectionHistoryDiagnostics: otopcua.dataconn.history.reads{variant,status_class,side} and
  otopcua.dataconn.history.continuations.active{side} on the exported OtOpcUa meter (the H2 origin
  counter sat on a private meter the host never exported); the plan's unknown-bits counter is the
  existing X0 otopcua.dataconnection.unknown_operations_dropped, reused
- per-connection projected answers by status class and open consumer continuations (settled on
  resume claim or release); origin sessions, open continuations and answers by status class
- negotiated features and advertised history variants/aggregates per connection
- AdminUI data-connections page renders them plus the dropped unknown-operation bits (#919)
- H4 unit-phase manifest key
This commit is contained in:
Joseph Doherty
2026-11-24 08:01:57 -05:00
parent b1973d6fdd
commit e3f21cb86c
19 changed files with 687 additions and 30 deletions
@@ -35,7 +35,9 @@ else
@if (live.Row.Serving is { } serving) { <span> · serving @serving.NodeId · role @serving.Role · incarnation @serving.Incarnation</span> }
<div>Streams @live.Row.ActiveStreams · calls @live.Row.ActiveCalls · retained import views @Measure(live.Row.SourceCount) · registrations @Measure(live.Row.RegistrationCount) · resets @Measure(live.Row.ResetCount) · coalesced notices @Measure(live.Row.CoalescedCount) · overflows @Measure(live.Row.OverflowCount)</div>
<div>Writes succeeded @Measure(live.Row.WriteSucceededCount) · rejected @Measure(live.Row.WriteRejectedCount) · failed @Measure(live.Row.WriteFailedCount) · unconfirmed @Measure(live.Row.WriteUnconfirmedCount) · unknown @Measure(live.Row.WriteUnknownCount)</div>
<div>Last observed sample bound @Time(live.Row.LastSampleAtUtc) (age upper bound @DataConnectionDiagnostics.SampleAge(live.Row)) · metadata lease expires @Time(live.Row.MetadataLeaseExpiresAtUtc) · last handshake @Time(live.Row.LastVerifiedAtUtc) · observed @live.Row.AsOfUtc.ToString("u") · artifact @live.Row.ArtifactRevision · protocol @(live.Row.ProtocolMajor is { } major && live.Row.ProtocolMinor is { } minor ? $"{major}.{minor}" : "unavailable")</div></div>
<div>Last observed sample bound @Time(live.Row.LastSampleAtUtc) (age upper bound @DataConnectionDiagnostics.SampleAge(live.Row)) · metadata lease expires @Time(live.Row.MetadataLeaseExpiresAtUtc) · last handshake @Time(live.Row.LastVerifiedAtUtc) · observed @live.Row.AsOfUtc.ToString("u") · artifact @live.Row.ArtifactRevision · protocol @(live.Row.ProtocolMajor is { } major && live.Row.ProtocolMinor is { } minor ? $"{major}.{minor}" : "unavailable")</div>
<div class="data-connection-history">Negotiated features @DataConnectionDiagnostics.Features(live.Row.NegotiatedFeatures) · origin history @DataConnectionDiagnostics.HistoryServed(live.Row) · projected history reads @DataConnectionDiagnostics.HistoryCounts(live.Row.HistoryReadsGood, live.Row.HistoryReadsUncertain, live.Row.HistoryReadsBad) · open remote continuations (local sessions) @Measure(live.Row.OpenRemoteContinuations)</div>
<div class="@(DataConnectionDiagnostics.HasDrops(live.Row.DroppedUnknownOperations, live.Row.MappingsWithDroppedOperations) ? "notice data-connection-dropped" : "data-connection-dropped")">Dropped unknown operation bits: connection @DataConnectionDiagnostics.DroppedBits(live.Row.DroppedUnknownOperations) · mappings with dropped bits @Measure(live.Row.MappingsWithDroppedOperations)@if (DataConnectionDiagnostics.HasDrops(live.Row.DroppedUnknownOperations, live.Row.MappingsWithDroppedOperations)) { <span> — this node's build is older than a feature authored here; the dropped bits grant nothing until the node is upgraded.</span> }</div></div>
}
@foreach (var applied in _applied.Where(x => Same(x.ConnectionId, row.Id))) { <span class="small">@applied.NodeId: last applied revision @applied.Revision (@(applied.Enabled ? "enabled" : "disabled"))</span> }
@if (row.Draft is { } editable) { <AuthorizeView Policy="@AdminUiPolicies.ConfigEditor"><button class="btn btn-sm btn-outline-primary" @onclick="() => Edit(editable)">Edit</button></AuthorizeView> }</div>
@@ -43,6 +45,30 @@ else
<AuthorizeView Policy="@AdminUiPolicies.ConfigEditor"><button class="btn btn-sm btn-primary" @onclick="NewConnection">New connection</button></AuthorizeView>
</div>
</section>
<section class="panel mt-3">
<h2 class="panel-head">Origin evidence by node</h2><div class="p-3">
@if (!_nodeSnapshots.Any()) { <p class="text-muted">No node has reported.</p> }
@foreach (var (nodeId, node) in _nodeSnapshots)
{
<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>
}
else { <span> · remote history evidence unavailable</span> }
@if (node.DroppedExportOperations is { } dropped)
{
@if (dropped.Count == 0) { <span> · dropped unknown export bits: none</span> }
else
{
<div class="notice" role="note">Exports with dropped unknown operation bits: @string.Join("; ", dropped.OrderBy(x => x.Key, StringComparer.OrdinalIgnoreCase).Select(x => $"{x.Key}: {DataConnectionDiagnostics.DroppedBits(x.Value)}")) — this node's build is older than a feature authored here; the dropped bits grant nothing until the node is upgraded.</div>
}
}
else { <span> · dropped unknown export bits unavailable</span> }
</div>
}
</div>
</section>
<section class="panel mt-3">
<h2 class="panel-head">Exports</h2><div class="p-3">
@if (!Exports.Any()) { <p class="text-muted">No export grants have been authored.</p> }
@@ -125,6 +151,7 @@ else
private object? _deleteCandidate;
private IReadOnlyList<AppliedConnection> _applied = [];
private List<(string NodeId, DataConnectionDiagnosticsSnapshot Row)> _live = [];
private List<(string NodeId, NodeDiagnosticsSnapshot Snapshot)> _nodeSnapshots = [];
private IReadOnlyList<ConnectionDisplayRow> ConnectionRows => DataConnectionDiagnostics.Rows(Connections, _applied.Select(x => x.ConnectionId), _live.Select(x => x.Row.ConnectionId));
private IEnumerable<DataConnection> Connections => _snapshot!.DataConnections.Where(x => Same(x.ClusterId, ClusterId));
private IEnumerable<DataExport> Exports => _snapshot!.DataExports.Where(x => Same(x.ClusterId, ClusterId));
@@ -139,6 +166,7 @@ else
try { return (node.NodeId, Snapshot: (NodeDiagnosticsSnapshot?)await Diagnostics.GetDiagnosticsAsync(NodeId.Parse($"{node.Host}:{node.AkkaPort}"), CancellationToken.None)); }
catch (Exception) { return (node.NodeId, Snapshot: (NodeDiagnosticsSnapshot?)null); }
}));
_nodeSnapshots = observations.Where(x => x.Snapshot is not null).Select(x => (x.NodeId, x.Snapshot!)).ToList();
_live = observations.Where(x => x.Snapshot?.DataConnections is not null)
.SelectMany(x => x.Snapshot!.DataConnections!.Select(row => (x.NodeId, row))).ToList();
}
@@ -1,4 +1,6 @@
using ZB.MOM.WW.OtOpcUa.Commons.Interfaces;
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.DataConnections;
@@ -23,6 +25,41 @@ public static class DataConnectionDiagnostics
"disabled" => "Disabled", "connecting" => "Connecting", "ready" => "Ready", "degraded" => "Degraded",
"auth-failed" => "Authentication failed", "backoff" => "Backoff", _ => "Unavailable"
};
/// <summary>H4: the features the last handshake negotiated; "none (v1)" when the peer negotiated nothing optional.</summary>
public static string Features(DataFeatures? features) => features switch
{
null => "unavailable",
DataFeatures.None => "none (v1 behaviour)",
{ } f => string.Join(", ", Enum.GetValues<DataFeatures>().Where(x => x != DataFeatures.None && f.HasFlag(x)).Select(x => x.ToString())
.DefaultIfEmpty($"0x{(int)f:X}")),
};
/// <summary>H4: the history variants and aggregate count the origin advertised to this caller.</summary>
public static string HistoryServed(DataConnectionDiagnosticsSnapshot row) =>
row.HistoryVariants is not { } variants ? "not advertised"
: variants.Count == 0 ? "advertised, no variant granted"
: string.Join(", ", variants) + (row.HistoryAggregateCount is { } n ? $" ({n} aggregates)" : "");
/// <summary>H4: history results by status class, "unavailable" from a node built before H4.</summary>
public static string HistoryCounts(long? good, long? uncertain, long? bad) =>
good is null && uncertain is null && bad is null ? "unavailable"
: $"good {good ?? 0} · uncertain {uncertain ?? 0} · bad {bad ?? 0}";
/// <summary>
/// #919: operation bits a node dropped because its build does not implement them. Named when this AdminUI knows the
/// bit, hex otherwise; "unavailable" from a node built before X0.
/// </summary>
public static string DroppedBits(DataOperations? bits) => bits switch
{
null => "unavailable",
DataOperations.None => "none",
{ } b => string.Join(", ", Enumerable.Range(0, 31).Select(i => (DataOperations)(1 << i)).Where(x => b.HasFlag(x))
.Select(x => Enum.IsDefined(x) ? DataOperationAuthoring.Label(x) : $"0x{(int)x:X}")),
};
/// <summary>#919: true when the drop deserves the "node build is older than the authored feature" hint.</summary>
public static bool HasDrops(DataOperations? bits, int? mappings = null) => bits is { } b && b != DataOperations.None || mappings is > 0;
public static string Endpoint(string? value) => Uri.TryCreate(value, UriKind.Absolute, out var uri)
&& uri.Scheme == Uri.UriSchemeHttps ? (uri.HostNameType == UriHostNameType.IPv6 ? $"https://[{uri.Host}]{(uri.IsDefaultPort ? "" : $":{uri.Port}")}" : $"https://{uri.IdnHost}{(uri.IsDefaultPort ? "" : $":{uri.Port}")}") : "Unavailable";
}