-
Notifications
You must be signed in to change notification settings - Fork 501
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
Support multiple formats of Azure region names for CosmosClientOptions #3857
Closed
pradeep-chellappan
wants to merge
4
commits into
Azure:master
from
pradeep-chellappan:pradeepc/regionname-mapping
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d2bc95d
Allow ComosClientOptions to take ApplicationRegion and ApplicationPre…
pradeep-chellappan-ds 855e1ad
Merge branch 'master' into pradeepc/regionname-mapping
pradeep-chellappan 7abed77
Address PR comment to avoid duplicating list of names.
pradeep-chellappan-ds 91c5a62
Merge branch 'pradeepc/regionname-mapping' of https://github.com/prad…
pradeep-chellappan-ds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
//------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//------------------------------------------------------------ | ||
|
||
namespace Microsoft.Azure.Cosmos | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// Maps a normalized region name to the format that CosmosDB is expecting (for e.g. from 'westus2' to 'West US 2') | ||
/// </summary> | ||
internal class RegionNameMapping | ||
{ | ||
private static readonly IReadOnlyDictionary<string, string> normalizedToCosmosDBRegionNameMapping = | ||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) | ||
{ | ||
{"westus", Regions.WestUS}, | ||
pradeep-chellappan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{"westus2", Regions.WestUS2}, | ||
{"westcentralus", Regions.WestCentralUS}, | ||
{"eastus", Regions.EastUS}, | ||
{"eastus2", Regions.EastUS2}, | ||
{"centralus", Regions.CentralUS}, | ||
{"southcentralus", Regions.SouthCentralUS}, | ||
{"northcentralus", Regions.NorthCentralUS}, | ||
{"westeurope", Regions.WestEurope}, | ||
{"northeurope", Regions.NorthEurope}, | ||
{"eastasia", Regions.EastAsia}, | ||
{"southeastasia", Regions.SoutheastAsia}, | ||
{"japaneast", Regions.JapanEast}, | ||
{"japanwest", Regions.JapanWest}, | ||
{"australiaeast", Regions.AustraliaEast}, | ||
{"australiasoutheast", Regions.AustraliaSoutheast}, | ||
{"centralindia", Regions.CentralIndia}, | ||
{"southindia", Regions.SouthIndia}, | ||
{"westindia", Regions.WestIndia}, | ||
{"canadaeast", Regions.CanadaEast}, | ||
{"canadacentral", Regions.CanadaCentral}, | ||
{"germanycentral", Regions.GermanyCentral}, | ||
{"germanynortheast", Regions.GermanyNortheast}, | ||
{"chinanorth", Regions.ChinaNorth}, | ||
{"chinaeast", Regions.ChinaEast}, | ||
{"chinanorth2", Regions.ChinaNorth2}, | ||
{"chinaeast2", Regions.ChinaEast2}, | ||
{"koreasouth", Regions.KoreaSouth}, | ||
{"koreacentral", Regions.KoreaCentral}, | ||
{"ukwest", Regions.UKWest}, | ||
{"uksouth", Regions.UKSouth}, | ||
{"brazilsouth", Regions.BrazilSouth}, | ||
{"usgovarizona", Regions.USGovArizona}, | ||
{"usgovtexas", Regions.USGovTexas}, | ||
{"usgovvirginia", Regions.USGovVirginia}, | ||
{"eastus2euap", Regions.EastUS2EUAP}, | ||
{"centraluseuap", Regions.CentralUSEUAP}, | ||
{"francecentral", Regions.FranceCentral}, | ||
{"francesouth", Regions.FranceSouth}, | ||
{"usdodcentral", Regions.USDoDCentral}, | ||
{"usdodeast", Regions.USDoDEast}, | ||
{"australiacentral", Regions.AustraliaCentral}, | ||
{"australiacentral2", Regions.AustraliaCentral2}, | ||
{"southafricanorth", Regions.SouthAfricaNorth}, | ||
{"southafricawest", Regions.SouthAfricaWest}, | ||
{"uaecentral", Regions.UAECentral}, | ||
{"uaenorth", Regions.UAENorth}, | ||
{"usnateast", Regions.USNatEast}, | ||
{"usnatwest", Regions.USNatWest}, | ||
{"usseceast", Regions.USSecEast}, | ||
{"ussecwest", Regions.USSecWest}, | ||
{"switzerlandnorth", Regions.SwitzerlandNorth}, | ||
{"switzerlandwest", Regions.SwitzerlandWest}, | ||
{"germanynorth", Regions.GermanyNorth}, | ||
{"germanywestcentral", Regions.GermanyWestCentral}, | ||
{"norwayeast", Regions.NorwayEast}, | ||
{"norwaywest", Regions.NorwayWest}, | ||
{"brazilsoutheast", Regions.BrazilSoutheast}, | ||
{"westus3", Regions.WestUS3}, | ||
{"jioindiacentral", Regions.JioIndiaCentral}, | ||
{"jioindiawest", Regions.JioIndiaWest}, | ||
{"eastusslv", Regions.EastUSSLV}, | ||
{"swedencentral", Regions.SwedenCentral}, | ||
{"swedensouth", Regions.SwedenSouth}, | ||
{"qatarcentral", Regions.QatarCentral}, | ||
{"chinanorth3", Regions.ChinaNorth3}, | ||
{"chinaeast3", Regions.ChinaEast3}, | ||
{"polandcentral", Regions.PolandCentral}, | ||
}; | ||
|
||
/// <summary> | ||
/// Given a normalized region name, this function retrieves the region name in the format that CosmosDB expects. | ||
/// If the region is not known, the same value as input is returned. | ||
/// </summary> | ||
/// <param name="normalizedRegionName">An Azure region name in a normalized format. The input is not case sensitive.</param> | ||
/// <returns>A string that contains the region name in the format that CosmosDB expects.</returns> | ||
public static string GetCosmosDBRegionName(string normalizedRegionName) | ||
kirankumarkolli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
if (normalizedRegionName != null && normalizedToCosmosDBRegionNameMapping.TryGetValue(normalizedRegionName, out string cosmosDBRegionName)) | ||
{ | ||
return cosmosDBRegionName; | ||
} | ||
|
||
return normalizedRegionName; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Application input is updated right on setter. Functionally works.
One other alternative is to keep original values as Application configured and then later during CosmosClient initialization do conversation.
@ealsur, @FabianMeiswinkel any preferences?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer also having the original UserAgent input in the diagnostics - so, both the normalized and original values. Keeping the original value in ApplicationRegion and then client on initialization normalizing it is porbably the easiest way to get above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No preference. On the Diagnostics we log the value of the public getter:
azure-cosmos-dotnet-v3/Microsoft.Azure.Cosmos/src/Tracing/TraceData/ClientConfigurationTraceDatum.cs
Lines 28 to 29 in d7fc282
The only thing with this approach is that the getter does not return the same value that was set, so if anyone is validating that if I set West US, I get West US, the test will fail.
Making the conversion internally on:
azure-cosmos-dotnet-v3/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs
Lines 782 to 790 in d7fc282
Would achieve the same thing while keeping the getter value matching the user input.