feat(mesh-phase5): tap the 4 telemetry publish seams into the local hub (DPS intact)
Each of the four telemetry publish seams now also emits its DPS payload into the node-local ITelemetryLocalHub (Phase 5), leaving the existing DistributedPubSub publish untouched: - driver-health AkkaDriverHealthPublisher -> TelemetryItem.Health - resilience DriverResilienceStatusPublisherService -> TelemetryItem.Resilience - alerts ScriptedAlarmHostActor + DriverHostActor (native) -> TelemetryItem.Alarm - script-logs VirtualTagActor + DpsScriptLogPublisher -> TelemetryItem.Script DI services take the hub as a required ctor param; actors take an optional nullable hub threaded through their Props and the real spawn sites (DriverHostActor <- ServiceCollectionExtensions; VirtualTagActor/ScriptedAlarmHostActor <- DriverHostActor), so existing test Props constructions keep compiling and simply do not emit. The hub is a no-op until a gRPC client subscribes, so the emit is safe on every node. Claude-Session: https://claude.ai/code/session_01GASWkNEi68FSCtvr6rLoEW
This commit is contained in:
+82
@@ -1,7 +1,12 @@
|
||||
using Akka.Actor;
|
||||
using Akka.Cluster;
|
||||
using Akka.Configuration;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Resilience;
|
||||
using ZB.MOM.WW.OtOpcUa.Host.Drivers;
|
||||
using ZB.MOM.WW.OtOpcUa.Runtime.Telemetry;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Host.IntegrationTests;
|
||||
|
||||
@@ -53,4 +58,81 @@ public sealed class DriverResilienceStatusPublisherServiceTests
|
||||
healthy.CurrentInFlight.ShouldBe(1);
|
||||
healthy.PublishedUtc.ShouldBe(Published);
|
||||
}
|
||||
|
||||
/// <summary>Per-cluster mesh Phase 5 — each snapshot the publish tick sends to the
|
||||
/// <c>driver-resilience-status</c> DPS topic is also emitted into the node-local
|
||||
/// <see cref="ITelemetryLocalHub"/> as a <see cref="TelemetryItem.Resilience"/>. Runs the background
|
||||
/// service against a single-node cluster (so DistributedPubSub resolves) for a few ticks and asserts the
|
||||
/// hub captured the tracked pair.</summary>
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_emits_Resilience_item_per_published_snapshot()
|
||||
{
|
||||
// Plain self-joined single-node cluster (mirrors SecretsReplicationRegistrationTests — the
|
||||
// xunit.v3 project cannot use Akka.TestKit.Xunit2). public-hostname is load-bearing for the bind.
|
||||
var hocon = ConfigurationFactory.ParseString("""
|
||||
akka {
|
||||
loglevel = WARNING
|
||||
actor.provider = cluster
|
||||
remote.dot-netty.tcp {
|
||||
hostname = "127.0.0.1"
|
||||
public-hostname = "127.0.0.1"
|
||||
port = 0
|
||||
}
|
||||
cluster { roles = ["driver"] }
|
||||
}
|
||||
""");
|
||||
var sys = ActorSystem.Create("resil-hub-test", hocon);
|
||||
try
|
||||
{
|
||||
var cluster = Akka.Cluster.Cluster.Get(sys);
|
||||
cluster.Join(cluster.SelfAddress);
|
||||
var upDeadline = DateTime.UtcNow.AddSeconds(10);
|
||||
while (!cluster.State.Members.Any(m => m.Status == MemberStatus.Up) && DateTime.UtcNow < upDeadline)
|
||||
await Task.Delay(50, TestContext.Current.CancellationToken);
|
||||
cluster.State.Members.ShouldContain(m => m.Status == MemberStatus.Up);
|
||||
|
||||
var tracker = new DriverResilienceStatusTracker();
|
||||
tracker.RecordCallStart("drv-1", "host-a");
|
||||
|
||||
var hub = new CapturingHub();
|
||||
var service = new DriverResilienceStatusPublisherService(
|
||||
tracker, () => sys, NullLogger<DriverResilienceStatusPublisherService>.Instance, hub,
|
||||
interval: TimeSpan.FromMilliseconds(50));
|
||||
|
||||
await service.StartAsync(TestContext.Current.CancellationToken);
|
||||
try
|
||||
{
|
||||
var deadline = DateTime.UtcNow.AddSeconds(5);
|
||||
while (hub.Items.Count == 0 && DateTime.UtcNow < deadline)
|
||||
await Task.Delay(50, TestContext.Current.CancellationToken);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await service.StopAsync(TestContext.Current.CancellationToken);
|
||||
}
|
||||
|
||||
hub.Items.ShouldNotBeEmpty();
|
||||
var item = hub.Items[0].ShouldBeOfType<TelemetryItem.Resilience>();
|
||||
item.E.DriverInstanceId.ShouldBe("drv-1");
|
||||
item.E.HostName.ShouldBe("host-a");
|
||||
item.E.CurrentInFlight.ShouldBe(1);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await sys.Terminate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Fake hub recording every emit; <see cref="Subscribe"/> is unused here.</summary>
|
||||
private sealed class CapturingHub : ITelemetryLocalHub
|
||||
{
|
||||
public List<TelemetryItem> Items { get; } = new();
|
||||
|
||||
public void Emit(TelemetryItem item)
|
||||
{
|
||||
lock (Items) Items.Add(item);
|
||||
}
|
||||
|
||||
public ITelemetrySubscription Subscribe(int boundedCapacity) => throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user