From e02a3298657bfccd45b3bec5d1c4264405919915 Mon Sep 17 00:00:00 2001 From: martincostello Date: Fri, 1 Dec 2023 16:35:56 +0000 Subject: [PATCH] Fix/improve CloudWatch logging - Fix broken filtering. - Log the request IDs. - Log the wait. - Log how many log events found. --- .../CloudWatchLogsFixture.cs | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/test/LondonTravel.Skill.EndToEndTests/CloudWatchLogsFixture.cs b/test/LondonTravel.Skill.EndToEndTests/CloudWatchLogsFixture.cs index d7acbac5..7243ca93 100644 --- a/test/LondonTravel.Skill.EndToEndTests/CloudWatchLogsFixture.cs +++ b/test/LondonTravel.Skill.EndToEndTests/CloudWatchLogsFixture.cs @@ -28,7 +28,23 @@ public async Task DisposeAsync() regionName is not null && credentials is not null) { - await Task.Delay(TimeSpan.FromSeconds(10)); + var builder = new StringBuilder() + .AppendLine() + .AppendLine() + .AppendLine(CultureInfo.InvariantCulture, $"AWS Request ID(s) (Count = {RequestIds.Count}):") + .AppendLine(); + + foreach (var requestId in RequestIds) + { + builder.AppendLine(CultureInfo.InvariantCulture, $" - {requestId}"); + } + + diagnosticMessageSink.OnMessage(new DiagnosticMessage(builder.ToString())); + + var delay = TimeSpan.FromSeconds(10); + + diagnosticMessageSink.OnMessage(new DiagnosticMessage($"Waiting {delay.Seconds} seconds for CloudWatch logs...")); + await Task.Delay(delay); string logGroupName = $"/aws/lambda/{functionName}"; var region = RegionEndpoint.GetBySystemName(regionName); @@ -63,14 +79,16 @@ regionName is not null && foreach (var @event in reports) { string[] split = @event.Message.Split('\t', StringSplitOptions.RemoveEmptyEntries); - string requestId = split[0][ReportPrefix.Length..]; + string requestIdLine = split[0][ReportPrefix.Length..]; + string requestId = requestIdLine.Split(' ')[1]; - var builder = new StringBuilder() + builder + .Clear() .AppendLine() .AppendLine() .AppendFormat(CultureInfo.InvariantCulture, $"Timestamp: {@event.Timestamp:u}") .AppendLine() - .AppendLine(requestId); + .AppendLine(requestIdLine); foreach (string value in split.Skip(1)) { @@ -89,6 +107,8 @@ regionName is not null && .OrderBy((p) => p.Timestamp) .ToList(); + diagnosticMessageSink.OnMessage(new DiagnosticMessage($"Found {events.Count} CloudWatch log events.")); + foreach (var (_, _, message) in events) { diagnosticMessageSink.OnMessage(new DiagnosticMessage(message));