feat(drivers): every driver reports the authored tags it skipped (Gitea #541)

A driver builds its RawPath -> definition table at init and tolerates a
per-tag miss: an unmappable TagConfig, an unparseable address, a
capability-matrix rejection. That tolerance is right -- one bad tag must not
take down the other few thousand. What was missing is any statement of the
fact afterwards. A skip is not an error and happens before any read, so the
driver stays Healthy, errors/5 min stays 0, Last error stays empty, and Last
read advances live off the tags that did map. On the wonder Makino in #540
that reading held while focas-z-34184 ignored 20 of its 22 tags.

New optional capability ISkippedTagReporter, backed by a shared
SkippedTagLedger so the reset/commit/cap rules are one implementation rather
than one per driver. The report -- authored count, exact skipped count, and a
capped sample of RawPath + reason -- rides DriverHealthChanged to a new Tags
column on /hosts, over the Phase 5 telemetry stream. No table: a driver-only
node has no ConfigDb to write to, the lesson from #521.

The issue named eight drivers. It is twelve -- every driver in
DriverTypeNames.All has an authored-tag skip path. Calculation (no scriptId),
MTConnect (no readable DataItem id), Galaxy (no attributeRef) and OpcUaClient
(no nodeId) were unlisted, and OpcUaClient's was the quietest of the twelve:
NamespaceMap drops such an entry with a bare `continue` and not even a log
line. SkippedTagReporterFleetTests pins the invariant reflectively over every
IDriver in src/Drivers/, so a thirteenth cannot re-introduce the silence.

Sql drops a tag at TWO points and its report is the union of both: a blob
that does not map, AND an identifier the 8.1 catalog gate rejects against the
live catalog. The second is what schema drift produces -- a renamed column, a
dropped view -- months after a deployment sealed green, and reporting only
the first would have that driver claim "0 skipped" while polling half its
tags, which is worse than reporting nothing because the column would then be
actively reassuring.

Deliberately additive to driver state, never a change of it. Latching
non-Healthy for a config problem would satisfy both halves of the #527
comms-loss conjunction -- 90 s without a successful read AND non-Healthy --
and a driver whose tags were ALL skipped has no successful reads by
construction, so it would reconnect-loop forever against a healthy device.

Three details that are load-bearing rather than incidental:

- The skip digest is part of the publish fingerprint. A skipped tag leaves
  every other fingerprint component identical to a clean driver's, so without
  it PublishHealthSnapshot's dedup swallows exactly the publish carrying the
  signal -- the trap that already bit the rediscovery and host-status
  channels. The digest covers the sample, not just the counts: a redeploy
  that fixes one tag and breaks another leaves both counts unchanged.
- The count is exact; only the sample is capped, and the tooltip says so when
  it is showing fewer than it counted. A truncated list that looked complete
  would have an operator fix twenty tags and believe the job done.
- The ledger stages and commits, so an init that throws part-way leaves the
  previous report standing. A partial snapshot would read as "we now skip
  fewer tags", the opposite of the truth.

The proto field needs no companion presence flag, unlike host_statuses: a
singular message field carries real presence in proto3, and a has_ flag would
collide with protoc's generated HasSkippedTags.

Verified red-first three ways: dropping SkippedTagDigest from the fingerprint
fails the two dedup tests, removing the seam from one driver fails the fleet
guard, and dropping the catalog-gate leg fails the Sql union test. Full
solution builds with zero new warnings against 4e22f024.
This commit is contained in:
Joseph Doherty
2026-08-05 19:23:40 -04:00
parent 4e22f02434
commit 39db75083d
34 changed files with 1572 additions and 30 deletions
@@ -213,4 +213,96 @@ public sealed class HostsDriverViewTests
row.HostStatuses.ShouldBeNull();
row.DegradedHosts.ShouldBeEmpty();
}
// ---- skipped tags (Gitea #541) ----
/// <summary>
/// The Makino case from Gitea #540, as the row renders it: every driver-level field reads healthy
/// while 20 of 22 tags are not being polled. The skip field is the only thing on the row that
/// contradicts it.
/// </summary>
[Fact]
public void A_healthy_row_still_reports_the_tags_its_driver_is_ignoring()
{
var snapshot = Snap("MAIN", "focas-z-34184") with
{
SkippedTags = new SkippedTagReport(22, 20,
[new SkippedTag("Makino/Identity/SeriesNumber", "invalid Address")]),
};
var row = HostsDriverView.Build([snapshot], nodes: null, instances: null).Single().Drivers.Single();
row.State.ShouldBe("Healthy");
row.ErrorCount5Min.ShouldBe(0);
row.LastError.ShouldBeNull();
row.HasSkippedTags.ShouldBeTrue("the row must contradict its own healthy-looking columns");
row.SkippedTags!.SkippedCount.ShouldBe(20);
}
/// <summary>
/// A truncated sample must SAY it is truncated. Without the note a capped list reads as the whole
/// list, and an operator who fixes the twenty named tags believes the job is done.
/// </summary>
[Fact]
public void The_skip_tooltip_admits_when_the_sample_is_shorter_than_the_count()
{
var snapshot = Snap("MAIN", "drv-a") with
{
SkippedTags = new SkippedTagReport(500, 137, [new SkippedTag("tag-0", "TagConfig did not map")]),
};
var title = HostsDriverView.Build([snapshot], nodes: null, instances: null)
.Single().Drivers.Single().SkippedTagsTitle();
title.ShouldContain("137 of 500");
title.ShouldContain("+136 more not shown");
}
/// <summary>A complete sample carries no truncation note.</summary>
[Fact]
public void The_skip_tooltip_omits_the_truncation_note_when_the_sample_is_complete()
{
var snapshot = Snap("MAIN", "drv-a") with
{
SkippedTags = new SkippedTagReport(5, 1, [new SkippedTag("tag-0", "TagConfig did not map")]),
};
HostsDriverView.Build([snapshot], nodes: null, instances: null)
.Single().Drivers.Single().SkippedTagsTitle()
.ShouldNotContain("more not shown");
}
/// <summary>
/// A driver polling NONE of its tags gets its own wording — it is the most likely of all to look
/// healthy, because it has no failing reads to report.
/// </summary>
[Fact]
public void A_driver_polling_nothing_is_called_out_as_such()
{
var snapshot = Snap("MAIN", "drv-a") with
{
SkippedTags = new SkippedTagReport(3, 3, [new SkippedTag("a", "r")]),
};
var row = HostsDriverView.Build([snapshot], nodes: null, instances: null).Single().Drivers.Single();
row.SkippedTags!.SkippedEverything.ShouldBeTrue();
row.SkippedTagsTitle().ShouldContain("NONE");
}
/// <summary>
/// A driver that cannot report skips keeps null — distinct from one reporting zero. The column
/// renders "—" for the former and "N tags" for the latter, and collapsing them would claim an
/// unreporting driver is positively known to be polling everything.
/// </summary>
[Fact]
public void A_driver_without_a_skip_report_keeps_null_and_claims_nothing()
{
var row = HostsDriverView.Build([Snap("MAIN", "drv-a")], nodes: null, instances: null)
.Single().Drivers.Single();
row.SkippedTags.ShouldBeNull();
row.HasSkippedTags.ShouldBeFalse();
row.SkippedTagsTitle().ShouldBeEmpty();
}
}
@@ -220,6 +220,62 @@ public sealed class TelemetryProtoMapCentralTests
TelemetryProtoMapCentral.ToHealth(absent).HostStatuses.ShouldBeNull();
}
/// <summary>
/// The skipped-tag report (Gitea #541) survives the wire with the same tri-state discipline:
/// <b>null</b> (the driver cannot report skips) must stay distinguishable from a <b>zero report</b>
/// (it can, and skipped nothing). Unlike the repeated host_statuses field this needs no companion
/// presence flag — a singular message field carries real presence in proto3 — but the distinction it
/// protects is the same one, and collapsing it would render an unreporting driver as positively
/// known-clean.
/// </summary>
[Fact]
public void ToHealth_skipped_tags_round_trip_with_the_null_vs_zero_distinction_intact()
{
var populated = new DriverHealth
{
ClusterId = "c1", DriverInstanceId = "d1", State = "Healthy",
PublishedUtc = Timestamp.FromDateTime(SampleUtc),
SkippedTags = new SkippedTags
{
AuthoredCount = 22,
// Deliberately larger than the sample: the cap is on the detail, never on the count.
SkippedCount = 20,
Sample =
{
new SkippedTag { RawPath = "Makino/Identity/SeriesNumber", Reason = "invalid Address" },
},
},
};
var mapped = TelemetryProtoMapCentral.ToHealth(populated).SkippedTags;
mapped.ShouldNotBeNull();
mapped!.AuthoredCount.ShouldBe(22);
mapped.SkippedCount.ShouldBe(20);
mapped.Sample.Count.ShouldBe(1, "a truncated sample must arrive truncated, not padded or dropped");
mapped.Sample[0].RawPath.ShouldBe("Makino/Identity/SeriesNumber");
mapped.Sample[0].Reason.ShouldBe("invalid Address");
// A driver that reports, and skipped nothing: a zero report, NOT null.
var clean = new DriverHealth
{
ClusterId = "c1", DriverInstanceId = "d1", State = "Healthy",
PublishedUtc = Timestamp.FromDateTime(SampleUtc),
SkippedTags = new SkippedTags { AuthoredCount = 12, SkippedCount = 0 },
};
var mappedClean = TelemetryProtoMapCentral.ToHealth(clean).SkippedTags;
mappedClean.ShouldNotBeNull();
mappedClean!.HasSkips.ShouldBeFalse();
mappedClean.AuthoredCount.ShouldBe(12);
// A driver that cannot report at all: null, NOT a zero report.
var absentSkips = new DriverHealth
{
ClusterId = "c1", DriverInstanceId = "d1", State = "Healthy",
PublishedUtc = Timestamp.FromDateTime(SampleUtc),
};
TelemetryProtoMapCentral.ToHealth(absentSkips).SkippedTags.ShouldBeNull();
}
/// <summary>
/// An unparseable host state degrades to <see cref="HostState.Unknown"/> rather than throwing. A node
/// running a newer build that added an enum member must not be able to kill central's telemetry
@@ -210,7 +210,8 @@ public sealed class DriverInstanceActorHostStatusTests : RuntimeActorTestBase
int errorCount5Min,
DateTime? rediscoveryNeededUtc = null,
string? rediscoveryReason = null,
IReadOnlyList<HostConnectivityStatus>? hostStatuses = null)
IReadOnlyList<HostConnectivityStatus>? hostStatuses = null,
SkippedTagReport? skippedTags = null)
{
lock (_published) _published.Add(new HealthPublish(health, hostStatuses));
}
@@ -186,7 +186,8 @@ public sealed class DriverInstanceActorRediscoverySignalTests : RuntimeActorTest
int errorCount5Min,
DateTime? rediscoveryNeededUtc = null,
string? rediscoveryReason = null,
IReadOnlyList<HostConnectivityStatus>? hostStatuses = null)
IReadOnlyList<HostConnectivityStatus>? hostStatuses = null,
SkippedTagReport? skippedTags = null)
{
lock (_published)
{
@@ -0,0 +1,269 @@
using Akka.Actor;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
using ZB.MOM.WW.OtOpcUa.Runtime.Drivers;
using ZB.MOM.WW.OtOpcUa.Runtime.Tests.Harness;
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.Drivers;
/// <summary>
/// Covers the <see cref="ISkippedTagReporter"/> consumer (Gitea #541) — the signal that contradicts a
/// driver reporting <c>Healthy</c>, 0 errors and a live-advancing last read while ignoring most of the
/// tags it was authored.
/// <para><b>Why it does not go to the DB</b> — the same reason the #521 host statuses do not: a
/// driver-only node has no ConfigDb connection since per-cluster mesh Phase 4, so the data rides the
/// driver-health snapshot and the Phase 5 telemetry stream instead.</para>
/// </summary>
[Trait("Category", "Unit")]
public sealed class DriverInstanceActorSkippedTagTests : RuntimeActorTestBase
{
/// <summary>The base case: a reporting driver's skips reach the health publisher.</summary>
[Fact]
public void Skipped_tags_reach_the_health_publisher()
{
var driver = new SkipStubDriver();
driver.SetReport(authored: 22, skipped: ["Makino/Identity/SeriesNumber", "Makino/Identity/Version"]);
var publisher = new RecordingHealthPublisher();
var actor = SpawnDriverActor(driver, publisher);
actor.Tell(new DriverInstanceActor.InitializeRequested("{}"));
AwaitAssert(
() =>
{
var latest = publisher.Published.LastOrDefault();
latest.ShouldNotBeNull();
latest!.SkippedTags.ShouldNotBeNull();
latest.SkippedTags!.AuthoredCount.ShouldBe(22);
latest.SkippedTags.SkippedCount.ShouldBe(2);
latest.SkippedTags.Sample.Select(s => s.RawPath)
.ShouldBe(["Makino/Identity/SeriesNumber", "Makino/Identity/Version"]);
},
TimeSpan.FromSeconds(3));
}
/// <summary>
/// <b>The load-bearing case, and the entire reason this channel exists.</b> The Makino in Gitea #540:
/// a driver ignoring 20 of its 22 tags while every driver-level field reads perfectly healthy.
/// <para>This is the same dedup trap that already bit the rediscovery signal and the host statuses.
/// <c>PublishHealthSnapshot</c> suppresses a publish whose fingerprint repeats, and a skipped tag by
/// construction leaves (state, lastSuccessfulRead, lastError, errorCount) ALL unchanged — a skip is
/// not an error and happens before any read. Unless the skip digest is part of the fingerprint, the
/// dedup swallows exactly the publish that carries the news.</para>
/// <para><b>Falsifiability:</b> the assertion is that the publish count STRICTLY INCREASES across the
/// change. An "eventually reports skips" assertion would be satisfied by the warm-up publish alone
/// and would prove nothing. Drop <c>SkippedTagDigest</c> from the fingerprint tuple in
/// <c>DriverInstanceActor</c> and this test must go red.</para>
/// </summary>
[Fact]
public void A_redeploy_that_starts_skipping_tags_is_not_swallowed_by_the_unchanged_health_dedup()
{
var driver = new SkipStubDriver();
driver.SetReport(authored: 22, skipped: []);
var publisher = new RecordingHealthPublisher();
var actor = SpawnDriverActor(driver, publisher);
actor.Tell(new DriverInstanceActor.InitializeRequested("{}"));
AwaitAssert(() => publisher.Published.Count.ShouldBeGreaterThan(0), TimeSpan.FromSeconds(3));
// Settle, so the baseline is a quiet actor: from here only the skip report changes. The driver's
// own health stays Healthy throughout — that is the point.
ExpectNoMsg(TimeSpan.FromMilliseconds(200));
var before = publisher.Published.Count;
driver.SetReport(authored: 22, skipped: [.. Enumerable.Range(0, 20).Select(i => $"Makino/Tag{i}")]);
AwaitAssert(
() => publisher.Published.Count.ShouldBeGreaterThan(before),
TimeSpan.FromSeconds(3));
var latest = publisher.Published[^1];
latest.Health.State.ShouldBe(DriverState.Healthy,
"the driver never faulted — a skip is a config problem, not an error, and must not latch state");
latest.SkippedTags!.SkippedCount.ShouldBe(20);
latest.SkippedTags.AuthoredCount.ShouldBe(22);
}
/// <summary>
/// A redeploy that swaps WHICH tags are broken without changing HOW MANY must still publish.
/// Digesting the counts alone would leave an operator staring at a stale sample naming tags that
/// are now fine, while the ones actually broken went unmentioned.
/// </summary>
[Fact]
public void Swapping_which_tags_are_skipped_republishes_even_though_the_count_is_unchanged()
{
var driver = new SkipStubDriver();
driver.SetReport(authored: 5, skipped: ["old-broken"]);
var publisher = new RecordingHealthPublisher();
var actor = SpawnDriverActor(driver, publisher);
actor.Tell(new DriverInstanceActor.InitializeRequested("{}"));
AwaitAssert(() => publisher.Published.Count.ShouldBeGreaterThan(0), TimeSpan.FromSeconds(3));
ExpectNoMsg(TimeSpan.FromMilliseconds(200));
var before = publisher.Published.Count;
driver.SetReport(authored: 5, skipped: ["newly-broken"]);
AwaitAssert(() => publisher.Published.Count.ShouldBeGreaterThan(before), TimeSpan.FromSeconds(3));
publisher.Published[^1].SkippedTags!.Sample.Single().RawPath.ShouldBe("newly-broken");
}
/// <summary>
/// The other half of the dedup contract: when nothing changes, the digest must NOT churn. A digest
/// comparing the sample list by reference would differ on every call and re-publish on every 30 s
/// heartbeat forever — turning the dedup off without anyone noticing.
/// </summary>
[Fact]
public void An_unchanged_skip_report_does_not_defeat_the_dedup()
{
var driver = new SkipStubDriver();
driver.SetReport(authored: 22, skipped: ["Makino/Identity/SeriesNumber"]);
var publisher = new RecordingHealthPublisher();
var actor = SpawnDriverActor(driver, publisher);
actor.Tell(new DriverInstanceActor.InitializeRequested("{}"));
AwaitAssert(() => publisher.Published.Count.ShouldBeGreaterThan(0), TimeSpan.FromSeconds(3));
ExpectNoMsg(TimeSpan.FromMilliseconds(200));
var before = publisher.Published.Count;
// A fresh-but-equal report, rebuilt exactly as a redeploy that changed nothing would.
driver.SetReport(authored: 22, skipped: ["Makino/Identity/SeriesNumber"]);
// Long enough for many heartbeats to fire and be deduped away.
ExpectNoMsg(TimeSpan.FromMilliseconds(600));
publisher.Published.Count.ShouldBe(before,
"an equal-but-distinct report must be deduped, not re-published — the digest must compare by VALUE");
}
/// <summary>
/// A driver that cannot report skips publishes null — NOT an empty report. The two mean different
/// things at the UI ("no skip detail available" vs "this driver skipped nothing"), and collapsing
/// them would render an unreporting driver as one that is positively known to be clean.
/// </summary>
[Fact]
public void A_driver_that_cannot_report_publishes_null_rather_than_an_empty_report()
{
var publisher = new RecordingHealthPublisher();
var actor = SpawnDriverActor(new StubDriver(), publisher);
actor.Tell(new DriverInstanceActor.InitializeRequested("{}"));
AwaitAssert(() => publisher.Published.Count.ShouldBeGreaterThan(0), TimeSpan.FromSeconds(3));
publisher.Published.ShouldAllBe(p => p.SkippedTags == null);
}
/// <summary>
/// A reporter that throws must not take the health publish down with it. Losing the skip detail is
/// strictly better than losing the whole health channel.
/// </summary>
[Fact]
public void A_throwing_reporter_degrades_to_null_without_killing_the_health_publish()
{
var driver = new SkipStubDriver { ThrowOnGetSkippedTags = true };
var publisher = new RecordingHealthPublisher();
var actor = SpawnDriverActor(driver, publisher);
actor.Tell(new DriverInstanceActor.InitializeRequested("{}"));
AwaitAssert(() => publisher.Published.Count.ShouldBeGreaterThan(0), TimeSpan.FromSeconds(3));
publisher.Published[^1].Health.State.ShouldBe(DriverState.Healthy);
publisher.Published[^1].SkippedTags.ShouldBeNull();
}
/// <summary>
/// Spawns the actor with a fast health heartbeat. The heartbeat is the production path by which a
/// changed skip report reaches the publisher — unlike host connectivity, a skip raises no event,
/// because it is discovered during the tag-table build and never afterwards. Driving the tests
/// through it rather than through a synthetic poke means the dedup assertions are made against the
/// mechanism that actually runs in production.
/// </summary>
private IActorRef SpawnDriverActor(IDriver driver, IDriverHealthPublisher publisher)
{
var parent = CreateTestProbe();
parent.IgnoreMessages(_ => true);
return parent.ChildActorOf(DriverInstanceActor.Props(
driver, healthPublisher: publisher, healthPollInterval: TimeSpan.FromMilliseconds(50)));
}
/// <summary>Captures every health publish so a test can assert on the skipped-tag field.</summary>
private sealed record HealthPublish(DriverHealth Health, SkippedTagReport? SkippedTags);
private sealed class RecordingHealthPublisher : IDriverHealthPublisher
{
private readonly List<HealthPublish> _published = [];
/// <summary>Thread-safe snapshot — <c>Publish</c> runs on the actor thread while the test asserts
/// from its own.</summary>
public IReadOnlyList<HealthPublish> Published
{
get { lock (_published) return _published.ToArray(); }
}
/// <inheritdoc />
public void Publish(
string clusterId,
string driverInstanceId,
DriverHealth health,
int errorCount5Min,
DateTime? rediscoveryNeededUtc = null,
string? rediscoveryReason = null,
IReadOnlyList<HostConnectivityStatus>? hostStatuses = null,
SkippedTagReport? skippedTags = null)
{
lock (_published) _published.Add(new HealthPublish(health, skippedTags));
}
}
/// <summary>
/// A stub driver exposing <see cref="ISkippedTagReporter"/>, backed by a real
/// <see cref="SkippedTagLedger"/> so the test exercises the production accumulator rather than a
/// parallel fake of it.
/// <para><b>Its own health is deliberately STABLE</b> (a fixed last-read timestamp). The shared
/// <c>StubDriver</c> returns <c>DateTime.UtcNow</c> from <c>GetHealth()</c>, so its fingerprint
/// differs on every call, the dedup never engages, and every dedup assertion here would pass
/// vacuously whether or not the fix is present.</para>
/// </summary>
private sealed class SkipStubDriver : IDriver, ISkippedTagReporter
{
private static readonly DateTime FixedLastRead = new(2026, 8, 5, 12, 0, 0, DateTimeKind.Utc);
private readonly SkippedTagLedger _ledger = new();
/// <summary>When set, <see cref="GetSkippedTags"/> throws — the misbehaving-reporter case.</summary>
public bool ThrowOnGetSkippedTags { get; init; }
/// <inheritdoc />
public string DriverInstanceId => "skip-stub-1";
/// <inheritdoc />
public string DriverType => "Stub";
/// <summary>Rebuilds the ledger as a real driver's tag-table build does.</summary>
public void SetReport(int authored, IReadOnlyList<string> skipped)
{
_ledger.BeginRebuild(authored);
foreach (var rawPath in skipped) _ledger.Skip(rawPath, "TagConfig did not map to a definition");
_ledger.Commit();
}
/// <inheritdoc />
public SkippedTagReport GetSkippedTags()
{
if (ThrowOnGetSkippedTags) throw new InvalidOperationException("reporter is broken");
return _ledger.Snapshot();
}
/// <inheritdoc />
public Task InitializeAsync(string driverConfigJson, CancellationToken cancellationToken) => Task.CompletedTask;
/// <inheritdoc />
public Task ReinitializeAsync(string driverConfigJson, CancellationToken cancellationToken) => Task.CompletedTask;
/// <inheritdoc />
public Task ShutdownAsync(CancellationToken cancellationToken) => Task.CompletedTask;
/// <inheritdoc />
public DriverHealth GetHealth() => new(DriverState.Healthy, FixedLastRead, null);
}
}
@@ -123,7 +123,8 @@ public sealed class DriverInstanceActorSubscriptionReconcileTests : RuntimeActor
int errorCount5Min,
DateTime? rediscoveryNeededUtc = null,
string? rediscoveryReason = null,
IReadOnlyList<HostConnectivityStatus>? hostStatuses = null)
IReadOnlyList<HostConnectivityStatus>? hostStatuses = null,
SkippedTagReport? skippedTags = null)
=> Interlocked.Increment(ref _count);
}
}