Files
lmxopcua/docs/plans/evidence/grpc-data-ext/H4.md
T

16 KiB
Raw Blame History

H4 evidence — remote-history diagnostics, metrics, docs (capability "supported")

Phase H4 of docs/plans/2026-11-23-grpc-data-connections-history-alarms-plan.md (revision 7), 2026-11-24. History part only; the alarm diagnostics are A4.

What changed

  • Runtime/DataConnections/DataConnectionHistoryDiagnostics.cs (new, DI singleton, no dependencies): shared by the origin services (LocalDataServices), the consumer gateway (ProjectedHistoryAccess) and the diagnostics readers (DataConnectionDeploymentRuntime, DriverHostActor), so none of them depends on another (the origin composition is resolved lazily after the driver host exists; a direct dependency would be a cycle).
  • Metrics on OtOpcUaTelemetry.Meter (ZB.MOM.WW.OtOpcUa, already in the host's exported-meter allowlist), no ids in labels:
    • otopcua.dataconn.history.reads{variant,status_class,side} — origin: one per item per wire call served to a peer (review 3); consumer: one per projected node per local HistoryRead, with the status the client got (review 1).
    • otopcua.dataconn.history.continuations.active{side} — observable gauge over the live diagnostics instances (weak table).
    • …operations.unknown_bits_dropped: reused, not added. X0's otopcua.dataconnection.unknown_operations_dropped{kind} counts exactly that (one per row per accepted artifact change); a second instrument would double-count. Pinned by The_plan_unknown_bit_counter_is_the_existing_X0_instrument_not_a_second_one.
  • Defect found: the H2 origin counter was never exported. otopcua.dataconn.history.reads sat on a private Meter("ZB.MOM.WW.OtOpcUa.DataConnections.History") that is not in ObservabilityExtensions.ObservedMeters (a strict allowlist), so it was absent from /metrics and OTLP. It now lives on the OtOpcUa meter (verified on the live rig's /metrics).
  • Consumer evidence per connection (ProjectedHistoryAccess): answers by status class, attributed to the connection the node resolved to; open consumer continuations — a RemoteCursor counts from creation until it is claimed for a resume (new ProjectedHistoryContinuation.OnClaimed hook) or its origin token is released, whichever first, once.
  • Origin evidence per node (LocalDataServices.HistoryDiagnostics init property): backend present, live peer history sessions, open origin continuations, answers by status class.
  • Negotiated features (GrpcDataConnection.RecordSelected): RequestedFeatures(capabilities) and the advertised history variants + aggregate count.
  • Contracts (Commons, additive optional members — older senders give null = "unavailable"): DataConnectionDiagnosticsSnapshot + NegotiatedFeatures, HistoryVariants, HistoryAggregateCount, HistoryReads{Good,Uncertain,Bad}, OpenRemoteContinuations; new OriginHistoryDiagnostics; NodeDiagnosticsSnapshot.OriginHistory.
  • AdminUI (ClusterDataConnections.razor, already inside <PageErrorBoundary>; helpers in DataConnectionDiagnostics): per connection a history line (negotiated features, origin history advertised, projected reads by class, open remote continuations) and a dropped-unknown-bits line; a new Origin evidence by node panel (remote history served, peer sessions, open origin continuations, answers by class, exports with dropped bits). Dropped bits are named when the AdminUI knows the bit, hex otherwise, and carry a "node build is older than the authored feature" hint when non-empty.
  • #919 closed by this work: the X0 fields (DroppedUnknownOperations, MappingsWithDroppedOperations, DroppedExportOperations) are now rendered on the data-connections page.
  • Docs: DataConnections.md (remote history supported, SqlServer/QuestDB verified, Gateway unverified pending #923; new §"Remote history diagnostics and metrics"; #919 note under Mixed versions), Historian.md (§"Remote history over data connections"), Client.CLI.md (projected-history note: opaque p1. ids resolved by browse, re-browse after deploy/idle, paging flags, what is refused).

Tests (H4 manifest key)

Suite What
R GrpcDataHistoryMetricsTests (5, new) counter on the exported meter with exactly variant,status_class,side (no id); gauge reports both sides; per-connection counts case-insensitive, settle never negative; origin evidence null until attached / when its probe throws; unknown-bit counter is X0's
R GrpcDataConfiguredDiscoveryWireTests H4 (2) real consumer SDK session + real projection + real origin: page 1 ⇒ consumer (1,0,0,open 1) and origin open 1; resume ⇒ (2,0,0,open 1); releaseContinuationPoints ⇒ consumer open 0, origin 0 after the coalesced release; an origin-refused aggregate ⇒ one Bad each side; session close ⇒ consumer open 0
R GrpcDataDeploymentActivationTests H4 (1) runtime diagnostics carry per-connection counts (zeros, not null, without traffic; null when no diagnostics wired)
AdminUI GrpcDataHistoryDiagnosticsDisplayTests (5, new) features / history-served / counts / dropped-bit rendering (#919) and the older-build hint
plus existing GrpcDataProjectedHistoryCursorTests, GrpcDataOriginHistorySessionTests, OpcUaServer ProjectedHistoryReadTests (base class gained OnClaimed), AdminUI GrpcDataDiagnosticsTests

Red/green: with RemoteCursor.OnClaimed => Settle() reverted, the wire test fails at the resume step (consumer open 2, not 1).

Gates

Gate Result
dotnet build ZB.MOM.WW.OtOpcUa.slnx 0 warnings, 0 errors
run-unit-phase.py H4 (new key: Runtime 25, OpcUaServer 11, AdminUI 9) passed
run-unit-phase.py H3 / H2 / H1 / X0 all passed (H3 107 + 144; H2 44/36/7/40/96/25; H1 578 + 17; X0 25/14/5/72/11)
AdminUI.Tests (Category!=E2E&Category!=LiveIntegration) 2698 passed
Runtime.Tests (same filter) 1911 passed, 3 skipped
OpcUaServer.Tests (same filter) 1419 passed, 1 skipped

Live gate — H3 scenarios on SqlServer with the metrics and the page

Fresh run h4a-sqlserver (OrbStack, macOS, normal build-hash checks, 2026-11-24, between ~13:01 and ~13:14 UTC): rig.py up --history --history-backend sqlserver --timeout 900, seed, ~80 s, deploy --timeout 300, history_gate.py, down.

  • H01–H06 all PASS (47 / 34 / 35 / 71 / 58 / 238 assertions, every scenario restored).
  • /metrics before traffic: both continuation gauges 0 on every node; no reads series.
  • /metrics after the gate: consumer-1 reads{side=consumer} raw good 31, raw bad 2, processed good 1, processed bad 1, attime good 2; source-2 (primary after H04's failover) reads{side=origin} raw good 7, raw bad 2. (The CLI's comparison reads on the SOURCE primary are local OPC UA reads and are not counted, as designed; source-1 restarted in H04, so its counts restart.)
  • AdminUI page (http://<control-1 admin>/clusters/CONSUMER/data-connections, login disabled on the rig, prerendered HTML via urllib): consumer-1 Ready · endpoint https://source-2:4057 · serving source-2 · role Primary, "Negotiated features History · origin history raw, processed, attime (19 aggregates) · projected history reads good 34 · uncertain 0 · bad 3 · open remote continuations (local sessions) 0" — equal to the sum of consumer-1's metric series; "Dropped unknown operation bits: connection none · mappings with dropped bits 0". The SOURCE page's origin panel: source-2 "remote history served · peer history sessions 0 · open origin continuations 0 · history items answered good 7 · uncertain 0 · bad 2" — equal to source-2's metric.
  • Held continuation probe (a scratch script driving the gate's own HistoryGate.held on the projected raw counter, page size 3, pause after page 1): while held — consumer-1 gauge consumer=1, source-2 gauge origin=1, the CONSUMER page "open remote continuations (local sessions) 1", the SOURCE page "peer history sessions 1"; after resume to completion — both gauges 0, page 0, projected good 35 ⇒ 54 (19 pages).
  • Mid-gate the page showed the connection Connecting with features "unavailable" — taken during a scenario's redeploy/failover; after the gate it read Ready with features History.
  • down ⇒ 0 run containers, 0 run volumes.

Gateway leg — BLOCKED (#923), substituted by doc scoping

The plan's required Gateway leg (origin ServerHistorian:Backend=Gateway against a local read-only HistorianGateway reading the real AVEVA Historian over VPN; H01–H04 with reverse/end-only and ceiling-bounded cases) was not attempted: the VPN to the historian is down. Per the plan's fallback, #923 (type:deploy-gate, blocked) tracks it, and the docs say remote history is verified on the SqlServer and QuestDB origin backends only, with the Gateway backend unverified pending #923 (DataConnections.md, Historian.md, Client.CLI.md).

Review (Fable, approve-with-changes) — fixes

One focused commit per item (5 and 6 share one AdminUI commit). Red/green by reverting the fix and re-running its test, unless noted.

# Finding Resolution Red/green
1 should-fix Consumer reads were counted from the gateway's outcomes: the non-local and batch limiter BadTooManyOperations, the pre-call BadTimeout and the count-mismatch BadInternalError were never counted, and a serve-time throw after the gateway returned counted Good The node manager counts where each projected status is set (Refuse + the served path) and hands the request's answers to IProjectedHistoryAccess.RecordAnswered (default no-op) in a finally; a fault escaping to the SDK (the service fails) counts every projected node of the request Bad. Attribution to a connection via ProjectedDataAccess.ConnectionOf (best effort, no authorization). Variant gains modified. 2f11a9c60 O Every_projected_answer_is_recorded_once_with_the_status_the_client_sees (served, unknown aggregate, modified, non-local limiter saturated, batch limiter saturated, spent deadline, count mismatch, serve-time throw) — red with the non-local limiter refusal routed back to the uncounted path
2 should-fix CaptureOrigin null until the first peer call composes the origin services ⇒ a fresh H4 origin read like a pre-H4 build Eager resolution is not clean: LocalDataRuntimeComposition needs the driver host actor registered and is composed by the first peer call through DeferredFactory. Instead the DI singleton gets a provisional probe of the same DeferredOriginHistoryPort (backend availability) and reports zeros with NoPeerTrafficYet = true; the page adds "no peer has called since start". Docs updated. 005720bd0 (+ rename in 7498f1ce8) R Before_any_peer_call_a_provisional_origin_reports_no_peer_traffic_yet_not_unavailable; live (below)
3 nit Origin reads count wire calls (chunk-token follow-ups count again) Kept per call; docs, the class remarks and this file say "per item per wire call". b5509dfc4 — (doc)
4 nit OpenContinuations = Cursors.Count + ChunkCount double-counted a chunk holding its page cursor OriginHistorySession.OpenContinuations counts chunks + cursors − cursors referenced by a live chunk (OriginHistoryCursors.Contains). 79cf50d50 R Open_continuations_count_a_chunk_holding_its_page_cursor_once (3, was 4) — red on revert
5 nit HistoryServed said "not advertised" with no handshake evidence "unavailable" when both NegotiatedFeatures and HistoryVariants are null. 2fba03617 AdminUI display test (new assertion fails against the previous helper by inspection)
6 nit Features() hid unknown bits beside a known one; DroppedBits scanned bits 0–30 Both render every set bit of all 32, named when known, hex otherwise. 2fba03617 AdminUI display tests: History, 0x8, 0x80000000, HistoryRead, 0x80000000 (fail against the previous helpers by inspection)
7 nit (tests) No unit round-trip of the snapshot on the cluster serializer; no mixed-version payload GrpcDataDiagnosticsSerializationTests round-trips a NodeDiagnosticsSnapshot with every H4 member through Sys.Serialization.FindSerializerFor (Akka's default JSON serializer — the fleet-diagnostics Ask has no custom binding), and decodes payloads stripped of the H4 members (null = "unavailable"). Found by it: Newtonsoft fills a missing constructor argument with the CLR default, not the C# default — the item-2 flag, first named PeerServicesStarted = true, would have decoded false from a sender without it; renamed NoPeerTrafficYet (default false) with a test. Also: a C# collection expression typed IReadOnlyList<T> is a synthesized type Newtonsoft cannot construct — production builds arrays (checked), the test fixture uses arrays. 7498f1ce8 new tests

Left as notes (no code change, per the review):

  • OriginHistoryPort._serving caches an unsynchronised nullable tuple — a pre-existing benign race (two callers may both compute it); H4 adds the metrics scrape thread as a caller through HistoryServing.
  • DataConnectionHistoryDiagnostics._consumer is never pruned; bounded by the deployed connection ids a process has seen.

Gates after the review fixes (HEAD 7498f1ce8), run one at a time: build 0 warnings / 0 errors; run-unit-phase.py H4 (9 + 12 + 29), H3 (107 + 145), H2, H1, X0 all passed; AdminUI.Tests 2698; Runtime.Tests 1915 (+3 skips); OpcUaServer.Tests 1420 (+1 skip) (Category!=E2E&Category!=LiveIntegration); no GrpcDataConfiguredDiscoveryWireTests (#920) failure.

Live re-run (fresh h4b-sqlserver, 2026-11-24): items 1 and 2 changed runtime behaviour (the consumer count moved into the node manager; a new DI-built provisional origin state), so the SqlServer leg was re-run.

  • Right after deploy, before any history traffic, the CONSUMER page's origin panel showed consumer-1/2 "remote history no historian backend · peer history sessions 0 · open origin continuations 0 · … · no peer has called since start", and source-2 (no peer call yet) "remote history served · … · no peer has called since start" — where h4a had shown "remote history evidence unavailable" (item 2).
  • H01–H06 all PASS (47 / 34 / 35 / 71 / 58 / 238, all restored).
  • After the gate: consumer-1 page "projected history reads good 36 · uncertain 0 · bad 3" = its reads{side=consumer} series (raw good 33, processed good 1, attime good 2; raw bad 2, processed bad 1); source-2 page "good 7 · bad 2" = its origin series.
  • Held probe: while held, consumer gauge 1, source-2 origin gauge 1, page "open remote continuations (local sessions) 1" and source-2 "peer history sessions 1"; after resume to completion all 0, projected good 37 ⇒ 56.
  • down ⇒ 0 run containers, 0 run volumes.

Not verified / notes

  • Gateway backend remotely (#923, above).
  • QuestDB was not re-run for H4: the H4 change is backend-independent (counting around the same port), and the H3 rounds passed H01–H06 on QuestDB at 713cbfb21. The brief asked for one SqlServer leg.
  • Browser-rendered page not driven (no Chrome session used); verified from the server-prerendered HTML, which runs the same OnInitializedAsync + render as the interactive circuit.
  • Akka serialization: now unit-tested (review 7) as well as exercised live.
  • Deviation: the reads counter carries a third label side (origin | consumer) beyond the plan's {variant,status_class} — a node can be both, and without it the two populations would be summed into one series. The gauge carries side too.
  • Consumer counts cover every projected node that reaches the projected half (review 1). A node the SDK or the node manager's authorization refuses before the split (no local HistoryRead grant ⇒ BadUserAccessDenied; not Historizing ⇒ BadHistoryOperationUnsupported from the SDK's access-level check) is not counted: it never reaches the projected half.
  • Counts are since process start (no persistence), as the docs say.
  • GrpcDataConfiguredDiscoveryWireTests (#920 flaky class): no failure in any run this phase (H4 manifest, H3 manifest, full Runtime suite).
  • Umbrella history entry (plan exit gate): not done here — it is a commit on scadaproj main plus a push, and this worktree brief forbids pushing; left to the orchestrator (append to ../scadaproj/.claude/skills/sister-project-history/otopcua.md). The Gitea close of #919 likewise belongs with the merge.