Skip to content

Commit

Permalink
Merge pull request #869 from DeveloperMetrics/ChasingNullErrors
Browse files Browse the repository at this point in the history
Fixing null errors
  • Loading branch information
samsmithnz authored Jun 4, 2023
2 parents d794906 + b9794a0 commit 2526067
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 48 deletions.
10 changes: 8 additions & 2 deletions src/DevOpsMetrics.Core/Models/Common/DORASummaryItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace DevOpsMetrics.Core.Models.Common
using System;

namespace DevOpsMetrics.Core.Models.Common
{
public class DORASummaryItem
{
Expand Down Expand Up @@ -62,7 +64,11 @@ public string ChangeFailureRateBadgeWithMetricURL
{
get; set;
}
public string ProcessingLogMessage
public string LastUpdatedMessage
{
get; set;
}
public DateTime LastUpdated
{
get; set;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.4" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Selenium.WebDriver" Version="4.9.1" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="113.0.5672.6300" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="114.0.5735.9000" />
</ItemGroup>

<ItemGroup>
Expand Down
28 changes: 21 additions & 7 deletions src/DevOpsMetrics.Service/Controllers/DORASummaryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
string clientId = null;
string clientSecret = null;
string patToken = null;
//Instead of throwing exceptions when there are no secrets, add the error message to the overall processing message
string errorMessage = null;
if (isGitHub == true)
{ //Get the client id and secret from the settings
string clientIdName = PartitionKeys.CreateGitHubSettingsPartitionKeyClientId(owner, repo);
Expand All @@ -73,7 +75,7 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
clientSecret = Configuration[clientSecretName];
if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(clientSecret))
{
throw new Exception($"clientId '{clientId}' or clientSecret '{clientSecret}' not found in key vault");
errorMessage = $"clientId '{clientId}' or clientSecret '{clientSecret}' not found in key vault";
}
}
else
Expand All @@ -82,7 +84,7 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
patToken = Configuration[patTokenName];
if (string.IsNullOrEmpty(patToken))
{
throw new Exception($"patToken '{patTokenName}' not found in key vault");
errorMessage = $"patToken '{patTokenName}' not found in key vault";
}
}

Expand All @@ -105,10 +107,12 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
//TODO: fix this - should be using a common interface, not this null hack
if (log == null)
{
Console.WriteLine(errorMessage);
Console.WriteLine(message);
}
else
{
log.LogInformation(errorMessage);
log.LogInformation(message);
}
if (useParallelProcessing)
Expand Down Expand Up @@ -177,6 +181,8 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
Task<LeadTimeForChangesModel> leadTimeForChangesTask;
Task<MeanTimeToRestoreModel> meanTimeToRestoreTask;
Task<ChangeFailureRateModel> changeFailureRateTask;

//Get the deployment frequency and lead time for changes in parallel
if (isGitHub == true)
{
deploymentFrequencyTask = DeploymentFrequencyDA.GetGitHubDeploymentFrequency(false, clientId, clientSecret, tableStorageConfig,
Expand All @@ -197,6 +203,7 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
owner, project, repo, branch, workflowName,
numberOfDays, maxNumberOfItems, useCache);
}
//Get the mean time to restore and change failure rate in parallel
if (resourceGroup != null)
{
meanTimeToRestoreTask = MeanTimeToRestoreDA.GetAzureMeanTimeToRestore(false, tableStorageConfig,
Expand All @@ -210,12 +217,12 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
meanTimeToRestoreModel.MTTRAverageDurationInHours = 0;
meanTimeToRestoreModel.MTTRAverageDurationDescription = MeanTimeToRestore.GetMeanTimeToRestoreRating(0);
}

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

//Process the tasks in parallel
if (meanTimeToRestoreTask != null)
{
await Task.WhenAll(deploymentFrequencyTask, leadTimeForChangesTask, meanTimeToRestoreTask, changeFailureRateTask);
Expand All @@ -236,6 +243,7 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
{
if (isGitHub == true)
{
//Get the deployment frequency and lead time for changes
deploymentFrequencyModel = await DeploymentFrequencyDA.GetGitHubDeploymentFrequency(false, clientId, clientSecret, tableStorageConfig,
owner, repo, branch, workflowName, workflowId,
numberOfDays, maxNumberOfItems, useCache);
Expand All @@ -254,6 +262,7 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
owner, project, repo, branch, workflowName,
numberOfDays, maxNumberOfItems, useCache);
}
//Get the mean time to restore and change failure rate
if (resourceGroup != null)
{
meanTimeToRestoreModel = await MeanTimeToRestoreDA.GetAzureMeanTimeToRestore(false, tableStorageConfig,
Expand All @@ -266,7 +275,6 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
meanTimeToRestoreModel.MTTRAverageDurationInHours = 0;
meanTimeToRestoreModel.MTTRAverageDurationDescription = MeanTimeToRestore.GetMeanTimeToRestoreRating(0);
}

changeFailureRateModel = await ChangeFailureRateDA.GetChangeFailureRate(false, tableStorageConfig,
DevOpsPlatform.GitHub,
owner, repo, branch, workflowName,
Expand All @@ -275,6 +283,10 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(

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

//Summarize the results into a new object
DORASummaryItem DORASummary = new()
Expand All @@ -294,7 +306,8 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
ChangeFailureRate = changeFailureRateModel.ChangeFailureRateMetric,
ChangeFailureRateBadgeURL = changeFailureRateModel.BadgeURL,
ChangeFailureRateBadgeWithMetricURL = changeFailureRateModel.BadgeWithMetricURL,
ProcessingLogMessage = processingLogMessage
LastUpdatedMessage = processingLogMessage,
LastUpdated = DateTime.Now
};

//Serialize the summary into an Azure storage table
Expand Down Expand Up @@ -323,7 +336,7 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
}
catch (Exception ex)
{
string error = $"Exception while processing GitHub owner {owner}, repo {repo}. {result.BuildsUpdated} builds and {result.PRsUpdated} prs/commits updated";
string error = $"Exception while processing GitHub owner {owner}, repo {repo}. {result.BuildsUpdated} builds and {result.PRsUpdated} prs/commits updated " + ex.ToString();
if (log == null)
{
Console.WriteLine(error);
Expand Down Expand Up @@ -375,7 +388,8 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
ChangeFailureRate = changeFailureRateModel.ChangeFailureRateMetric,
ChangeFailureRateBadgeURL = changeFailureRateModel.BadgeURL,
ChangeFailureRateBadgeWithMetricURL = changeFailureRateModel.BadgeWithMetricURL,
ProcessingLogMessage = processingLogMessage
LastUpdatedMessage = processingLogMessage,
LastUpdated = DateTime.Now
};
//Serialize the summary into an Azure storage table
await AzureTableStorageDA.UpdateDORASummaryItem(tableStorageConfig, owner, project, repo, DORASummary);
Expand Down
6 changes: 3 additions & 3 deletions src/DevOpsMetrics.Tests/DevOpsMetrics.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.24" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.1" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.3" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.4" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Loading

0 comments on commit 2526067

Please sign in to comment.