test(grpc-data): A4 live scenarios part 1 harness — run-owned opc-plc --alm, native alarm + 2 referencing equipment + 3 condition mappings, UNS-only origin principal, no-grant consumer principal; probe condition-records; node-probe alert-transitions; conditions_scenarios.py (A01/A02/A04/A05/A08)
This commit is contained in:
@@ -137,6 +137,46 @@ public sealed partial class NodeProbeWorker(IServiceProvider services) : Backgro
|
||||
return new(command.Id, command.Operation, false, assertions, observations, error.GetType().Name);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// A4 (A08/§5.7): listen to THIS node's own authenticated telemetry stream for the command's window and return every
|
||||
/// <c>alerts</c> transition it carries — the exact feed central's <c>/alerts</c> page and the alarm-history adapter
|
||||
/// consume. A consumer node must publish none for imported conditions; the SOURCE Primary's list is the positive control.
|
||||
/// </summary>
|
||||
private static async Task<ProbeResult> AlertTransitionsAsync(ProbeCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
var observations = new Dictionary<string, object?>();
|
||||
var transitions = new List<object>();
|
||||
var envelopes = 0;
|
||||
var host = Environment.GetEnvironmentVariable("HOSTNAME");
|
||||
var key = Environment.GetEnvironmentVariable("Telemetry__ApiKey");
|
||||
if (string.IsNullOrWhiteSpace(host) || string.IsNullOrWhiteSpace(key) || command.TimeoutSeconds is < 3 or > 120)
|
||||
return new(command.Id, command.Operation, false, 0, observations, "InvalidCommand");
|
||||
using var handler = new SocketsHttpHandler { AllowAutoRedirect = false, UseProxy = false, ConnectTimeout = TimeSpan.FromSeconds(5) };
|
||||
using var channel = GrpcChannel.ForAddress($"http://{host}:4056", new GrpcChannelOptions { HttpHandler = handler, MaxReceiveMessageSize = 1024 * 1024 });
|
||||
var client = new T.TelemetryStreamService.TelemetryStreamServiceClient(channel);
|
||||
var headers = new Metadata { { "authorization", "Bearer " + key } };
|
||||
string? failure = null;
|
||||
try
|
||||
{
|
||||
using var call = client.Subscribe(new T.TelemetryStreamRequest { CorrelationId = command.Id }, headers,
|
||||
deadline: DateTime.UtcNow.AddSeconds(command.TimeoutSeconds - 2), cancellationToken: cancellationToken);
|
||||
while (await call.ResponseStream.MoveNext(cancellationToken))
|
||||
{
|
||||
envelopes++;
|
||||
if (call.ResponseStream.Current.AlarmTransition is { } alarm)
|
||||
transitions.Add(new { alarmId = alarm.AlarmId, alarmName = alarm.AlarmName, kind = alarm.TransitionKind,
|
||||
equipmentPath = alarm.EquipmentPath, user = alarm.User, comment = alarm.HasComment ? alarm.Comment : null,
|
||||
at = alarm.TimestampUtc?.ToDateTime().ToString("O") });
|
||||
}
|
||||
}
|
||||
catch (RpcException error) when (error.StatusCode is StatusCode.DeadlineExceeded or StatusCode.Cancelled) { }
|
||||
catch (Exception error) when (error is not OutOfMemoryException) { failure = error.GetType().Name; }
|
||||
observations["node"] = host;
|
||||
observations["envelopes"] = envelopes;
|
||||
observations["alarmTransitions"] = transitions;
|
||||
return new(command.Id, command.Operation, failure is null, 1, observations, failure);
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
var configured = Environment.GetEnvironmentVariable("GRPC_DATA_NODE_PROBE_DIR");
|
||||
@@ -217,6 +257,10 @@ public sealed partial class NodeProbeWorker(IServiceProvider services) : Backgro
|
||||
{
|
||||
result = CaptureProjectionDiagnostics(command);
|
||||
}
|
||||
else if (command.Operation == "alert-transitions")
|
||||
{
|
||||
result = await AlertTransitionsAsync(command, timeout.Token);
|
||||
}
|
||||
else if (command.Operation == "legacy-telemetry")
|
||||
{
|
||||
// Feature-disable validation must bypass DataConnection acquisition.
|
||||
|
||||
Reference in New Issue
Block a user