feat(auditlog): ParentExecutionId on site SQLite schema + gRPC AuditEventDto
This commit is contained in:
@@ -115,6 +115,7 @@ public class SqliteAuditWriter : IAuditWriter, ISiteAuditQueue, IAsyncDisposable
|
|||||||
Extra TEXT NULL,
|
Extra TEXT NULL,
|
||||||
ForwardState TEXT NOT NULL,
|
ForwardState TEXT NOT NULL,
|
||||||
ExecutionId TEXT NULL,
|
ExecutionId TEXT NULL,
|
||||||
|
ParentExecutionId TEXT NULL,
|
||||||
PRIMARY KEY (EventId)
|
PRIMARY KEY (EventId)
|
||||||
);
|
);
|
||||||
CREATE INDEX IF NOT EXISTS IX_SiteAuditLog_ForwardState_Occurred
|
CREATE INDEX IF NOT EXISTS IX_SiteAuditLog_ForwardState_Occurred
|
||||||
@@ -135,6 +136,14 @@ public class SqliteAuditWriter : IAuditWriter, ISiteAuditQueue, IAsyncDisposable
|
|||||||
// nullable with no default, so any row written before this migration
|
// nullable with no default, so any row written before this migration
|
||||||
// reads back ExecutionId = null (back-compat).
|
// reads back ExecutionId = null (back-compat).
|
||||||
AddColumnIfMissing("ExecutionId", "TEXT NULL");
|
AddColumnIfMissing("ExecutionId", "TEXT NULL");
|
||||||
|
|
||||||
|
// Audit Log #23 (ParentExecutionId): same idempotent upgrade path as
|
||||||
|
// ExecutionId above. A deployment that already ran the ExecutionId
|
||||||
|
// branch has an auditlog.db with the 21-column schema and no
|
||||||
|
// ParentExecutionId column; CREATE TABLE IF NOT EXISTS cannot add it,
|
||||||
|
// so it is ALTER-ed in here. Nullable with no default — rows written
|
||||||
|
// before this migration read back ParentExecutionId = null.
|
||||||
|
AddColumnIfMissing("ParentExecutionId", "TEXT NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -263,13 +272,13 @@ public class SqliteAuditWriter : IAuditWriter, ISiteAuditQueue, IAsyncDisposable
|
|||||||
SourceSiteId, SourceInstanceId, SourceScript, Actor, Target,
|
SourceSiteId, SourceInstanceId, SourceScript, Actor, Target,
|
||||||
Status, HttpStatus, DurationMs, ErrorMessage, ErrorDetail,
|
Status, HttpStatus, DurationMs, ErrorMessage, ErrorDetail,
|
||||||
RequestSummary, ResponseSummary, PayloadTruncated, Extra, ForwardState,
|
RequestSummary, ResponseSummary, PayloadTruncated, Extra, ForwardState,
|
||||||
ExecutionId
|
ExecutionId, ParentExecutionId
|
||||||
) VALUES (
|
) VALUES (
|
||||||
$EventId, $OccurredAtUtc, $Channel, $Kind, $CorrelationId,
|
$EventId, $OccurredAtUtc, $Channel, $Kind, $CorrelationId,
|
||||||
$SourceSiteId, $SourceInstanceId, $SourceScript, $Actor, $Target,
|
$SourceSiteId, $SourceInstanceId, $SourceScript, $Actor, $Target,
|
||||||
$Status, $HttpStatus, $DurationMs, $ErrorMessage, $ErrorDetail,
|
$Status, $HttpStatus, $DurationMs, $ErrorMessage, $ErrorDetail,
|
||||||
$RequestSummary, $ResponseSummary, $PayloadTruncated, $Extra, $ForwardState,
|
$RequestSummary, $ResponseSummary, $PayloadTruncated, $Extra, $ForwardState,
|
||||||
$ExecutionId
|
$ExecutionId, $ParentExecutionId
|
||||||
);
|
);
|
||||||
""";
|
""";
|
||||||
|
|
||||||
@@ -294,6 +303,7 @@ public class SqliteAuditWriter : IAuditWriter, ISiteAuditQueue, IAsyncDisposable
|
|||||||
var pExtra = cmd.Parameters.Add("$Extra", SqliteType.Text);
|
var pExtra = cmd.Parameters.Add("$Extra", SqliteType.Text);
|
||||||
var pForwardState = cmd.Parameters.Add("$ForwardState", SqliteType.Text);
|
var pForwardState = cmd.Parameters.Add("$ForwardState", SqliteType.Text);
|
||||||
var pExecutionId = cmd.Parameters.Add("$ExecutionId", SqliteType.Text);
|
var pExecutionId = cmd.Parameters.Add("$ExecutionId", SqliteType.Text);
|
||||||
|
var pParentExecutionId = cmd.Parameters.Add("$ParentExecutionId", SqliteType.Text);
|
||||||
|
|
||||||
foreach (var pending in batch)
|
foreach (var pending in batch)
|
||||||
{
|
{
|
||||||
@@ -319,6 +329,7 @@ public class SqliteAuditWriter : IAuditWriter, ISiteAuditQueue, IAsyncDisposable
|
|||||||
pExtra.Value = (object?)e.Extra ?? DBNull.Value;
|
pExtra.Value = (object?)e.Extra ?? DBNull.Value;
|
||||||
pForwardState.Value = (e.ForwardState ?? AuditForwardState.Pending).ToString();
|
pForwardState.Value = (e.ForwardState ?? AuditForwardState.Pending).ToString();
|
||||||
pExecutionId.Value = (object?)e.ExecutionId?.ToString() ?? DBNull.Value;
|
pExecutionId.Value = (object?)e.ExecutionId?.ToString() ?? DBNull.Value;
|
||||||
|
pParentExecutionId.Value = (object?)e.ParentExecutionId?.ToString() ?? DBNull.Value;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -377,7 +388,7 @@ public class SqliteAuditWriter : IAuditWriter, ISiteAuditQueue, IAsyncDisposable
|
|||||||
SourceSiteId, SourceInstanceId, SourceScript, Actor, Target,
|
SourceSiteId, SourceInstanceId, SourceScript, Actor, Target,
|
||||||
Status, HttpStatus, DurationMs, ErrorMessage, ErrorDetail,
|
Status, HttpStatus, DurationMs, ErrorMessage, ErrorDetail,
|
||||||
RequestSummary, ResponseSummary, PayloadTruncated, Extra, ForwardState,
|
RequestSummary, ResponseSummary, PayloadTruncated, Extra, ForwardState,
|
||||||
ExecutionId
|
ExecutionId, ParentExecutionId
|
||||||
FROM AuditLog
|
FROM AuditLog
|
||||||
WHERE ForwardState = $pending
|
WHERE ForwardState = $pending
|
||||||
ORDER BY OccurredAtUtc ASC, EventId ASC
|
ORDER BY OccurredAtUtc ASC, EventId ASC
|
||||||
@@ -426,7 +437,7 @@ public class SqliteAuditWriter : IAuditWriter, ISiteAuditQueue, IAsyncDisposable
|
|||||||
SourceSiteId, SourceInstanceId, SourceScript, Actor, Target,
|
SourceSiteId, SourceInstanceId, SourceScript, Actor, Target,
|
||||||
Status, HttpStatus, DurationMs, ErrorMessage, ErrorDetail,
|
Status, HttpStatus, DurationMs, ErrorMessage, ErrorDetail,
|
||||||
RequestSummary, ResponseSummary, PayloadTruncated, Extra, ForwardState,
|
RequestSummary, ResponseSummary, PayloadTruncated, Extra, ForwardState,
|
||||||
ExecutionId
|
ExecutionId, ParentExecutionId
|
||||||
FROM AuditLog
|
FROM AuditLog
|
||||||
WHERE ForwardState = $forwarded
|
WHERE ForwardState = $forwarded
|
||||||
ORDER BY OccurredAtUtc ASC, EventId ASC
|
ORDER BY OccurredAtUtc ASC, EventId ASC
|
||||||
@@ -513,7 +524,7 @@ public class SqliteAuditWriter : IAuditWriter, ISiteAuditQueue, IAsyncDisposable
|
|||||||
SourceSiteId, SourceInstanceId, SourceScript, Actor, Target,
|
SourceSiteId, SourceInstanceId, SourceScript, Actor, Target,
|
||||||
Status, HttpStatus, DurationMs, ErrorMessage, ErrorDetail,
|
Status, HttpStatus, DurationMs, ErrorMessage, ErrorDetail,
|
||||||
RequestSummary, ResponseSummary, PayloadTruncated, Extra, ForwardState,
|
RequestSummary, ResponseSummary, PayloadTruncated, Extra, ForwardState,
|
||||||
ExecutionId
|
ExecutionId, ParentExecutionId
|
||||||
FROM AuditLog
|
FROM AuditLog
|
||||||
WHERE ForwardState IN ($pending, $forwarded)
|
WHERE ForwardState IN ($pending, $forwarded)
|
||||||
AND OccurredAtUtc >= $since
|
AND OccurredAtUtc >= $since
|
||||||
@@ -691,6 +702,7 @@ public class SqliteAuditWriter : IAuditWriter, ISiteAuditQueue, IAsyncDisposable
|
|||||||
Extra = reader.IsDBNull(18) ? null : reader.GetString(18),
|
Extra = reader.IsDBNull(18) ? null : reader.GetString(18),
|
||||||
ForwardState = Enum.Parse<AuditForwardState>(reader.GetString(19)),
|
ForwardState = Enum.Parse<AuditForwardState>(reader.GetString(19)),
|
||||||
ExecutionId = reader.IsDBNull(20) ? null : Guid.Parse(reader.GetString(20)),
|
ExecutionId = reader.IsDBNull(20) ? null : Guid.Parse(reader.GetString(20)),
|
||||||
|
ParentExecutionId = reader.IsDBNull(21) ? null : Guid.Parse(reader.GetString(21)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public static class AuditEventDtoMapper
|
|||||||
Kind = evt.Kind.ToString(),
|
Kind = evt.Kind.ToString(),
|
||||||
CorrelationId = evt.CorrelationId?.ToString() ?? string.Empty,
|
CorrelationId = evt.CorrelationId?.ToString() ?? string.Empty,
|
||||||
ExecutionId = evt.ExecutionId?.ToString() ?? string.Empty,
|
ExecutionId = evt.ExecutionId?.ToString() ?? string.Empty,
|
||||||
|
ParentExecutionId = evt.ParentExecutionId?.ToString() ?? string.Empty,
|
||||||
SourceSiteId = evt.SourceSiteId ?? string.Empty,
|
SourceSiteId = evt.SourceSiteId ?? string.Empty,
|
||||||
SourceInstanceId = evt.SourceInstanceId ?? string.Empty,
|
SourceInstanceId = evt.SourceInstanceId ?? string.Empty,
|
||||||
SourceScript = evt.SourceScript ?? string.Empty,
|
SourceScript = evt.SourceScript ?? string.Empty,
|
||||||
@@ -94,6 +95,7 @@ public static class AuditEventDtoMapper
|
|||||||
Kind = Enum.Parse<AuditKind>(dto.Kind),
|
Kind = Enum.Parse<AuditKind>(dto.Kind),
|
||||||
CorrelationId = NullIfEmpty(dto.CorrelationId) is { } cid ? Guid.Parse(cid) : null,
|
CorrelationId = NullIfEmpty(dto.CorrelationId) is { } cid ? Guid.Parse(cid) : null,
|
||||||
ExecutionId = NullIfEmpty(dto.ExecutionId) is { } eid ? Guid.Parse(eid) : null,
|
ExecutionId = NullIfEmpty(dto.ExecutionId) is { } eid ? Guid.Parse(eid) : null,
|
||||||
|
ParentExecutionId = NullIfEmpty(dto.ParentExecutionId) is { } pid ? Guid.Parse(pid) : null,
|
||||||
SourceSiteId = NullIfEmpty(dto.SourceSiteId),
|
SourceSiteId = NullIfEmpty(dto.SourceSiteId),
|
||||||
SourceInstanceId = NullIfEmpty(dto.SourceInstanceId),
|
SourceInstanceId = NullIfEmpty(dto.SourceInstanceId),
|
||||||
SourceScript = NullIfEmpty(dto.SourceScript),
|
SourceScript = NullIfEmpty(dto.SourceScript),
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ message AuditEventDto {
|
|||||||
bool payload_truncated = 18;
|
bool payload_truncated = 18;
|
||||||
string extra = 19;
|
string extra = 19;
|
||||||
string execution_id = 20; // empty string represents null
|
string execution_id = 20; // empty string represents null
|
||||||
|
string parent_execution_id = 21; // empty string represents null
|
||||||
}
|
}
|
||||||
|
|
||||||
message AuditEventBatch { repeated AuditEventDto events = 1; }
|
message AuditEventBatch { repeated AuditEventDto events = 1; }
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace ScadaLink.Communication.Grpc {
|
|||||||
"c3RhdGUYAyABKA4yGi5zaXRlc3RyZWFtLkFsYXJtU3RhdGVFbnVtEhAKCHBy",
|
"c3RhdGUYAyABKA4yGi5zaXRlc3RyZWFtLkFsYXJtU3RhdGVFbnVtEhAKCHBy",
|
||||||
"aW9yaXR5GAQgASgFEi0KCXRpbWVzdGFtcBgFIAEoCzIaLmdvb2dsZS5wcm90",
|
"aW9yaXR5GAQgASgFEi0KCXRpbWVzdGFtcBgFIAEoCzIaLmdvb2dsZS5wcm90",
|
||||||
"b2J1Zi5UaW1lc3RhbXASKQoFbGV2ZWwYBiABKA4yGi5zaXRlc3RyZWFtLkFs",
|
"b2J1Zi5UaW1lc3RhbXASKQoFbGV2ZWwYBiABKA4yGi5zaXRlc3RyZWFtLkFs",
|
||||||
"YXJtTGV2ZWxFbnVtEg8KB21lc3NhZ2UYByABKAkiiwQKDUF1ZGl0RXZlbnRE",
|
"YXJtTGV2ZWxFbnVtEg8KB21lc3NhZ2UYByABKAkiqAQKDUF1ZGl0RXZlbnRE",
|
||||||
"dG8SEAoIZXZlbnRfaWQYASABKAkSMwoPb2NjdXJyZWRfYXRfdXRjGAIgASgL",
|
"dG8SEAoIZXZlbnRfaWQYASABKAkSMwoPb2NjdXJyZWRfYXRfdXRjGAIgASgL",
|
||||||
"MhouZ29vZ2xlLnByb3RvYnVmLlRpbWVzdGFtcBIPCgdjaGFubmVsGAMgASgJ",
|
"MhouZ29vZ2xlLnByb3RvYnVmLlRpbWVzdGFtcBIPCgdjaGFubmVsGAMgASgJ",
|
||||||
"EgwKBGtpbmQYBCABKAkSFgoOY29ycmVsYXRpb25faWQYBSABKAkSFgoOc291",
|
"EgwKBGtpbmQYBCABKAkSFgoOY29ycmVsYXRpb25faWQYBSABKAkSFgoOc291",
|
||||||
@@ -53,42 +53,43 @@ namespace ScadaLink.Communication.Grpc {
|
|||||||
"bWVzc2FnZRgOIAEoCRIUCgxlcnJvcl9kZXRhaWwYDyABKAkSFwoPcmVxdWVz",
|
"bWVzc2FnZRgOIAEoCRIUCgxlcnJvcl9kZXRhaWwYDyABKAkSFwoPcmVxdWVz",
|
||||||
"dF9zdW1tYXJ5GBAgASgJEhgKEHJlc3BvbnNlX3N1bW1hcnkYESABKAkSGQoR",
|
"dF9zdW1tYXJ5GBAgASgJEhgKEHJlc3BvbnNlX3N1bW1hcnkYESABKAkSGQoR",
|
||||||
"cGF5bG9hZF90cnVuY2F0ZWQYEiABKAgSDQoFZXh0cmEYEyABKAkSFAoMZXhl",
|
"cGF5bG9hZF90cnVuY2F0ZWQYEiABKAgSDQoFZXh0cmEYEyABKAkSFAoMZXhl",
|
||||||
"Y3V0aW9uX2lkGBQgASgJIjwKD0F1ZGl0RXZlbnRCYXRjaBIpCgZldmVudHMY",
|
"Y3V0aW9uX2lkGBQgASgJEhsKE3BhcmVudF9leGVjdXRpb25faWQYFSABKAki",
|
||||||
"ASADKAsyGS5zaXRlc3RyZWFtLkF1ZGl0RXZlbnREdG8iJwoJSW5nZXN0QWNr",
|
"PAoPQXVkaXRFdmVudEJhdGNoEikKBmV2ZW50cxgBIAMoCzIZLnNpdGVzdHJl",
|
||||||
"EhoKEmFjY2VwdGVkX2V2ZW50X2lkcxgBIAMoCSL0AgoWU2l0ZUNhbGxPcGVy",
|
"YW0uQXVkaXRFdmVudER0byInCglJbmdlc3RBY2sSGgoSY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iIuc2l0",
|
||||||
"dBojLnNpdGVzdHJlYW0uUHVsbEF1ZGl0RXZlbnRzUmVzcG9uc2VCH6oCHFNj",
|
"ZXN0cmVhbS5QdWxsQXVkaXRFdmVudHNSZXF1ZXN0GiMuc2l0ZXN0cmVhbS5Q",
|
||||||
"YWRhTGluay5Db21tdW5pY2F0aW9uLkdycGNiBnByb3RvMw=="));
|
"dWxsQXVkaXRFdmVudHNSZXNwb25zZUIfqgIcU2NhZGFMaW5rLkNvbW11bmlj",
|
||||||
|
"YXRpb24uR3JwY2IGcHJvdG8z"));
|
||||||
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
|
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
|
||||||
new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.TimestampReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor, },
|
new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.TimestampReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor, },
|
||||||
new pbr::GeneratedClrTypeInfo(new[] {typeof(global::ScadaLink.Communication.Grpc.Quality), typeof(global::ScadaLink.Communication.Grpc.AlarmStateEnum), typeof(global::ScadaLink.Communication.Grpc.AlarmLevelEnum), }, null, new pbr::GeneratedClrTypeInfo[] {
|
new pbr::GeneratedClrTypeInfo(new[] {typeof(global::ScadaLink.Communication.Grpc.Quality), typeof(global::ScadaLink.Communication.Grpc.AlarmStateEnum), typeof(global::ScadaLink.Communication.Grpc.AlarmLevelEnum), }, null, new pbr::GeneratedClrTypeInfo[] {
|
||||||
@@ -96,7 +97,7 @@ namespace ScadaLink.Communication.Grpc {
|
|||||||
new pbr::GeneratedClrTypeInfo(typeof(global::ScadaLink.Communication.Grpc.SiteStreamEvent), global::ScadaLink.Communication.Grpc.SiteStreamEvent.Parser, new[]{ "CorrelationId", "AttributeChanged", "AlarmChanged" }, new[]{ "Event" }, null, null, null),
|
new pbr::GeneratedClrTypeInfo(typeof(global::ScadaLink.Communication.Grpc.SiteStreamEvent), global::ScadaLink.Communication.Grpc.SiteStreamEvent.Parser, new[]{ "CorrelationId", "AttributeChanged", "AlarmChanged" }, new[]{ "Event" }, null, null, null),
|
||||||
new pbr::GeneratedClrTypeInfo(typeof(global::ScadaLink.Communication.Grpc.AttributeValueUpdate), global::ScadaLink.Communication.Grpc.AttributeValueUpdate.Parser, new[]{ "InstanceUniqueName", "AttributePath", "AttributeName", "Value", "Quality", "Timestamp" }, null, null, null, null),
|
new pbr::GeneratedClrTypeInfo(typeof(global::ScadaLink.Communication.Grpc.AttributeValueUpdate), global::ScadaLink.Communication.Grpc.AttributeValueUpdate.Parser, new[]{ "InstanceUniqueName", "AttributePath", "AttributeName", "Value", "Quality", "Timestamp" }, null, null, null, null),
|
||||||
new pbr::GeneratedClrTypeInfo(typeof(global::ScadaLink.Communication.Grpc.AlarmStateUpdate), global::ScadaLink.Communication.Grpc.AlarmStateUpdate.Parser, new[]{ "InstanceUniqueName", "AlarmName", "State", "Priority", "Timestamp", "Level", "Message" }, null, null, null, null),
|
new pbr::GeneratedClrTypeInfo(typeof(global::ScadaLink.Communication.Grpc.AlarmStateUpdate), global::ScadaLink.Communication.Grpc.AlarmStateUpdate.Parser, new[]{ "InstanceUniqueName", "AlarmName", "State", "Priority", "Timestamp", "Level", "Message" }, null, null, null, null),
|
||||||
new pbr::GeneratedClrTypeInfo(typeof(global::ScadaLink.Communication.Grpc.AuditEventDto), global::ScadaLink.Communication.Grpc.AuditEventDto.Parser, new[]{ "EventId", "OccurredAtUtc", "Channel", "Kind", "CorrelationId", "SourceSiteId", "SourceInstanceId", "SourceScript", "Actor", "Target", "Status", "HttpStatus", "DurationMs", "ErrorMessage", "ErrorDetail", "RequestSummary", "ResponseSummary", "PayloadTruncated", "Extra", "ExecutionId" }, null, null, null, null),
|
new pbr::GeneratedClrTypeInfo(typeof(global::ScadaLink.Communication.Grpc.AuditEventDto), global::ScadaLink.Communication.Grpc.AuditEventDto.Parser, new[]{ "EventId", "OccurredAtUtc", "Channel", "Kind", "CorrelationId", "SourceSiteId", "SourceInstanceId", "SourceScript", "Actor", "Target", "Status", "HttpStatus", "DurationMs", "ErrorMessage", "ErrorDetail", "RequestSummary", "ResponseSummary", "PayloadTruncated", "Extra", "ExecutionId", "ParentExecutionId" }, null, null, null, null),
|
||||||
new pbr::GeneratedClrTypeInfo(typeof(global::ScadaLink.Communication.Grpc.AuditEventBatch), global::ScadaLink.Communication.Grpc.AuditEventBatch.Parser, new[]{ "Events" }, null, null, null, null),
|
new pbr::GeneratedClrTypeInfo(typeof(global::ScadaLink.Communication.Grpc.AuditEventBatch), global::ScadaLink.Communication.Grpc.AuditEventBatch.Parser, new[]{ "Events" }, null, null, null, null),
|
||||||
new pbr::GeneratedClrTypeInfo(typeof(global::ScadaLink.Communication.Grpc.IngestAck), global::ScadaLink.Communication.Grpc.IngestAck.Parser, new[]{ "AcceptedEventIds" }, null, null, null, null),
|
new pbr::GeneratedClrTypeInfo(typeof(global::ScadaLink.Communication.Grpc.IngestAck), global::ScadaLink.Communication.Grpc.IngestAck.Parser, new[]{ "AcceptedEventIds" }, null, null, null, null),
|
||||||
new pbr::GeneratedClrTypeInfo(typeof(global::ScadaLink.Communication.Grpc.SiteCallOperationalDto), global::ScadaLink.Communication.Grpc.SiteCallOperationalDto.Parser, new[]{ "TrackedOperationId", "Channel", "Target", "SourceSite", "Status", "RetryCount", "LastError", "HttpStatus", "CreatedAtUtc", "UpdatedAtUtc", "TerminalAtUtc" }, null, null, null, null),
|
new pbr::GeneratedClrTypeInfo(typeof(global::ScadaLink.Communication.Grpc.SiteCallOperationalDto), global::ScadaLink.Communication.Grpc.SiteCallOperationalDto.Parser, new[]{ "TrackedOperationId", "Channel", "Target", "SourceSite", "Status", "RetryCount", "LastError", "HttpStatus", "CreatedAtUtc", "UpdatedAtUtc", "TerminalAtUtc" }, null, null, null, null),
|
||||||
@@ -1592,6 +1593,7 @@ namespace ScadaLink.Communication.Grpc {
|
|||||||
payloadTruncated_ = other.payloadTruncated_;
|
payloadTruncated_ = other.payloadTruncated_;
|
||||||
extra_ = other.extra_;
|
extra_ = other.extra_;
|
||||||
executionId_ = other.executionId_;
|
executionId_ = other.executionId_;
|
||||||
|
parentExecutionId_ = other.parentExecutionId_;
|
||||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1854,6 +1856,21 @@ namespace ScadaLink.Communication.Grpc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Field number for the "parent_execution_id" field.</summary>
|
||||||
|
public const int ParentExecutionIdFieldNumber = 21;
|
||||||
|
private string parentExecutionId_ = "";
|
||||||
|
/// <summary>
|
||||||
|
/// empty string represents null
|
||||||
|
/// </summary>
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||||
|
public string ParentExecutionId {
|
||||||
|
get { return parentExecutionId_; }
|
||||||
|
set {
|
||||||
|
parentExecutionId_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||||
public override bool Equals(object other) {
|
public override bool Equals(object other) {
|
||||||
@@ -1889,6 +1906,7 @@ namespace ScadaLink.Communication.Grpc {
|
|||||||
if (PayloadTruncated != other.PayloadTruncated) return false;
|
if (PayloadTruncated != other.PayloadTruncated) return false;
|
||||||
if (Extra != other.Extra) return false;
|
if (Extra != other.Extra) return false;
|
||||||
if (ExecutionId != other.ExecutionId) return false;
|
if (ExecutionId != other.ExecutionId) return false;
|
||||||
|
if (ParentExecutionId != other.ParentExecutionId) return false;
|
||||||
return Equals(_unknownFields, other._unknownFields);
|
return Equals(_unknownFields, other._unknownFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1916,6 +1934,7 @@ namespace ScadaLink.Communication.Grpc {
|
|||||||
if (PayloadTruncated != false) hash ^= PayloadTruncated.GetHashCode();
|
if (PayloadTruncated != false) hash ^= PayloadTruncated.GetHashCode();
|
||||||
if (Extra.Length != 0) hash ^= Extra.GetHashCode();
|
if (Extra.Length != 0) hash ^= Extra.GetHashCode();
|
||||||
if (ExecutionId.Length != 0) hash ^= ExecutionId.GetHashCode();
|
if (ExecutionId.Length != 0) hash ^= ExecutionId.GetHashCode();
|
||||||
|
if (ParentExecutionId.Length != 0) hash ^= ParentExecutionId.GetHashCode();
|
||||||
if (_unknownFields != null) {
|
if (_unknownFields != null) {
|
||||||
hash ^= _unknownFields.GetHashCode();
|
hash ^= _unknownFields.GetHashCode();
|
||||||
}
|
}
|
||||||
@@ -2012,6 +2031,10 @@ namespace ScadaLink.Communication.Grpc {
|
|||||||
output.WriteRawTag(162, 1);
|
output.WriteRawTag(162, 1);
|
||||||
output.WriteString(ExecutionId);
|
output.WriteString(ExecutionId);
|
||||||
}
|
}
|
||||||
|
if (ParentExecutionId.Length != 0) {
|
||||||
|
output.WriteRawTag(170, 1);
|
||||||
|
output.WriteString(ParentExecutionId);
|
||||||
|
}
|
||||||
if (_unknownFields != null) {
|
if (_unknownFields != null) {
|
||||||
_unknownFields.WriteTo(output);
|
_unknownFields.WriteTo(output);
|
||||||
}
|
}
|
||||||
@@ -2100,6 +2123,10 @@ namespace ScadaLink.Communication.Grpc {
|
|||||||
output.WriteRawTag(162, 1);
|
output.WriteRawTag(162, 1);
|
||||||
output.WriteString(ExecutionId);
|
output.WriteString(ExecutionId);
|
||||||
}
|
}
|
||||||
|
if (ParentExecutionId.Length != 0) {
|
||||||
|
output.WriteRawTag(170, 1);
|
||||||
|
output.WriteString(ParentExecutionId);
|
||||||
|
}
|
||||||
if (_unknownFields != null) {
|
if (_unknownFields != null) {
|
||||||
_unknownFields.WriteTo(ref output);
|
_unknownFields.WriteTo(ref output);
|
||||||
}
|
}
|
||||||
@@ -2170,6 +2197,9 @@ namespace ScadaLink.Communication.Grpc {
|
|||||||
if (ExecutionId.Length != 0) {
|
if (ExecutionId.Length != 0) {
|
||||||
size += 2 + pb::CodedOutputStream.ComputeStringSize(ExecutionId);
|
size += 2 + pb::CodedOutputStream.ComputeStringSize(ExecutionId);
|
||||||
}
|
}
|
||||||
|
if (ParentExecutionId.Length != 0) {
|
||||||
|
size += 2 + pb::CodedOutputStream.ComputeStringSize(ParentExecutionId);
|
||||||
|
}
|
||||||
if (_unknownFields != null) {
|
if (_unknownFields != null) {
|
||||||
size += _unknownFields.CalculateSize();
|
size += _unknownFields.CalculateSize();
|
||||||
}
|
}
|
||||||
@@ -2249,6 +2279,9 @@ namespace ScadaLink.Communication.Grpc {
|
|||||||
if (other.ExecutionId.Length != 0) {
|
if (other.ExecutionId.Length != 0) {
|
||||||
ExecutionId = other.ExecutionId;
|
ExecutionId = other.ExecutionId;
|
||||||
}
|
}
|
||||||
|
if (other.ParentExecutionId.Length != 0) {
|
||||||
|
ParentExecutionId = other.ParentExecutionId;
|
||||||
|
}
|
||||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2357,6 +2390,10 @@ namespace ScadaLink.Communication.Grpc {
|
|||||||
ExecutionId = input.ReadString();
|
ExecutionId = input.ReadString();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 170: {
|
||||||
|
ParentExecutionId = input.ReadString();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -2465,6 +2502,10 @@ namespace ScadaLink.Communication.Grpc {
|
|||||||
ExecutionId = input.ReadString();
|
ExecutionId = input.ReadString();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 170: {
|
||||||
|
ParentExecutionId = input.ReadString();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ public class SqliteAuditWriterSchemaTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Opens_Creates_AuditLog_Table_With_21Columns_And_PK_On_EventId()
|
public void Opens_Creates_AuditLog_Table_With_22Columns_And_PK_On_EventId()
|
||||||
{
|
{
|
||||||
var (writer, dataSource) = CreateWriter(nameof(Opens_Creates_AuditLog_Table_With_21Columns_And_PK_On_EventId));
|
var (writer, dataSource) = CreateWriter(nameof(Opens_Creates_AuditLog_Table_With_22Columns_And_PK_On_EventId));
|
||||||
using (writer)
|
using (writer)
|
||||||
{
|
{
|
||||||
using var connection = OpenVerifierConnection(dataSource);
|
using var connection = OpenVerifierConnection(dataSource);
|
||||||
@@ -59,7 +59,7 @@ public class SqliteAuditWriterSchemaTests
|
|||||||
columns.Add((reader.GetString(1), reader.GetInt32(5)));
|
columns.Add((reader.GetString(1), reader.GetInt32(5)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Equal(21, columns.Count);
|
Assert.Equal(22, columns.Count);
|
||||||
|
|
||||||
var expected = new[]
|
var expected = new[]
|
||||||
{
|
{
|
||||||
@@ -67,7 +67,7 @@ public class SqliteAuditWriterSchemaTests
|
|||||||
"SourceSiteId", "SourceInstanceId", "SourceScript", "Actor", "Target",
|
"SourceSiteId", "SourceInstanceId", "SourceScript", "Actor", "Target",
|
||||||
"Status", "HttpStatus", "DurationMs", "ErrorMessage", "ErrorDetail",
|
"Status", "HttpStatus", "DurationMs", "ErrorMessage", "ErrorDetail",
|
||||||
"RequestSummary", "ResponseSummary", "PayloadTruncated", "Extra",
|
"RequestSummary", "ResponseSummary", "PayloadTruncated", "Extra",
|
||||||
"ForwardState", "ExecutionId",
|
"ForwardState", "ExecutionId", "ParentExecutionId",
|
||||||
};
|
};
|
||||||
Assert.Equal(expected.OrderBy(n => n), columns.Select(c => c.Name).OrderBy(n => n));
|
Assert.Equal(expected.OrderBy(n => n), columns.Select(c => c.Name).OrderBy(n => n));
|
||||||
|
|
||||||
@@ -245,4 +245,136 @@ public class SqliteAuditWriterSchemaTests
|
|||||||
Assert.True(ColumnExists(seedConnection, "ExecutionId"));
|
Assert.True(ColumnExists(seedConnection, "ExecutionId"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----- ParentExecutionId schema-upgrade regression (persistent auditlog.db) ----- //
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The pre-ParentExecutionId-branch <c>AuditLog</c> schema — the 21-column
|
||||||
|
/// CREATE TABLE that HAS <c>ExecutionId</c> but is WITHOUT
|
||||||
|
/// <c>ParentExecutionId</c>. A deployment that ran the ExecutionId branch
|
||||||
|
/// already has an on-disk <c>auditlog.db</c> in exactly this shape, and
|
||||||
|
/// <c>CREATE TABLE IF NOT EXISTS</c> is a no-op against it.
|
||||||
|
/// </summary>
|
||||||
|
private const string OldPreParentExecutionIdSchema = """
|
||||||
|
CREATE TABLE IF NOT EXISTS AuditLog (
|
||||||
|
EventId TEXT NOT NULL,
|
||||||
|
OccurredAtUtc TEXT NOT NULL,
|
||||||
|
Channel TEXT NOT NULL,
|
||||||
|
Kind TEXT NOT NULL,
|
||||||
|
CorrelationId TEXT NULL,
|
||||||
|
SourceSiteId TEXT NULL,
|
||||||
|
SourceInstanceId TEXT NULL,
|
||||||
|
SourceScript TEXT NULL,
|
||||||
|
Actor TEXT NULL,
|
||||||
|
Target TEXT NULL,
|
||||||
|
Status TEXT NOT NULL,
|
||||||
|
HttpStatus INTEGER NULL,
|
||||||
|
DurationMs INTEGER NULL,
|
||||||
|
ErrorMessage TEXT NULL,
|
||||||
|
ErrorDetail TEXT NULL,
|
||||||
|
RequestSummary TEXT NULL,
|
||||||
|
ResponseSummary TEXT NULL,
|
||||||
|
PayloadTruncated INTEGER NOT NULL,
|
||||||
|
Extra TEXT NULL,
|
||||||
|
ForwardState TEXT NOT NULL,
|
||||||
|
ExecutionId TEXT NULL,
|
||||||
|
PRIMARY KEY (EventId)
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS IX_SiteAuditLog_ForwardState_Occurred
|
||||||
|
ON AuditLog (ForwardState, OccurredAtUtc);
|
||||||
|
""";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Seeds a shared-cache in-memory database with the pre-ParentExecutionId
|
||||||
|
/// 21-column schema and returns the open connection. The connection MUST
|
||||||
|
/// stay open for the lifetime of the test — a shared-cache in-memory
|
||||||
|
/// database is dropped once its last connection closes.
|
||||||
|
/// </summary>
|
||||||
|
private static SqliteConnection SeedPreParentExecutionIdSchemaDatabase(string dataSource)
|
||||||
|
{
|
||||||
|
var connection = new SqliteConnection($"Data Source={dataSource};Cache=Shared");
|
||||||
|
connection.Open();
|
||||||
|
using var cmd = connection.CreateCommand();
|
||||||
|
cmd.CommandText = OldPreParentExecutionIdSchema;
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Opening_Over_PreExisting_PreParentExecutionId_Db_Adds_ParentExecutionId_Column_And_WriteAsync_RoundTrips()
|
||||||
|
{
|
||||||
|
var dataSource = $"file:{nameof(Opening_Over_PreExisting_PreParentExecutionId_Db_Adds_ParentExecutionId_Column_And_WriteAsync_RoundTrips)}-{Guid.NewGuid():N}?mode=memory&cache=shared";
|
||||||
|
|
||||||
|
// A deployment that ran the ExecutionId branch: auditlog.db already
|
||||||
|
// exists with the 21-column schema and NO ParentExecutionId column.
|
||||||
|
using var seedConnection = SeedPreParentExecutionIdSchemaDatabase(dataSource);
|
||||||
|
Assert.True(ColumnExists(seedConnection, "ExecutionId"));
|
||||||
|
Assert.False(ColumnExists(seedConnection, "ParentExecutionId"));
|
||||||
|
|
||||||
|
// Upgrade: a post-branch SqliteAuditWriter opens the same database. Its
|
||||||
|
// InitializeSchema must ALTER the missing ParentExecutionId column in —
|
||||||
|
// the CREATE TABLE IF NOT EXISTS alone is a no-op against the existing
|
||||||
|
// table.
|
||||||
|
var executionId = Guid.NewGuid();
|
||||||
|
var parentExecutionId = Guid.NewGuid();
|
||||||
|
await using (var writer = CreateWriterOver(dataSource))
|
||||||
|
{
|
||||||
|
Assert.True(
|
||||||
|
ColumnExists(seedConnection, "ParentExecutionId"),
|
||||||
|
"SqliteAuditWriter must ALTER the ParentExecutionId column into a pre-existing AuditLog table.");
|
||||||
|
|
||||||
|
// A WriteAsync binding $ParentExecutionId must now succeed and
|
||||||
|
// round-trip; without the ALTER it would fail with "no such column:
|
||||||
|
// ParentExecutionId" and — because audit writes are best-effort —
|
||||||
|
// silently drop the row.
|
||||||
|
var evt = new AuditEvent
|
||||||
|
{
|
||||||
|
EventId = Guid.NewGuid(),
|
||||||
|
OccurredAtUtc = DateTime.UtcNow,
|
||||||
|
Channel = AuditChannel.ApiOutbound,
|
||||||
|
Kind = AuditKind.ApiCall,
|
||||||
|
Status = AuditStatus.Delivered,
|
||||||
|
PayloadTruncated = false,
|
||||||
|
ExecutionId = executionId,
|
||||||
|
ParentExecutionId = parentExecutionId,
|
||||||
|
};
|
||||||
|
await writer.WriteAsync(evt);
|
||||||
|
|
||||||
|
var rows = await writer.ReadPendingAsync(limit: 10);
|
||||||
|
var row = Assert.Single(rows);
|
||||||
|
Assert.Equal(executionId, row.ExecutionId);
|
||||||
|
Assert.Equal(parentExecutionId, row.ParentExecutionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Idempotency: a second writer over the now-upgraded DB must not error
|
||||||
|
// (the probe sees ParentExecutionId already present and skips the ALTER).
|
||||||
|
await using (var writerAgain = CreateWriterOver(dataSource))
|
||||||
|
{
|
||||||
|
Assert.True(ColumnExists(seedConnection, "ParentExecutionId"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WriteAsync_NullParentExecutionId_RoundTripsAsNull()
|
||||||
|
{
|
||||||
|
var (writer, _) = CreateWriter(nameof(WriteAsync_NullParentExecutionId_RoundTripsAsNull));
|
||||||
|
await using (writer)
|
||||||
|
{
|
||||||
|
var evt = new AuditEvent
|
||||||
|
{
|
||||||
|
EventId = Guid.NewGuid(),
|
||||||
|
OccurredAtUtc = DateTime.UtcNow,
|
||||||
|
Channel = AuditChannel.Notification,
|
||||||
|
Kind = AuditKind.NotifySend,
|
||||||
|
Status = AuditStatus.Submitted,
|
||||||
|
PayloadTruncated = false,
|
||||||
|
// ParentExecutionId left null
|
||||||
|
};
|
||||||
|
await writer.WriteAsync(evt);
|
||||||
|
|
||||||
|
var rows = await writer.ReadPendingAsync(limit: 10);
|
||||||
|
var row = Assert.Single(rows);
|
||||||
|
Assert.Null(row.ParentExecutionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ public class AuditEventDtoMapperTests
|
|||||||
var ingestedAt = new DateTime(2026, 5, 20, 10, 15, 31, 0, DateTimeKind.Utc);
|
var ingestedAt = new DateTime(2026, 5, 20, 10, 15, 31, 0, DateTimeKind.Utc);
|
||||||
var correlationId = Guid.NewGuid();
|
var correlationId = Guid.NewGuid();
|
||||||
var executionId = Guid.NewGuid();
|
var executionId = Guid.NewGuid();
|
||||||
|
var parentExecutionId = Guid.NewGuid();
|
||||||
var eventId = Guid.NewGuid();
|
var eventId = Guid.NewGuid();
|
||||||
|
|
||||||
var original = new AuditEvent
|
var original = new AuditEvent
|
||||||
@@ -31,6 +32,7 @@ public class AuditEventDtoMapperTests
|
|||||||
Kind = AuditKind.ApiCallCached,
|
Kind = AuditKind.ApiCallCached,
|
||||||
CorrelationId = correlationId,
|
CorrelationId = correlationId,
|
||||||
ExecutionId = executionId,
|
ExecutionId = executionId,
|
||||||
|
ParentExecutionId = parentExecutionId,
|
||||||
SourceSiteId = "site-1",
|
SourceSiteId = "site-1",
|
||||||
SourceInstanceId = "Pump01",
|
SourceInstanceId = "Pump01",
|
||||||
SourceScript = "OnDemand",
|
SourceScript = "OnDemand",
|
||||||
@@ -57,6 +59,7 @@ public class AuditEventDtoMapperTests
|
|||||||
Assert.Equal(original.Kind, roundTripped.Kind);
|
Assert.Equal(original.Kind, roundTripped.Kind);
|
||||||
Assert.Equal(original.CorrelationId, roundTripped.CorrelationId);
|
Assert.Equal(original.CorrelationId, roundTripped.CorrelationId);
|
||||||
Assert.Equal(original.ExecutionId, roundTripped.ExecutionId);
|
Assert.Equal(original.ExecutionId, roundTripped.ExecutionId);
|
||||||
|
Assert.Equal(original.ParentExecutionId, roundTripped.ParentExecutionId);
|
||||||
Assert.Equal(original.SourceSiteId, roundTripped.SourceSiteId);
|
Assert.Equal(original.SourceSiteId, roundTripped.SourceSiteId);
|
||||||
Assert.Equal(original.SourceInstanceId, roundTripped.SourceInstanceId);
|
Assert.Equal(original.SourceInstanceId, roundTripped.SourceInstanceId);
|
||||||
Assert.Equal(original.SourceScript, roundTripped.SourceScript);
|
Assert.Equal(original.SourceScript, roundTripped.SourceScript);
|
||||||
@@ -94,6 +97,7 @@ public class AuditEventDtoMapperTests
|
|||||||
|
|
||||||
Assert.Equal(string.Empty, dto.CorrelationId);
|
Assert.Equal(string.Empty, dto.CorrelationId);
|
||||||
Assert.Equal(string.Empty, dto.ExecutionId);
|
Assert.Equal(string.Empty, dto.ExecutionId);
|
||||||
|
Assert.Equal(string.Empty, dto.ParentExecutionId);
|
||||||
Assert.Equal(string.Empty, dto.SourceSiteId);
|
Assert.Equal(string.Empty, dto.SourceSiteId);
|
||||||
Assert.Equal(string.Empty, dto.SourceInstanceId);
|
Assert.Equal(string.Empty, dto.SourceInstanceId);
|
||||||
Assert.Equal(string.Empty, dto.SourceScript);
|
Assert.Equal(string.Empty, dto.SourceScript);
|
||||||
@@ -118,6 +122,7 @@ public class AuditEventDtoMapperTests
|
|||||||
Status = nameof(AuditStatus.Submitted),
|
Status = nameof(AuditStatus.Submitted),
|
||||||
CorrelationId = string.Empty,
|
CorrelationId = string.Empty,
|
||||||
ExecutionId = string.Empty,
|
ExecutionId = string.Empty,
|
||||||
|
ParentExecutionId = string.Empty,
|
||||||
SourceSiteId = string.Empty,
|
SourceSiteId = string.Empty,
|
||||||
SourceInstanceId = string.Empty,
|
SourceInstanceId = string.Empty,
|
||||||
SourceScript = string.Empty,
|
SourceScript = string.Empty,
|
||||||
@@ -134,6 +139,7 @@ public class AuditEventDtoMapperTests
|
|||||||
|
|
||||||
Assert.Null(evt.CorrelationId);
|
Assert.Null(evt.CorrelationId);
|
||||||
Assert.Null(evt.ExecutionId);
|
Assert.Null(evt.ExecutionId);
|
||||||
|
Assert.Null(evt.ParentExecutionId);
|
||||||
Assert.Null(evt.SourceSiteId);
|
Assert.Null(evt.SourceSiteId);
|
||||||
Assert.Null(evt.SourceInstanceId);
|
Assert.Null(evt.SourceInstanceId);
|
||||||
Assert.Null(evt.SourceScript);
|
Assert.Null(evt.SourceScript);
|
||||||
|
|||||||
Reference in New Issue
Block a user