From a528d4331d8424c157fb6781548ee281b8821d72 Mon Sep 17 00:00:00 2001 From: Matt Galbraith Date: Thu, 16 Dec 2021 16:53:54 -0800 Subject: [PATCH] [WIP] Trying out the AzDO pipeline warnings by setting the warning window to the next 2,100, not 21, days. --- .../JobSender/JobDefinition.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Microsoft.DotNet.Helix/JobSender/JobDefinition.cs b/src/Microsoft.DotNet.Helix/JobSender/JobDefinition.cs index 078cff49c71..4cfc8e1d385 100644 --- a/src/Microsoft.DotNet.Helix/JobSender/JobDefinition.cs +++ b/src/Microsoft.DotNet.Helix/JobSender/JobDefinition.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Collections.ObjectModel; +using System.Globalization; using System.IO; using System.Linq; using System.Text.RegularExpressions; @@ -158,6 +159,7 @@ public async Task SendAsync(Action log, CancellationToken canc try { QueueInfo queueInfo = await HelixApi.Information.QueueInfoAsync(queueId, false, cancellationToken); + WarnForImpendingRemoval(log, queueInfo); } // 404 = this queue does not exist, or did and was removed. catch (RestApiException ex) when (ex.Response?.Status == 404) @@ -234,6 +236,36 @@ public async Task SendAsync(Action log, CancellationToken canc return new SentJob(JobApi, newJob, newJob.ResultsUri, newJob.ResultsUriRSAS); } + private void WarnForImpendingRemoval(Action log, QueueInfo queueInfo) + { + bool azDoVariableDefined = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SYSTEM_TEAMPROJECT")); + DateTime whenItExpires = DateTime.MaxValue; + + if (DateTime.TryParseExact(queueInfo.EstimatedRemovalDate, "yyyy-MM-dd", null, DateTimeStyles.AssumeUniversal, out DateTime dtIso)) + { + whenItExpires = dtIso; + } + // This branch can be removed once the strings start coming in in ISO-8601 format + // Currently the API provides values in this format though and they are unlikely to get confused with each other. + else if (DateTime.TryParseExact(queueInfo.EstimatedRemovalDate, "M/d/yyyy", null, DateTimeStyles.AssumeUniversal, out DateTime dtUsa)) + { + whenItExpires = dtUsa; + } + + if (whenItExpires != DateTime.MaxValue) // We recognized a date from the string + { + TimeSpan untilRemoved = whenItExpires.ToUniversalTime().Subtract(DateTime.UtcNow); + if (untilRemoved.TotalDays <= 2100) // This will be 21, it's set to 21 to demonstrate the warnings in a pipeline for a do-not-merge draft PR + { + Console.WriteLine($"{(azDoVariableDefined ? "##vso[task.logissue type=warning]" : "")}Helix queue {queueInfo.QueueId} {(untilRemoved.TotalDays < 0 ? "was" : "is")} slated for removal on {queueInfo.EstimatedRemovalDate}. Please discontinue usage. Contact dnceng for questions / concerns "); + } + } + else + { + Console.WriteLine($"{(azDoVariableDefined ? "##vso[task.logissue type=warning]" : "")}Unable to parse estimated removal date '{queueInfo.EstimatedRemovalDate}' for queue '{queueInfo.QueueId}' (please contact dnceng with this information)"); + } + } + private (string queueId, string dockerTag, string queueAlias) ParseQueueId(string value) { var @index = value.IndexOf('@');