fix(grpc-data): A1 review nit — colliding condition placements are logged at Warning (locally)

DistinctPlacements still drops every placement of an address claimed twice (fail closed); Compile takes an
optional logger (the coordinator passes its own) and the drop is reported in the local log only.
This commit is contained in:
Joseph Doherty
2026-11-24 10:44:00 -05:00
parent 16166c21e5
commit 2fdf9d87c2
3 changed files with 54 additions and 5 deletions
@@ -168,7 +168,7 @@ public sealed class LocalCatalogCoordinator
&& string.Equals(node.ClusterId, snapshot.ClusterId, StringComparison.OrdinalIgnoreCase)
&& node.Enabled && !node.MaintenanceMode)) return false;
var token = _activation.CaptureStagedAuthority(attempt.Epoch, state.AuthorityEpoch);
_staged = LocalExportCatalog.Compile(snapshot, serving, token);
_staged = LocalExportCatalog.Compile(snapshot, serving, token, logger: Logger);
if (_staged.DroppedUnknownOperations.Count != 0 && !string.Equals(_droppedExportRevision, attempt.Revision, StringComparison.Ordinal))
dropped = _staged.DroppedUnknownOperations;
_droppedExportRevision = attempt.Revision;
@@ -21,7 +21,8 @@ public sealed partial class LocalExportCatalog
/// <summary>Compile origin views from the deployed snapshot using the same identity and ACL producers as the SDK.</summary>
public static LocalExportCatalog Compile(DraftSnapshot snapshot, ServingIdentity serving,
IDataMappedCatalogAuthority activation, int maximumNodes = 100_000)
IDataMappedCatalogAuthority activation, int maximumNodes = 100_000,
Microsoft.Extensions.Logging.ILogger? logger = null)
{
ArgumentNullException.ThrowIfNull(snapshot);
serving.Validate(requireEpochs: true);
@@ -184,7 +185,7 @@ public sealed partial class LocalExportCatalog
kind == DataValueKind.Unspecified ? DataValueKind.Null : kind, supported: kind != DataValueKind.Unspecified, enabled: value.Enabled);
}
AddConditionPlacements();
return new(cluster, serving, activation, nodes, snapshot.DataExports, maximumNodes, DistinctPlacements(conditionPlacements));
return new(cluster, serving, activation, nodes, snapshot.DataExports, maximumNodes, DistinctPlacements(conditionPlacements, logger));
// A1 (§5.2): the UNS placements. Native: the RESERVED reference id Area/Line/Equipment/EffectiveName of every
// reference to an alarm-bearing tag — the same derivation as AddressSpaceComposer.BuildUnsReferenceVariables, which
@@ -231,8 +232,22 @@ public sealed partial class LocalExportCatalog
/// An address claimed by two placements is ambiguous: neither is listed (fail closed for conditions), and the v1
/// catalog compiles exactly as before.
/// </summary>
private static IReadOnlyList<LocalConditionPlacement> DistinctPlacements(IEnumerable<LocalConditionPlacement> placements) =>
placements.GroupBy(x => (x.View.Realm, x.View.Address.Identifier)).Where(x => x.Count() == 1).Select(x => x.Single()).ToArray();
/// <remarks>Review nit: the drop is logged at Warning — LOCALLY only (the identifiers may be RawPaths; nothing about
/// the collision reaches a peer, which simply does not see those conditions listed).</remarks>
private static IReadOnlyList<LocalConditionPlacement> DistinctPlacements(IEnumerable<LocalConditionPlacement> placements,
Microsoft.Extensions.Logging.ILogger? logger)
{
var groups = placements.GroupBy(x => (x.View.Realm, x.View.Address.Identifier)).ToList();
var colliding = groups.Where(x => x.Count() > 1).ToList();
if (colliding.Count > 0 && logger is not null)
{
Microsoft.Extensions.Logging.LoggerExtensions.LogWarning(logger,
"Origin catalog: {Count} condition placement address(es) are claimed by more than one placement and are not listed (fail closed): {Addresses}",
colliding.Count, string.Join(", ", colliding.Take(10).Select(g => $"{g.Key.Realm}:{g.Key.Identifier} x{g.Count()}")));
}
return groups.Where(x => x.Count() == 1).Select(x => x.Single()).ToArray();
}
private static DataValueKind ValueKind(string type) => type switch
{
@@ -101,6 +101,40 @@ public sealed class GrpcDataConditionPlacementTests
catalog.TryResolveConditionPlacement(placements[2].View with { MappingId = "m", MappingRevision = 1 }, out _).ShouldBeFalse();
}
/// <summary>Review nit: an address claimed by two placements drops both (fail closed) and says so at Warning in the
/// LOCAL log; the listing simply does not carry them.</summary>
[Fact]
public void Colliding_placements_are_dropped_and_logged_at_Warning()
{
using var fixture = new LocalDataFixture();
var b = Fixed();
var clash = new ScriptedAlarm
{
ScriptedAlarmId = "Area/Line/Filler/OverTemp", EquipmentId = "eq-1", Name = "Clash", AlarmType = "AlarmCondition",
MessageTemplate = "x", PredicateScriptId = "script",
};
var log = new CapturingLogger();
var catalog = LocalExportCatalog.Compile(With(b, scripted: [.. b.ScriptedAlarms, clash]), fixture.Serving,
fixture.Activation.CaptureAuthority(), logger: log);
catalog.ConditionPlacements.ShouldNotContain(p => p.View.Address.Identifier == "Area/Line/Filler/OverTemp");
catalog.ConditionPlacements.Count.ShouldBe(3);
log.Warnings.ShouldHaveSingleItem().ShouldContain("Area/Line/Filler/OverTemp");
}
private sealed class CapturingLogger : Microsoft.Extensions.Logging.ILogger
{
public List<string> Warnings { get; } = [];
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => null;
public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) => true;
public void Log<TState>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, TState state,
Exception? exception, Func<TState, Exception?, string> formatter)
{
if (logLevel == Microsoft.Extensions.Logging.LogLevel.Warning) Warnings.Add(formatter(state, exception));
}
}
[Fact]
public void The_v1_catalog_is_unchanged_by_the_enumeration()
{