From a200c1ea536f8c037e21bbcee3de8ecb10a33698 Mon Sep 17 00:00:00 2001 From: Anna Owens <35906111+annaowens@users.noreply.github.com> Date: Tue, 22 Aug 2023 12:44:55 -0700 Subject: [PATCH] feat(go): break down telemetry on go cli command failures (#734) --- .../Telemetry/Records/GoGraphTelemetryRecord.cs | 8 +++++--- .../go/GoComponentDetector.cs | 14 ++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/GoGraphTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/GoGraphTelemetryRecord.cs index c0b1dd8d1..db4d4a87d 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/GoGraphTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/GoGraphTelemetryRecord.cs @@ -1,4 +1,4 @@ -namespace Microsoft.ComponentDetection.Common.Telemetry.Records; +namespace Microsoft.ComponentDetection.Common.Telemetry.Records; public class GoGraphTelemetryRecord : BaseDetectionTelemetryRecord { @@ -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; } } diff --git a/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs index c708c4053..4bc74bc8f 100644 --- a/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs @@ -1,4 +1,4 @@ -namespace Microsoft.ComponentDetection.Detectors.Go; +namespace Microsoft.ComponentDetection.Detectors.Go; using System; using System.Collections.Generic; @@ -53,9 +53,6 @@ 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))) @@ -63,6 +60,10 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID return; } + using var record = new GoGraphTelemetryRecord(); + record.WasGoCliDisabled = false; + record.WasGoFallbackStrategyUsed = false; + var wasGoCliScanSuccessful = false; try { @@ -120,7 +121,7 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID private async Task 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; @@ -130,7 +131,6 @@ private async Task UseGoCliToScanAsync(string location, ISingleFileCompone if (!isGoAvailable) { this.Logger.LogInformation("Go CLI was not found in the system"); - record.WasGoCliNotFound = true; return false; } @@ -142,6 +142,8 @@ private async Task 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; }