fix(historian): #1109 a proxy-fabricated Unimplemented on SendEvents is an outage, not a missing batch RPC

IsSystemicFailure (which covers client-fabricated statuses) now runs before the
Unimplemented probe, so a proxy 404 retries the batch instead of flipping the
writer to single sends for its lifetime. Classify also treats a client-fabricated
status as RetryPlease, so a fabricated Unimplemented/InvalidArgument on a single
SendEvent no longer dead-letters an event the gateway never judged. (#1103)
This commit is contained in:
Joseph Doherty
2026-12-04 22:02:14 -05:00
parent da23fd970d
commit e38b9030b7
2 changed files with 75 additions and 9 deletions
@@ -35,7 +35,8 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway;
/// which the sink counts toward <c>MaxAttempts</c> on that Ack'd drain and dead-letters alone. If NO single send
/// Acks, it was not the event: later chunks are RetryPlease as for an outage (so such an outage costs at most one
/// chunk of single sends per drain);</item>
/// <item><c>Unimplemented</c> (a gateway older than the RPC) ⇒ the writer stops trying batches for its lifetime and
/// <item><c>Unimplemented</c> SENT BY the gateway (one older than the RPC — a proxy's client-fabricated 404
/// "Unimplemented" is an outage, above, #1103) ⇒ the writer stops trying batches for its lifetime and
/// sends every event individually;</item>
/// <item>any other refusal (<c>InvalidArgument</c> — a poison event or an over-limit batch, nothing sent — and the
/// other permanent codes) ⇒ that call's events are sent individually, so the poison event dead-letters alone.</item>
@@ -232,6 +233,15 @@ public sealed class GatewayAlarmHistorianWriter : IAlarmHistorianWriter, IDispos
catch (Exception exception)
{
NoteAnswered(exception);
// #1109/#1103: the outage check runs FIRST. A proxy's non-gRPC 404 surfaces as a client-FABRICATED
// Unimplemented ("Bad gRPC response. HTTP status code: 404"): a broken path, not a gateway that lacks
// SendEvents — it must not flip the writer to single sends for its lifetime.
if (IsSystemicFailure(exception))
{
_logger.LogDebug("Alarm SendEvents transiently failed ({Exception}); the batch will retry.", exception.GetType().Name);
foreach (var i in indexes) outcomes[i] = HistorianWriteOutcome.RetryPlease;
return false;
}
if (StatusOf(exception) == StatusCode.Unimplemented)
{
_batchUnsupported = true;
@@ -242,13 +252,6 @@ public sealed class GatewayAlarmHistorianWriter : IAlarmHistorianWriter, IDispos
}
if (Classify(exception) == HistorianWriteOutcome.RetryPlease)
{
if (IsSystemicFailure(exception))
{
_logger.LogDebug("Alarm SendEvents transiently failed ({Exception}); the batch will retry.", exception.GetType().Name);
foreach (var i in indexes) outcomes[i] = HistorianWriteOutcome.RetryPlease;
return false;
}
// #976 review: a RetryPlease the writer cannot vouch for as an outage (Unknown — the gateway handler threw —
// Internal, DataLoss, an unlisted code, a non-transport client exception) may be ONE event's fault. Retrying
// the whole chunk tied every sibling to it, and the sink counts a RetryPlease only on a drain with an Ack, so
@@ -424,7 +427,11 @@ public sealed class GatewayAlarmHistorianWriter : IAlarmHistorianWriter, IDispos
/// one is a transport-level fault and retries. Never dead-letter on what might be an outage (lmxopcua#976 G-8).
/// </summary>
private static HistorianWriteOutcome Classify(Exception exception) =>
StatusOf(exception) is { } code ? ClassifyStatus(code) : HistorianWriteOutcome.RetryPlease;
FirstRpc(exception) is { } rpc && !IsClientFabricated(rpc)
? ClassifyStatus(rpc.StatusCode)
// No status, or one Grpc.Net.Client fabricated (a proxy 404 => "Unimplemented", a reset => "Internal"): the
// gateway never judged the event, so it must not dead-letter (#1109/#1103).
: HistorianWriteOutcome.RetryPlease;
/// <summary>
/// Only the codes that prove the EVENT is bad dead-letter; every other code — transient, auth, <c>Cancelled</c>