Skip to content

Commit

Permalink
Merge pull request #2184 from aws/metrics
Browse files Browse the repository at this point in the history
Added optional account id in telemetry metric
  • Loading branch information
JiayuW2 authored Jan 29, 2024
2 parents e2c6076 + 542cae6 commit 2e8bc94
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/PortingAssistant.Client.Telemetry/Model/APIMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ public class APIMetrics : MetricsBase
public string nameSpace { get; set; }
public string originalDefinition { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public Compatibility compatibility { get; set; }
public PortingAssistant.Client.Model.Compatibility compatibility { get; set; }
public string packageId { get; set; }
public string packageVersion { get; set; }
public string projectGuid { get; set; }
public string solutionGuid { get; set; }
public string? accountId { get; set; }

}
}
3 changes: 2 additions & 1 deletion src/PortingAssistant.Client.Telemetry/Model/NugetMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ public class NugetMetrics : MetricsBase
public string pacakgeName { get; set; }
public string packageVersion { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public Compatibility compatibility { get; set; }
public PortingAssistant.Client.Model.Compatibility compatibility { get; set; }
public string projectGuid { get; set; }
public string solutionGuid { get; set; }
public string? accountId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

<ItemGroup>
<PackageReference Include="AWSSDK.APIGateway" Version="3.7.2.70" />
<PackageReference Include="AWSSDK.Core" Version="3.7.106.13" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="AWSSDK.Core" Version="3.7.106.24" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Expressions" Version="3.4.1" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
Expand All @@ -20,6 +20,7 @@

<ItemGroup>
<ProjectReference Include="..\PortingAssistant.Client.Common\PortingAssistant.Client.Common.csproj" />
<ProjectReference Include="..\PortingAssistant.Compatibility.Common\PortingAssistant.Compatibility.Common.csproj" />
</ItemGroup>

</Project>
90 changes: 83 additions & 7 deletions src/PortingAssistant.Client.Telemetry/TelemetryCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
using ILogger = Serilog.ILogger;
using System.Linq;
using System.Net.NetworkInformation;
using YamlDotNet.Core.Tokens;
using PortingAssistant.Compatibility.Common.Model;
using System.Collections;
using System.Collections.Generic;
using Microsoft.CodeAnalysis.Diagnostics;
using CodeEntityType = PortingAssistant.Client.Model.CodeEntityType;
using CompatibilityResult = PortingAssistant.Client.Model.CompatibilityResult;
using Amazon.Runtime.Internal.Transform;
using PortingAssistant.Compatibility.Common.Utils;

namespace PortingAssistantExtensionTelemetry
{
Expand Down Expand Up @@ -144,9 +151,10 @@ public static NugetMetrics CreateNugetMetric
DateTime date,
string packageId,
string packageVersion,
Compatibility compatibility,
PortingAssistant.Client.Model.Compatibility compatibility,
string projectGuid,
string solutionGuid
string solutionGuid,
string? accountId = null
) {
return new NugetMetrics
{
Expand All @@ -161,6 +169,7 @@ string solutionGuid
compatibility = compatibility,
projectGuid = projectGuid,
solutionGuid = solutionGuid,
accountId = accountId,
SessionId = _sessionId
};
}
Expand All @@ -174,7 +183,8 @@ public static APIMetrics CreateAPIMetric
string tag,
DateTime date,
string projectGuid,
string solutionGuid
string solutionGuid,
string? accountId = null
)
{
return new APIMetrics
Expand All @@ -193,6 +203,7 @@ string solutionGuid
packageVersion = apiAnalysisResult.CodeEntityDetails.Package.Version,
projectGuid = projectGuid,
solutionGuid = solutionGuid,
accountId = accountId,
SessionId = _sessionId
};
}
Expand Down Expand Up @@ -226,16 +237,16 @@ string tag

foreach (var nuget in project.PackageAnalysisResults)
{
CompatibilityResult defaultCompatibilityResult = new CompatibilityResult()
PortingAssistant.Client.Model.CompatibilityResult defaultCompatibilityResult = new PortingAssistant.Client.Model.CompatibilityResult()
{
Compatibility = Compatibility.UNKNOWN,
Compatibility = PortingAssistant.Client.Model.Compatibility.UNKNOWN,
CompatibleVersions = new System.Collections.Generic.List<string>()
};

nuget.Value.Wait();
var packageID = nuget.Value.Result.PackageVersionPair.PackageId;
var packageVersion = nuget.Value.Result.PackageVersionPair.Version;
CompatibilityResult compatability;
PortingAssistant.Client.Model.CompatibilityResult compatability;
if (!nuget.Value.Result.CompatibilityResults.TryGetValue(targetFramework, out compatability))
{
compatability = defaultCompatibilityResult;
Expand Down Expand Up @@ -277,6 +288,71 @@ string solutionGuid
}
}

public static void SolutionAssessmentCollect(CompatibilityCheckerResponse result, string targetFramework, string version, string source, double analysisTime, string tag, string accountId)
{
var date = DateTime.Now;
var metrics = new ArrayList();
var count = 0;

// nuget metrics
foreach (var nuget in result.PackageAnalysisResults)
{
var packageID = nuget.Key.PackageId;
var packageVersion = nuget.Key.Version;
PortingAssistant.Client.Model.Compatibility compatibility = (PortingAssistant.Client.Model.Compatibility)nuget.Value.CompatibilityResults[targetFramework].Compatibility;
var nugetMetrics = CreateNugetMetric(targetFramework, version, source, analysisTime, tag, date, packageID, packageVersion, compatibility, null, null, accountId);
metrics.Add(nugetMetrics);
count++;
if (count >= 2000)
{
Collect(metrics);
metrics.Clear();
count = 0;
}
}

//API metrics
var apiAnalysisResults = result.ApiAnalysisResults;
foreach (var apiResult in apiAnalysisResults)
{
var packageVersionPair = apiResult.Key;
foreach (var analysisResultPair in apiResult.Value)
{
var apiAnalysisResult = new ApiAnalysisResult
{
CodeEntityDetails = new CodeEntityDetails
{
Package = new PortingAssistant.Client.Model.PackageVersionPair
{
PackageId = packageVersionPair.PackageId,
Version = packageVersionPair.Version,
PackageSourceType = (PortingAssistant.Client.Model.PackageSourceType)packageVersionPair.PackageSourceType
},
CodeEntityType = CodeEntityType.Method,
OriginalDefinition = analysisResultPair.Key,
Namespace = packageVersionPair.PackageId
},
CompatibilityResults = analysisResultPair.Value.CompatibilityResults
.ToDictionary(kvp => kvp.Key, kvp => new CompatibilityResult
{
Compatibility = (PortingAssistant.Client.Model.Compatibility)kvp.Value.Compatibility,
CompatibleVersions = kvp.Value.CompatibleVersions
})
};
var apiMetrics = CreateAPIMetric(apiAnalysisResult, targetFramework, version, source, tag, date, null, null, accountId);
metrics.Add(apiMetrics);
count++;
if (count >= 2000)
{
Collect(metrics);
metrics.Clear();
count = 0;
}
}
}
Collect(metrics);
}

public static void ToggleMetrics(bool disabledMetrics)
{
_disabledMetrics = disabledMetrics;
Expand Down

0 comments on commit 2e8bc94

Please sign in to comment.