Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: record telemetry on Go fallback detection strategy #718

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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; }
}
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,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)))
Expand All @@ -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");
}
Expand All @@ -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)
{
Expand Down Expand Up @@ -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<bool> UseGoCliToScanAsync(string location, ISingleFileComponentRecorder singleFileComponentRecorder)
private async Task<bool> 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;

Expand All @@ -126,6 +130,7 @@ 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 Down
Loading