From 02593f45fef2f64f37533823654cc62b668f604d Mon Sep 17 00:00:00 2001 From: Ivan Gavryliuk Date: Wed, 5 Feb 2020 23:51:27 +0000 Subject: [PATCH] Add Azure Table storage to the list of store providers (#323) * add Azure Table storage to the list of store providers * find & replace bug --- howto/setup-state-store/README.md | 1 + .../setup-azure-tablestorage.md | 102 ++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 howto/setup-state-store/setup-azure-tablestorage.md diff --git a/howto/setup-state-store/README.md b/howto/setup-state-store/README.md index 53244106d..c5f3446ac 100644 --- a/howto/setup-state-store/README.md +++ b/howto/setup-state-store/README.md @@ -48,6 +48,7 @@ kubectl apply -f statestore.yaml * [Setup Consul](./setup-consul.md) * [Setup Memcached](./setup-memcached.md) * [Setup Azure CosmosDB](./setup-azure-cosmosdb.md) +* [Setup Azure Table Storage](./setup-azure-tablestorage.md) * [Setup Google Cloud Firestore (Datastore mode)](./setup-firestore.md) * [Setup MongoDB](./setup-mongodb.md) * [Setup Zookeeper](./setup-zookeeper.md) diff --git a/howto/setup-state-store/setup-azure-tablestorage.md b/howto/setup-state-store/setup-azure-tablestorage.md new file mode 100644 index 000000000..c526765c7 --- /dev/null +++ b/howto/setup-state-store/setup-azure-tablestorage.md @@ -0,0 +1,102 @@ +# Setup Azure Table Storage + +## Creating Azure Storage account + +[Follow the instructions](https://docs.microsoft.com/en-us/azure/storage/common/storage-account-create?tabs=azure-portal) from the Azure documentation on how to create an Azure Storage Account. + +If you wish to create a table for Dapr to use, you can do so beforehand. However, Table Storage state provider will create one for you automatically if it doesn't exist. + +In order to setup Azure Table Storage as a state store, you will need the following properties: + +* **AccountName**: The storage account name. For example: **mystorageaccount**. +* **AccountKey**: Primary or secondary storage key. +* **TableName**: The name of the table to be used for Dapr state. The table will be created for you if it doesn't exist. + +## Create a Dapr component + +The next step is to create a Dapr component for Azure Table Storage. + +Create the following YAML file named `azuretable.yaml`: + +``` +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: +spec: + type: state.azure.tablestorage + metadata: + - name: accountName + value: + - name: accountKey + value: + - name: tableName + value: +``` + +The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described [here](../../concepts/components/secrets.md). + +The following example uses the Kubernetes secret store to retrieve the secrets: + +``` +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: +spec: + type: state.azure.tablestorage + metadata: + - name: accountName + value: + - name: accountKey + secretKeyRef: + name: + key: + - name: tableName + value: +``` + +## Apply the configuration + +### In Kubernetes + +To apply Azure Table Storage state store to Kubernetes, use the `kubectl` CLI: + +``` +kubectl apply -f azuretable.yaml +``` + +### Running locally + +The Dapr CLI will automatically create a directory named `components` in your current working directory with a Redis component. +To use Azure Table Storage, replace the redis.yaml file with azuretable.yaml file above. + +## Partitioning + +The Azure Table Storage state store will use the `key` property provided in the requests to the Dapr API to determine the `row key`. Service Name is used for `partition key`. This provides best performance, as each service type will store state in it's own table partition. + +This state store creates a column called `Value` in the table storage and puts raw state inside it. + +For example, the following operation coming from service called `myservice` + +```shell +curl -X POST http://localhost:3500/v1.0/state \ + -H "Content-Type: application/json" + -d '[ + { + "key": "nihilus", + "value": "darth" + } + ]' +``` + +will create the following record in a table: + +| PartitionKey | RowKey | Value | +| ------------ | ------- | ----- | +| myservice | nihilus | darth | + +## Concurrency + +Azure Table Storage state concurrency is achieved by using `ETag`s according to [the official documenation]( https://docs.microsoft.com/en-us/azure/storage/common/storage-concurrency#managing-concurrency-in-table-storage). +