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:
@@ -34,4 +34,8 @@ public sealed record DataConnectionDiagnosticsSnapshot(
|
||||
long? CompactFrameCount = null,
|
||||
long? FallbackFrameCount = null,
|
||||
long? SerializedValueFrameBytes = null,
|
||||
string? AccountingInstanceId = null);
|
||||
string? AccountingInstanceId = null,
|
||||
// X0 tolerant reader: operation bits this connection row was authored with that this node does not implement and
|
||||
// dropped (None = nothing dropped; null = from an older sender), and how many of its mappings had bits dropped.
|
||||
DataOperations? DroppedUnknownOperations = null,
|
||||
int? MappingsWithDroppedOperations = null);
|
||||
|
||||
@@ -43,10 +43,15 @@ public sealed record DriverInstanceDiagnostics(
|
||||
/// needs to be explicitly visible rather than inferred. Defaults to false, which is also what
|
||||
/// every node that booted normally reports.
|
||||
/// </param>
|
||||
/// <param name="DroppedExportOperations">
|
||||
/// X0 tolerant reader: origin exports on this node whose operation bits this build does not implement, with the
|
||||
/// bits dropped (no grant). Empty when none; null from a sender built before X0 or when no catalog is staged.
|
||||
/// </param>
|
||||
public sealed record NodeDiagnosticsSnapshot(
|
||||
NodeId NodeId,
|
||||
RevisionHash? CurrentRevision,
|
||||
IReadOnlyList<DriverInstanceDiagnostics> Drivers,
|
||||
DateTime AsOfUtc,
|
||||
bool RunningFromCache = false,
|
||||
IReadOnlyList<DataConnectionDiagnosticsSnapshot>? DataConnections = null);
|
||||
IReadOnlyList<DataConnectionDiagnosticsSnapshot>? DataConnections = null,
|
||||
IReadOnlyDictionary<string, ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections.DataOperations>? DroppedExportOperations = null);
|
||||
|
||||
@@ -21,10 +21,11 @@ public static class DataConnectionValidator
|
||||
|
||||
/// <summary>
|
||||
/// Node-side re-validation of an already-deployed artifact (artifact parse, origin catalog compile). Identical to
|
||||
/// <see cref="Validate(DraftSnapshot)"/> except that the X0-RESERVED operation bits (<see cref="DataOperationSets.Reserved"/>)
|
||||
/// are IGNORED rather than rejected: a newer central may author them, and rejecting would take down every data
|
||||
/// connection/export on the node. Each consumer of the rows keeps only the bits it understands (fail closed). A bit
|
||||
/// outside both sets is still a malformed row (nothing can author it).
|
||||
/// <see cref="Validate(DraftSnapshot)"/> except that operation bits outside <see cref="DataOperationSets.Understood"/>
|
||||
/// are IGNORED rather than rejected (X0 tolerant reader): a newer central may author them, and rejecting would take
|
||||
/// down every data connection/export on the node. The understood subset is still validated (a row must be non-empty;
|
||||
/// a mapping may not grant an understood operation its connection lacks), and every consumer of the rows masks the
|
||||
/// rest away, so an unknown bit grants nothing (fail closed).
|
||||
/// </summary>
|
||||
public static IReadOnlyList<ValidationError> ValidateDeployed(DraftSnapshot draft) => Validate(draft, deployed: true);
|
||||
|
||||
@@ -34,8 +35,8 @@ public static class DataConnectionValidator
|
||||
var errors = new List<ValidationError>();
|
||||
void Add(string code, string id, string message) => errors.Add(new(code, message, id));
|
||||
bool Same(string? a, string? b) => Ids.Equals(a, b);
|
||||
var accepted = deployed ? KnownOperations | DataOperationSets.Reserved : KnownOperations;
|
||||
bool ValidOps(DataOperations operations) => operations != DataOperations.None && (operations & ~accepted) == 0;
|
||||
bool ValidOps(DataOperations operations) => operations != DataOperations.None &&
|
||||
(deployed || (operations & ~KnownOperations) == 0);
|
||||
DataOperations Understood(DataOperations operations) => deployed ? operations & DataOperationSets.Understood : operations;
|
||||
bool NodesValid(IEnumerable<string> ids, string owner)
|
||||
{
|
||||
|
||||
@@ -33,6 +33,8 @@ public static class DataConnectionRegistration
|
||||
services.AddSingleton<IValidateOptions<DataConnectionOptions>>(new DataConnectionOptionsValidator(environment));
|
||||
if (!options.Enabled) return options;
|
||||
if (!hasDriver) throw new InvalidOperationException("DataConnections requires this node's driver role.");
|
||||
// Fail host start on a wire-contract drift (frozen field numbers and the X0 reservations); a descriptor walk, cheap.
|
||||
ZB.MOM.WW.OtOpcUa.Commons.Protos.DataConnectionProtoContract.Validate();
|
||||
|
||||
services.TryAddSingleton<TimeProvider>(TimeProvider.System);
|
||||
services.TryAddSingleton<DataWriteDispatchFence>();
|
||||
@@ -56,7 +58,7 @@ public static class DataConnectionRegistration
|
||||
var state = CaptureReadRole(role, warm);
|
||||
var servingRole = settings.IsWarm && state.WarmRole != WarmRole.Active ? "Standby" : state.Role;
|
||||
return new(identity.NodeId, identity.Incarnation, servingRole, 0, 0, state.Generation);
|
||||
});
|
||||
}) { Logger = LoggerFor<LocalCatalogCoordinator>(sp) };
|
||||
});
|
||||
services.AddSingleton(sp => new PartitionedSampleHub(options.Hub, sp.GetRequiredService<TimeProvider>()));
|
||||
services.AddSingleton(sp => new SourceSamplePublisher(sp.GetRequiredService<PartitionedSampleHub>(),
|
||||
@@ -72,7 +74,8 @@ public static class DataConnectionRegistration
|
||||
sp.GetRequiredService<BrowseContinuationRegistry>(), sp.GetRequiredService<IGrpcDataAdapterConnectionSource>(),
|
||||
sp.GetRequiredService<DataOperationPolicy>(), 256, options.MaxConcurrentCalls));
|
||||
services.AddSingleton<IFederatedProjectionCatalog>(sp => sp.GetRequiredService<RemoteNamespaceResolver>());
|
||||
services.AddSingleton<ProjectedMappingDeploymentRuntime>();
|
||||
services.AddSingleton(sp => new ProjectedMappingDeploymentRuntime(sp.GetRequiredService<LocalCatalogCoordinator>(),
|
||||
sp.GetRequiredService<RemoteNamespaceResolver>()) { Logger = LoggerFor<ProjectedMappingDeploymentRuntime>(sp) });
|
||||
services.TryAddSingleton<DeferredAddressSpaceSink>();
|
||||
services.AddSingleton<DeferredProjectedNodeAccess>();
|
||||
services.AddSingleton<IProjectedNodeLookup>(sp => sp.GetRequiredService<DeferredProjectedNodeAccess>());
|
||||
@@ -214,8 +217,7 @@ public static class DataConnectionRegistration
|
||||
return new DataConnectionConsumerRoleSnapshot(mode, eligible, state.Generation);
|
||||
})
|
||||
{
|
||||
Logger = (Microsoft.Extensions.Logging.ILogger?)sp.GetService<Microsoft.Extensions.Logging.ILoggerFactory>()?.CreateLogger<DataConnectionDeploymentRuntime>()
|
||||
?? Microsoft.Extensions.Logging.Abstractions.NullLogger.Instance,
|
||||
Logger = LoggerFor<DataConnectionDeploymentRuntime>(sp),
|
||||
};
|
||||
return runtime;
|
||||
});
|
||||
@@ -237,6 +239,9 @@ public static class DataConnectionRegistration
|
||||
return options;
|
||||
}
|
||||
|
||||
private static Microsoft.Extensions.Logging.ILogger LoggerFor<T>(IServiceProvider sp) =>
|
||||
(Microsoft.Extensions.Logging.ILogger?)sp.GetService<Microsoft.Extensions.Logging.ILoggerFactory>()?.CreateLogger<T>()
|
||||
?? Microsoft.Extensions.Logging.Abstractions.NullLogger.Instance;
|
||||
private static (string Role, long Generation, WarmRole? WarmRole, long ReadEpoch) CaptureReadRole(
|
||||
RedundancyRoleView role, DataConnectionWarmRoleView warm)
|
||||
{
|
||||
|
||||
+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));
|
||||
|
||||
@@ -46,6 +46,10 @@ public sealed class LocalCatalogCoordinator
|
||||
// A test can hold the host's existing subscription boundary to observe ordering.
|
||||
internal Action? BeforeSubscriptionApplyForTests { get; set; }
|
||||
|
||||
private string? _droppedExportRevision;
|
||||
/// <summary>Diagnostics sink for the X0 dropped export-operation warning.</summary>
|
||||
public Microsoft.Extensions.Logging.ILogger Logger { private get; init; } = Microsoft.Extensions.Logging.Abstractions.NullLogger.Instance;
|
||||
|
||||
public LocalCatalogCoordinator(CatalogActivation activation, DataPlaneAuthorityState authority, Func<ServingIdentity> serving)
|
||||
{
|
||||
_activation = activation ?? throw new ArgumentNullException(nameof(activation));
|
||||
@@ -132,6 +136,7 @@ public sealed class LocalCatalogCoordinator
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(attempt);
|
||||
ArgumentNullException.ThrowIfNull(snapshot);
|
||||
IReadOnlyDictionary<string, DataOperations>? dropped = null;
|
||||
lock (_gate)
|
||||
{
|
||||
var state = _activation.Current;
|
||||
@@ -145,8 +150,13 @@ public sealed class LocalCatalogCoordinator
|
||||
&& node.Enabled && !node.MaintenanceMode)) return false;
|
||||
var token = _activation.CaptureStagedAuthority(attempt.Epoch, state.AuthorityEpoch);
|
||||
_staged = LocalExportCatalog.Compile(snapshot, serving, token);
|
||||
return true;
|
||||
if (_staged.DroppedUnknownOperations.Count != 0 && !string.Equals(_droppedExportRevision, attempt.Revision, StringComparison.Ordinal))
|
||||
dropped = _staged.DroppedUnknownOperations;
|
||||
_droppedExportRevision = attempt.Revision;
|
||||
}
|
||||
// Collected under _gate, reported after release.
|
||||
if (dropped is not null) UnknownOperationDrops.Report(Logger, UnknownOperationDrops.ExportKind, attempt.Revision, dropped);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Complete(CatalogAttempt attempt, bool topologySucceeded)
|
||||
|
||||
@@ -78,6 +78,7 @@ public sealed partial class LocalExportCatalog
|
||||
.ToDictionary(x => x.Key, x => x.OrderBy(n => n.Metadata.BrowseName, StringComparer.Ordinal)
|
||||
.ThenBy(n => n.Metadata.View.Address.Identifier, StringComparer.Ordinal).ToArray());
|
||||
var rules = new List<ExportRule>();
|
||||
var dropped = new Dictionary<string, DataOperations>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var export in exports.Where(x => x.Enabled && string.Equals(x.ClusterId, clusterId, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
var wholeRealm = export.RootKind == "Cluster" && string.Equals(export.RootEntityId, clusterId, StringComparison.OrdinalIgnoreCase);
|
||||
@@ -91,12 +92,17 @@ public sealed partial class LocalExportCatalog
|
||||
rules.Add(new(export.DataExportId, export.PrincipalId, export.Realm, wholeRealm ? null : roots[0].Metadata.View, wholeRealm,
|
||||
// X0: an export bit this build does not implement grants nothing (a None-after-mask rule is kept and inert).
|
||||
export.AllowedOperations & DataOperationSets.Understood, export.MaxBatchItems, export.MaxPageItems, export.MaxMonitoredItems, export.MaxStreams));
|
||||
if (UnknownOperationDrops.Unknown(export.AllowedOperations) is var unknown && unknown != DataOperations.None)
|
||||
dropped[export.DataExportId] = unknown;
|
||||
}
|
||||
_exports = rules.ToArray();
|
||||
DroppedUnknownOperations = dropped;
|
||||
Nodes = new ReadOnlyCollection<LocalDataNode>(_nodes.Values.ToArray());
|
||||
}
|
||||
|
||||
public string ClusterId { get; }
|
||||
/// <summary>X0 diagnostics: exports whose operation bits this build does not implement were dropped, by export id.</summary>
|
||||
public IReadOnlyDictionary<string, DataOperations> DroppedUnknownOperations { get; }
|
||||
public ServingIdentity Serving { get; }
|
||||
internal IDataMappedCatalogAuthority MappingAuthority => _activation;
|
||||
public long AuthorityEpoch => _activation.AuthorityEpoch;
|
||||
@@ -112,6 +118,7 @@ public sealed partial class LocalExportCatalog
|
||||
throw new ArgumentException("A new process or catalog generation requires a newly compiled catalog.", nameof(serving));
|
||||
ClusterId = current.ClusterId; Serving = serving; _activation = current._activation;
|
||||
_nodes = current._nodes; _children = current._children; _exports = current._exports; Nodes = current.Nodes;
|
||||
DroppedUnknownOperations = current.DroppedUnknownOperations;
|
||||
}
|
||||
|
||||
/// <summary>A role-only transition changes serving provenance without freshening source acquisitions.</summary>
|
||||
|
||||
+39
@@ -29,6 +29,12 @@ public sealed class ProjectedMappingDeploymentRuntime : IDisposable
|
||||
private object _configuredStamp = new();
|
||||
private bool _disposed;
|
||||
|
||||
private IReadOnlyDictionary<string, (string ConnectionId, DataOperations Bits)> _droppedOperations =
|
||||
new Dictionary<string, (string, DataOperations)>();
|
||||
private string? _droppedRevision;
|
||||
/// <summary>Diagnostics sink for the X0 dropped-operation warning (init so the DI constructor shape is unchanged).</summary>
|
||||
public Microsoft.Extensions.Logging.ILogger Logger { private get; init; } = Microsoft.Extensions.Logging.Abstractions.NullLogger.Instance;
|
||||
|
||||
public ProjectedMappingDeploymentRuntime(LocalCatalogCoordinator coordinator, RemoteNamespaceResolver resolver)
|
||||
{
|
||||
_coordinator = coordinator ?? throw new ArgumentNullException(nameof(coordinator));
|
||||
@@ -123,13 +129,45 @@ public sealed class ProjectedMappingDeploymentRuntime : IDisposable
|
||||
ArgumentNullException.ThrowIfNull(connections);
|
||||
var frozenMappings = mappings.Select(Copy).ToArray();
|
||||
var frozenConnections = connections.Select(Copy).ToArray();
|
||||
// X0 tolerant reader: a mapping bit this build does not implement grants nothing. Mask the frozen copies (the
|
||||
// caller's rows are untouched) so every downstream check sees only understood operations.
|
||||
var dropped = new Dictionary<string, (string ConnectionId, DataOperations Bits)>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var mapping in frozenMappings)
|
||||
{
|
||||
var unknown = UnknownOperationDrops.Unknown(mapping.AllowedOperations);
|
||||
if (unknown == DataOperations.None) continue;
|
||||
mapping.AllowedOperations &= DataOperationSets.Understood;
|
||||
dropped[mapping.RemoteNamespaceMappingId] = (mapping.DataConnectionId, unknown);
|
||||
}
|
||||
var report = false;
|
||||
lock (_gate)
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
if (!ReferenceEquals(attempt, _attempt)) return;
|
||||
_staged = frozenMappings;
|
||||
_connections = frozenConnections;
|
||||
_droppedOperations = dropped;
|
||||
report = dropped.Count != 0 && !string.Equals(_droppedRevision, attempt.Revision, StringComparison.Ordinal);
|
||||
_droppedRevision = attempt.Revision;
|
||||
}
|
||||
// Collected under _gate, reported after release.
|
||||
if (report)
|
||||
UnknownOperationDrops.Report(Logger, UnknownOperationDrops.MappingKind, attempt.Revision,
|
||||
dropped.ToDictionary(x => x.Key, x => x.Value.Bits, StringComparer.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
/// <summary>X0 diagnostics: the staged mappings whose unknown operation bits were dropped, by mapping id.</summary>
|
||||
public IReadOnlyDictionary<string, DataOperations> DroppedUnknownOperations
|
||||
{
|
||||
get { lock (_gate) return _droppedOperations.ToDictionary(x => x.Key, x => x.Value.Bits, StringComparer.OrdinalIgnoreCase); }
|
||||
}
|
||||
|
||||
/// <summary>Per data connection id, how many of the staged mappings had unknown operation bits dropped.</summary>
|
||||
public IReadOnlyDictionary<string, int> CaptureDroppedByConnection()
|
||||
{
|
||||
lock (_gate)
|
||||
return _droppedOperations.Values.GroupBy(x => x.ConnectionId, StringComparer.OrdinalIgnoreCase)
|
||||
.ToDictionary(x => x.Key, x => x.Count(), StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
internal void AttemptBegan(CatalogAttempt attempt)
|
||||
@@ -144,6 +182,7 @@ public sealed class ProjectedMappingDeploymentRuntime : IDisposable
|
||||
Volatile.Write(ref _configuredStamp, new object());
|
||||
_configuredCapabilities.Clear();
|
||||
_staged = []; _connections = [];
|
||||
_droppedOperations = new Dictionary<string, (string, DataOperations)>();
|
||||
changed = _active.Count != 0;
|
||||
Volatile.Write(ref _active, Array.Empty<ProjectedMappingPlacement>());
|
||||
_byMapping.Clear();
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
using System.Diagnostics.Metrics;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Observability;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Runtime.DataConnections;
|
||||
|
||||
/// <summary>
|
||||
/// X0 tolerant-reader diagnostics. A deployed row (connection, export or mapping) may carry operation bits a newer
|
||||
/// central authored and this build does not implement. They are dropped (no grant). Each drop is logged and counted.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Semantics: counted once per row per ACCEPTED ARTIFACT CHANGE for that kind. Re-applying the same revision does not
|
||||
/// recount, but A → B → A does (each is a change), and a process restart resets the per-kind memory.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The counter is <see cref="CounterName"/>, tagged <c>kind</c> = <c>connection</c> | <c>export</c> | <c>mapping</c>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Callers collect under their own lock and call <see cref="Report"/> after releasing it.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public static class UnknownOperationDrops
|
||||
{
|
||||
public const string CounterName = "otopcua.dataconnection.unknown_operations_dropped";
|
||||
public const string ConnectionKind = "connection";
|
||||
public const string ExportKind = "export";
|
||||
public const string MappingKind = "mapping";
|
||||
|
||||
private static readonly Counter<long> Counter = OtOpcUaTelemetry.Meter.CreateCounter<long>(CounterName, unit: "{row}",
|
||||
description: "Deployed data-connection, export or mapping rows carrying operation bits this node does not implement; " +
|
||||
"the bits were dropped (no grant). Counted once per row per accepted artifact change.");
|
||||
|
||||
/// <summary>The bits of <paramref name="authored"/> this build drops (zero when it understands all of them).</summary>
|
||||
public static DataOperations Unknown(DataOperations authored) => authored & ~DataOperationSets.Understood;
|
||||
|
||||
/// <summary>Logs a Warning and counts one per row. Never call while holding a component lock.</summary>
|
||||
public static void Report(ILogger logger, string kind, string revision, IReadOnlyDictionary<string, DataOperations> dropped)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(logger);
|
||||
ArgumentNullException.ThrowIfNull(dropped);
|
||||
foreach (var (id, bits) in dropped)
|
||||
{
|
||||
Counter.Add(1, new KeyValuePair<string, object?>("kind", kind));
|
||||
logger.LogWarning("Data {Kind} {Id} in artifact {ArtifactRevision} grants operation bits 0x{UnknownOperations:X} this node " +
|
||||
"does not implement; they were dropped (no grant). Upgrade this node before relying on them.",
|
||||
kind, id, revision, (int)bits);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2981,7 +2981,9 @@ public sealed class DriverHostActor : ReceiveActor, IWithTimers, IWithUnboundedS
|
||||
Drivers: drivers,
|
||||
AsOfUtc: DateTime.UtcNow,
|
||||
RunningFromCache: _isRunningFromCache,
|
||||
DataConnections: _dataConnections?.CaptureDiagnostics(_projectedPublisher?.CaptureSourceCounts()));
|
||||
DataConnections: _dataConnections?.CaptureDiagnostics(_projectedPublisher?.CaptureSourceCounts(),
|
||||
_catalogCoordinator?.ProjectedMappings?.CaptureDroppedByConnection()),
|
||||
DroppedExportOperations: _catalogCoordinator?.Current?.DroppedUnknownOperations);
|
||||
Sender.Tell(snapshot);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user