feat(health): wire up NodeHostname, ConnectionEndpoint, TagQuality, ParkedMessageCount collectors
- AkkaHostedService: SetNodeHostname from NodeOptions - DataConnectionActor: UpdateConnectionEndpoint on state transitions, track per-tag quality counts and UpdateTagQuality on value changes - HealthReportSender: query StoreAndForwardStorage for parked message count - StoreAndForwardStorage: add GetParkedMessageCountAsync()
This commit is contained in:
@@ -66,6 +66,11 @@ public class DataConnectionActor : UntypedActor, IWithStash, IWithTimers
|
||||
private int _totalSubscribed;
|
||||
private int _resolvedTags;
|
||||
|
||||
private int _tagsGoodQuality;
|
||||
private int _tagsBadQuality;
|
||||
private int _tagsUncertainQuality;
|
||||
private readonly Dictionary<string, QualityCode> _lastTagQuality = new();
|
||||
|
||||
private IDictionary<string, string> _connectionDetails;
|
||||
private readonly IDictionary<string, string> _primaryConfig;
|
||||
private readonly IDictionary<string, string>? _backupConfig;
|
||||
@@ -144,6 +149,7 @@ public class DataConnectionActor : UntypedActor, IWithStash, IWithTimers
|
||||
{
|
||||
_log.Info("[{0}] Entering Connecting state", _connectionName);
|
||||
_healthCollector.UpdateConnectionHealth(_connectionName, ConnectionHealth.Connecting);
|
||||
_healthCollector.UpdateConnectionEndpoint(_connectionName, "Connecting");
|
||||
Become(Connecting);
|
||||
Self.Tell(new AttemptConnect());
|
||||
}
|
||||
@@ -179,6 +185,8 @@ public class DataConnectionActor : UntypedActor, IWithStash, IWithTimers
|
||||
_log.Info("[{0}] Entering Connected state", _connectionName);
|
||||
_healthCollector.UpdateConnectionHealth(_connectionName, ConnectionHealth.Connected);
|
||||
_healthCollector.UpdateTagResolution(_connectionName, _totalSubscribed, _resolvedTags);
|
||||
var endpointLabel = _backupConfig == null ? "Connected" : $"Connected to {_activeEndpoint.ToString().ToLower()}";
|
||||
_healthCollector.UpdateConnectionEndpoint(_connectionName, endpointLabel);
|
||||
Become(Connected);
|
||||
Stash.UnstashAll();
|
||||
}
|
||||
@@ -226,6 +234,7 @@ public class DataConnectionActor : UntypedActor, IWithStash, IWithTimers
|
||||
{
|
||||
_log.Warning("[{0}] Entering Reconnecting state", _connectionName);
|
||||
_healthCollector.UpdateConnectionHealth(_connectionName, ConnectionHealth.Disconnected);
|
||||
_healthCollector.UpdateConnectionEndpoint(_connectionName, "Disconnected");
|
||||
Become(Reconnecting);
|
||||
|
||||
// WP-9: Push bad quality for all subscribed tags on disconnect
|
||||
@@ -552,6 +561,14 @@ public class DataConnectionActor : UntypedActor, IWithStash, IWithTimers
|
||||
|
||||
subscriber.Tell(new ConnectionQualityChanged(_connectionName, QualityCode.Bad, now));
|
||||
}
|
||||
|
||||
// All tags now bad quality
|
||||
_tagsGoodQuality = 0;
|
||||
_tagsUncertainQuality = 0;
|
||||
_tagsBadQuality = _lastTagQuality.Count;
|
||||
foreach (var key in _lastTagQuality.Keys.ToList())
|
||||
_lastTagQuality[key] = QualityCode.Bad;
|
||||
_healthCollector.UpdateTagQuality(_connectionName, _tagsGoodQuality, _tagsBadQuality, _tagsUncertainQuality);
|
||||
}
|
||||
|
||||
// ── Re-subscribe (WP-10) ──
|
||||
@@ -646,6 +663,27 @@ public class DataConnectionActor : UntypedActor, IWithStash, IWithTimers
|
||||
_connectionName, msg.TagPath, msg.Value.Value, msg.Value.Quality, msg.Value.Timestamp));
|
||||
}
|
||||
}
|
||||
|
||||
// Track quality transitions
|
||||
if (_lastTagQuality.TryGetValue(msg.TagPath, out var prevQuality))
|
||||
{
|
||||
// Decrement old quality bucket
|
||||
switch (prevQuality)
|
||||
{
|
||||
case QualityCode.Good: _tagsGoodQuality--; break;
|
||||
case QualityCode.Bad: _tagsBadQuality--; break;
|
||||
case QualityCode.Uncertain: _tagsUncertainQuality--; break;
|
||||
}
|
||||
}
|
||||
// Increment new quality bucket
|
||||
switch (msg.Value.Quality)
|
||||
{
|
||||
case QualityCode.Good: _tagsGoodQuality++; break;
|
||||
case QualityCode.Bad: _tagsBadQuality++; break;
|
||||
case QualityCode.Uncertain: _tagsUncertainQuality++; break;
|
||||
}
|
||||
_lastTagQuality[msg.TagPath] = msg.Value.Quality;
|
||||
_healthCollector.UpdateTagQuality(_connectionName, _tagsGoodQuality, _tagsBadQuality, _tagsUncertainQuality);
|
||||
}
|
||||
|
||||
// ── Internal messages ──
|
||||
|
||||
Reference in New Issue
Block a user