Skip to content
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

Add Azure CosmosDB implementation for KV #1463

Merged
merged 5 commits into from
May 18, 2023

Conversation

radu-matei
Copy link
Member

@radu-matei radu-matei commented May 8, 2023

This commit adds an implementation of Azure CosmosDB as a backend for Spin's key/value store.
Specifically, this uses a CosmosDB account created with the NoSQL API, and requires the following contents for the runtime configuration file:

[key_value_store.default]
type = "azure_cosmos"
key = "<key>"
account = "<cosmos-account>"
database = "<cosmos-database>"
container = "<cosmos-container>"

The CosmosDB container must be created with the default partition key, /id:

Screenshot 2023-05-07 at 15 47 05

To test the changes in this commit, the runtime configuration file above
can be passed (and can be further tested with the KV explorer template):

$ spin up --runtime-config-file runtime-config.toml --key-value keyfromcli=valuefromcli 
Storing default key-value data to Azure CosmosDB

Thanks to @fibonacci1729 for pairing on this one!

cc @Mossaka @devigned

async fn get_keys(&self) -> Result<Vec<String>, Error> {
let client = self.client.lock().await;
let query = client
.query_documents(Query::new("SELECT * FROM c".to_string()))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can tweak the query to only return c.id instead of the entire document?

@michelleN michelleN added this to the 1.2.0 milestone May 8, 2023
Copy link
Contributor

@Mossaka Mossaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

crates/key-value-azure/src/lib.rs Outdated Show resolved Hide resolved
crates/key-value-azure/src/lib.rs Outdated Show resolved Hide resolved
This commit adds an implementation of Azure CosmosDB as a backend for
Spin's key/value store.
Specifically, this uses a CosmosDB account created with the NoSQL API,
and requires the following contents for the runtime configuration file:

```toml
[key_value_store.default]
type = "azure_cosmos"
key = "<key>"
account = "<cosmos-account>"
database = "<cosmos-database>"
container = "<cosmos-container>"

The CosmosDB container *must* be created with the default partition key, `/id`.

To test the changes in this commit, the runtime configuration file above
can be passed (and can be further tested with the KV explorer template):

```bash
$ spin up --runtime-config-file runtime-config.toml --key-value keyfromcli=valuefromcli
Storing default key-value data to Azure CosmosDB
```

Signed-off-by: Radu Matei <radu.matei@fermyon.com>

Update CosmosDB backend for KV

Signed-off-by: Radu Matei <radu.matei@fermyon.com>

Update CosmosDB backend for KV

Signed-off-by: Radu Matei <radu.matei@fermyon.com>

Update CosmosDB backend for KV

Signed-off-by: Radu Matei <radu.matei@fermyon.com>
crates/key-value-azure/src/lib.rs Outdated Show resolved Hide resolved
crates/key-value-azure/src/lib.rs Outdated Show resolved Hide resolved
crates/key-value-azure/src/lib.rs Show resolved Hide resolved
crates/key-value-azure/src/lib.rs Outdated Show resolved Hide resolved
crates/key-value-azure/src/lib.rs Outdated Show resolved Hide resolved
crates/trigger/Cargo.toml Outdated Show resolved Hide resolved
crates/trigger/src/runtime_config/key_value.rs Outdated Show resolved Hide resolved
radu-matei and others added 2 commits May 10, 2023 14:13
This commit removes the `OnceCell` dependency from the Azure CosmosDB
backend for KV and simplifies the client setup and creation.

Co-authored-by: Ryan Levick <ryan.levick@fermyon.com>
Signed-off-by: Radu Matei <radu.matei@fermyon.com>
Signed-off-by: Radu Matei <radu.matei@fermyon.com>
@radu-matei
Copy link
Member Author

@rylev and I paired on this earlier today and addressed most of the feedback. This should be ready for a re-review.

Thanks!

Copy link
Contributor

@Mossaka Mossaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just have one comment there.

crates/key-value-azure/src/lib.rs Outdated Show resolved Hide resolved
The Spin key-value API for `delete` states that "no error is raised if a tuple did
not previously exist for key".

This commit updates the Azure CosmosDB implementation to follow that.

Signed-off-by: Radu Matei <radu.matei@fermyon.com>
Signed-off-by: Radu Matei <radu.matei@fermyon.com>
rylev

This comment was marked as duplicate.

Copy link
Collaborator

@rylev rylev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@tpmccallum
Copy link
Contributor

tpmccallum commented May 15, 2023

Documentation for this is being worked on at fermyon/developer#611 and fermyon/developer#648

@radu-matei radu-matei merged commit 75e065b into fermyon:main May 18, 2023
@radu-matei radu-matei deleted the feat/kv-azure-cosmos branch May 18, 2023 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants