Skip to content

Commit

Permalink
Merge branch 'users/aavasthy/TraceId_NullException' of https://github…
Browse files Browse the repository at this point in the history
….com/Azure/azure-cosmos-dotnet-v3 into users/aavasthy/TraceId_NullException
  • Loading branch information
aavasthy committed Oct 10, 2023
2 parents 857da88 + 168f806 commit c2be390
Show file tree
Hide file tree
Showing 22 changed files with 625 additions and 356 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public class BenchmarkConfig
[Option(Required = false, HelpText = "Disable core SDK logging")]
public bool DisableCoreSdkLogging { get; set; }

[Option(Required = false, HelpText = "Disable Distributed Tracing feature from source")]
public bool DisableDistributedTracing { get; set; } = false;
[Option(Required = false, HelpText = "Enable Distributed Tracing")]
public bool EnableDistributedTracing { get; set; } = false;

[Option(Required = false, HelpText = "Client Telemetry Schedule in Seconds")]
public int TelemetryScheduleInSec { get; set; }
Expand Down Expand Up @@ -138,8 +138,8 @@ public class BenchmarkConfig
[Option(Required = false, HelpText = "Application Insights connection string")]
public string AppInsightsConnectionString { get; set; }

[Option(Required = false, HelpText = "Disable Client Telemetry Feature in SDK. Make sure you enable it from the portal also.")]
public bool DisableClientTelemetry { get; set; } = false;
[Option(Required = false, HelpText = "Enable Client Telemetry Feature in SDK. Make sure you enable it from the portal also.")]
public bool EnableTelemetry { get; set; } = false;

internal int GetTaskCount(int containerThroughput)
{
Expand Down Expand Up @@ -222,8 +222,8 @@ internal Microsoft.Azure.Cosmos.CosmosClient CreateCosmosClient(string accountKe
MaxTcpConnectionsPerEndpoint = this.MaxTcpConnectionsPerEndpoint,
CosmosClientTelemetryOptions = new Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions()
{
DisableSendingMetricsToService = this.DisableClientTelemetry,
DisableDistributedTracing = this.DisableDistributedTracing
DisableSendingMetricsToService = !this.EnableTelemetry,
DisableDistributedTracing = !this.EnableDistributedTracing
}
};

Expand Down
12 changes: 1 addition & 11 deletions Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ namespace CosmosBenchmark
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Azure.Monitor.OpenTelemetry.Exporter;
using CosmosBenchmark.Fx;
using Microsoft.Azure.Cosmos;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using OpenTelemetry;
using OpenTelemetry.Metrics;
Expand Down Expand Up @@ -323,14 +320,7 @@ private static Type[] AvailableBenchmarks()
private static async Task<ContainerResponse> CreatePartitionedContainerAsync(BenchmarkConfig options, CosmosClient cosmosClient)
{
Microsoft.Azure.Cosmos.Database database = await cosmosClient.CreateDatabaseIfNotExistsAsync(options.Database);

// Show user cost of running this test
double estimatedCostPerMonth = 0.06 * options.Throughput;
double estimatedCostPerHour = estimatedCostPerMonth / (24 * 30);
Utility.TeeTraceInformation($"The container will cost an estimated ${Math.Round(estimatedCostPerHour, 2)} per hour (${Math.Round(estimatedCostPerMonth, 2)} per month)");
Utility.TeeTraceInformation("Press enter to continue ...");
Console.ReadLine();


string partitionKeyPath = options.PartitionKeyPath;
return await database.CreateContainerIfNotExistsAsync(options.Container, partitionKeyPath, options.Throughput);
}
Expand Down
19 changes: 11 additions & 8 deletions Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -785,14 +785,17 @@ internal virtual ConnectionPolicy GetConnectionPolicy(int clientId)
connectionPolicy.CosmosClientTelemetryOptions = this.CosmosClientTelemetryOptions;
}

if (this.ApplicationRegion != null)
{
connectionPolicy.SetCurrentLocation(this.ApplicationRegion);
}

if (this.ApplicationPreferredRegions != null)
{
connectionPolicy.SetPreferredLocations(this.ApplicationPreferredRegions);
RegionNameMapper mapper = new RegionNameMapper();
if (!string.IsNullOrEmpty(this.ApplicationRegion))
{
connectionPolicy.SetCurrentLocation(mapper.GetCosmosDBRegionName(this.ApplicationRegion));
}

if (this.ApplicationPreferredRegions != null)
{
List<string> mappedRegions = this.ApplicationPreferredRegions.Select(s => mapper.GetCosmosDBRegionName(s)).ToList();

connectionPolicy.SetPreferredLocations(mappedRegions);
}

if (this.MaxRetryAttemptsOnRateLimitedRequests != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ private static class FirstValueOffsets
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,

// Encoded 1-byte system string (64 values)
// Encoded 1-byte system string (32 values)
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,

// Encoded 1-byte user string (32 values)
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ public static class NodeTypes
Number, Number, Number, Number, Number, Number, Number, Number,
Number, Number, Number, Number, Number, Number, Number, Number,

// Encoded 1-byte system string (64 values)
// Encoded 1-byte system string (32 values)
String, String, String, String, String, String, String, String,
String, String, String, String, String, String, String, String,
String, String, String, String, String, String, String, String,
String, String, String, String, String, String, String, String,

// Encoded 1-byte user string (32 values)
String, String, String, String, String, String, String, String,
String, String, String, String, String, String, String, String,
String, String, String, String, String, String, String, String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private static class StringLengths
NotStr, NotStr, NotStr, NotStr, NotStr, NotStr, NotStr, NotStr,
NotStr, NotStr, NotStr, NotStr, NotStr, NotStr, NotStr, NotStr,

// Encoded 1-byte system string (64 values)
// Encoded 1-byte system string (32 values)
SystemStrings.Strings[0].Utf8String.Length, SystemStrings.Strings[1].Utf8String.Length,
SystemStrings.Strings[2].Utf8String.Length, SystemStrings.Strings[3].Utf8String.Length,
SystemStrings.Strings[4].Utf8String.Length, SystemStrings.Strings[5].Utf8String.Length,
Expand All @@ -54,22 +54,12 @@ private static class StringLengths
SystemStrings.Strings[26].Utf8String.Length, SystemStrings.Strings[27].Utf8String.Length,
SystemStrings.Strings[28].Utf8String.Length, SystemStrings.Strings[29].Utf8String.Length,
SystemStrings.Strings[30].Utf8String.Length, SystemStrings.Strings[31].Utf8String.Length,
SystemStrings.Strings[32].Utf8String.Length, SystemStrings.Strings[33].Utf8String.Length,
SystemStrings.Strings[34].Utf8String.Length, SystemStrings.Strings[35].Utf8String.Length,
SystemStrings.Strings[36].Utf8String.Length, SystemStrings.Strings[37].Utf8String.Length,
SystemStrings.Strings[38].Utf8String.Length, SystemStrings.Strings[39].Utf8String.Length,
SystemStrings.Strings[40].Utf8String.Length, SystemStrings.Strings[41].Utf8String.Length,
SystemStrings.Strings[42].Utf8String.Length, SystemStrings.Strings[43].Utf8String.Length,
SystemStrings.Strings[44].Utf8String.Length, SystemStrings.Strings[45].Utf8String.Length,
SystemStrings.Strings[46].Utf8String.Length, SystemStrings.Strings[47].Utf8String.Length,
SystemStrings.Strings[48].Utf8String.Length, SystemStrings.Strings[49].Utf8String.Length,
SystemStrings.Strings[50].Utf8String.Length, SystemStrings.Strings[51].Utf8String.Length,
SystemStrings.Strings[52].Utf8String.Length, SystemStrings.Strings[53].Utf8String.Length,
SystemStrings.Strings[54].Utf8String.Length, SystemStrings.Strings[55].Utf8String.Length,
SystemStrings.Strings[56].Utf8String.Length, SystemStrings.Strings[57].Utf8String.Length,
SystemStrings.Strings[58].Utf8String.Length, SystemStrings.Strings[59].Utf8String.Length,
SystemStrings.Strings[60].Utf8String.Length, SystemStrings.Strings[61].Utf8String.Length,
SystemStrings.Strings[62].Utf8String.Length, SystemStrings.Strings[63].Utf8String.Length,

// Encoded 1-byte user string (32 values)
UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1,
UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1,
UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1,
UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1,

// Encoded 2-byte user string (8 values)
UsrStr2, UsrStr2, UsrStr2, UsrStr2, UsrStr2, UsrStr2, UsrStr2, UsrStr2,
Expand Down
29 changes: 23 additions & 6 deletions Microsoft.Azure.Cosmos/src/Json/JsonBinaryEncoding.Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ internal static partial class JsonBinaryEncoding
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,

// Encoded 0-byte system string (64 values)
// Encoded 0-byte system string (32 values)
true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true,

// Encoded true-byte user string (32 values)
true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true,
Expand Down Expand Up @@ -384,14 +386,29 @@ private static bool TryGetUserStringId(ReadOnlySpan<byte> stringToken, out int u
return false;
}

// JsonBinaryEncoding.TypeMarker.IsTwoByteEncodedUserString(typeMarker) must be true
if (stringToken.Length < 2)
if (JsonBinaryEncoding.TypeMarker.IsOneByteEncodedUserString(typeMarker))
{
userStringId = default;
return false;
if (stringToken.Length < 1)
{
userStringId = default;
return false;
}

userStringId = typeMarker - JsonBinaryEncoding.TypeMarker.UserString1ByteLengthMin;
}
else //// JsonBinaryEncoding.TypeMarker.IsTwoByteEncodedUserString(typeMarker)
{
if (stringToken.Length < 2)
{
userStringId = default;
return false;
}

userStringId = stringToken[1] + ((stringToken[0] - JsonBinaryEncoding.TypeMarker.UserString2ByteLengthMin) * 0xFF);
const byte OneByteCount = JsonBinaryEncoding.TypeMarker.UserString1ByteLengthMax - JsonBinaryEncoding.TypeMarker.UserString1ByteLengthMin;
userStringId = OneByteCount
+ stringToken[1]
+ ((stringToken[0] - JsonBinaryEncoding.TypeMarker.UserString2ByteLengthMin) * 0xFF);
}

return true;
}
Expand Down
Loading

0 comments on commit c2be390

Please sign in to comment.