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

Telemetry: Fixes Inconsistent behavior of VM Metadata Async Initialization #3252

Merged
merged 5 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -31,6 +31,7 @@ public ClientConfigurationTraceDatum(CosmosClientContext cosmosClientContext, Da
this.cachedNumberOfClientCreated = CosmosClient.numberOfClientsCreated;
this.cachedNumberOfActiveClient = CosmosClient.NumberOfActiveClients;
this.cachedUserAgentString = this.UserAgentContainer.UserAgent;
this.cachedMachineId = VmMetadataApiHandler.GetMachineId();
this.cachedSerializedJson = this.GetSerializedDatum();
this.ProcessorCount = Environment.ProcessorCount;
this.ConnectionMode = cosmosClientContext.ClientOptions.ConnectionMode;
Expand All @@ -56,11 +57,13 @@ public ReadOnlyMemory<byte> SerializedJson
{
if (this.cachedUserAgentString != this.UserAgentContainer.UserAgent ||
this.cachedNumberOfClientCreated != CosmosClient.numberOfClientsCreated ||
this.cachedNumberOfActiveClient != CosmosClient.NumberOfActiveClients)
this.cachedNumberOfActiveClient != CosmosClient.NumberOfActiveClients ||
this.cachedMachineId != VmMetadataApiHandler.GetMachineId())
{
this.cachedNumberOfActiveClient = CosmosClient.NumberOfActiveClients;
this.cachedNumberOfClientCreated = CosmosClient.numberOfClientsCreated;
this.cachedUserAgentString = this.UserAgentContainer.UserAgent;
this.cachedMachineId = VmMetadataApiHandler.GetMachineId();
this.cachedSerializedJson = this.GetSerializedDatum();
}

Expand All @@ -76,6 +79,8 @@ public ReadOnlyMemory<byte> SerializedJson

private string cachedUserAgentString;

private string cachedMachineId;

internal override void Accept(ITraceDatumVisitor traceDatumVisitor)
{
traceDatumVisitor.Visit(this);
Expand All @@ -89,7 +94,7 @@ private ReadOnlyMemory<byte> GetSerializedDatum()
jsonTextWriter.WriteFieldName("Client Created Time Utc");
jsonTextWriter.WriteStringValue(this.ClientCreatedDateTimeUtc.ToString("o", CultureInfo.InvariantCulture));
jsonTextWriter.WriteFieldName("MachineId");
jsonTextWriter.WriteStringValue(VmMetadataApiHandler.GetMachineId());
jsonTextWriter.WriteStringValue(this.cachedMachineId);
jsonTextWriter.WriteFieldName("NumberOfClientsCreated");
jsonTextWriter.WriteNumber64Value(this.cachedNumberOfClientCreated);
jsonTextWriter.WriteFieldName("NumberOfActiveClients");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,6 @@ private static void AssertAccountLevelInformation(
}
}

Assert.AreEqual(1, machineId.Count, $"Multiple Machine Id has been generated i.e {JsonConvert.SerializeObject(machineId)}");

if(isAzureInstance.HasValue)
{
if (isAzureInstance.Value)
Expand All @@ -955,6 +953,7 @@ private static void AssertAccountLevelInformation(
else
{
Assert.AreNotEqual("vmId:d0cb93eb-214b-4c2b-bd3d-cc93e90d9efd", machineId.First(), $"Generated Machine id is : {machineId.First()}");
Assert.AreEqual(1, machineId.Count, $"Multiple Machine Id has been generated i.e {JsonConvert.SerializeObject(machineId)}");
}
}

Expand Down