Skip to content

Commit

Permalink
Merge pull request #855 from DeveloperMetrics/FixToProjectBug
Browse files Browse the repository at this point in the history
Fix to project bug
  • Loading branch information
samsmithnz authored May 26, 2023
2 parents e47d832 + 4ffc3bb commit 186f2d8
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 106 deletions.
8 changes: 8 additions & 0 deletions src/DevOpsMetrics.Core/Models/Common/DORASummaryItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public string Repo
{
get; set;
}
public int NumberOfDays
{
get; set;
}
public float DeploymentFrequency
{
get; set;
Expand Down Expand Up @@ -58,5 +62,9 @@ public string ChangeFailureRateBadgeWithMetricURL
{
get; set;
}
public string ProcessingLogMessage
{
get; set;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.3" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
53 changes: 48 additions & 5 deletions src/DevOpsMetrics.Service/Controllers/DORASummaryController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using DevOpsMetrics.Core;
using DevOpsMetrics.Core.DataAccess;
Expand Down Expand Up @@ -55,6 +56,8 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
bool useCache = true,
bool isGitHub = true)
{
//Start timer
DateTime startTime = DateTime.Now;
AzureTableStorageDA azureTableStorageDA = new();
TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);
string clientId = null;
Expand Down Expand Up @@ -82,6 +85,10 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
}

ProcessingResult result = new();
DeploymentFrequencyModel deploymentFrequencyModel = new();
LeadTimeForChangesModel leadTimeForChangesModel = new();
MeanTimeToRestoreModel meanTimeToRestoreModel = new();
ChangeFailureRateModel changeFailureRateModel = new();
try
{
string message = "";
Expand Down Expand Up @@ -130,8 +137,6 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(

//Process summary results for last 90 days, creating badges for the four metrics
//Get the DORA metrics for the last 90 days
DeploymentFrequencyModel deploymentFrequencyModel = new();
LeadTimeForChangesModel leadTimeForChangesModel = new();
if (isGitHub == true)
{
deploymentFrequencyModel = await DeploymentFrequencyDA.GetGitHubDeploymentFrequency(false, clientId, clientSecret, tableStorageConfig,
Expand All @@ -152,7 +157,6 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
owner, project, repo, branch, workflowName,
numberOfDays, maxNumberOfItems, useCache);
}
MeanTimeToRestoreModel meanTimeToRestoreModel = new();
if (resourceGroup != null)
{
meanTimeToRestoreModel = MeanTimeToRestoreDA.GetAzureMeanTimeToRestore(false, tableStorageConfig,
Expand All @@ -166,16 +170,20 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
meanTimeToRestoreModel.MTTRAverageDurationDescription = MeanTimeToRestore.GetMeanTimeToRestoreRating(0);
}

ChangeFailureRateModel changeFailureRateModel = ChangeFailureRateDA.GetChangeFailureRate(false, tableStorageConfig,
changeFailureRateModel = ChangeFailureRateDA.GetChangeFailureRate(false, tableStorageConfig,
DevOpsPlatform.GitHub,
owner, repo, branch, workflowName,
numberOfDays, maxNumberOfItems);

//Get the total time since startTime
string processingLogMessage = $"Processed summary for {owner}, repo {repo} in {(DateTime.Now - startTime).TotalSeconds} seconds";

//Summarize the results into a new object
DORASummaryItem DORASummary = new()
{
Owner = owner,
Repo = repo,
NumberOfDays = numberOfDays,
DeploymentFrequency = deploymentFrequencyModel.DeploymentsPerDayMetric,
DeploymentFrequencyBadgeURL = deploymentFrequencyModel.BadgeURL,
DeploymentFrequencyBadgeWithMetricURL = deploymentFrequencyModel.BadgeWithMetricURL,
Expand All @@ -187,7 +195,8 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
MeanTimeToRestoreBadgeWithMetricURL = meanTimeToRestoreModel.BadgeWithMetricURL,
ChangeFailureRate = changeFailureRateModel.ChangeFailureRateMetric,
ChangeFailureRateBadgeURL = changeFailureRateModel.BadgeURL,
ChangeFailureRateBadgeWithMetricURL = changeFailureRateModel.BadgeWithMetricURL
ChangeFailureRateBadgeWithMetricURL = changeFailureRateModel.BadgeWithMetricURL,
ProcessingLogMessage = processingLogMessage
};

//Serialize the summary into an Azure storage table
Expand Down Expand Up @@ -244,6 +253,40 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
owner + "_" + project + "_" + repo + "_" + branch + "_" + numberOfDays + "_" + maxNumberOfItems,
ex.ToString(), error);
}
//Update the DORA object with the error message
try
{
//Get the total time since startTime
string processingLogMessage = $"Error processing summary for {owner}, repo {repo} in {(DateTime.Now - startTime).TotalSeconds} seconds";

//Summarize the results into a new object
DORASummaryItem DORASummary = new()
{
Owner = owner,
Repo = repo,
NumberOfDays = numberOfDays,
DeploymentFrequency = deploymentFrequencyModel.DeploymentsPerDayMetric,
DeploymentFrequencyBadgeURL = deploymentFrequencyModel.BadgeURL,
DeploymentFrequencyBadgeWithMetricURL = deploymentFrequencyModel.BadgeWithMetricURL,
LeadTimeForChanges = leadTimeForChangesModel.LeadTimeForChangesMetric,
LeadTimeForChangesBadgeURL = leadTimeForChangesModel.BadgeURL,
LeadTimeForChangesBadgeWithMetricURL = leadTimeForChangesModel.BadgeWithMetricURL,
MeanTimeToRestore = meanTimeToRestoreModel.MTTRAverageDurationInHours,
MeanTimeToRestoreBadgeURL = meanTimeToRestoreModel.BadgeURL,
MeanTimeToRestoreBadgeWithMetricURL = meanTimeToRestoreModel.BadgeWithMetricURL,
ChangeFailureRate = changeFailureRateModel.ChangeFailureRateMetric,
ChangeFailureRateBadgeURL = changeFailureRateModel.BadgeURL,
ChangeFailureRateBadgeWithMetricURL = changeFailureRateModel.BadgeWithMetricURL,
ProcessingLogMessage = processingLogMessage
};
//Serialize the summary into an Azure storage table
await AzureTableStorageDA.UpdateDORASummaryItem(tableStorageConfig, owner, project, repo, DORASummary);
}
catch
{
//Do nothing, we handled the error above
}

if (projectLog != null)
{
await azureTableStorageDA.UpdateProjectLogInStorage(tableStorageConfig, projectLog);
Expand Down
4 changes: 2 additions & 2 deletions src/DevOpsMetrics.Tests/DevOpsMetrics.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.3" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
110 changes: 56 additions & 54 deletions src/DevOpsMetrics.Tests/Service/DORASummaryControllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using DevOpsMetrics.Core.DataAccess.TableStorage;
using DevOpsMetrics.Core.Models.AzureDevOps;
using DevOpsMetrics.Core.Models.Common;
using DevOpsMetrics.Core.Models.GitHub;
using DevOpsMetrics.Service.Controllers;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand Down Expand Up @@ -107,59 +112,56 @@ public async Task DORASummaryControllerAzureDevOpsUpdateIntegrationTest()
Assert.IsNotNull(model);
}

//[TestMethod]
//public async Task DORASummaryControllerUpdateALLIntegrationTest()
//{
// //Arrange
// int numberOfDays = 30;
// int maxNumberOfItems = 20;
// int totalResults = 0;
// DORASummaryController controller = new(base.Configuration);
// SettingsController settingsController = new(base.Configuration, new AzureTableStorageDA());

// //Act
// List<AzureDevOpsSettings> azSettings = settingsController.GetAzureDevOpsSettings();
// List<GitHubSettings> ghSettings = settingsController.GetGitHubSettings();

// foreach (AzureDevOpsSettings item in azSettings)
// {
// // (int, string) buildsUpdated = (0, null);
// // (int, string) prsUpdated = (0, null);
// // try
// // {
// //log.LogInformation($"Processing Azure DevOps organization {item.Organization}, project {item.Project}");
// // buildsUpdated = await api.UpdateAzureDevOpsBuilds(item.Organization, item.Project, item.Repository, item.Branch, item.BuildName, item.BuildId, numberOfDays, maxNumberOfItems);
// // prsUpdated = await api.UpdateAzureDevOpsPullRequests(item.Organization, item.Project, item.Repository, numberOfDays, maxNumberOfItems);
// // log.LogInformation($"Processed Azure DevOps organization {item.Organization}, project {item.Project}. {buildsUpdated.Item1} builds and {prsUpdated.Item1} prs/commits updated");
// // totalResults += buildsUpdated.Item1 + prsUpdated.Item1;
// // await api.UpdateAzureDevOpsProjectLog(item.Organization, item.Project, item.Repository, buildsUpdated.Item1, prsUpdated.Item1, buildsUpdated.Item2, prsUpdated.Item2, null, null);
// // }
// // catch (Exception ex)
// // {
// // string error = $"Exception while processing Azure DevOps organization {item.Organization}, project {item.Project}. {buildsUpdated.Item1} builds and {prsUpdated.Item1} prs/commits updated";
// // log.LogInformation(error);
// // await api.UpdateAzureDevOpsProjectLog(item.Organization, item.Project, item.Repository, buildsUpdated.Item1, prsUpdated.Item1, buildsUpdated.Item2, prsUpdated.Item2, ex.Message, error);
// // }
// }

// foreach (GitHubSettings ghSetting in ghSettings)
// {
// Debug.WriteLine($"Owner {ghSetting.Owner}, Repo {ghSetting.Repo}");
// ProcessingResult ghResult = await controller.UpdateDORASummaryItem(
// ghSetting.Owner, ghSetting.Repo, ghSetting.Branch,
// ghSetting.WorkflowName, ghSetting.WorkflowId,
// ghSetting.ProductionResourceGroup,
// numberOfDays, maxNumberOfItems);
// totalResults += ghResult.TotalResults;
// Assert.IsNotNull(ghResult);
// }

// //ProcessingResult model = await controller.UpdateDORASummaryItem(organization, repository,
// // branch, workflowName, workflowId, resourceGroup, numberOfDays, maxNumberOfItems);

// //Assert
// Assert.IsTrue(totalResults > 0);
//}
[TestMethod]
public async Task DORASummaryControllerUpdateALLIntegrationTest()
{
//Arrange
int numberOfDays = 30;
int maxNumberOfItems = 20;
int totalResults = 0;
DORASummaryController controller = new(base.Configuration);
SettingsController settingsController = new(base.Configuration, new AzureTableStorageDA());
bool runExpensiveTest = false;

//Act
if (runExpensiveTest)
{
List<AzureDevOpsSettings> azSettings = settingsController.GetAzureDevOpsSettings();
List<GitHubSettings> ghSettings = settingsController.GetGitHubSettings();

foreach (AzureDevOpsSettings azSetting in azSettings)
{
Debug.WriteLine($"Processing Azure DevOps organization {azSetting.Organization}, project {azSetting.Project}");
ProcessingResult ghResult = await controller.UpdateDORASummaryItem(
azSetting.Organization, azSetting.Project, azSetting.Repository,
azSetting.Branch, azSetting.BuildName, azSetting.BuildId,
azSetting.ProductionResourceGroup,
numberOfDays, maxNumberOfItems, null, true, false);
totalResults += ghResult.TotalResults;
}

foreach (GitHubSettings ghSetting in ghSettings)
{
Debug.WriteLine($"Processing GitHub owner {ghSetting.Owner}, repo {ghSetting.Repo}");
ProcessingResult ghResult = await controller.UpdateDORASummaryItem(
ghSetting.Owner, "", ghSetting.Repo, ghSetting.Branch,
ghSetting.WorkflowName, ghSetting.WorkflowId,
ghSetting.ProductionResourceGroup,
numberOfDays, maxNumberOfItems, null, true, true);
totalResults += ghResult.TotalResults;
}
}

//Assert
if (runExpensiveTest)
{
Assert.IsTrue(totalResults > 0);
}
else
{
Assert.IsTrue(totalResults == 0);
}
}

}
}
Loading

0 comments on commit 186f2d8

Please sign in to comment.