Merge historian follow-up (#1089): HistorianUnreachable on /alarms-historian + otopcua.alarm_historian.unreachable gauge; per-writer reachability tests; SqlServer writer no longer counts login/connection failures as answered
This commit is contained in:
+13
-1
@@ -145,10 +145,22 @@ internal sealed class QuestDbAlarmHistorianWriter : IAlarmHistorianWriter
|
||||
// #1071: a server-side refusal (not a transport/transient fault) proves the historian answered.
|
||||
private bool NoteAnswered(Exception ex)
|
||||
{
|
||||
if (!QuestDbConnection.IsTransient(ex)) _reach.Touch();
|
||||
if (Answered(ex)) _reach.Touch();
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether a failed statement proves QuestDB answered (#1089): a server rejection of the statement does; a transient
|
||||
/// transport fault, or a connection/authentication-level refusal (SQLSTATE class 08 / 28 / 53 / 57) does not.
|
||||
/// </summary>
|
||||
/// <param name="ex">The failure.</param>
|
||||
/// <returns>Whether the server demonstrably answered.</returns>
|
||||
internal static bool Answered(Exception ex) =>
|
||||
!QuestDbConnection.IsTransient(ex)
|
||||
&& !(ex is PostgresException pg && pg.SqlState is { Length: >= 2 } st
|
||||
&& (st.StartsWith("08", StringComparison.Ordinal) || st.StartsWith("28", StringComparison.Ordinal)
|
||||
|| st.StartsWith("53", StringComparison.Ordinal) || st.StartsWith("57", StringComparison.Ordinal)));
|
||||
|
||||
/// <summary>Classifies a write exception as retryable or a permanent dead-letter failure.</summary>
|
||||
/// <param name="ex">The exception raised by the write.</param>
|
||||
/// <returns>The write outcome the exception maps to.</returns>
|
||||
|
||||
+11
-1
@@ -151,10 +151,20 @@ internal sealed class SqlServerAlarmHistorianWriter : IAlarmHistorianWriter
|
||||
// #1071: a server-side refusal (not a transport/transient fault) proves the historian answered.
|
||||
private bool NoteAnswered(Exception ex)
|
||||
{
|
||||
if (!SqlHistorianConnection.IsTransient(ex)) _reach.Touch();
|
||||
if (Answered(ex)) _reach.Touch();
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether a failed statement proves the SQL Server answered (#1089): a statement-level refusal (data error, constraint)
|
||||
/// does; a transient fault, a timeout or a connection-level failure (login failed, server unreachable, pool exhausted)
|
||||
/// does not. It used <c>!IsTransient</c>, which counted a login failure or a refused connection as an answer and so
|
||||
/// reported a dead historian reachable.
|
||||
/// </summary>
|
||||
/// <param name="ex">The failure.</param>
|
||||
/// <returns>Whether the server demonstrably answered.</returns>
|
||||
internal static bool Answered(Exception ex) => !SqlHistorianConnection.IsOutage(ex);
|
||||
|
||||
/// <summary>Classifies a write failure. Only a data error SQL Server will reject forever dead-letters; anything unknown or non-SQL retries (never lose alarm history).</summary>
|
||||
/// <param name="ex">The exception raised by the write.</param>
|
||||
/// <returns>The write outcome the retry queue should act on.</returns>
|
||||
|
||||
@@ -52,6 +52,15 @@ else
|
||||
<div class="metric-card">
|
||||
<h2 class="panel-head">Drain state</h2>
|
||||
<div class="kv"><span class="k">State</span><span class="v"><span class="@StateChipClass(_status.DrainState)">@_status.DrainState</span></span></div>
|
||||
@if (_status.HistorianUnreachable)
|
||||
{
|
||||
@* #1089: an outage (the historian itself is not answering; rows are held) - distinct from a stuck queue. *@
|
||||
<div class="kv"><span class="k">Health</span><span class="v"><span class="chip chip-bad" data-testid="historian-unreachable" title="No write has reached the historian recently; queued rows are held and will drain when it answers again.">Historian unreachable</span></span></div>
|
||||
}
|
||||
else if (_status.Stalled)
|
||||
{
|
||||
<div class="kv"><span class="k">Health</span><span class="v"><span class="chip chip-warn" data-testid="queue-stalled" title="Rows are queued but none has been delivered or dead-lettered for the stall threshold, and the historian is not known to be down.">Queue stalled</span></span></div>
|
||||
}
|
||||
<div class="kv"><span class="k">Last drain</span><span class="v">@(_status.LastDrainUtc?.ToString("u") ?? "—")</span></div>
|
||||
<div class="kv"><span class="k">Last success</span><span class="v">@(_status.LastSuccessUtc?.ToString("u") ?? "—")</span></div>
|
||||
@if (!string.IsNullOrWhiteSpace(_status.LastError))
|
||||
|
||||
@@ -13,6 +13,8 @@ namespace ZB.MOM.WW.OtOpcUa.Runtime.Historian;
|
||||
/// <list type="bullet">
|
||||
/// <item><c>otopcua.alarm_historian.queue.stalled</c> — 1 when rows are queued on the draining node and none has been
|
||||
/// delivered or dead-lettered for <c>AlarmHistorian:StallThresholdHours</c>; else 0. Alert on it.</item>
|
||||
/// <item><c>otopcua.alarm_historian.unreachable</c> — 1 when the queue is held because the historian is unreachable (#1089,
|
||||
/// mutually exclusive with <c>queue.stalled</c>).</item>
|
||||
/// <item><c>otopcua.alarm_historian.queue.depth</c> / <c>.dead_letter_depth</c> — rows waiting / dead-lettered.</item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
@@ -21,6 +23,9 @@ public static class AlarmHistorianMetrics
|
||||
/// <summary>Gauge name: 1 while the queue is stalled.</summary>
|
||||
public const string StalledGaugeName = "otopcua.alarm_historian.queue.stalled";
|
||||
|
||||
/// <summary>Gauge name: 1 while the historian is unreachable and the queue is held (#1089).</summary>
|
||||
public const string UnreachableGaugeName = "otopcua.alarm_historian.unreachable";
|
||||
|
||||
private static volatile IAlarmHistorianSink? _sink;
|
||||
|
||||
static AlarmHistorianMetrics()
|
||||
@@ -28,6 +33,9 @@ public static class AlarmHistorianMetrics
|
||||
OtOpcUaTelemetry.Meter.CreateObservableGauge(
|
||||
StalledGaugeName, () => Status()?.Stalled == true ? 1 : 0, unit: "{state}",
|
||||
description: "1 when alarm events are queued on the draining node and none was delivered or dead-lettered for AlarmHistorian:StallThresholdHours (a long outage or retry-forever rows at the queue head).");
|
||||
OtOpcUaTelemetry.Meter.CreateObservableGauge(
|
||||
UnreachableGaugeName, () => Status()?.HistorianUnreachable == true ? 1 : 0, unit: "{state}",
|
||||
description: "1 when the alarm queue has made no progress for AlarmHistorian:StallThresholdHours because the historian itself is unreachable (an outage, not a stuck queue; rows are held). Distinct from queue.stalled.");
|
||||
OtOpcUaTelemetry.Meter.CreateObservableGauge(
|
||||
"otopcua.alarm_historian.queue.depth", () => Status()?.QueueDepth ?? 0L, unit: "{event}",
|
||||
description: "Alarm events waiting in the store-and-forward queue.");
|
||||
|
||||
Reference in New Issue
Block a user