Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nkolev92 committed Jan 6, 2025
1 parent 4c634cc commit adf6e52
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
18 changes: 16 additions & 2 deletions src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ private readonly Dictionary<RestoreTargetGraph, Dictionary<string, LibraryInclud
private const string TreatWarningsAsErrors = nameof(TreatWarningsAsErrors);
private const string SDKAnalysisLevel = nameof(SDKAnalysisLevel);
private const string UsingMicrosoftNETSdk = nameof(UsingMicrosoftNETSdk);
private const string UpdatedAssetsFile = nameof(UpdatedAssetsFile);
private const string UpdatedMSBuildFiles = nameof(UpdatedMSBuildFiles);
private const string IsPackageInstallationTrigger = nameof(IsPackageInstallationTrigger);

// no-op data names
private const string NoOpDuration = nameof(NoOpDuration);
Expand All @@ -71,6 +74,7 @@ private readonly Dictionary<RestoreTargetGraph, Dictionary<string, LibraryInclud
private const string NoOpRestoreOutputEvaluationResult = nameof(NoOpRestoreOutputEvaluationResult);
private const string NoOpReplayLogsDuration = nameof(NoOpReplayLogsDuration);
private const string NoOpCacheFileAgeDays = nameof(NoOpCacheFileAgeDays);
private const string ForceRestore = nameof(ForceRestore);

// lock file data names
private const string EvaluateLockFileDuration = nameof(EvaluateLockFileDuration);
Expand Down Expand Up @@ -292,7 +296,7 @@ public async Task<RestoreResult> ExecuteAsync(CancellationToken token)
restoreTime.Stop();

// Create result
return new RestoreResult(
var restoreResult = new RestoreResult(
_success,
graphs,
checkResults,
Expand All @@ -311,6 +315,11 @@ public async Task<RestoreResult> ExecuteAsync(CancellationToken token)
{
AuditRan = auditRan
};

telemetry.TelemetryEvent[UpdatedAssetsFile] = restoreResult._isAssetsFileDirty.Value;
telemetry.TelemetryEvent[UpdatedMSBuildFiles] = restoreResult._dirtyMSBuildFiles.Value.Count > 0;

return restoreResult;
}
}

Expand All @@ -329,9 +338,9 @@ private void InitializeTelemetry(TelemetryActivity telemetry, int httpSourcesCou
telemetry.TelemetryEvent[TargetFrameworksCount] = _request.Project.RestoreMetadata.TargetFrameworks.Count;
telemetry.TelemetryEvent[RuntimeIdentifiersCount] = _request.Project.RuntimeGraph.Runtimes.Count;
telemetry.TelemetryEvent[TreatWarningsAsErrors] = _request.Project.RestoreMetadata.ProjectWideWarningProperties.AllWarningsAsErrors;

telemetry.TelemetryEvent[SDKAnalysisLevel] = _request.Project.RestoreMetadata.SdkAnalysisLevel;
telemetry.TelemetryEvent[UsingMicrosoftNETSdk] = _request.Project.RestoreMetadata.UsingMicrosoftNETSdk;
telemetry.TelemetryEvent[IsPackageInstallationTrigger] = !_request.IsRestoreOriginalAction;
_operationId = telemetry.OperationId;

var isCpvmEnabled = _request.Project.RestoreMetadata?.CentralPackageVersionsEnabled ?? false;
Expand All @@ -357,6 +366,8 @@ private void InitializeTelemetry(TelemetryActivity telemetry, int httpSourcesCou
if (NuGetEventSource.IsEnabled) TraceEvents.CalcNoOpRestoreStop(_request.Project.FilePath);

telemetry.TelemetryEvent[NoOpCacheFileEvaluationResult] = noOp;
telemetry.TelemetryEvent[ForceRestore] = !_request.AllowNoOp;

telemetry.EndIntervalMeasure(NoOpCacheFileEvaluateDuration);
if (noOp)
{
Expand All @@ -381,6 +392,9 @@ private void InitializeTelemetry(TelemetryActivity telemetry, int httpSourcesCou
telemetry.TelemetryEvent[RestoreSuccess] = _success;
telemetry.TelemetryEvent[TotalUniquePackagesCount] = cacheFile.ExpectedPackageFilePaths?.Count ?? -1;
telemetry.TelemetryEvent[NewPackagesInstalledCount] = 0;
telemetry.TelemetryEvent[UpdatedAssetsFile] = false;
telemetry.TelemetryEvent[UpdatedMSBuildFiles] = false;

if (cacheFileAge.HasValue) { telemetry.TelemetryEvent[NoOpCacheFileAgeDays] = cacheFileAge.Value.TotalDays; }

return (new NoOpRestoreResult(
Expand Down
4 changes: 2 additions & 2 deletions src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public class RestoreResult : IRestoreResult

private readonly DependencyGraphSpec _dependencyGraphSpec;

private readonly Lazy<bool> _isAssetsFileDirty;
private readonly Lazy<List<MSBuildOutputFile>> _dirtyMSBuildFiles;
internal readonly Lazy<bool> _isAssetsFileDirty;
internal readonly Lazy<List<MSBuildOutputFile>> _dirtyMSBuildFiles;


public RestoreResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2907,6 +2907,10 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
["TreatWarningsAsErrors"] = value => value.Should().Be(false),
["SDKAnalysisLevel"] = value => value.Should().Be(null),
["UsingMicrosoftNETSdk"] = value => value.Should().Be(false),
["IsPackageInstallationTrigger"] = value => value.Should().Be(false),
["ForceRestore"] = value => value.Should().Be(false),
["UpdatedAssetsFile"] = value => value.Should().Be(true),
["UpdatedMSBuildFiles"] = value => value.Should().Be(true),
};

HashSet<string> actualProperties = new();
Expand Down Expand Up @@ -2981,7 +2985,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(

var projectInformationEvent = telemetryEvents.Single(e => e.Name.Equals("ProjectRestoreInformation"));

projectInformationEvent.Count.Should().Be(30);
projectInformationEvent.Count.Should().Be(34);
projectInformationEvent["RestoreSuccess"].Should().Be(true);
projectInformationEvent["NoOpResult"].Should().Be(true);
projectInformationEvent["IsCentralVersionManagementEnabled"].Should().Be(false);
Expand Down Expand Up @@ -3012,6 +3016,10 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
projectInformationEvent["TreatWarningsAsErrors"].Should().Be(true);
projectInformationEvent["SDKAnalysisLevel"].Should().Be(NuGetVersion.Parse("9.0.100"));
projectInformationEvent["UsingMicrosoftNETSdk"].Should().Be(true);
projectInformationEvent["IsPackageInstallationTrigger"].Should().Be(false);
projectInformationEvent["ForceRestore"].Should().Be(false);
projectInformationEvent["UpdatedAssetsFile"].Should().Be(false);
projectInformationEvent["UpdatedMSBuildFiles"].Should().Be(false);
}

[Fact]
Expand Down Expand Up @@ -3069,12 +3077,16 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(

var projectInformationEvent = telemetryEvents.Single(e => e.Name.Equals("ProjectRestoreInformation"));

projectInformationEvent.Count.Should().Be(36);
projectInformationEvent.Count.Should().Be(40);
projectInformationEvent["RestoreSuccess"].Should().Be(true);
projectInformationEvent["NoOpResult"].Should().Be(false);
projectInformationEvent["TotalUniquePackagesCount"].Should().Be(2);
projectInformationEvent["NewPackagesInstalledCount"].Should().Be(1);
projectInformationEvent["PackageSourceMapping.IsMappingEnabled"].Should().Be(false);
projectInformationEvent["UpdatedAssetsFile"].Should().Be(true);
projectInformationEvent["UpdatedMSBuildFiles"].Should().Be(true);
projectInformationEvent["IsPackageInstallationTrigger"].Should().Be(false);
projectInformationEvent["ForceRestore"].Should().Be(false);
}

/// A 1.0.0 -> C 1.0.0 -> D 1.1.0
Expand Down

0 comments on commit adf6e52

Please sign in to comment.