Azure / azure-sdk-for-rust

This repository is for the active development of the Azure SDK for Rust. For consumers of the SDK we recommend visiting Docs.rs and looking up the docs for any of libraries in the SDK.
MIT License
717 stars 248 forks source link

add support for Cosmos Serverless #257

Open ctaggart opened 3 years ago

ctaggart commented 3 years ago

I get this error when trying to use a Cosmos Serverless cluster.

Setting offer throughput or autopilot on container is not supported for serverless accounts.

Steps to reproduce:

$env:COSMOS_ACCOUNT=""
$env:COSMOS_MASTER_KEY=""
cargo run --example create_delete_database dbname
MindFlavor commented 3 years ago

Calling CreateDatabase with an empty account is not supported.

On linux I'm getting:

 Error: AzureHttpError(ExecuteRequestError(reqwest::Error { kind: Request, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain(".documents.azure.com")), port: None, path: "/dbs", query: None, fragment: None }, source: hyper::Error(Connect, ConnectError("dns error", Custom { kind: Other, error: "failed to lookup address information: Name or service not known" })) }))

That's because the cosmosdb account is an element of the constructed URI.

In your case the constructed URI would be: https://.documents.azure.com/dbs which is clearly invalid.

My question is, should we return an error during client construction if the caller passes an empty string (like you did)? Right now the CosmosClient constructor if infallible.

MindFlavor commented 3 years ago

Sorry I didn't address your issue (got sidetracked by the aforementioned problem) 🤦 ...

About the offer, notice that that field is not mandatory. The example you are using valorizes it:

let create_collection_response = db_client
  .create_collection("/id")
  .indexing_policy(ip)
  .offer(Offer::Throughput(400))  // <-- this is optional
  .execute("panzadoro")
  .await?;

In order to use CosmosDB serverless you must not specify it.

It's not compile-time checked because right now there is no CosmosServelessClient. We could add it in the future and make sure the offer option is not settable.