fix(hosts): driver health is per (driver, node) — ReportingNodeId on DriverHealthChanged + telemetry proto (#847)

This commit is contained in:
Joseph Doherty
2026-11-11 03:41:59 -05:00
parent 3b1b32f0c1
commit 038aa007ac
11 changed files with 150 additions and 21 deletions
@@ -56,4 +56,39 @@ public sealed class DriverStatusSnapshotStoreTests
count.ShouldBe(1);
}
[Fact]
public void Snapshots_from_two_nodes_for_one_driver_are_kept_side_by_side_847()
{
var store = new InMemoryDriverStatusSnapshotStore();
var t0 = new DateTime(2026, 11, 11, 0, 0, 0, DateTimeKind.Utc);
store.Upsert(new DriverHealthChanged("MAIN", "drv", "Faulted", null, "x", 1, t0, ReportingNodeId: "central-1"));
store.Upsert(new DriverHealthChanged("MAIN", "drv", "Healthy", null, null, 0, t0.AddSeconds(1), ReportingNodeId: "central-2"));
// A re-publish from central-1 replaces only central-1's entry.
store.Upsert(new DriverHealthChanged("MAIN", "drv", "Faulted", null, "y", 2, t0.AddSeconds(2), ReportingNodeId: "central-1"));
var all = store.GetAll();
all.Count.ShouldBe(2);
all.Single(s => s.ReportingNodeId == "central-1").LastError.ShouldBe("y");
all.Single(s => s.ReportingNodeId == "central-2").State.ShouldBe("Healthy");
// TryGet (the per-driver panel / hub) answers the most recently published across nodes.
store.TryGet("drv", out var latest).ShouldBeTrue();
latest.ReportingNodeId.ShouldBe("central-1");
latest.LastError.ShouldBe("y");
store.TryGet("other", out _).ShouldBeFalse();
}
[Fact]
public void Eviction_removes_every_node_entry_of_an_unconfigured_stale_driver_847()
{
var store = new InMemoryDriverStatusSnapshotStore();
var old = new DateTime(2026, 1, 1, 0, 0, 0, DateTimeKind.Utc);
store.Upsert(new DriverHealthChanged("MAIN", "gone", "Healthy", null, null, 0, old, ReportingNodeId: "a"));
store.Upsert(new DriverHealthChanged("MAIN", "gone", "Healthy", null, null, 0, old, ReportingNodeId: "b"));
store.Upsert(new DriverHealthChanged("MAIN", "kept", "Healthy", null, null, 0, old, ReportingNodeId: "a"));
store.EvictUnconfiguredStale(new HashSet<string> { "kept" }, old.AddMinutes(1)).ShouldBe(2);
store.GetAll().ShouldHaveSingleItem().DriverInstanceId.ShouldBe("kept");
}
}
@@ -356,4 +356,35 @@ public sealed class HostsDriverViewTests
row.HasSkippedTags.ShouldBeFalse();
row.SkippedTagsTitle().ShouldBeEmpty();
}
[Fact]
public void A_driver_reported_by_two_nodes_yields_one_row_per_node_847()
{
// lmxopcua#847: both nodes of a redundant pair run the same driver; keyed by driver id alone the row
// flipped between central-1's Faulted and central-2's Healthy on every publish.
var snaps = new[]
{
new DriverHealthChanged("c", "drv", "Healthy", null, null, 0, When, ReportingNodeId: "central-2"),
new DriverHealthChanged("c", "drv", "Faulted", null, "boom", 1, When, ReportingNodeId: "central-1"),
};
var rows = HostsDriverView.Build(snaps, null, [Instance("drv", "c", "Line 1", "Modbus")])
.ShouldHaveSingleItem().Drivers;
rows.Count.ShouldBe(2);
rows.Select(r => r.NodeId).ShouldBe(["central-1", "central-2"]);
rows.Select(r => r.State).ShouldBe(["Faulted", "Healthy"]);
rows.Select(r => r.RowKey).Distinct().Count().ShouldBe(2);
rows.ShouldAllBe(r => r.Name == "Line 1");
}
[Fact]
public void Hosts_page_renders_a_node_column_and_keys_rows_by_driver_and_node_847()
{
var src = AdminUiSource.Read("Components", "Pages", "Hosts.razor");
src.ShouldContain("@key=\"@($\"row-{d.RowKey}\")\"");
src.ShouldNotContain("@key=\"@($\"row-{d.DriverInstanceId}\")\"");
src.ShouldContain(">Node</th>");
src.ShouldContain("@d.NodeId");
}
}