[opcuaclient] OpcUaClient — Diagnostics counters #334

Merged
dohertj2 merged 1 commits from auto/opcuaclient/4 into auto/driver-gaps 2026-04-25 15:56:23 -04:00
Owner

Summary

Per-driver diagnostics counters for the OpcUaClient driver, surfaced via the established DriverHealth.Diagnostics shape so the existing driver-diagnostics RPC pattern (Modbus task #154) can consume them without per-driver wiring.

  • Core.Abstractions/DriverHealth.cs — optional 4th parameter IReadOnlyDictionary<string,double>? Diagnostics (default null). Back-compat with the seven existing driver constructors. New DiagnosticsOrEmpty accessor.
  • OpcUaClientDiagnostics.cs (new) — lock-free counter helper:
    • PublishRequestCount, NotificationCount, MissingPublishRequestCount, DroppedNotificationCount, SessionResetCount, LastReconnectUtcTicks via Interlocked
    • NotificationsPerSecond — 5-second half-life EWMA
  • OpcUaClientDriver.cs — wires ISession.Notification + ISession.PublishError on connect, unwires on shutdown, rewires (and records a session-reset) on OnReconnectComplete. GetHealth() snapshots the counters into the Diagnostics dictionary on every poll.

Test plan

  • dotnet build Core.Abstractions + Driver.OpcUaClient + tests project — clean (0 / 0)
  • dotnet test tests/ZB.MOM.WW.OtOpcUa.Driver.OpcUaClient.Tests115 / 115 passed (11 new in OpcUaClientDiagnosticsTests: counter increments, EWMA decay/sample, session-reset on reconnect, snapshot dictionary keys, hot-path lock-free)
  • Integration tests — skipped (live UA server required)

Note: Modbus task #154's driver-diagnostics RPC consumer scaffolding is on master but not in this auto/driver-gaps branch yet, so the data shape lands here ready for it.

🤖 Auto-generated by the Mode-B execution loop. Closes #276.

Closes #276

## Summary Per-driver diagnostics counters for the OpcUaClient driver, surfaced via the established `DriverHealth.Diagnostics` shape so the existing `driver-diagnostics` RPC pattern (Modbus task #154) can consume them without per-driver wiring. - **`Core.Abstractions/DriverHealth.cs`** — optional 4th parameter `IReadOnlyDictionary<string,double>? Diagnostics` (default `null`). Back-compat with the seven existing driver constructors. New `DiagnosticsOrEmpty` accessor. - **`OpcUaClientDiagnostics.cs`** (new) — lock-free counter helper: - `PublishRequestCount`, `NotificationCount`, `MissingPublishRequestCount`, `DroppedNotificationCount`, `SessionResetCount`, `LastReconnectUtcTicks` via `Interlocked` - `NotificationsPerSecond` — 5-second half-life EWMA - **`OpcUaClientDriver.cs`** — wires `ISession.Notification` + `ISession.PublishError` on connect, unwires on shutdown, rewires (and records a session-reset) on `OnReconnectComplete`. `GetHealth()` snapshots the counters into the `Diagnostics` dictionary on every poll. ## Test plan - [x] `dotnet build Core.Abstractions + Driver.OpcUaClient + tests project` — clean (0 / 0) - [x] `dotnet test tests/ZB.MOM.WW.OtOpcUa.Driver.OpcUaClient.Tests` — **115 / 115 passed** (11 new in `OpcUaClientDiagnosticsTests`: counter increments, EWMA decay/sample, session-reset on reconnect, snapshot dictionary keys, hot-path lock-free) - [ ] Integration tests — skipped (live UA server required) > Note: Modbus task #154's `driver-diagnostics` RPC consumer scaffolding is on master but not in this `auto/driver-gaps` branch yet, so the data shape lands here ready for it. 🤖 Auto-generated by the Mode-B execution loop. Closes #276. Closes #276
dohertj2 added 1 commit 2026-04-25 15:56:18 -04:00
Per-driver counters surfaced via DriverHealth.Diagnostics for the
driver-diagnostics RPC. New OpcUaClientDiagnostics tracks
PublishRequestCount, NotificationCount, NotificationsPerSecond (5s-half-life
EWMA), MissingPublishRequestCount, DroppedNotificationCount,
SessionResetCount and LastReconnectUtcTicks via Interlocked on the hot path.

DriverHealth gains an optional IReadOnlyDictionary<string,double>?
Diagnostics parameter (defaulted null for back-compat with the seven other
drivers' constructors). OpcUaClientDriver wires Session.Notification +
Session.PublishError on connect and on reconnect-complete (recording a
session-reset there); GetHealth snapshots the counters on every poll so the
RPC sees fresh values without a tick source.

Tests: 11 new OpcUaClientDiagnosticsTests cover counter increments, EWMA
convergence, snapshot shape, GetHealth integration, and DriverHealth
back-compat. Full OpcUaClient.Tests 115/115 green.

Closes #276

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
dohertj2 merged commit d57e24a7fa into auto/driver-gaps 2026-04-25 15:56:23 -04:00
dohertj2 deleted branch auto/opcuaclient/4 2026-04-25 15:56:23 -04:00
Sign in to join this conversation.