Skip to content

Commit

Permalink
Diagnostics: Adds Application region into Client Configuration Trace (#…
Browse files Browse the repository at this point in the history
…3202)

Logs the application region into the client configuration trace for diagnostics.
  • Loading branch information
imanvt authored May 19, 2022
1 parent dd9f480 commit 976de9b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ClientConfigurationTraceDatum(CosmosClientContext cosmosClientContext, Da
cosmosClientContext.ClientOptions.AllowBulkExecution);

this.ConsistencyConfig = new ConsistencyConfig(cosmosClientContext.ClientOptions.ConsistencyLevel,
cosmosClientContext.ClientOptions.ApplicationPreferredRegions);
cosmosClientContext.ClientOptions.ApplicationPreferredRegions, cosmosClientContext.ClientOptions.ApplicationRegion);

this.cachedNumberOfClientCreated = CosmosClient.numberOfClientsCreated;
this.cachedNumberOfActiveClient = CosmosClient.NumberOfActiveClients;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@ internal class ConsistencyConfig
{
public ConsistencyConfig(
ConsistencyLevel? consistencyLevel,
IReadOnlyList<string> preferredRegions)
IReadOnlyList<string> preferredRegions,
string applicationRegion)
{
this.ConsistencyLevel = consistencyLevel;
this.PreferredRegions = preferredRegions;
this.ApplicationRegion = applicationRegion;
this.lazyString = new Lazy<string>(() => string.Format(CultureInfo.InvariantCulture,
"(consistency: {0}, prgns:[{1}])",
"(consistency: {0}, prgns:[{1}], apprgn: {2})",
consistencyLevel?.ToString() ?? "NotSet",
ConsistencyConfig.PreferredRegionsInternal(preferredRegions)));
ConsistencyConfig.PreferredRegionsInternal(preferredRegions),
applicationRegion));
this.lazyJsonString = new Lazy<string>(() => Newtonsoft.Json.JsonConvert.SerializeObject(this));
}

public ConsistencyLevel? ConsistencyLevel { get; }
public IReadOnlyList<string> PreferredRegions { get; }
public string ApplicationRegion { get; }

private readonly Lazy<string> lazyString;
private readonly Lazy<string> lazyJsonString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,37 @@ public void ClientConfigWithOptionsTest()

ConsistencyConfig consistencyConfig = cosmosClient.ClientConfigurationTraceDatum.ConsistencyConfig;
Assert.AreEqual(consistencyConfig.ConsistencyLevel.Value, ConsistencyLevel.Session);

CosmosClientOptions clientOptions = new CosmosClientOptions
{
ApplicationRegion = "East US"
};

CosmosClientContext context = ClientContextCore.Create(
cosmosClient,
clientOptions);

ClientConfigurationTraceDatum clientConfig = new ClientConfigurationTraceDatum(context, DateTime.UtcNow);
Assert.AreEqual(clientConfig.ConsistencyConfig.ApplicationRegion, "East US");
Assert.IsNull(clientConfig.ConsistencyConfig.PreferredRegions);

}

[TestMethod]
public void ConsistencyConfigSerializationTest()
{
List<string> preferredRegions = new List<string> { "EastUS", "WestUs" };
ConsistencyLevel consistencyLevel = ConsistencyLevel.Session;
string appRegion = "EastUS";

ConsistencyConfig consistencyConfig = new ConsistencyConfig(consistencyLevel, preferredRegions);
Assert.AreEqual(consistencyConfig.ToString(), "(consistency: Session, prgns:[EastUS, WestUs])");
ConsistencyConfig consistencyConfig = new ConsistencyConfig(consistencyLevel, preferredRegions, appRegion);
Assert.AreEqual(consistencyConfig.ToString(), "(consistency: Session, prgns:[EastUS, WestUs], apprgn: EastUS)");

ConsistencyConfig consistencyConfigWithNull = new ConsistencyConfig(consistencyLevel: null,
preferredRegions: null);
preferredRegions: null,
applicationRegion: null);

Assert.AreEqual(consistencyConfigWithNull.ToString(), "(consistency: NotSet, prgns:[])");
Assert.AreEqual(consistencyConfigWithNull.ToString(), "(consistency: NotSet, prgns:[], apprgn: )");
}

[TestMethod]
Expand Down

0 comments on commit 976de9b

Please sign in to comment.