Skip to content

Commit 05dfe82

Browse files
authored
link-index-updater: More logging (#1215)
Trying to understand why messages are not sent back to the queue and reprocessed by the lambda
1 parent 42dad89 commit 05dfe82

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/infra/docs-lambda-index-publisher/LinkIndexProvider.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class LinkIndexProvider(IAmazonS3 s3Client, ILambdaLogger logger, string
1919
{
2020
private string? _etag;
2121
private LinkReferenceRegistry? _linkIndex;
22+
private bool _modified;
2223

2324
private async Task<LinkReferenceRegistry> GetLinkIndex()
2425
{
@@ -56,12 +57,18 @@ public async Task UpdateLinkIndexEntry(LinkRegistryEntry linkRegistryEntry)
5657
{
5758
{ linkRegistryEntry.Branch, linkRegistryEntry }
5859
});
60+
_modified = true;
5961
logger.LogInformation("Added new entry for {repository}@{branch}", linkRegistryEntry.Repository, linkRegistryEntry.Branch);
6062
}
6163
}
6264

6365
public async Task Save()
6466
{
67+
if (!_modified)
68+
{
69+
logger.LogInformation("Skipping Save() because the link index was not modified");
70+
return;
71+
}
6572
if (_etag == null || _linkIndex == null)
6673
throw new InvalidOperationException("You must call UpdateLinkIndexEntry() before Save()");
6774
var json = LinkReferenceRegistry.Serialize(_linkIndex);

src/infra/docs-lambda-index-publisher/Program.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
// See the LICENSE file in the project root for more information
44

55
using System.Collections.Concurrent;
6+
using System.Text.Json;
67
using Amazon.Lambda.Core;
78
using Amazon.Lambda.RuntimeSupport;
89
using Amazon.Lambda.Serialization.SystemTextJson;
910
using Amazon.Lambda.SQSEvents;
1011
using Amazon.S3;
1112
using Amazon.S3.Util;
12-
using Elastic.Documentation;
1313
using Elastic.Documentation.Lambda.LinkIndexUploader;
1414
using Elastic.Documentation.Links;
1515

@@ -30,6 +30,8 @@ static async Task<SQSBatchResponse> Handler(SQSEvent ev, ILambdaContext context)
3030
var batchItemFailures = new List<SQSBatchResponse.BatchItemFailure>();
3131
foreach (var message in ev.Records)
3232
{
33+
context.Logger.LogInformation("Processing message {MessageId}", message.MessageId);
34+
context.Logger.LogInformation("Message body: {MessageBody}", message.Body);
3335
try
3436
{
3537
var s3RecordLinkReferenceTuples = await GetS3RecordLinkReferenceTuples(s3Client, message, context);
@@ -55,6 +57,8 @@ static async Task<SQSBatchResponse> Handler(SQSEvent ev, ILambdaContext context)
5557
var response = new SQSBatchResponse(batchItemFailures);
5658
if (batchItemFailures.Count > 0)
5759
context.Logger.LogInformation("Failed to process {batchItemFailuresCount} of {allMessagesCount} messages. Returning them to the queue.", batchItemFailures.Count, ev.Records.Count);
60+
var jsonStr = JsonSerializer.Serialize(response, SerializerContext.Default.SQSBatchResponse);
61+
context.Logger.LogInformation(jsonStr);
5862
return response;
5963
}
6064
catch (Exception ex)
@@ -67,6 +71,8 @@ static async Task<SQSBatchResponse> Handler(SQSEvent ev, ILambdaContext context)
6771
{
6872
ItemIdentifier = r.MessageId
6973
}).ToList());
74+
var jsonStr = JsonSerializer.Serialize(response, SerializerContext.Default.SQSBatchResponse);
75+
context.Logger.LogInformation(jsonStr);
7076
return response;
7177
}
7278
}

0 commit comments

Comments
 (0)