fix: wire DCL connection state changes into ISiteHealthCollector

DataConnectionActor now calls UpdateConnectionHealth() on state
transitions (Connecting/Connected/Reconnecting) and UpdateTagResolution()
on connection establishment. DataConnectionManagerActor calls
RemoveConnection() on actor removal. Health reports now include
data connection statuses when instances are deployed with bindings.
This commit is contained in:
Joseph Doherty
2026-03-18 00:20:02 -04:00
parent 4f22ca2b1f
commit 75a6636a2c
6 changed files with 28 additions and 7 deletions

View File

@@ -3,6 +3,7 @@ using Akka.Event;
using ScadaLink.Commons.Interfaces.Protocol;
using ScadaLink.Commons.Messages.DataConnection;
using ScadaLink.Commons.Types.Enums;
using ScadaLink.HealthMonitoring;
namespace ScadaLink.DataConnectionLayer.Actors;
@@ -28,6 +29,7 @@ public class DataConnectionActor : UntypedActor, IWithStash, IWithTimers
private readonly string _connectionName;
private readonly IDataConnection _adapter;
private readonly DataConnectionOptions _options;
private readonly ISiteHealthCollector _healthCollector;
public IStash Stash { get; set; } = null!;
public ITimerScheduler Timers { get; set; } = null!;
@@ -64,11 +66,13 @@ public class DataConnectionActor : UntypedActor, IWithStash, IWithTimers
string connectionName,
IDataConnection adapter,
DataConnectionOptions options,
ISiteHealthCollector healthCollector,
IDictionary<string, string>? connectionDetails = null)
{
_connectionName = connectionName;
_adapter = adapter;
_options = options;
_healthCollector = healthCollector;
_connectionDetails = connectionDetails ?? new Dictionary<string, string>();
}
@@ -96,6 +100,7 @@ public class DataConnectionActor : UntypedActor, IWithStash, IWithTimers
private void BecomeConnecting()
{
_log.Info("[{0}] Entering Connecting state", _connectionName);
_healthCollector.UpdateConnectionHealth(_connectionName, ConnectionHealth.Connecting);
Become(Connecting);
Self.Tell(new AttemptConnect());
}
@@ -129,6 +134,8 @@ public class DataConnectionActor : UntypedActor, IWithStash, IWithTimers
private void BecomeConnected()
{
_log.Info("[{0}] Entering Connected state", _connectionName);
_healthCollector.UpdateConnectionHealth(_connectionName, ConnectionHealth.Connected);
_healthCollector.UpdateTagResolution(_connectionName, _totalSubscribed, _resolvedTags);
Become(Connected);
Stash.UnstashAll();
}
@@ -166,6 +173,7 @@ public class DataConnectionActor : UntypedActor, IWithStash, IWithTimers
private void BecomeReconnecting()
{
_log.Warning("[{0}] Entering Reconnecting state", _connectionName);
_healthCollector.UpdateConnectionHealth(_connectionName, ConnectionHealth.Disconnected);
Become(Reconnecting);
// WP-9: Push bad quality for all subscribed tags on disconnect

View File

@@ -2,6 +2,7 @@ using Akka.Actor;
using Akka.Event;
using ScadaLink.Commons.Interfaces.Protocol;
using ScadaLink.Commons.Messages.DataConnection;
using ScadaLink.HealthMonitoring;
namespace ScadaLink.DataConnectionLayer.Actors;
@@ -15,14 +16,17 @@ public class DataConnectionManagerActor : ReceiveActor
private readonly ILoggingAdapter _log = Context.GetLogger();
private readonly IDataConnectionFactory _factory;
private readonly DataConnectionOptions _options;
private readonly ISiteHealthCollector _healthCollector;
private readonly Dictionary<string, IActorRef> _connectionActors = new();
public DataConnectionManagerActor(
IDataConnectionFactory factory,
DataConnectionOptions options)
DataConnectionOptions options,
ISiteHealthCollector healthCollector)
{
_factory = factory;
_options = options;
_healthCollector = healthCollector;
Receive<CreateConnectionCommand>(HandleCreateConnection);
Receive<SubscribeTagsRequest>(HandleRoute);
@@ -44,7 +48,7 @@ public class DataConnectionManagerActor : ReceiveActor
var adapter = _factory.Create(command.ProtocolType, command.ConnectionDetails);
var props = Props.Create(() => new DataConnectionActor(
command.ConnectionName, adapter, _options, command.ConnectionDetails));
command.ConnectionName, adapter, _options, _healthCollector, command.ConnectionDetails));
// Sanitize name for Akka actor path (replace spaces and invalid chars)
var actorName = new string(command.ConnectionName
@@ -97,6 +101,7 @@ public class DataConnectionManagerActor : ReceiveActor
{
Context.Stop(actor);
_connectionActors.Remove(command.ConnectionName);
_healthCollector.RemoveConnection(command.ConnectionName);
_log.Info("Removed DataConnectionActor for {0}", command.ConnectionName);
}
}