Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
83cee90
Code changes to add regional endpoints for account metadata calls.
kundadebdatta Jan 17, 2024
1e12015
Code changes to refactor some codes.
kundadebdatta Jan 19, 2024
7f68b28
Code changes to add unit tests.
kundadebdatta Jan 22, 2024
7aa43f8
Code changes to make minor code clean-up.
kundadebdatta Jan 23, 2024
58517ed
Merge branch 'master' into users/kundadebdatta/4236_add_custom_domain…
kundadebdatta Jan 23, 2024
60a0803
Code changes to fix tests. Refactored API.
kundadebdatta Jan 23, 2024
a3b4c78
Merge branch 'users/kundadebdatta/4236_add_custom_domain_names' of ht…
kundadebdatta Jan 23, 2024
6efe507
Code changes to refactor the enumeration logic inside global endpoint…
kundadebdatta Jan 25, 2024
fb5af02
Code changes to address review comments.
kundadebdatta Jan 25, 2024
55f1ace
Code changes to fix minor API parameter.
kundadebdatta Jan 25, 2024
94b0058
Code changes to update the API naming.
kundadebdatta Jan 26, 2024
9cc57ad
Code changes to update some attribute names.
kundadebdatta Jan 26, 2024
3c4498f
Merge branch 'master' into users/kundadebdatta/4236_add_custom_domain…
kundadebdatta Jan 26, 2024
348e4a7
Code changes to refactor service endpoint creation logic.
kundadebdatta Jan 29, 2024
ea51744
Code changes to address review comments.
kundadebdatta Jan 30, 2024
b8788d4
Merge branch 'master' into users/kundadebdatta/4236_add_custom_domain…
kundadebdatta Jan 30, 2024
f177371
Code changes to address review comments.
kundadebdatta Feb 6, 2024
35d1c9a
Merge branch 'master' into users/kundadebdatta/4236_add_custom_domain…
kundadebdatta Feb 6, 2024
d4c3526
Code changes to update the API contract.
kundadebdatta Feb 6, 2024
5a39ba3
Merge branch 'master' into users/kundadebdatta/4236_add_custom_domain…
kundadebdatta Feb 6, 2024
65b9b44
Cosmetic code changes.
kundadebdatta Feb 6, 2024
be9b5d7
Merge branch 'master' into users/kundadebdatta/4236_add_custom_domain…
kundadebdatta Feb 7, 2024
3a9d168
Code changes to address review comments.
kundadebdatta Feb 8, 2024
581c6af
Merge branch 'master' into users/kundadebdatta/4236_add_custom_domain…
kundadebdatta Feb 8, 2024
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
Prev Previous commit
Next Next commit
Code changes to fix tests. Refactored API.
  • Loading branch information
kundadebdatta committed Jan 23, 2024
commit 60a080352b2d4e901b547e59c90ac101fd1c6357
9 changes: 8 additions & 1 deletion Microsoft.Azure.Cosmos/src/ConnectionPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ public void SetPreferredLocations(IReadOnlyList<string> regions)
}
}

public void SetRegionalEndpoints(IReadOnlyList<string> regionalEndpoints)
/// <summary>
/// Sets the regional endpoints required to fetch account information from
/// private domain names.
/// </summary>
/// <param name="regionalEndpoints">An instance of <see cref="ISet{T}"/> containing the regional endpoints
/// provided by the customer.</param>
public void SetRegionalEndpoints(
ISet<string> regionalEndpoints)
{
if (regionalEndpoints == null)
{
Expand Down
14 changes: 5 additions & 9 deletions Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,39 +192,35 @@ public string ApplicationName
public IReadOnlyList<string> ApplicationPreferredRegions { get; set; }

/// <summary>
/// Gets and sets the preferred regions for geo-replicated database accounts in the Azure Cosmos DB service.
/// Gets and sets the regional private endpoints for geo-replicated database accounts in the Azure Cosmos DB service.
/// </summary>
/// <remarks>
/// <para>
/// During the CosmosClient initialization the account information, including the available regions, is obtained from the <see cref="CosmosClient.Endpoint"/>.
/// The CosmosClient will use the value of <see cref="RegionalEndpoints"/> to populate the preferred list with the account available regions that intersect with its value.
/// If the value of <see cref="RegionalEndpoints"/> contains regions that are not an available region in the account, the values will be ignored. If the these invalid regions are added later to the account, the CosmosClient will use them if they are higher in the preference order.
/// Should the global endpoint become inaccessible, the CosmosClient will attempt to obtain the account information issuing requests to the regional endpoints provided in <see cref="RegionalEndpoints"/>.
/// </para>
/// <para>
/// If during CosmosClient initialization, the <see cref="CosmosClient.Endpoint"/> is not reachable, the CosmosClient will attempt to recover and obtain the account information issuing requests to the regions in <see cref="ApplicationPreferredRegions"/> in the order that they are listed.
/// Nevertheless, this parameter remains optional and is recommended for implementation when a customer has configured a private endpoint for their Cosmos DB account.
/// </para>
/// <para>
/// See also <seealso href="https://docs.microsoft.com/azure/cosmos-db/sql/troubleshoot-sdk-availability">Diagnose
/// and troubleshoot the availability of Cosmos SDKs</seealso> for more details.
/// </para>
/// <para>
/// This configuration is an alternative to <see cref="ApplicationRegion"/>, either one can be set but not both.
/// </para>
/// </remarks>
/// <example>
/// <code language="c#">
/// <![CDATA[
/// CosmosClientOptions clientOptions = new CosmosClientOptions()
/// {
/// RegionalEndpoints = new List<string>(){ "custom.p-1.documents.azure.com", "custom.p-2.documents.azure.com" }
/// RegionalEndpoints = new HashSet<string>(){ "custom.p-1.documents.azure.com", "custom.p-2.documents.azure.com" }
/// };
///
/// CosmosClient client = new CosmosClient("endpoint", "key", clientOptions);
/// ]]>
/// </code>
/// </example>
/// <seealso href="https://docs.microsoft.com/azure/cosmos-db/high-availability#high-availability-with-cosmos-db-in-the-event-of-regional-outages">High availability on regional outages</seealso>
public IReadOnlyList<string> RegionalEndpoints { get; set; }
public ISet<string> RegionalEndpoints { get; set; }

/// <summary>
/// Get or set the maximum number of concurrent connections allowed for the target
Expand Down
30 changes: 30 additions & 0 deletions Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,36 @@ public CosmosClientBuilder WithApplicationPreferredRegions(IReadOnlyList<string>
return this;
}

/// <summary>
/// Sets the regional private endpoints for geo-replicated database accounts in the Azure Cosmos DB service.
/// During the CosmosClient initialization the account information, including the available regions, is obtained from the <see cref="CosmosClient.Endpoint"/>.
/// Should the global endpoint become inaccessible, the CosmosClient will attempt to obtain the account information issuing requests to the regional endpoints
/// provided in the regionalEndpoints set.
/// </summary>
/// <param name="regionalEndpoints">A set of string containing the regional private endpoints for the cosmos db account.</param>
/// <remarks>
/// This function is optional and is recommended for implementation when a customer has configured one or more private endpoints for their Cosmos DB account.
/// </remarks>
/// <example>
/// The example below creates a new instance of <see cref="CosmosClientBuilder"/> with the regional endpoints.
/// <code language="c#">
/// <![CDATA[
/// CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder(
/// accountEndpoint: "https://testcosmos.documents.azure.com:443/",
/// authKeyOrResourceToken: "SuperSecretKey")
/// .WithRegionalEndpoints(new HashSet<string>() { "https://region-1.documents-test.windows-int.net:443/", "https://region-2.documents-test.windows-int.net:443/" });
/// CosmosClient client = cosmosClientBuilder.Build();
/// ]]>
/// </code>
/// </example>
/// <returns>The current <see cref="CosmosClientBuilder"/>.</returns>
/// <seealso cref="CosmosClientOptions.RegionalEndpoints"/>
public CosmosClientBuilder WithRegionalEndpoints(ISet<string> regionalEndpoints)
{
this.clientOptions.RegionalEndpoints = regionalEndpoints;
return this;
}

/// <summary>
/// Limits the operations to the provided endpoint on the CosmosClientBuilder constructor.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2782,6 +2782,18 @@
],
"MethodInfo": "System.Collections.Generic.IReadOnlyList`1[System.String] get_ApplicationPreferredRegions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Collections.Generic.ISet`1[System.String] get_RegionalEndpoints()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [
"CompilerGeneratedAttribute"
],
"MethodInfo": "System.Collections.Generic.ISet`1[System.String] get_RegionalEndpoints();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Collections.Generic.ISet`1[System.String] RegionalEndpoints": {
"Type": "Property",
"Attributes": [],
"MethodInfo": "System.Collections.Generic.ISet`1[System.String] RegionalEndpoints;CanRead:True;CanWrite:True;System.Collections.Generic.ISet`1[System.String] get_RegionalEndpoints();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_RegionalEndpoints(System.Collections.Generic.ISet`1[System.String]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Collections.ObjectModel.Collection`1[Microsoft.Azure.Cosmos.RequestHandler] CustomHandlers[Newtonsoft.Json.JsonConverterAttribute(typeof(Microsoft.Azure.Cosmos.CosmosClientOptions+ClientOptionJsonConverter))]": {
"Type": "Property",
"Attributes": [
Expand Down Expand Up @@ -3096,6 +3108,13 @@
"Attributes": [],
"MethodInfo": "Void set_PortReuseMode(System.Nullable`1[Microsoft.Azure.Cosmos.PortReuseMode]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Void set_RegionalEndpoints(System.Collections.Generic.ISet`1[System.String])[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [
"CompilerGeneratedAttribute"
],
"MethodInfo": "Void set_RegionalEndpoints(System.Collections.Generic.ISet`1[System.String]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Void set_RequestTimeout(System.TimeSpan)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [
Expand Down Expand Up @@ -4599,6 +4618,11 @@
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithLimitToEndpoint(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithRegionalEndpoints(System.Collections.Generic.ISet`1[System.String])": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithRegionalEndpoints(System.Collections.Generic.ISet`1[System.String]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithRequestTimeout(System.TimeSpan)": {
"Type": "Method",
"Attributes": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ public void VerifyCosmosConfigurationPropertiesGetUpdated()
Assert.IsFalse(policy.EnablePartitionLevelFailover);
Assert.IsTrue(clientOptions.EnableAdvancedReplicaSelectionForTcp.Value);

IReadOnlyList<string> preferredLocations = new List<string>() { Regions.AustraliaCentral, Regions.AustraliaCentral2 };
IReadOnlyList<string> preferredLocations = new List<string>() { Regions.AustraliaCentral, Regions.AustraliaCentral2 };
ISet<string> regionalEndpoints = new HashSet<string>() { "https://testfed2.documents-test.windows-int.net:443/", "https://testfed4.documents-test.windows-int.net:443/" };

//Verify Direct Mode settings
cosmosClientBuilder = new CosmosClientBuilder(
accountEndpoint: endpoint,
Expand All @@ -168,7 +170,8 @@ public void VerifyCosmosConfigurationPropertiesGetUpdated()
maxTcpConnectionsPerEndpoint,
portReuseMode,
enableTcpConnectionEndpointRediscovery)
.WithApplicationPreferredRegions(preferredLocations)
.WithApplicationPreferredRegions(preferredLocations)
.WithRegionalEndpoints(regionalEndpoints)
.WithClientTelemetryOptions(new CosmosClientTelemetryOptions()
{
DisableDistributedTracing = false,
Expand All @@ -188,7 +191,8 @@ public void VerifyCosmosConfigurationPropertiesGetUpdated()
Assert.AreEqual(maxTcpConnectionsPerEndpoint, clientOptions.MaxTcpConnectionsPerEndpoint);
Assert.AreEqual(portReuseMode, clientOptions.PortReuseMode);
Assert.IsTrue(clientOptions.EnableTcpConnectionEndpointRediscovery);
CollectionAssert.AreEqual(preferredLocations.ToArray(), clientOptions.ApplicationPreferredRegions.ToArray());
CollectionAssert.AreEqual(preferredLocations.ToArray(), clientOptions.ApplicationPreferredRegions.ToArray());
CollectionAssert.AreEqual(regionalEndpoints.ToArray(), clientOptions.RegionalEndpoints.ToArray());
Assert.AreEqual(TimeSpan.FromMilliseconds(100), clientOptions.CosmosClientTelemetryOptions.CosmosThresholdOptions.PointOperationLatencyThreshold);
Assert.AreEqual(TimeSpan.FromMilliseconds(100), clientOptions.CosmosClientTelemetryOptions.CosmosThresholdOptions.NonPointOperationLatencyThreshold);
Assert.IsFalse(clientOptions.CosmosClientTelemetryOptions.DisableDistributedTracing);
Expand Down Expand Up @@ -320,6 +324,13 @@ public void CosmosClientOptions_WhenPartitionLevelFailoverEnabledAndPreferredReg
Regions.NorthCentralUS,
Regions.WestUS,
Regions.EastAsia,
})
.WithRegionalEndpoints(
new HashSet<string>()
{
"https://testfed2.documents-test.windows-int.net:443/",
"https://testfed3.documents-test.windows-int.net:443/",
"https://testfed4.documents-test.windows-int.net:443/",
});

CosmosClientOptions clientOptions = cosmosClientBuilder.Build().ClientOptions;
Expand All @@ -337,7 +348,8 @@ public void CosmosClientOptions_WhenPartitionLevelFailoverEnabledAndPreferredReg
Assert.IsFalse(clientOptions.AllowBulkExecution);
Assert.AreEqual(consistencyLevel, clientOptions.ConsistencyLevel);
Assert.IsTrue(clientOptions.EnablePartitionLevelFailover);
Assert.IsNotNull(clientOptions.ApplicationPreferredRegions);
Assert.IsNotNull(clientOptions.ApplicationPreferredRegions);
Assert.IsNotNull(clientOptions.RegionalEndpoints);
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public async Task InvalidKey_ExceptionFullStacktrace(string endpoint, string key
}
catch (Exception ex)
{
Assert.IsTrue(ex.StackTrace.Contains("GatewayAccountReader.GetDatabaseAccountAsync"), ex.StackTrace);
Assert.IsTrue(ex.StackTrace.Contains("GatewayAccountReader.InitializeReaderAsync"), ex.StackTrace);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public async Task InitializeReaderAsync_WhenRegionalEndpointsProvided_ShouldRetr
if (regionalEndpointsProvided)
{
connectionPolicy.SetRegionalEndpoints(
new List<string>()
new HashSet<string>()
{
"https://testfed2.documents-test.windows-int.net:443/",
"https://testfed3.documents-test.windows-int.net:443/",
Expand Down Expand Up @@ -193,7 +193,7 @@ public async Task InitializeReaderAsync_WhenRegionalEndpointsProvided_ShouldThro
};

connectionPolicy.SetRegionalEndpoints(
new List<string>()
new HashSet<string>()
{
"https://testfed2.documents-test.windows-int.net:443/",
"https://testfed3.documents-test.windows-int.net:443/",
Expand Down