Skip to content

Commit bb37a4c

Browse files
authored
Revert usage of CimInstances (#165)
1 parent 58e1566 commit bb37a4c

File tree

8 files changed

+21
-80
lines changed

8 files changed

+21
-80
lines changed

.pipelines/azure-pipelines-linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pool:
1313
vmImage: ubuntu-latest
1414

1515
variables:
16-
VcVersion : 1.9.4
16+
VcVersion : 1.9.5
1717
ROOT: $(Build.SourcesDirectory)
1818
CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning
1919
ENABLE_PRS_DELAYSIGN: 1

.pipelines/azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pool:
1818
vmImage: windows-latest
1919

2020
variables:
21-
VcVersion : 1.9.4
21+
VcVersion : 1.9.5
2222
ROOT: $(Build.SourcesDirectory)
2323
CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning
2424
ENABLE_PRS_DELAYSIGN: 1

src/VirtualClient/Module.props

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@
9494

9595
<!-- Microsoft.Extensions.Http.Polly -->
9696
<Microsoft_Extensions_Http_Polly_PackageVersion>6.0.9</Microsoft_Extensions_Http_Polly_PackageVersion>
97-
98-
<!-- Microsoft.Management.Infrastructure -->
99-
<Microsoft_Management_Infrastructure_PackageVersion>2.0.0</Microsoft_Management_Infrastructure_PackageVersion>
10097

10198
<!-- Microsoft.Windows.Compatibility -->
10299
<Microsoft_Windows_Compatibility_PackageVersion>6.0.0</Microsoft_Windows_Compatibility_PackageVersion>

src/VirtualClient/VirtualClient.Core/SystemManagement.cs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ namespace VirtualClient
1313
using System.Text.RegularExpressions;
1414
using System.Threading;
1515
using System.Threading.Tasks;
16-
using Microsoft.Management.Infrastructure;
17-
using Microsoft.Management.Infrastructure.Options;
1816
using Microsoft.Win32;
1917
using Polly;
2018
using VirtualClient.Common;
@@ -319,40 +317,7 @@ private async Task<MemoryInfo> GetMemoryInfoOnUnixAsync()
319317

320318
private MemoryInfo GetMemoryInfoOnWindows()
321319
{
322-
List<MemoryChipInfo> chips = null;
323-
CimSession session = CimSession.Create("localhost", new DComSessionOptions());
324-
IEnumerable<CimInstance> hardwareDefinitions = session.QueryInstances(@"Root\CIMV2", "WQL", "SELECT * FROM CIM_PhysicalMemory");
325-
326-
if (hardwareDefinitions?.Any() == true)
327-
{
328-
chips = new List<MemoryChipInfo>();
329-
int chipIndex = 0;
330-
foreach (CimInstance instance in hardwareDefinitions)
331-
{
332-
object capacity = instance.CimInstanceProperties["Capacity"]?.Value;
333-
object speed = instance.CimInstanceProperties["Speed"]?.Value;
334-
335-
// Physical blades will produce full specs for the hardware memory modules. This means
336-
// that we will have the speed as well as valid manufacturer information. VMs will not have
337-
// this information and there is not much useful there to capture.
338-
chipIndex++;
339-
if (long.TryParse(capacity?.ToString(), out long memoryCapacity) && long.TryParse(speed?.ToString(), out long memorySpeed))
340-
{
341-
object manufacturer = instance.CimInstanceProperties["Manufacturer"]?.Value;
342-
object partNumber = instance.CimInstanceProperties["PartNumber"]?.Value;
343-
344-
chips.Add(new MemoryChipInfo(
345-
$"Memory_{chipIndex}",
346-
$"{manufacturer} Memory Chip",
347-
memoryCapacity,
348-
memorySpeed,
349-
manufacturer?.ToString().Trim(),
350-
partNumber?.ToString().Trim()));
351-
}
352-
}
353-
}
354-
355-
return new MemoryInfo(this.GetTotalSystemMemoryKiloBytes(), chips);
320+
return new MemoryInfo(this.GetTotalSystemMemoryKiloBytes());
356321
}
357322

358323
private async Task<NetworkInfo> GetNetworkInfoOnUnixAsync()

src/VirtualClient/VirtualClient.Core/VirtualClient.Core.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<!-- Global package dependency versions are defined in the Module.props for the solution. -->
1313
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="$(Microsoft_AspNetCore_Hosting_PackageVersion)" />
1414
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="$(Microsoft_CodeAnalysis_CSharp_Scripting_PackageVersion)" />
15-
<PackageReference Include="Microsoft.Management.Infrastructure" Version="$(Microsoft_Management_Infrastructure_PackageVersion)" />
1615
<PackageReference Include="Microsoft.Win32.Registry" Version="$(Microsoft_Win32_Registry_PackageVersion)" />
1716
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="$(System_Diagnostics_PerformanceCounter_PackageVersion)" />
1817
</ItemGroup>

src/VirtualClient/VirtualClient.IntegrationTests/CimIntegrationTests.cs

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/VirtualClient/VirtualClient.Main/RunProfileCommand.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace VirtualClient
1818
using Microsoft.Extensions.Logging;
1919
using Newtonsoft.Json;
2020
using Polly;
21+
using Serilog.Core;
2122
using VirtualClient.Common;
2223
using VirtualClient.Common.Contracts;
2324
using VirtualClient.Common.Extensions;
@@ -138,6 +139,8 @@ await this.InitializePackagesAsync(packageManager, cancellationToken)
138139
await this.InstallExtensionsAsync(packageManager, cancellationToken)
139140
.ConfigureAwait(false);
140141

142+
this.SetHostMetadata(profileNames, dependencies);
143+
141144
// Ensure all Virtual Client types are loaded from .dlls in the execution directory.
142145
ComponentTypeCache.Instance.LoadComponentTypes(Path.GetDirectoryName(Assembly.GetAssembly(typeof(Program)).Location));
143146

@@ -618,8 +621,17 @@ protected void SetGlobalTelemetryProperties(IEnumerable<string> profiles, IServi
618621
// VC on the command line.
619622
metadata["experimentId"] = this.ExperimentId.ToLowerInvariant();
620623
metadata["agentId"] = this.AgentId;
621-
622624
MetadataContract.Persist(metadata, MetadataContractCategory.Default);
625+
}
626+
627+
/// <summary>
628+
/// Initializes the global/persistent telemetry properties that will be included
629+
/// with all telemetry emitted from the Virtual Client.
630+
/// </summary>
631+
protected void SetHostMetadata(IEnumerable<string> profiles, IServiceCollection dependencies)
632+
{
633+
ILogger logger = dependencies.GetService<ILogger>();
634+
ISystemManagement systemManagement = dependencies.GetService<ISystemManagement>();
623635

624636
IDictionary<string, object> hostMetadata = systemManagement.GetHostMetadataAsync(logger)
625637
.GetAwaiter().GetResult();

src/VirtualClient/VirtualClient.UnitTests/RunProfileCommandTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ private class TestRunProfileCommand : RunProfileCommand
224224
{
225225
base.SetGlobalTelemetryProperties(profiles, dependencies);
226226
}
227+
228+
public new void SetHostMetadata(IEnumerable<string> profiles, IServiceCollection dependencies)
229+
{
230+
base.SetHostMetadata(profiles, dependencies);
231+
}
227232
}
228233

229234
private static Tuple<string, string> GetAccessTokenPair()

0 commit comments

Comments
 (0)