diff --git a/docs/testing/archive.md b/docs/testing/archive.md index 4abf1d3a8..17d79474d 100644 --- a/docs/testing/archive.md +++ b/docs/testing/archive.md @@ -7,4 +7,6 @@ description: Browse the archive for legacy Elastic products and documentation. A This is a test modification on 9.0 branch -These are other modifications \ No newline at end of file +These are other modifications + +Another set of modifications \ No newline at end of file diff --git a/src/infra/docs-lambda-index-publisher/LinkIndexProvider.cs b/src/infra/docs-lambda-index-publisher/LinkIndexProvider.cs index d6965ebc7..4cd5780cd 100644 --- a/src/infra/docs-lambda-index-publisher/LinkIndexProvider.cs +++ b/src/infra/docs-lambda-index-publisher/LinkIndexProvider.cs @@ -2,6 +2,7 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information +using System.Net; using Amazon.Lambda.Core; using Amazon.S3; using Amazon.S3.Model; @@ -36,27 +37,40 @@ private async Task GetLinkIndex() return _linkIndex; } - public async Task UpdateLinkIndexEntry(LinkRegistryEntry linkRegistryEntry) + public async Task UpdateLinkIndexEntry(LinkRegistryEntry newEntry) { _linkIndex ??= await GetLinkIndex(); - if (_linkIndex.Repositories.TryGetValue(linkRegistryEntry.Repository, out var existingEntry)) + var repository = newEntry.Repository; + var branch = newEntry.Branch; + // repository already exists in links.json + if (_linkIndex.Repositories.TryGetValue(repository, out var existingRepositoryEntry)) { - var newEntryIsNewer = DateTime.Compare(linkRegistryEntry.UpdatedAt, existingEntry[linkRegistryEntry.Branch].UpdatedAt) > 0; - if (newEntryIsNewer) + // The branch already exists in the repository entry + if (existingRepositoryEntry.TryGetValue(branch, out var existingBranchEntry)) { - existingEntry[linkRegistryEntry.Branch] = linkRegistryEntry; - logger.LogInformation("Updated existing entry for {repository}@{branch}", linkRegistryEntry.Repository, linkRegistryEntry.Branch); + if (newEntry.UpdatedAt > existingBranchEntry.UpdatedAt) + { + existingRepositoryEntry[branch] = newEntry; + logger.LogInformation("Updated existing entry for {repository}@{branch}", repository, branch); + } + else + logger.LogInformation("Skipping update for {repository}@{branch} because the existing entry is newer or equal", repository, branch); } + // branch does not exist in the repository entry else - logger.LogInformation("Skipping update for {repository}@{branch} because the existing entry is newer", linkRegistryEntry.Repository, linkRegistryEntry.Branch); + { + existingRepositoryEntry[branch] = newEntry; + logger.LogInformation("Added new entry '{repository}@{branch}' to existing entry for '{repository}'", repository, branch, repository); + } } + // onboarding new repository else { - _linkIndex.Repositories.Add(linkRegistryEntry.Repository, new Dictionary + _linkIndex.Repositories.Add(repository, new Dictionary { - { linkRegistryEntry.Branch, linkRegistryEntry } + { branch, newEntry } }); - logger.LogInformation("Added new entry for {repository}@{branch}", linkRegistryEntry.Repository, linkRegistryEntry.Branch); + logger.LogInformation("Added new entry for {repository}@{branch}", repository, branch); } } @@ -74,7 +88,13 @@ public async Task Save() ContentType = "application/json", IfMatch = _etag // Only update if the ETag matches. Meaning the object has not been changed in the meantime. }; - _ = await s3Client.PutObjectAsync(putObjectRequest); - logger.LogInformation("Successfully saved link index to s3://{bucketName}/{key}", bucketName, key); + var putResponse = await s3Client.PutObjectAsync(putObjectRequest); + if (putResponse.HttpStatusCode == HttpStatusCode.OK) + logger.LogInformation("Successfully saved link index to s3://{bucketName}/{key}", bucketName, key); + else + { + logger.LogError("Unable to save index to s3://{bucketName}/{key}", bucketName, key); + throw new Exception($"Unable to save index to s3://{bucketName}/{key}"); + } } }