feat(grpc-data): H4 remote-history diagnostics and metrics
Consumer and origin history evidence for data connections (plan §6):
- DataConnectionHistoryDiagnostics: otopcua.dataconn.history.reads{variant,status_class,side} and
otopcua.dataconn.history.continuations.active{side} on the exported OtOpcUa meter (the H2 origin
counter sat on a private meter the host never exported); the plan's unknown-bits counter is the
existing X0 otopcua.dataconnection.unknown_operations_dropped, reused
- per-connection projected answers by status class and open consumer continuations (settled on
resume claim or release); origin sessions, open continuations and answers by status class
- negotiated features and advertised history variants/aggregates per connection
- AdminUI data-connections page renders them plus the dropped unknown-operation bits (#919)
- H4 unit-phase manifest key
This commit is contained in:
+58
@@ -0,0 +1,58 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.DataConnections;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Interfaces;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.DataConnections;
|
||||
|
||||
/// <summary>H4 diagnostics display (plan §6) and the X0 dropped-bit rendering (#919) on the data-connections page.</summary>
|
||||
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "H4")]
|
||||
public sealed class GrpcDataHistoryDiagnosticsDisplayTests
|
||||
{
|
||||
private static DataConnectionDiagnosticsSnapshot Row() =>
|
||||
new("link", 1, "ready", null, null, 0, 0, 1, "artifact", DateTime.UtcNow);
|
||||
|
||||
[Fact]
|
||||
public void Negotiated_features_distinguish_unavailable_v1_and_history()
|
||||
{
|
||||
DataConnectionDiagnostics.Features(null).ShouldBe("unavailable");
|
||||
DataConnectionDiagnostics.Features(DataFeatures.None).ShouldBe("none (v1 behaviour)");
|
||||
DataConnectionDiagnostics.Features(DataFeatures.History).ShouldBe("History");
|
||||
DataConnectionDiagnostics.Features(DataFeatures.History | DataFeatures.Conditions).ShouldBe("History, Conditions");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Origin_history_shows_the_advertised_variants_and_aggregate_count()
|
||||
{
|
||||
DataConnectionDiagnostics.HistoryServed(Row()).ShouldBe("not advertised");
|
||||
DataConnectionDiagnostics.HistoryServed(Row() with { HistoryVariants = [] }).ShouldBe("advertised, no variant granted");
|
||||
DataConnectionDiagnostics.HistoryServed(Row() with { HistoryVariants = ["raw", "processed", "attime"], HistoryAggregateCount = 12 })
|
||||
.ShouldBe("raw, processed, attime (12 aggregates)");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void History_counts_by_status_class_are_unavailable_from_an_older_node_not_zero()
|
||||
{
|
||||
DataConnectionDiagnostics.HistoryCounts(null, null, null).ShouldBe("unavailable");
|
||||
DataConnectionDiagnostics.HistoryCounts(5, 0, 2).ShouldBe("good 5 · uncertain 0 · bad 2");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Dropped_bits_are_named_when_known_and_hex_when_not()
|
||||
{
|
||||
DataConnectionDiagnostics.DroppedBits(null).ShouldBe("unavailable");
|
||||
DataConnectionDiagnostics.DroppedBits(DataOperations.None).ShouldBe("none");
|
||||
DataConnectionDiagnostics.DroppedBits(DataOperations.HistoryRead | DataOperations.AlarmSubscribe).ShouldBe("HistoryRead, AlarmSubscribe");
|
||||
DataConnectionDiagnostics.DroppedBits((DataOperations)(1 << 20)).ShouldBe("0x100000");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_older_build_hint_shows_only_when_something_was_dropped()
|
||||
{
|
||||
DataConnectionDiagnostics.HasDrops(null).ShouldBeFalse();
|
||||
DataConnectionDiagnostics.HasDrops(DataOperations.None, 0).ShouldBeFalse();
|
||||
DataConnectionDiagnostics.HasDrops(DataOperations.HistoryRead).ShouldBeTrue();
|
||||
DataConnectionDiagnostics.HasDrops(DataOperations.None, 2).ShouldBeTrue("a mapping's drop counts even when the connection dropped none");
|
||||
}
|
||||
}
|
||||
+24
@@ -51,6 +51,30 @@ public sealed class GrpcDataDeploymentActivationTests
|
||||
runtime.CaptureDiagnostics().ShouldHaveSingleItem().State.ShouldBe("connecting");
|
||||
}
|
||||
|
||||
[Fact, Trait("Phase", "H4")]
|
||||
public async Task Diagnostics_carry_the_consumer_history_counts_and_open_continuations_per_connection()
|
||||
{
|
||||
var activator = new PausedActivator();
|
||||
var history = new DataConnectionHistoryDiagnostics();
|
||||
await using var runtime = new DataConnectionDeploymentRuntime("node-a", "owner", new Security(), activator, 4) { HistoryDiagnostics = history };
|
||||
runtime.Apply(Snapshot(1, Definition("link", "secret-reference"), Definition("other", "secret-reference")));
|
||||
await activator.Entered.Task.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
|
||||
history.RecordConsumerRead("LINK", "raw", 0);
|
||||
history.RecordConsumerRead("link", "processed", 0x40000000u);
|
||||
history.RecordConsumerRead("link", "attime", 0x80720000u);
|
||||
history.ConsumerContinuationOpened("link");
|
||||
var rows = runtime.CaptureDiagnostics();
|
||||
var link = rows.Single(x => x.ConnectionId == "link");
|
||||
(link.HistoryReadsGood, link.HistoryReadsUncertain, link.HistoryReadsBad, link.OpenRemoteContinuations).ShouldBe((1L, 1L, 1L, 1));
|
||||
var other = rows.Single(x => x.ConnectionId == "other");
|
||||
(other.HistoryReadsGood, other.HistoryReadsBad, other.OpenRemoteContinuations).ShouldBe((0L, 0L, 0), "zeros, not unavailable: no traffic yet");
|
||||
activator.Release.TrySetResult();
|
||||
await using var plain = new DataConnectionDeploymentRuntime("node-a", "owner", new Security(), new PausedActivator { PauseFirst = false }, 4);
|
||||
plain.Apply(Snapshot(1, Definition("link", "secret-reference")));
|
||||
await EventuallyAsync(() => plain.CaptureDiagnostics().Count == 1);
|
||||
plain.CaptureDiagnostics().ShouldHaveSingleItem().HistoryReadsGood.ShouldBeNull("no history diagnostics wired = unavailable");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Transient_security_resolution_exception_retries_without_a_change_event()
|
||||
{
|
||||
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
using Opc.Ua;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
using ZB.MOM.WW.OtOpcUa.Runtime.DataConnections;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.DataConnections;
|
||||
|
||||
/// <summary>
|
||||
/// H4 — the remote-history diagnostics follow real traffic: a real consumer OPC UA session reads a projected node through
|
||||
/// the real projection stack and a real in-process origin; both sides' counts by status class and open continuations
|
||||
/// move with each page, resume and release.
|
||||
/// </summary>
|
||||
public sealed partial class GrpcDataConfiguredDiscoveryWireTests
|
||||
{
|
||||
[Fact(Timeout = 90000)]
|
||||
[Trait("Phase", "H4")]
|
||||
public async Task History_diagnostics_count_answers_by_status_class_and_track_open_continuations_on_both_sides()
|
||||
{
|
||||
await using var originServer = await HistoryOrigin.StartAsync(7);
|
||||
originServer.Source.Aggregates = new HashSet<HistoryAggregateType> { HistoryAggregateType.Average };
|
||||
using var origin = new LocalDataFixture(servingGeneration: 1, history: originServer.Port);
|
||||
ProjectedHistoryAccess? history = null;
|
||||
await WithComposedServer(origin, origin.Raw, async (session, _, _, _, _, _, anchor) =>
|
||||
{
|
||||
var client = (SessionClient)session;
|
||||
await BrowseAll(client, anchor, 1);
|
||||
var consumer = history!.Diagnostics;
|
||||
|
||||
// Before any history traffic: nothing counted, nothing open; the origin reports its backend.
|
||||
consumer.CaptureConsumer("link").ShouldBe(new ConsumerHistoryCounts(0, 0, 0, 0));
|
||||
var idle = origin.HistoryDiagnostics.CaptureOrigin().ShouldNotBeNull();
|
||||
idle.Available.ShouldBeTrue();
|
||||
(idle.ReadsGood, idle.ReadsBad, idle.OpenContinuations).ShouldBe((0L, 0L, 0));
|
||||
|
||||
// Page 1 of 7 at 2 per page: one Good answer on each side, one continuation open on each side.
|
||||
var page = await RawHistory(client, anchor, 2, default);
|
||||
page.ContinuationPoint.IsEmpty.ShouldBeFalse();
|
||||
consumer.CaptureConsumer("link").ShouldBe(new ConsumerHistoryCounts(1, 0, 0, 1));
|
||||
consumer.CaptureConsumer("LINK").Good.ShouldBe(1, "connection ids are case-insensitive");
|
||||
origin.HistoryDiagnostics.CaptureOrigin()!.OpenContinuations.ShouldBe(1);
|
||||
origin.HistoryDiagnostics.CaptureOrigin()!.ReadsGood.ShouldBe(1);
|
||||
|
||||
// Resume: the claimed cursor settles, its successor opens — still one open, two Good answers.
|
||||
var next = await RawHistory(client, anchor, 2, page.ContinuationPoint);
|
||||
next.ContinuationPoint.IsEmpty.ShouldBeFalse();
|
||||
consumer.CaptureConsumer("link").ShouldBe(new ConsumerHistoryCounts(2, 0, 0, 1));
|
||||
consumer.OpenConsumerContinuations.ShouldBe(1);
|
||||
|
||||
// releaseContinuationPoints: the consumer cursor settles at once, the origin's after the coalesced release.
|
||||
await client.HistoryReadAsync(new RequestHeader(), new ExtensionObject(RawDetails(2)), TimestampsToReturn.Both, true,
|
||||
[new HistoryReadValueId { NodeId = anchor, ContinuationPoint = next.ContinuationPoint }], TestContext.Current.CancellationToken);
|
||||
consumer.CaptureConsumer("link").OpenContinuations.ShouldBe(0);
|
||||
await AwaitReleases(history, () => origin.Services.HistoryOpenContinuations == 0);
|
||||
origin.HistoryDiagnostics.CaptureOrigin()!.OpenContinuations.ShouldBe(0);
|
||||
|
||||
// An aggregate the origin refuses: one Bad answer on each side.
|
||||
var refused = await ProcessedHistory(client, anchor, ObjectIds.AggregateFunction_Count);
|
||||
refused.StatusCode.Code.ShouldBe(StatusCodes.BadAggregateNotSupported.Code);
|
||||
consumer.CaptureConsumer("link").ShouldBe(new ConsumerHistoryCounts(2, 0, 1, 0));
|
||||
var after = origin.HistoryDiagnostics.CaptureOrigin()!;
|
||||
(after.ReadsGood, after.ReadsUncertain, after.ReadsBad).ShouldBe((2L, 0L, 1L));
|
||||
}, localPermissions: 15, allowHistory: true, connectionSource: new PersistentConnections(origin), onHistory: (h, _) => history = h);
|
||||
}
|
||||
|
||||
[Fact(Timeout = 90000)]
|
||||
[Trait("Phase", "H4")]
|
||||
public async Task Consumer_session_close_settles_its_open_consumer_continuations()
|
||||
{
|
||||
await using var originServer = await HistoryOrigin.StartAsync(7);
|
||||
using var origin = new LocalDataFixture(servingGeneration: 1, history: originServer.Port);
|
||||
ProjectedHistoryAccess? history = null;
|
||||
await WithComposedServer(origin, origin.Raw, async (session, _, _, _, _, _, anchor) =>
|
||||
{
|
||||
var client = (SessionClient)session;
|
||||
await BrowseAll(client, anchor, 1);
|
||||
(await RawHistory(client, anchor, 2, default)).ContinuationPoint.IsEmpty.ShouldBeFalse();
|
||||
history!.Diagnostics.OpenConsumerContinuations.ShouldBe(1);
|
||||
await session.CloseAsync(TestContext.Current.CancellationToken);
|
||||
await AwaitReleases(history, () => origin.Services.HistoryOpenContinuations == 0);
|
||||
history.Diagnostics.OpenConsumerContinuations.ShouldBe(0, "the SDK disposed the Remote point on session close");
|
||||
origin.HistoryDiagnostics.CaptureOrigin()!.OpenContinuations.ShouldBe(0);
|
||||
}, localPermissions: 15, allowHistory: true, connectionSource: new PersistentConnections(origin), onHistory: (h, _) => history = h);
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
using System.Diagnostics.Metrics;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Observability;
|
||||
using ZB.MOM.WW.OtOpcUa.Runtime.DataConnections;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.DataConnections;
|
||||
|
||||
/// <summary>
|
||||
/// H4 metrics (plan §6): <c>otopcua.dataconn.history.reads{variant,status_class,side}</c> and
|
||||
/// <c>otopcua.dataconn.history.continuations.active{side}</c> on the exported OtOpcUa meter, no ids in labels; the plan's
|
||||
/// unknown-bit counter is the existing X0 instrument (reused, not duplicated).
|
||||
/// </summary>
|
||||
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "H4")]
|
||||
public sealed class GrpcDataHistoryMetricsTests
|
||||
{
|
||||
private static readonly string[] AllowedLabels = ["variant", "status_class", "side"];
|
||||
|
||||
[Fact]
|
||||
public void History_reads_are_counted_on_the_exported_meter_with_variant_status_class_and_side_only()
|
||||
{
|
||||
var seen = new List<(long Value, Dictionary<string, object?> Tags)>();
|
||||
using var listener = new MeterListener();
|
||||
listener.InstrumentPublished = (instrument, l) =>
|
||||
{
|
||||
if (instrument.Meter.Name == OtOpcUaTelemetry.MeterName && instrument.Name == DataConnectionHistoryDiagnostics.ReadsCounterName)
|
||||
l.EnableMeasurementEvents(instrument);
|
||||
};
|
||||
listener.SetMeasurementEventCallback<long>((_, value, tags, _) =>
|
||||
{
|
||||
var map = new Dictionary<string, object?>();
|
||||
foreach (var tag in tags) map[tag.Key] = tag.Value;
|
||||
lock (seen) seen.Add((value, map));
|
||||
});
|
||||
listener.Start();
|
||||
|
||||
var diagnostics = new DataConnectionHistoryDiagnostics();
|
||||
diagnostics.RecordConsumerRead("connection-with-an-id", "processed", 0x40000000u);
|
||||
diagnostics.RecordOriginRead("attime", 0x80720000u);
|
||||
listener.Dispose();
|
||||
|
||||
List<(long Value, Dictionary<string, object?> Tags)> snapshot;
|
||||
lock (seen) snapshot = seen.ToList();
|
||||
// Other tests may count in parallel on the same static counter: assert presence of ours and the label set of all.
|
||||
snapshot.ShouldContain(x => Equals(x.Tags["side"], "consumer") && Equals(x.Tags["variant"], "processed")
|
||||
&& Equals(x.Tags["status_class"], "uncertain"));
|
||||
snapshot.ShouldContain(x => Equals(x.Tags["side"], "origin") && Equals(x.Tags["variant"], "attime")
|
||||
&& Equals(x.Tags["status_class"], "bad"));
|
||||
foreach (var (value, tags) in snapshot)
|
||||
{
|
||||
value.ShouldBe(1);
|
||||
tags.Keys.OrderBy(x => x).ShouldBe(AllowedLabels.OrderBy(x => x), "no connection, node or principal id in labels");
|
||||
tags.Values.ShouldNotContain("connection-with-an-id");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Open_continuations_gauge_reports_origin_and_consumer_sides()
|
||||
{
|
||||
var diagnostics = new DataConnectionHistoryDiagnostics();
|
||||
diagnostics.AttachOrigin(() => (true, 1, 3));
|
||||
diagnostics.ConsumerContinuationOpened("link");
|
||||
diagnostics.ConsumerContinuationOpened("link");
|
||||
|
||||
var observed = new Dictionary<string, int>();
|
||||
using var listener = new MeterListener();
|
||||
listener.InstrumentPublished = (instrument, l) =>
|
||||
{
|
||||
if (instrument.Meter.Name == OtOpcUaTelemetry.MeterName && instrument.Name == DataConnectionHistoryDiagnostics.ContinuationsGaugeName)
|
||||
l.EnableMeasurementEvents(instrument);
|
||||
};
|
||||
listener.SetMeasurementEventCallback<int>((_, value, tags, _) =>
|
||||
{
|
||||
foreach (var tag in tags) if (tag.Key == "side") observed[(string)tag.Value!] = value;
|
||||
});
|
||||
listener.Start();
|
||||
listener.RecordObservableInstruments();
|
||||
|
||||
// Sums across live instances (other tests' instances may add), so at least ours.
|
||||
observed.Keys.OrderBy(x => x).ShouldBe(["consumer", "origin"]);
|
||||
observed["origin"].ShouldBeGreaterThanOrEqualTo(3);
|
||||
observed["consumer"].ShouldBeGreaterThanOrEqualTo(2);
|
||||
GC.KeepAlive(diagnostics);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Consumer_counts_are_per_connection_case_insensitive_and_settle_never_goes_negative()
|
||||
{
|
||||
var diagnostics = new DataConnectionHistoryDiagnostics();
|
||||
diagnostics.RecordConsumerRead("Link", "raw", 0);
|
||||
diagnostics.RecordConsumerRead(null, "raw", 0x80000000u); // unresolved node: metric only
|
||||
diagnostics.ConsumerContinuationOpened("link");
|
||||
diagnostics.ConsumerContinuationSettled("LINK");
|
||||
diagnostics.ConsumerContinuationSettled("never-opened");
|
||||
diagnostics.CaptureConsumer("LINK").ShouldBe(new ConsumerHistoryCounts(1, 0, 0, 0));
|
||||
diagnostics.CaptureConsumer("never-opened").ShouldBe(new ConsumerHistoryCounts(0, 0, 0, 0));
|
||||
diagnostics.OpenConsumerContinuations.ShouldBe(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Origin_evidence_is_unavailable_until_attached_and_when_the_state_probe_fails()
|
||||
{
|
||||
var diagnostics = new DataConnectionHistoryDiagnostics();
|
||||
diagnostics.CaptureOrigin().ShouldBeNull();
|
||||
diagnostics.RecordOriginRead("raw", 0);
|
||||
diagnostics.AttachOrigin(() => (false, 0, 0));
|
||||
diagnostics.CaptureOrigin().ShouldBe(new ZB.MOM.WW.OtOpcUa.Commons.Interfaces.OriginHistoryDiagnostics(false, 0, 0, 1, 0, 0));
|
||||
diagnostics.AttachOrigin(() => throw new InvalidOperationException("history port not ready"));
|
||||
diagnostics.CaptureOrigin().ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_plan_unknown_bit_counter_is_the_existing_X0_instrument_not_a_second_one()
|
||||
{
|
||||
// Plan §6 names "…operations.unknown_bits_dropped"; X0 already counts exactly that (one per row per accepted change).
|
||||
UnknownOperationDrops.CounterName.ShouldBe("otopcua.dataconnection.unknown_operations_dropped");
|
||||
var names = new List<string>();
|
||||
using var listener = new MeterListener();
|
||||
listener.InstrumentPublished = (instrument, _) =>
|
||||
{
|
||||
if (instrument.Meter.Name == OtOpcUaTelemetry.MeterName) lock (names) names.Add(instrument.Name);
|
||||
};
|
||||
listener.Start();
|
||||
_ = new DataConnectionHistoryDiagnostics();
|
||||
lock (names) names.ShouldNotContain(x => x.Contains("unknown_bits", StringComparison.Ordinal));
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -125,6 +125,8 @@ internal sealed class LocalDataFixture : IDisposable
|
||||
internal readonly DataView Raw = new(new("cluster", "https://zb.com/otopcua/raw", "string", "Plant/Driver/Device/Speed"), DataRealm.Raw, null, 0, "Plant/Driver/Device/Speed");
|
||||
internal readonly DataView Uns = new(new("cluster", "https://zb.com/otopcua/uns", "string", "Area/Line/Equipment/Speed"), DataRealm.Uns, null, 0, "Area/Line/Equipment/Speed");
|
||||
internal readonly LocalDataServices Services;
|
||||
/// <summary>H4: the origin's history diagnostics (counts by status class, live sessions and continuations).</summary>
|
||||
internal readonly DataConnectionHistoryDiagnostics HistoryDiagnostics = new();
|
||||
internal readonly LocalExportCatalog Catalog;
|
||||
internal readonly DataAuthenticatedContext Context;
|
||||
|
||||
@@ -196,7 +198,7 @@ internal sealed class LocalDataFixture : IDisposable
|
||||
var capabilities = new DataCapabilitiesProvider("cluster", () => Serving, () => Catalog.IsActive, limits);
|
||||
Services = new LocalDataServices(() => Catalog, Hub, new DataOperationPolicy(Authority,
|
||||
new TriePermissionEvaluator(Authority.Tries, Clock), Clock), capabilities, Clock, writes: writes, subscriptions: subscriptions,
|
||||
targetSubscriptions: targetSubscriptions, history: history);
|
||||
targetSubscriptions: targetSubscriptions, history: history) { HistoryDiagnostics = HistoryDiagnostics };
|
||||
}
|
||||
|
||||
internal IDataConnection Connection() => Services.Create(Context, new(DataTargetMode.Node, "cluster", Serving.NodeId));
|
||||
|
||||
Reference in New Issue
Block a user