From 12b62c370af436ce54a87c8e9deb2d758e621581 Mon Sep 17 00:00:00 2001 From: Patrick Hallisey Date: Fri, 1 Nov 2024 11:00:54 -0700 Subject: [PATCH 1/2] Update build tags before exporting to kusto --- .../AzurePipelines/BuildCompleteQueueWorker.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/pipeline-witness/Azure.Sdk.Tools.PipelineWitness/AzurePipelines/BuildCompleteQueueWorker.cs b/tools/pipeline-witness/Azure.Sdk.Tools.PipelineWitness/AzurePipelines/BuildCompleteQueueWorker.cs index e1e4a3fe981..3ce7f78b01c 100644 --- a/tools/pipeline-witness/Azure.Sdk.Tools.PipelineWitness/AzurePipelines/BuildCompleteQueueWorker.cs +++ b/tools/pipeline-witness/Azure.Sdk.Tools.PipelineWitness/AzurePipelines/BuildCompleteQueueWorker.cs @@ -62,9 +62,9 @@ internal override async Task ProcessMessageAsync(QueueMessage message, Cancellat return; } - await this.runProcessor.UploadBuildBlobsAsync(queueMessage.Account, queueMessage.ProjectId, queueMessage.BuildId); - await this.runProcessor.AddAdditionalBuildTagsAsync(queueMessage.Account, queueMessage.ProjectId, queueMessage.BuildId); + + await this.runProcessor.UploadBuildBlobsAsync(queueMessage.Account, queueMessage.ProjectId, queueMessage.BuildId); } } } From 2c4c147934b8568fb7c4d51c60ea0397542701f5 Mon Sep 17 00:00:00 2001 From: Patrick Hallisey Date: Fri, 1 Nov 2024 11:10:57 -0700 Subject: [PATCH 2/2] Add error handling to tag code --- .../AzurePipelines/AzurePipelinesProcessor.cs | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/tools/pipeline-witness/Azure.Sdk.Tools.PipelineWitness/AzurePipelines/AzurePipelinesProcessor.cs b/tools/pipeline-witness/Azure.Sdk.Tools.PipelineWitness/AzurePipelines/AzurePipelinesProcessor.cs index 5596e02d8e1..fdd97a06fea 100644 --- a/tools/pipeline-witness/Azure.Sdk.Tools.PipelineWitness/AzurePipelines/AzurePipelinesProcessor.cs +++ b/tools/pipeline-witness/Azure.Sdk.Tools.PipelineWitness/AzurePipelines/AzurePipelinesProcessor.cs @@ -908,14 +908,15 @@ internal async Task AddAdditionalBuildTagsAsync(string account, Guid projectId, const string attachmentType = "AdditionalTags"; + HashSet additionalTags = []; + List attachments = await this.buildClient.GetAttachmentsAsync(projectId, buildId, attachmentType); IEnumerable attachmentLinks = attachments - .Select(x => x.Links.Links["self"]) + .Select(x => x.Links?.Links?.TryGetValue("self", out var value) == true ? value : null) .OfType() - .Select(x => x.Href); - - HashSet additionalTags = []; + .Select(x => x.Href) + .Where(x => !string.IsNullOrEmpty(x)); foreach (string attachmentLink in attachmentLinks) { @@ -925,6 +926,7 @@ internal async Task AddAdditionalBuildTagsAsync(string account, Guid projectId, !Guid.TryParse(match.Groups["timelineId"].Value, out Guid timelineId) || !Guid.TryParse(match.Groups["recordId"].Value, out Guid recordId)) { + // retries won't help here, so we log and continue this.logger.LogWarning("Unable to parse attachment link {AttachmentLink}", attachmentLink); continue; } @@ -941,11 +943,20 @@ internal async Task AddAdditionalBuildTagsAsync(string account, Guid projectId, attachmentType, match.Groups["name"].Value); - using StreamReader reader = new StreamReader(contentStream); - - string[] tags = JsonConvert.DeserializeObject(reader.ReadToEnd()); + using StreamReader reader = new (contentStream); + var content = reader.ReadToEnd(); - additionalTags.UnionWith(tags); + try + { + string[] tags = JsonConvert.DeserializeObject(content); + additionalTags.UnionWith(tags); + } + catch(Exception ex) + { + // retries won't help here, so we log and continue + this.logger.LogError(ex, "Error parsing AdditionalTags attachment {TimelineId}/{RecordId}/{Name} for build {BuildId}", timelineId, recordId, name, buildId); + continue; + } } if (additionalTags.Count != 0)