From 2ad8f27a2410f3326087a0d072ba76bc2508d623 Mon Sep 17 00:00:00 2001 From: Anna Owens Date: Thu, 10 Aug 2023 15:20:27 -0700 Subject: [PATCH] extend GoGraph telemetry object --- .../Telemetry/Records/GoGraphTelemetryRecord.cs | 8 +++++++- .../go/GoComponentDetector.cs | 15 ++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/GoGraphTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/GoGraphTelemetryRecord.cs index aea328541..c0b1dd8d1 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 { @@ -9,4 +9,10 @@ public class GoGraphTelemetryRecord : BaseDetectionTelemetryRecord public bool IsGoAvailable { get; set; } public bool WasGraphSuccessful { get; set; } + + public bool WasGoCliDisabled { get; set; } + + public bool WasGoCliNotFound { get; set; } + + public bool WasGoFallbackStrategyUsed { get; set; } } diff --git a/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs index 5b4a5faf7..c708c4053 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,6 +53,9 @@ 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))) @@ -65,10 +68,11 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID { if (!this.IsGoCliManuallyDisabled()) { - wasGoCliScanSuccessful = await this.UseGoCliToScanAsync(file.Location, singleFileComponentRecorder); + wasGoCliScanSuccessful = await this.UseGoCliToScanAsync(file.Location, singleFileComponentRecorder, record); } else { + record.WasGoCliDisabled = true; this.Logger.LogInformation("Go cli scan was manually disabled, fallback strategy performed." + " More info: https://github.com/microsoft/component-detection/blob/main/docs/detectors/go.md#fallback-detection-strategy"); } @@ -85,6 +89,7 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID } else { + record.WasGoFallbackStrategyUsed = true; var fileExtension = Path.GetExtension(file.Location).ToUpperInvariant(); switch (fileExtension) { @@ -112,11 +117,10 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID } [SuppressMessage("Maintainability", "CA1508:Avoid dead conditional code", Justification = "False positive")] - private async Task UseGoCliToScanAsync(string location, ISingleFileComponentRecorder singleFileComponentRecorder) + private async Task UseGoCliToScanAsync(string location, ISingleFileComponentRecorder singleFileComponentRecorder, GoGraphTelemetryRecord record) { - using var record = new GoGraphTelemetryRecord(); record.WasGraphSuccessful = false; - + record.WasGoCliNotFound = false; var projectRootDirectory = Directory.GetParent(location); record.ProjectRoot = projectRootDirectory.FullName; @@ -126,6 +130,7 @@ 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; }