Azure / azure-cosmos-dotnet-v3

.NET SDK for Azure Cosmos DB for the core SQL API
MIT License
731 stars 489 forks source link

How to check if a Cosmos DB account is a serverless account? #1901

Open thomaslevesque opened 3 years ago

thomaslevesque commented 3 years ago

There doesn't seem to be any way to check if an account is serverless. ReadAccountAsync returns some properties, but nothing that lets me check the type of account.

Calling ReadThroughputAsync on a database or container on a serverless account returns a 400 response, so I guess I could use that; but if there isn't a database yet, I can't even do that.

Is there a way with the SDK to check if an account is serverless? Even the REST API documentation doesn't say anything about that...

ThomasWeiss commented 3 years ago

Hi @thomaslevesque, right now the only way to check if an account is serverless is by trying to read the throughput of an existing container, or trying to create a container by explicitly passing some throughput. Both these operations will fail on a serverless account with an explicit error message. We acknowledge that there is a gap here and that we should provide a better way to do this check through our SDKs. This gap will be addressed as serverless goes GA.

thomaslevesque commented 3 years ago

Hi @ThomasWeiss, thanks for your reply. In the meantime, is this information available in the REST API?

ThomasWeiss commented 3 years ago

@thomaslevesque yes the REST API should behave similarly, i.e. trying to read "offers" should return the same error

thomaslevesque commented 3 years ago

@ThomasWeiss thanks, but I meant an API not exposed in the SDK, that would explicitly return the information that it's a serverless account, not something that returns an error when I try. Maybe an undocumented REST endpoint? For instance, it looks like ReadAccountAsync makes a request to the root account endpoint, but this endpoint isn't mentioned in the REST API doc. I tried to call it myself to see what it returns, but I was unable to generate an appropriate authorization token (I don't know which value to use for resourceType and resourceLink).

ThomasWeiss commented 3 years ago

@thomaslevesque no I'm afraid that no underlying data plane API would return the information you're looking for. The only place where you would find the information is by reading your account from our control plane API; this call would return an EnableServerless entry in the capabilities property, but be aware that this is something that may change as the feature goes GA (hence, not documented).

thomaslevesque commented 3 years ago

Ah, I see. Unfortunately in my scenario I can't call the resource provider API, and attempting to create a container isn't an acceptable approach either. I guess I'll just have to wait for the feature to go GA. Thanks!

sdg002 commented 3 years ago

Any recent updates on this problem?
I have a similar requirement.

Determine the capabilities of the Account (serverless or not) and accordingly enable Analytical store.

ThomasWeiss commented 3 years ago

@sdg002 This is still being worked on as we plan an update to the programming model of Cosmos DB's serverless offer. Note that we're also lifting the restriction that prevents you from enabling the analytical store on a serverless account - this change should be deployed in 4 to 6 weeks.

sdg002 commented 3 years ago

@ThomasWeiss Thanks for the quick response.

MrFixiter commented 1 year ago

@ThomasWeiss - Just checking if there is any update on this. Specifically, if the existing instance of Cosmos DB is Serverless or Provisioned?

ThomasWeiss commented 1 year ago

I'm not working on Cosmos DB anymore, adding @deborahc who might know the answer.

MrFixiter commented 1 year ago

It seems it has been added as a Capacity Mode under Overview blade of the CosmosDB.

Additionally, you can run the below PowerShell command to find the same,

$CosmosDBDetails = (Get-AzCosmosDBAccount -Name $CosmosDB -ResourceGroupName $RGName) $CosmosDBDetails.Capabilities

thomaslevesque commented 1 year ago

@MrFixiter I needed to do this from the .NET SDK, and I can't use the resource provider API (I only have the connection string for the account, not Azure credentials)