Skip to content

Commit

Permalink
feat(go): break down telemetry on go cli command failures (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
annaowens committed Aug 22, 2023
1 parent ff6fd1a commit a200c1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Microsoft.ComponentDetection.Common.Telemetry.Records;
namespace Microsoft.ComponentDetection.Common.Telemetry.Records;

public class GoGraphTelemetryRecord : BaseDetectionTelemetryRecord
{
Expand All @@ -12,7 +12,9 @@ public class GoGraphTelemetryRecord : BaseDetectionTelemetryRecord

public bool WasGoCliDisabled { get; set; }

public bool WasGoCliNotFound { get; set; }

public bool WasGoFallbackStrategyUsed { get; set; }

public bool DidGoCliCommandFail { get; set; }

public string GoCliCommandError { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Microsoft.ComponentDetection.Detectors.Go;
namespace Microsoft.ComponentDetection.Detectors.Go;

using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -53,16 +53,17 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID
{
var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder;
var file = processRequest.ComponentStream;
using var record = new GoGraphTelemetryRecord();
record.WasGoCliDisabled = false;
record.WasGoFallbackStrategyUsed = false;

var projectRootDirectory = Directory.GetParent(file.Location);
if (this.projectRoots.Any(path => projectRootDirectory.FullName.StartsWith(path)))
{
return;
}

using var record = new GoGraphTelemetryRecord();
record.WasGoCliDisabled = false;
record.WasGoFallbackStrategyUsed = false;

var wasGoCliScanSuccessful = false;
try
{
Expand Down Expand Up @@ -120,7 +121,7 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID
private async Task<bool> UseGoCliToScanAsync(string location, ISingleFileComponentRecorder singleFileComponentRecorder, GoGraphTelemetryRecord record)
{
record.WasGraphSuccessful = false;
record.WasGoCliNotFound = false;
record.DidGoCliCommandFail = false;
var projectRootDirectory = Directory.GetParent(location);
record.ProjectRoot = projectRootDirectory.FullName;

Expand All @@ -130,7 +131,6 @@ private async Task<bool> UseGoCliToScanAsync(string location, ISingleFileCompone
if (!isGoAvailable)
{
this.Logger.LogInformation("Go CLI was not found in the system");
record.WasGoCliNotFound = true;
return false;
}

Expand All @@ -142,6 +142,8 @@ private async Task<bool> UseGoCliToScanAsync(string location, ISingleFileCompone
{
this.Logger.LogError("Go CLI command \"go list -m -json all\" failed with error: {GoDependenciesProcessStdErr}", goDependenciesProcess.StdErr);
this.Logger.LogError("Go CLI could not get dependency build list at location: {Location}. Fallback go.sum/go.mod parsing will be used.", location);
record.DidGoCliCommandFail = true;
record.GoCliCommandError = goDependenciesProcess.StdErr;
return false;
}

Expand Down

0 comments on commit a200c1e

Please sign in to comment.