Azure-docs: Verify Readable Locations property

Created on 2 Sep 2019  Â·  12Comments  Â·  Source: MicrosoftDocs/azure-docs

The example to find the readable locations using REST API is the below URL.
_https://{databaseaccount}.documents.azure.com/_

However, this URL does not seem to work . In the page the results can be seen for the url which provides the readable locations set based on preferred locations policy. How can we find if the client indeed tried the locations in the order of the preference given?

When I tried the above url using a postman collection , I got the following error
_Unauthorized - The input authorization token can't serve the request._

We tried setting the locations using ConnectionPolicy preferred locations in .Net V2 SDK and using the ClientOptions Application Region in .Net V3 SDK.
Both give the response for the readendpoint and writeendpoint as _https://{databaseaccount}.documents.azure.com/_

Is there a way to get the region-specific read and write endpoints used by client (DocumentClient/CosmosClient) in Cosmos (like _https://contoso-westus.documents.azure.com:443/_
provided in the Cosmos V3 Tests folder). How can we verify multi region read and writes using the SDK?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri2 cosmos-dsvc cxp product-question triaged

All 12 comments

@karthiksubramanians Did you see the detail in the .NET SDK section? It appears something is not resolving correctly for you. Does your client code look something like the following:

//Setting read region selection preference
connectionPolicy.PreferredLocations.Add(LocationNames.WestUS); // first preference
connectionPolicy.PreferredLocations.Add(LocationNames.EastUS); // second preference
connectionPolicy.PreferredLocations.Add(LocationNames.NorthEurope); // third preference

Can you provide an example of the code being used by the client?

@Mike-Ubezzi-MSFT Thanks for the response. I did not have a problem with creating preferred locations property in .NET. My issues are:

  1. The REST API url that was provided in the page to check the locations is not working.
  2. The read and write endpoint property after creating the client gives the generic URI like _https://contoso.documents.azure.com:443/_ instead of region specific URI like _https://contoso-westus.documents.azure.com:443/_
  3. How to verify which region the request went to and the list of all regions associated with the database account.

Currently the only way we could measure, is by comparing the response time between different regions, but we need a more explicit way to determine the specific region.

Thanks for all the help.

From the error for the REST call, it looks like the auth token was incorrect. Using SDK, you can call GetDatabaseAccountAsync to list all the read and write endpoints.

ReadEndpoint and WriteEndpoint will point to the regional DNS addresses if the PreferredLocations is setup. Like Mike mentioned, if you send sample code, we can check.

This is the code I am using to set preferred locations:

ConnectionPolicy connectionPolicyNA = new ConnectionPolicy();
 connectionPolicyNA.EnableEndpointDiscovery = true;
 connectionPolicyNA.PreferredLocations.Add(LocationNames.CentralUS); // first preference
 connectionPolicyNA.PreferredLocations.Add(LocationNames.SouthIndia); // second preference
 DocumentClient clientNA = new DocumentClient(new Uri(endpoint), authKey, connectionPolicyNA);


   log.LogInformation(clientNA.ReadEndpoint.ToString());
   log.LogInformation(clientNA.WriteEndpoint.ToString());

The logs show that the read and write endpoint are still pointing to the portal endpoints and not the regional specific endpoints.

Regarding REST API, i created the postman collection for azure services and all other rest calls like databases, collections, querying documents is working fine. Is the authorization for the regions only different from all other requests. I have attached my postman collection for azure in which all other requests are working fine. Thanks for all the help.

AzureRestCollection.zip

I would recommend a few things here:

First, can you please call OpenAsync before checking for the endpoints. This will ensure that the client is initialized and it has fetched the data from the server. Additionally, since you were looking to find out the regions where the requests were being sent, can you please make the calls to perform the operations and check the endpoints? Please let me know. Thanks!

@karthiksubramanians Do you have any additional questions, and did this information help you? Additionally, the REST reference needs to have the {databaseaccount} portion updated with your specific account name. If you are replacing {databaseaccount} and still receiving an error, can you please be more specific with the error message.

https://{databaseaccount}.documents.azure.com/

The recommendations above should allow your client to have specific account information for the responses to be valid but did want to be sure this is the case.

Apologies for the late reply..

I was able to find the locations in v2 of SDK with the following code.

DatabaseAccount DbAccount = await client.GetDatabaseAccountAsync();
 IEnumerable<DatabaseAccountLocation> writeLocations = DbAccount.WritableLocations;
 IEnumerable<DatabaseAccountLocation> readLocations = DbAccount.ReadableLocations;

While this answers my primary question, the REST API part from the documentation is still not working.

For _https://{{DocumentDBHost}}/dbs_ with appropriate value filled in, I am getting the proper response with the databases metadata.

{
"_rid": "",
"Databases": [
{
"id": "",
"_rid": "==",
"_self": "dbs/==/",
"_etag": "",
"_colls": "colls/",
"_users": "users/",
"_ts": 1564158116
}
],
"_count": 1
}

But for _https://{{DocumentDBHost}}_ , it is giving this error:

"code": "Unauthorized",
"message": "The input authorization token can't serve the request. Please check that the expected payload is built as per the protocol, and check the key being used. Server used the following payload to sign: 'get\n\n\nthu, 05 sep 2019 21:01:04 gmt\n\n'\r\nActivityId: 4cfa94e1-871e-4cb2-8808-79af45040576, Microsoft.Azure.Documents.Common/2.5.1"

@karthiksubramanians Thank you for this additional detail! I will verify this and make a doc update accordingly.

It looks like auth token generated for the root endpoint is not correct. Can you please try with empty string for resource type and resource id? If you still run into issue, I will pull in more folks who can help with this.

Is this comment for @Mike-Ubezzi-MSFT ? If it is for me, could you provide some clarification? Should I give empty string for the url endpoint or in the pre-request script?

@karthiksubramanians Please follow instruction from @sharma-pankaj and let us know the results or questions. We are closing this thread as this moment no doc enhancement is required. But we can definitely continue the dialogue depending on your question.

I was able to get it to work based on the instructions. Thanks to everyone for your help!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bityob picture bityob  Â·  3Comments

ianpowell2017 picture ianpowell2017  Â·  3Comments

spottedmahn picture spottedmahn  Â·  3Comments

Agazoth picture Agazoth  Â·  3Comments

JamesDLD picture JamesDLD  Â·  3Comments