From 0aa42a7100e98d34634d615a83b8578f4423de3e Mon Sep 17 00:00:00 2001 From: missymessa Date: Mon, 16 Dec 2024 09:33:43 -0800 Subject: [PATCH 1/2] Remove RolloutScorer Azure Function from solution --- dnceng.sln | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/dnceng.sln b/dnceng.sln index ce752938..11e09857 100644 --- a/dnceng.sln +++ b/dnceng.sln @@ -55,8 +55,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RolloutScorer", "src\Rollou EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RolloutScorer.Tests", "src\RolloutScorer\RolloutScorer.Tests\RolloutScorer.Tests.csproj", "{A45374B1-53B4-4799-B2BF-A04F28347AF1}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RolloutScorerAzureFunction", "src\RolloutScorer\RolloutScorerAzureFunction\RolloutScorerAzureFunction.csproj", "{AC6F874D-9DA8-409C-B054-4DE1044C718D}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Monitoring", "Monitoring", "{4614FF66-8594-4D7E-BEF8-31611B6087C5}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Monitoring.Sdk", "src\Monitoring\Sdk\Microsoft.DotNet.Monitoring.Sdk.csproj", "{BC62FD8B-FC12-434F-9958-4EA0A52D60B2}" @@ -211,14 +209,6 @@ Global {A45374B1-53B4-4799-B2BF-A04F28347AF1}.Release|Any CPU.Build.0 = Release|Any CPU {A45374B1-53B4-4799-B2BF-A04F28347AF1}.Release|x64.ActiveCfg = Release|Any CPU {A45374B1-53B4-4799-B2BF-A04F28347AF1}.Release|x64.Build.0 = Release|Any CPU - {AC6F874D-9DA8-409C-B054-4DE1044C718D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AC6F874D-9DA8-409C-B054-4DE1044C718D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AC6F874D-9DA8-409C-B054-4DE1044C718D}.Debug|x64.ActiveCfg = Debug|Any CPU - {AC6F874D-9DA8-409C-B054-4DE1044C718D}.Debug|x64.Build.0 = Debug|Any CPU - {AC6F874D-9DA8-409C-B054-4DE1044C718D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AC6F874D-9DA8-409C-B054-4DE1044C718D}.Release|Any CPU.Build.0 = Release|Any CPU - {AC6F874D-9DA8-409C-B054-4DE1044C718D}.Release|x64.ActiveCfg = Release|Any CPU - {AC6F874D-9DA8-409C-B054-4DE1044C718D}.Release|x64.Build.0 = Release|Any CPU {BC62FD8B-FC12-434F-9958-4EA0A52D60B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {BC62FD8B-FC12-434F-9958-4EA0A52D60B2}.Debug|Any CPU.Build.0 = Debug|Any CPU {BC62FD8B-FC12-434F-9958-4EA0A52D60B2}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -255,7 +245,6 @@ Global {2DBCBD85-13B6-41DD-A00F-C40116C46B61} = {EC7A0A22-5BCD-4B94-8E17-510A54E42ED1} {6C694352-8990-4A5A-A890-9539FFDFEEB8} = {C77B1797-82F6-4AA9-A5EA-F466C4032067} {A45374B1-53B4-4799-B2BF-A04F28347AF1} = {C77B1797-82F6-4AA9-A5EA-F466C4032067} - {AC6F874D-9DA8-409C-B054-4DE1044C718D} = {C77B1797-82F6-4AA9-A5EA-F466C4032067} {BC62FD8B-FC12-434F-9958-4EA0A52D60B2} = {4614FF66-8594-4D7E-BEF8-31611B6087C5} {02046914-EAB2-4128-BD3E-06C8730B9D9F} = {4614FF66-8594-4D7E-BEF8-31611B6087C5} EndGlobalSection From 43b27ee136ff48585efc3359b80d071637bcd42f Mon Sep 17 00:00:00 2001 From: missymessa Date: Mon, 16 Dec 2024 14:21:14 -0800 Subject: [PATCH 2/2] Attempt to delete again --- .../RolloutScorerAzureFunction.csproj | 27 ---- .../RolloutScorerFunction.cs | 141 ------------------ .../RolloutScorerAzureFunction/host.json | 3 - .../local.settings.json | 7 - 4 files changed, 178 deletions(-) delete mode 100644 src/RolloutScorer/RolloutScorerAzureFunction/RolloutScorerAzureFunction.csproj delete mode 100644 src/RolloutScorer/RolloutScorerAzureFunction/RolloutScorerFunction.cs delete mode 100644 src/RolloutScorer/RolloutScorerAzureFunction/host.json delete mode 100644 src/RolloutScorer/RolloutScorerAzureFunction/local.settings.json diff --git a/src/RolloutScorer/RolloutScorerAzureFunction/RolloutScorerAzureFunction.csproj b/src/RolloutScorer/RolloutScorerAzureFunction/RolloutScorerAzureFunction.csproj deleted file mode 100644 index a9e151ec..00000000 --- a/src/RolloutScorer/RolloutScorerAzureFunction/RolloutScorerAzureFunction.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - v4 - 40 - false - 2.0 - - - - - - - - - - - - - - PreserveNewest - - - PreserveNewest - Never - - - diff --git a/src/RolloutScorer/RolloutScorerAzureFunction/RolloutScorerFunction.cs b/src/RolloutScorer/RolloutScorerAzureFunction/RolloutScorerFunction.cs deleted file mode 100644 index 2ebbbe17..00000000 --- a/src/RolloutScorer/RolloutScorerAzureFunction/RolloutScorerFunction.cs +++ /dev/null @@ -1,141 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Azure; -using Azure.Data.Tables; -using Azure.Identity; -using Azure.Security.KeyVault.Secrets; -using Microsoft.Azure.WebJobs; -using Microsoft.Extensions.Logging; -using RolloutScorer; -using RolloutScorer.Models; - -namespace RolloutScorerAzureFunction; - -public static class RolloutScorerFunction -{ - private const int ScoringBufferInDays = 2; - - [FunctionName("RolloutScorerFunction")] - public static async Task Run([TimerTrigger("0 0 0 * * *")]TimerInfo myTimer, ILogger log) - { - DefaultAzureCredential tokenProvider = new(); - - string deploymentEnvironment = Environment.GetEnvironmentVariable("DeploymentEnvironment") ?? "Staging"; - log.LogInformation($"INFO: Deployment Environment: {deploymentEnvironment}"); - - log.LogInformation("INFO: Getting scorecard storage account key and deployment table's SAS URI from KeyVault..."); - SecretClient engKeyVaultClient = new(new Uri(Utilities.KeyVaultUri), tokenProvider); - - log.LogInformation("INFO: Getting cloud tables..."); - TableClient scorecardsTable = Utilities.GetTableClient(ScorecardsStorageAccount.Name, ScorecardsStorageAccount.ScorecardsTableName); - TableClient deploymentsTable = Utilities.GetTableClient(DeploymentsStorageAccount.Name, DeploymentsStorageAccount.DeploymentsTableName); - - List scorecardEntries = (await GetAllTableEntriesAsync(scorecardsTable)) - .OrderBy(s => DateTimeOffset.ParseExact(s.PartitionKey, "yyyy-MM-dd", null)).ToList(); - List deploymentEntries = - await GetAllTableEntriesAsync(deploymentsTable); - deploymentEntries.Sort((x, y) => (x.Ended ?? DateTimeOffset.MaxValue).CompareTo(y.Ended ?? DateTimeOffset.MaxValue)); - log.LogInformation($"INFO: Found {scorecardEntries?.Count ?? -1} scorecard table entries and {deploymentEntries?.Count ?? -1} deployment table entries." + - $"(-1 indicates that null was returned.)"); - - // The deployments we care about are ones that occurred after the last scorecard - IEnumerable relevantDeployments = deploymentEntries.Where(d => - (d.Ended ?? DateTimeOffset.MaxValue) > scorecardEntries.Last().Timestamp?.AddDays(ScoringBufferInDays)); - log.LogInformation($"INFO: Found {relevantDeployments?.Count() ?? -1} relevant deployments (deployments which occurred " + - $"after the last scorecard). (-1 indicates that null was returned.)"); - - if (relevantDeployments.Count() > 0) - { - log.LogInformation($"INFO: Checking to see if the most recent deployment occurred more than {ScoringBufferInDays} days ago..."); - // We have only want to score if the buffer period has elapsed since the last deployment - // Alternatively, if too much time has elapsed since that deployment started, it means there's the BAD BUG and we should just assume this rollout completed - if ((relevantDeployments.Last().Ended ?? DateTimeOffset.MaxValue) < DateTimeOffset.UtcNow - TimeSpan.FromDays(ScoringBufferInDays) - || ((relevantDeployments.Last().Started ?? DateTimeOffset.MaxValue) < DateTimeOffset.UtcNow - TimeSpan.FromDays(ScoringBufferInDays + 1) && relevantDeployments.Last().Ended is null)) - { - var scorecards = new List(); - - log.LogInformation("INFO: Rollouts will be scored. Fetching GitHub PAT..."); - KeyVaultSecret githubPat = await engKeyVaultClient.GetSecretAsync(Utilities.GitHubPatSecretName); - - // We'll score the deployments by service - foreach (var deploymentGroup in relevantDeployments.GroupBy(d => d.PartitionKey)) - { - foreach (var deployment in deploymentGroup) - { - if (deployment.Ended is null) - { - deployment.Ended = DateTimeOffset.UtcNow; - await deploymentsTable.UpdateEntityAsync(deployment,ETag.All, TableUpdateMode.Replace); - } - } - - log.LogInformation($"INFO: Scoring {deploymentGroup?.Count() ?? -1} rollouts for repo '{deploymentGroup.Key}'"); - RolloutScorer.RolloutScorer rolloutScorer = new() - { - Repo = deploymentGroup.Key, - RolloutStartDate = deploymentGroup.First().Started.GetValueOrDefault().Date, - RolloutWeightConfig = StandardConfig.DefaultConfig.RolloutWeightConfig, - GithubConfig = StandardConfig.DefaultConfig.GithubConfig, - Log = log, - }; - log.LogInformation($"INFO: Finding repo config for {rolloutScorer.Repo}..."); - rolloutScorer.RepoConfig = StandardConfig.DefaultConfig.RepoConfigs - .Find(r => r.Repo == rolloutScorer.Repo); - log.LogInformation($"INFO: Repo config: {rolloutScorer.RepoConfig.Repo}"); - log.LogInformation($"INFO: Finding AzDO config for {rolloutScorer.RepoConfig.AzdoInstance}..."); - rolloutScorer.AzdoConfig = StandardConfig.DefaultConfig.AzdoInstanceConfigs - .Find(a => a.Name == rolloutScorer.RepoConfig.AzdoInstance); - - log.LogInformation($"INFO: Fetching AzDO PAT from KeyVault..."); - SecretClient azdoConfigVaultClient = new SecretClient(new Uri(rolloutScorer.AzdoConfig.KeyVaultUri), tokenProvider); - KeyVaultSecret azdoPatSecret = await azdoConfigVaultClient.GetSecretAsync(rolloutScorer.AzdoConfig.PatSecretName); - rolloutScorer.SetupHttpClient(azdoPatSecret.Value); - rolloutScorer.SetupGithubClient(githubPat.Value); - - log.LogInformation($"INFO: Attempting to initialize RolloutScorer..."); - try - { - await rolloutScorer.InitAsync(); - } - catch (ArgumentException e) - { - log.LogError($"ERROR: Error while processing {rolloutScorer.RolloutStartDate} rollout of {rolloutScorer.Repo}."); - log.LogError($"ERROR: {e.Message}"); - continue; - } - - log.LogInformation($"INFO: Creating rollout scorecard..."); - scorecards.Add(await Scorecard.CreateScorecardAsync(rolloutScorer)); - log.LogInformation($"INFO: Successfully created scorecard for {rolloutScorer.RolloutStartDate?.Date} rollout of {rolloutScorer.Repo}."); - } - - log.LogInformation($"INFO: Uploading results for {string.Join(", ", scorecards.Select(s => s.Repo))}"); - await RolloutUploader.UploadResultsAsync(scorecards, Utilities.GetGithubClient(githubPat.Value), StandardConfig.DefaultConfig.GithubConfig, skipPr: deploymentEnvironment != "Production"); - } - else - { - log.LogInformation(relevantDeployments.Last().Ended.HasValue ? $"INFO: Most recent rollout occurred less than two days ago " + - $"({relevantDeployments.Last().PartitionKey} on {relevantDeployments.Last().Ended.Value}); waiting to score." : - $"Most recent rollout ({relevantDeployments.Last().PartitionKey}) is still in progress."); - } - } - else - { - log.LogInformation($"INFO: Found no rollouts which occurred after last recorded rollout " + - $"({(scorecardEntries.Count > 0 ? $"date {scorecardEntries.Last().PartitionKey}" : "no rollouts in table")})"); - } - } - - private static async Task> GetAllTableEntriesAsync(TableClient table) where T : class, ITableEntity, new() - { - List items = new List(); - - await foreach (Page page in table.QueryAsync().AsPages()) - { - items.AddRange(page.Values); - } - return items; - } -} \ No newline at end of file diff --git a/src/RolloutScorer/RolloutScorerAzureFunction/host.json b/src/RolloutScorer/RolloutScorerAzureFunction/host.json deleted file mode 100644 index b9f92c0d..00000000 --- a/src/RolloutScorer/RolloutScorerAzureFunction/host.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "version": "2.0" -} \ No newline at end of file diff --git a/src/RolloutScorer/RolloutScorerAzureFunction/local.settings.json b/src/RolloutScorer/RolloutScorerAzureFunction/local.settings.json deleted file mode 100644 index 4fce9ff3..00000000 --- a/src/RolloutScorer/RolloutScorerAzureFunction/local.settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "IsEncrypted": false, - "Values": { - "AzureWebJobsStorage": "UseDevelopmentStorage=true", - "FUNCTIONS_WORKER_RUNTIME": "dotnet" - } -} \ No newline at end of file