feat(grpc-data): X0 review - tolerate any unknown bit at the artifact/catalog seam; drop diagnostics for exports and mappings
- ValidateDeployed ignores every bit outside Understood (understood subset still validated); P02's two 1<<30 rows become 'tolerated, grants nothing'. - UnknownOperationDrops: Warning + counter tagged kind=connection|export|mapping, counted once per row per accepted artifact change; collected under each lock, logged after release. Mappings masked at Stage. - Surfaced via DataConnectionDiagnosticsSnapshot (DroppedUnknownOperations, MappingsWithDroppedOperations) and NodeDiagnosticsSnapshot.DroppedExportOperations. - End-to-end test: 1<<30 through parse -> catalog compile -> mapping stage -> runtime apply. - DataConnectionProtoContract.Validate() now runs at AddOtOpcUaDataConnections.
This commit is contained in:
+29
-26
@@ -1,7 +1,5 @@
|
||||
using System.Diagnostics.Metrics;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Observability;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
||||
@@ -43,11 +41,8 @@ public sealed class DataConnectionDeploymentRuntime : IAsyncDisposable
|
||||
internal bool Ready;
|
||||
internal int Leases;
|
||||
}
|
||||
/// <summary>Counter of connection rows whose unknown operation bits were dropped (X0 tolerant reader).</summary>
|
||||
public const string UnknownOperationsCounterName = "otopcua.dataconnection.unknown_operations_dropped";
|
||||
private static readonly Counter<long> UnknownOperationsCounter = OtOpcUaTelemetry.Meter.CreateCounter<long>(
|
||||
UnknownOperationsCounterName, unit: "{row}",
|
||||
description: "Data-connection rows carrying operation bits this node does not understand; the bits were dropped (no grant).");
|
||||
/// <summary>Counter of rows whose unknown operation bits were dropped (X0 tolerant reader); see <see cref="UnknownOperationDrops"/>.</summary>
|
||||
public const string UnknownOperationsCounterName = UnknownOperationDrops.CounterName;
|
||||
private readonly object _sync = new();
|
||||
/// <summary>Diagnostics sink for the X0 dropped-operation warning; optional (an init property keeps the constructor shape).</summary>
|
||||
public ILogger Logger { private get; init; } = NullLogger.Instance;
|
||||
@@ -99,25 +94,40 @@ public sealed class DataConnectionDeploymentRuntime : IAsyncDisposable
|
||||
/// this node does not understand and therefore dropped (an unknown grant is no grant). Empty when none.
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, DataOperations> DroppedUnknownOperations { get { lock (_sync) return _droppedOperations; } }
|
||||
/// <summary>Cumulative count of connection rows that had unknown bits dropped, once per accepted artifact.</summary>
|
||||
/// <summary>
|
||||
/// Cumulative count of connection rows that had unknown bits dropped: once per row per accepted artifact change
|
||||
/// (same revision re-applied does not recount; A → B → A does; a restart resets).
|
||||
/// </summary>
|
||||
public long UnknownOperationRowsDropped => Interlocked.Read(ref _unknownOperationRows);
|
||||
/// <summary>Configured redundancy mode from the current validated artifact.</summary>
|
||||
public RedundancyMode CurrentConsumerMode { get { lock (_sync) return _desired?.ConsumerMode ?? RedundancyMode.None; } }
|
||||
|
||||
/// <summary>Captures only this node's applied scope and current transport evidence.</summary>
|
||||
public IReadOnlyList<ZB.MOM.WW.OtOpcUa.Commons.Interfaces.DataConnectionDiagnosticsSnapshot> CaptureDiagnostics(IReadOnlyDictionary<string, int>? retainedSourceCounts = null)
|
||||
/// <param name="retainedSourceCounts">Per connection id, the projected sources retained (host-supplied).</param>
|
||||
/// <param name="mappingsWithDroppedOperations">
|
||||
/// Per connection id, how many of its mappings had unknown operation bits dropped (from
|
||||
/// <see cref="ProjectedMappingDeploymentRuntime.CaptureDroppedByConnection"/>); null = not available.
|
||||
/// </param>
|
||||
public IReadOnlyList<ZB.MOM.WW.OtOpcUa.Commons.Interfaces.DataConnectionDiagnosticsSnapshot> CaptureDiagnostics(IReadOnlyDictionary<string, int>? retainedSourceCounts = null,
|
||||
IReadOnlyDictionary<string, int>? mappingsWithDroppedOperations = null)
|
||||
{
|
||||
lock (_sync)
|
||||
{
|
||||
if (_disposed || _desired is not { } desired) return [];
|
||||
var dropped = _droppedOperations;
|
||||
DataOperations? Dropped(string id) => dropped.TryGetValue(id, out var bits) ? bits : DataOperations.None;
|
||||
int? MappingDrops(string id) => mappingsWithDroppedOperations is null ? null
|
||||
: mappingsWithDroppedOperations.TryGetValue(id, out var count) ? count : 0;
|
||||
return desired.Specs.Values.Select(spec =>
|
||||
{
|
||||
if (!_attemptPending && _scopeReady && _entries.TryGetValue(spec.Id, out var entry) && entry.Ready)
|
||||
return entry.Connection.CaptureDiagnostics(spec.Revision, desired.ScopeVersion, desired.ArtifactRevision) with
|
||||
{ SourceCount = retainedSourceCounts is null ? null : retainedSourceCounts.TryGetValue(spec.Id, out var count) ? count : 0 };
|
||||
{ SourceCount = retainedSourceCounts is null ? null : retainedSourceCounts.TryGetValue(spec.Id, out var count) ? count : 0,
|
||||
DroppedUnknownOperations = Dropped(spec.Id), MappingsWithDroppedOperations = MappingDrops(spec.Id) };
|
||||
return new ZB.MOM.WW.OtOpcUa.Commons.Interfaces.DataConnectionDiagnosticsSnapshot(spec.Id, spec.Revision,
|
||||
_attemptPending ? "connecting" : _retryNotBefore > _clock.GetTimestamp() ? "backoff" : "connecting",
|
||||
null, null, 0, 0, desired.ScopeVersion, desired.ArtifactRevision, _clock.GetUtcNow().UtcDateTime);
|
||||
null, null, 0, 0, desired.ScopeVersion, desired.ArtifactRevision, _clock.GetUtcNow().UtcDateTime)
|
||||
{ DroppedUnknownOperations = Dropped(spec.Id), MappingsWithDroppedOperations = MappingDrops(spec.Id) };
|
||||
}).ToArray();
|
||||
}
|
||||
}
|
||||
@@ -173,7 +183,8 @@ public sealed class DataConnectionDeploymentRuntime : IAsyncDisposable
|
||||
// dropped from THIS row only, fail closed, and counted. It used to reject the whole snapshot. A row left
|
||||
// with no understood operation stays configured and grants nothing.
|
||||
var operations = item.AllowedOperations & DataOperationSets.Understood;
|
||||
if (operations != item.AllowedOperations) dropped[item.DataConnectionId] = item.AllowedOperations & ~DataOperationSets.Understood;
|
||||
if (UnknownOperationDrops.Unknown(item.AllowedOperations) is var unknown && unknown != DataOperations.None)
|
||||
dropped[item.DataConnectionId] = unknown;
|
||||
var endpoints = item.Endpoints.Select(value => Uri.TryCreate(value, UriKind.Absolute, out var uri) && uri.Scheme == Uri.UriSchemeHttps
|
||||
? uri : throw new ArgumentException("Only HTTPS endpoints are accepted.", nameof(snapshot))).Distinct().ToArray();
|
||||
var eligible = new HashSet<string>(item.EligibleTargetNodeIds, StringComparer.OrdinalIgnoreCase);
|
||||
@@ -186,6 +197,7 @@ public sealed class DataConnectionDeploymentRuntime : IAsyncDisposable
|
||||
throw new ArgumentException("Duplicate connection identity.", nameof(snapshot));
|
||||
}
|
||||
Entry[] old;
|
||||
var report = false;
|
||||
lock (_sync)
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
@@ -210,26 +222,17 @@ public sealed class DataConnectionDeploymentRuntime : IAsyncDisposable
|
||||
foreach (var id in specs.Keys) _routeRevisions.Add(id, generation);
|
||||
var priorRevision = _desired?.ArtifactRevision;
|
||||
_desired = new(snapshot.ScopeVersion, snapshot.ArtifactRevision, generation, snapshot.ConsumerMode, specs, allow);
|
||||
RecordDroppedLocked(snapshot.ArtifactRevision, priorRevision, dropped);
|
||||
_droppedOperations = dropped;
|
||||
report = dropped.Count != 0 && !string.Equals(snapshot.ArtifactRevision, priorRevision, StringComparison.Ordinal);
|
||||
if (report) Interlocked.Add(ref _unknownOperationRows, dropped.Count);
|
||||
_scopeReady = false;
|
||||
old = _entries.Values.ToArray(); _entries.Clear();
|
||||
ApplyManagerScopeLocked(_desired);
|
||||
foreach (var entry in old) Retire(entry);
|
||||
WakeLocked();
|
||||
}
|
||||
}
|
||||
private void RecordDroppedLocked(string revision, string? priorRevision, Dictionary<string, DataOperations> dropped)
|
||||
{
|
||||
_droppedOperations = dropped;
|
||||
if (dropped.Count == 0 || string.Equals(revision, priorRevision, StringComparison.Ordinal)) return;
|
||||
Interlocked.Add(ref _unknownOperationRows, dropped.Count);
|
||||
foreach (var (id, bits) in dropped)
|
||||
{
|
||||
UnknownOperationsCounter.Add(1);
|
||||
Logger.LogWarning("Data connection {DataConnectionId} in artifact {ArtifactRevision} grants operation bits {UnknownOperations} " +
|
||||
"this node does not implement; they were dropped (no grant). Upgrade this node before relying on them.",
|
||||
id, revision, (int)bits);
|
||||
}
|
||||
// Collected under _sync, reported after release (logging may block).
|
||||
if (report) UnknownOperationDrops.Report(Logger, UnknownOperationDrops.ConnectionKind, snapshot.ArtifactRevision, dropped);
|
||||
}
|
||||
private static bool SameAllowlist(IReadOnlyDictionary<string, string> left, IReadOnlyDictionary<string, string> right) =>
|
||||
left.Count == right.Count && left.All(x => right.TryGetValue(x.Key, out var value) && string.Equals(value, x.Value, StringComparison.Ordinal));
|
||||
|
||||
Reference in New Issue
Block a user