Skip to content

Commit 024f092

Browse files
authored
feat: record telemetry on Go fallback detection strategy (#718)
1 parent 79ef626 commit 024f092

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/Microsoft.ComponentDetection.Common/Telemetry/Records/GoGraphTelemetryRecord.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Microsoft.ComponentDetection.Common.Telemetry.Records;
1+
namespace Microsoft.ComponentDetection.Common.Telemetry.Records;
22

33
public class GoGraphTelemetryRecord : BaseDetectionTelemetryRecord
44
{
@@ -9,4 +9,10 @@ public class GoGraphTelemetryRecord : BaseDetectionTelemetryRecord
99
public bool IsGoAvailable { get; set; }
1010

1111
public bool WasGraphSuccessful { get; set; }
12+
13+
public bool WasGoCliDisabled { get; set; }
14+
15+
public bool WasGoCliNotFound { get; set; }
16+
17+
public bool WasGoFallbackStrategyUsed { get; set; }
1218
}

src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Microsoft.ComponentDetection.Detectors.Go;
1+
namespace Microsoft.ComponentDetection.Detectors.Go;
22

33
using System;
44
using System.Collections.Generic;
@@ -53,6 +53,9 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID
5353
{
5454
var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder;
5555
var file = processRequest.ComponentStream;
56+
using var record = new GoGraphTelemetryRecord();
57+
record.WasGoCliDisabled = false;
58+
record.WasGoFallbackStrategyUsed = false;
5659

5760
var projectRootDirectory = Directory.GetParent(file.Location);
5861
if (this.projectRoots.Any(path => projectRootDirectory.FullName.StartsWith(path)))
@@ -65,10 +68,11 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID
6568
{
6669
if (!this.IsGoCliManuallyDisabled())
6770
{
68-
wasGoCliScanSuccessful = await this.UseGoCliToScanAsync(file.Location, singleFileComponentRecorder);
71+
wasGoCliScanSuccessful = await this.UseGoCliToScanAsync(file.Location, singleFileComponentRecorder, record);
6972
}
7073
else
7174
{
75+
record.WasGoCliDisabled = true;
7276
this.Logger.LogInformation("Go cli scan was manually disabled, fallback strategy performed." +
7377
" More info: https://github.com/microsoft/component-detection/blob/main/docs/detectors/go.md#fallback-detection-strategy");
7478
}
@@ -85,6 +89,7 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID
8589
}
8690
else
8791
{
92+
record.WasGoFallbackStrategyUsed = true;
8893
var fileExtension = Path.GetExtension(file.Location).ToUpperInvariant();
8994
switch (fileExtension)
9095
{
@@ -112,11 +117,10 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID
112117
}
113118

114119
[SuppressMessage("Maintainability", "CA1508:Avoid dead conditional code", Justification = "False positive")]
115-
private async Task<bool> UseGoCliToScanAsync(string location, ISingleFileComponentRecorder singleFileComponentRecorder)
120+
private async Task<bool> UseGoCliToScanAsync(string location, ISingleFileComponentRecorder singleFileComponentRecorder, GoGraphTelemetryRecord record)
116121
{
117-
using var record = new GoGraphTelemetryRecord();
118122
record.WasGraphSuccessful = false;
119-
123+
record.WasGoCliNotFound = false;
120124
var projectRootDirectory = Directory.GetParent(location);
121125
record.ProjectRoot = projectRootDirectory.FullName;
122126

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

0 commit comments

Comments
 (0)