feat(historian-gateway): native TimeAverage/Total on by default, SendEvents batches, server-side max_events (#694, #746)

#694 item 3 — historiangw#27 is fixed and now live-verified through OtOpcUa:
- ServerHistorian:Gateway:EnableNativeTimeWeighted defaults to true (false is
  the kill switch for a gateway older than 9f711c1). TimeAverage / Total are
  served and advertised again (12 aggregates).
- The gateway sends the interval as max(1, round(ms)) and AVEVA clips its last
  interval at the request end (live). NativeAggregatePlan therefore sends a
  multi-interval grid only for whole-ms intervals; a fractional interval is read
  one interval per request (at most 1,000, else BadTooManyOperations), and every
  one-interval request goes out rounded UP to whole ms so AVEVA answers one
  clipped row. Live, a 3.0004 s clipped interval sent at its own width lost its
  last 0.4 ms (Total 123 vs 123.0172).

#746 — HistorianGateway Contracts/Client 1.0.0 surface:
- Alarm history: GatewayAlarmHistorianWriter sends SendEvents batches of <=200.
  A failed per-event result is re-sent alone via SendEvent (classified as
  before); a refused batch (InvalidArgument etc.) goes event by event so a
  poison event dead-letters alone; a systemic fault retries the rest without
  sending more; Unimplemented (older gateway) falls back to SendEvent for good.
  IHistorianGatewayClient.SendEventsAsync defaults to Unimplemented.
- Events reads: a capped page sends cap + 1 as ReadEventsRequest.max_events, so
  the gateway completes the stream instead of the client cancelling it. An
  ambiguous capped answer (foreign rows filtered out of the server's cut) or a
  refused cap is re-read uncapped with the existing EventDrainBudget drain.

Tests: GatewayServerCappedEventsTests, GatewayAlarmWriterBatchTests,
GatewayNativeWholeMillisecondGridTests (gateway-faithful rounding fake), gate
tests flipped to the new default; every new test mutation-checked (each
mutation of the production change fails at least one). Live harness
AvevaGatewayHistorianFollowupsLiveGateTests (read-only) for #694/#700/#746.

Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
Joseph Doherty
2026-11-12 23:57:38 -05:00
parent 09b373e4db
commit 53978ca638
22 changed files with 1847 additions and 176 deletions
@@ -64,7 +64,8 @@ public sealed class AvevaGatewayHistoryLiveGateTests
private const string MissingTag = "OtOpcUa.Gate801.DoesNotExist";
private const double IntervalMs = 60_000;
// The ten per-sample aggregates the Gateway backend serves (#681) and a set it must refuse (time-weighted / never).
// The aggregates the Gateway backend serves: the ten per-sample ones (#681) plus AVEVA's native TimeAverage / Total (on by
// default since lmxopcua#694), and a set it must refuse (the other time-weighted ones / never).
private static readonly (string Name, NodeId Id, HistoryAggregateType? Domain)[] Served =
[
("Average", ObjectIds.AggregateFunction_Average, HistoryAggregateType.Average),
@@ -77,12 +78,12 @@ public sealed class AvevaGatewayHistoryLiveGateTests
("Delta", ObjectIds.AggregateFunction_Delta, HistoryAggregateType.Delta),
("MinimumActualTime", ObjectIds.AggregateFunction_MinimumActualTime, HistoryAggregateType.MinimumActualTime),
("MaximumActualTime", ObjectIds.AggregateFunction_MaximumActualTime, HistoryAggregateType.MaximumActualTime),
("TimeAverage", ObjectIds.AggregateFunction_TimeAverage, HistoryAggregateType.TimeAverage),
("Total", ObjectIds.AggregateFunction_Total, HistoryAggregateType.Total),
];
private static readonly (string Name, NodeId Id)[] Refused =
[
("TimeAverage", ObjectIds.AggregateFunction_TimeAverage),
("Total", ObjectIds.AggregateFunction_Total),
("TimeAverage2", ObjectIds.AggregateFunction_TimeAverage2),
("Interpolative", ObjectIds.AggregateFunction_Interpolative),
("PercentGood", ObjectIds.AggregateFunction_PercentGood),
@@ -186,7 +187,7 @@ public sealed class AvevaGatewayHistoryLiveGateTests
var caps = await ReadHistoryCapabilitiesAsync(session, ct);
report.Add(new Case("metadata.historyServerCapabilities", null, null, "wire", "Good", null, caps));
Check(failures, caps["AggregateFunctions"] == string.Join(",", Served.Select(a => a.Name).OrderBy(n => n, StringComparer.Ordinal)),
$"advertised history aggregates must be exactly the Gateway's ten, got {caps["AggregateFunctions"]}");
$"advertised history aggregates must be exactly the Gateway's twelve, got {caps["AggregateFunctions"]}");
// lmxopcua#881: the Boolean capabilities follow the Gateway backend — data + event reads, no HistoryUpdate path, no
// stored server timestamps, never event / annotation updates (this gate recorded all-false before the fix).
foreach (var flag in new[] { "AccessHistoryDataCapability", "AccessHistoryEventsCapability" })