Merge historian follow-up (#1089): HistorianUnreachable on /alarms-historian + otopcua.alarm_historian.unreachable gauge; per-writer reachability tests; SqlServer writer no longer counts login/connection failures as answered
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using Akka.Actor;
|
||||
using Akka.Hosting;
|
||||
using Bunit;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.AlarmHistorian;
|
||||
using ZB.MOM.WW.OtOpcUa.Runtime;
|
||||
using ZB.MOM.WW.OtOpcUa.Runtime.Historian;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Pages;
|
||||
|
||||
/// <summary>#1089: <c>/alarms-historian</c> shows a historian outage with its own badge, distinct from "stalled".</summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class AlarmsHistorianPageTests : BunitContext
|
||||
{
|
||||
private sealed class StatusActor : ReceiveActor
|
||||
{
|
||||
public StatusActor(HistorianSinkStatus status) => Receive<HistorianAdapterActor.GetStatus>(_ => Sender.Tell(status));
|
||||
}
|
||||
|
||||
private sealed class Required(IActorRef actor) : IRequiredActor<HistorianAdapterActorKey>
|
||||
{
|
||||
public IActorRef ActorRef { get; } = actor;
|
||||
public Task<IActorRef> GetAsync(CancellationToken cancellationToken = default) => Task.FromResult(ActorRef);
|
||||
}
|
||||
|
||||
private static HistorianSinkStatus Status(bool stalled, bool unreachable) =>
|
||||
new(5, 0, null, null, "Historian unavailable", HistorianDrainState.BackingOff, Stalled: stalled, HistorianUnreachable: unreachable);
|
||||
|
||||
private IRenderedComponent<AlarmsHistorian> RenderPage(ActorSystem sys, HistorianSinkStatus status)
|
||||
{
|
||||
JSInterop.Mode = JSRuntimeMode.Loose;
|
||||
var actor = sys.ActorOf(Props.Create(() => new StatusActor(status)));
|
||||
Services.AddSingleton<IRequiredActor<HistorianAdapterActorKey>>(new Required(actor));
|
||||
return Render<AlarmsHistorian>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_unreachable_historian_shows_its_own_badge_and_not_the_stalled_one()
|
||||
{
|
||||
using var sys = ActorSystem.Create("hist-ui-1");
|
||||
var cut = RenderPage(sys, Status(stalled: false, unreachable: true));
|
||||
cut.WaitForAssertion(() => cut.Find("[data-testid=historian-unreachable]").TextContent.ShouldContain("unreachable"));
|
||||
cut.FindAll("[data-testid=queue-stalled]").ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_stalled_queue_shows_the_stalled_badge_and_not_the_unreachable_one()
|
||||
{
|
||||
using var sys = ActorSystem.Create("hist-ui-2");
|
||||
var cut = RenderPage(sys, Status(stalled: true, unreachable: false));
|
||||
cut.WaitForAssertion(() => cut.Find("[data-testid=queue-stalled]").TextContent.ShouldContain("stalled"));
|
||||
cut.FindAll("[data-testid=historian-unreachable]").ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_healthy_sink_shows_neither_badge()
|
||||
{
|
||||
using var sys = ActorSystem.Create("hist-ui-3");
|
||||
var cut = RenderPage(sys, Status(stalled: false, unreachable: false));
|
||||
cut.WaitForAssertion(() => cut.Find(".metric-card").TextContent.ShouldContain("Depth"));
|
||||
cut.FindAll("[data-testid=queue-stalled],[data-testid=historian-unreachable]").ShouldBeEmpty();
|
||||
}
|
||||
}
|
||||
+19
-4
@@ -24,23 +24,37 @@ public sealed class AlarmHistorianMetricsTests
|
||||
Observe().ShouldBe(0);
|
||||
}
|
||||
|
||||
private static int Observe()
|
||||
private static int Observe(string name = AlarmHistorianMetrics.StalledGaugeName)
|
||||
{
|
||||
var seen = new List<int>();
|
||||
using var listener = new MeterListener
|
||||
{
|
||||
InstrumentPublished = (inst, l) =>
|
||||
{
|
||||
if (ReferenceEquals(inst.Meter, OtOpcUaTelemetry.Meter) && inst.Name == AlarmHistorianMetrics.StalledGaugeName)
|
||||
if (ReferenceEquals(inst.Meter, OtOpcUaTelemetry.Meter) && inst.Name == name)
|
||||
l.EnableMeasurementEvents(inst);
|
||||
},
|
||||
};
|
||||
listener.SetMeasurementEventCallback<int>((inst, v, _, _) => { if (inst.Name == AlarmHistorianMetrics.StalledGaugeName) seen.Add(v); });
|
||||
listener.SetMeasurementEventCallback<int>((inst, v, _, _) => { if (inst.Name == name) seen.Add(v); });
|
||||
listener.Start();
|
||||
listener.RecordObservableInstruments();
|
||||
return seen.Single();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_unreachable_gauge_reads_1_only_for_an_outage_and_is_distinct_from_stalled()
|
||||
{
|
||||
var sink = new SwitchSink();
|
||||
AlarmHistorianMetrics.Bind(sink);
|
||||
|
||||
Observe(AlarmHistorianMetrics.UnreachableGaugeName).ShouldBe(0);
|
||||
sink.Unreachable = true;
|
||||
Observe(AlarmHistorianMetrics.UnreachableGaugeName).ShouldBe(1);
|
||||
Observe().ShouldBe(0); // an outage is not "stalled"
|
||||
sink.Unreachable = false;
|
||||
Observe(AlarmHistorianMetrics.UnreachableGaugeName).ShouldBe(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Options_default_to_a_two_hour_stall_threshold_and_no_revival_and_zero_disables()
|
||||
{
|
||||
@@ -54,7 +68,8 @@ public sealed class AlarmHistorianMetricsTests
|
||||
private sealed class SwitchSink : IAlarmHistorianSink
|
||||
{
|
||||
public volatile bool Stalled;
|
||||
public volatile bool Unreachable;
|
||||
public Task EnqueueAsync(AlarmHistorianEvent evt, CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
public HistorianSinkStatus GetStatus() => new(1, 0, null, null, null, HistorianDrainState.BackingOff, Stalled: Stalled);
|
||||
public HistorianSinkStatus GetStatus() => new(1, 0, null, null, null, HistorianDrainState.BackingOff, Stalled: Stalled, HistorianUnreachable: Unreachable);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user