Skip to content

Commit

Permalink
fix autoscale sql sample
Browse files Browse the repository at this point in the history
  • Loading branch information
markjbrown committed May 19, 2020
1 parent 46bc9e0 commit 6ff6311
Show file tree
Hide file tree
Showing 3 changed files with 291 additions and 0 deletions.
26 changes: 26 additions & 0 deletions 101-cosmosdb-sql-autoscale/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Create an Azure Cosmos DB account for Core (SQL) API with autoscale

![Azure Public Test Date](https://azurequickstartsservice.blob.core.windows.net/badges/101-cosmosdb-sql-autoscale/PublicLastTestDate.svg)
![Azure Public Test Result](https://azurequickstartsservice.blob.core.windows.net/badges/101-cosmosdb-sql-autoscale/PublicDeployment.svg)

![Azure US Gov Last Test Date](https://azurequickstartsservice.blob.core.windows.net/badges/101-cosmosdb-sql-autoscale/FairfaxLastTestDate.svg)
![Azure US Gov Last Test Result](https://azurequickstartsservice.blob.core.windows.net/badges/101-cosmosdb-sql-autoscale/FairfaxDeployment.svg)

![Best Practice Check](https://azurequickstartsservice.blob.core.windows.net/badges/101-cosmosdb-sql-autoscale/BestPracticeResult.svg)
![Cred Scan Check](https://azurequickstartsservice.blob.core.windows.net/badges/101-cosmosdb-sql-autoscale/CredScanResult.svg)

This template will create an Azure Cosmos account for Core (SQL) API, provisioned for two regions, a database, a container configured for autoscale with dedicated throughput showing multiple indexing and policy options.

Below are the parameters which can be user configured in the parameters file or template including:

- **Consistency Level:** Select from one of the 5 consistency levels: Strong, Bounded Staleness, Session, Consistent Prefix, Eventual.
- **Primary Region:** Enter location for the primary write region.
- **Secondary Region:** Enter location for secondary read region.
- **Automatic Failover:** Select whether to enable automatic failover on the account.
- **Database Name:** Enter the database name for the account.
- **Container Name:** Enter the name for the container for the account.
- **Throughput Policy:** Select Manual or Autoscale throughput policy.
- **Manual Provisioned Throughput:** Enter the RU/s for the container when Throughput Policy is Manual (default 400).
- **Autoscale Max Throughput:** Enter the maximum RU/s for the container when Throughput Policy is Autoscale (default 4000).

[![Deploy To Azure](https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/1-CONTRIBUTION-GUIDE/images/deploytoazure.svg?sanitize=true)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-quickstart-templates%2Fmaster%2F101-cosmosdb-sql-autoscale%2Fazuredeploy.json) [![Visualize](https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/1-CONTRIBUTION-GUIDE/images/visualizebutton.svg?sanitize=true)](http://armviz.io/#/?load=https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-quickstart-templates%2Fmaster%2F101-cosmosdb-sql-autoscale%2Fazuredeploy.json)
253 changes: 253 additions & 0 deletions 101-cosmosdb-sql-autoscale/azuredeploy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"accountName": {
"type": "string",
"defaultValue": "[concat('sql-', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Cosmos DB account name, max length 44 characters, lowercase"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for the Cosmos DB account."
}
},
"primaryRegion":{
"type":"string",
"metadata": {
"description": "The primary replica region for the Cosmos DB account."
}
},
"secondaryRegion":{
"type":"string",
"metadata": {
"description": "The secondary replica region for the Cosmos DB account."
}
},
"defaultConsistencyLevel": {
"type": "string",
"defaultValue": "Session",
"allowedValues": [
"Eventual",
"ConsistentPrefix",
"Session",
"BoundedStaleness",
"Strong"
],
"metadata": {
"description": "The default consistency level of the Cosmos DB account."
}
},
"maxStalenessPrefix": {
"type": "int",
"minValue": 10,
"defaultValue": 100000,
"maxValue": 2147483647,
"metadata": {
"description": "Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 1000000. Multi Region: 100000 to 1000000."
}
},
"maxIntervalInSeconds": {
"type": "int",
"minValue": 5,
"defaultValue": 300,
"maxValue": 86400,
"metadata": {
"description": "Max lag time (minutes). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400."
}
},
"automaticFailover": {
"type": "bool",
"defaultValue": true,
"allowedValues": [
true,
false
],
"metadata": {
"description": "Enable automatic failover for regions"
}
},
"databaseName": {
"type": "string",
"metadata": {
"description": "The name for the database"
}
},
"containerName": {
"type": "string",
"metadata": {
"description": "The name for the container"
}
},
"throughputPolicy":{
"type": "string",
"defaultValue": "Autoscale",
"allowedValues": [ "Manual", "Autoscale" ],
"metadata": {
"description": "The throughput policy for the Container"
}
},
"manualProvisionedThroughput": {
"type": "int",
"defaultValue": 400,
"minValue": 400,
"maxValue": 1000000,
"metadata": {
"description": "Throughput value when using Manual Throughput Policy for the container"
}
},
"autoscaleMaxThroughput": {
"type": "int",
"defaultValue": 4000,
"minValue": 4000,
"maxValue": 1000000,
"metadata": {
"description": "Maximum throughput when using Autoscale Throughput Policy for the container"
}
}
},
"variables": {
"accountName": "[toLower(parameters('accountName'))]",
"consistencyPolicy": {
"Eventual": {
"defaultConsistencyLevel": "Eventual"
},
"ConsistentPrefix": {
"defaultConsistencyLevel": "ConsistentPrefix"
},
"Session": {
"defaultConsistencyLevel": "Session"
},
"BoundedStaleness": {
"defaultConsistencyLevel": "BoundedStaleness",
"maxStalenessPrefix": "[parameters('maxStalenessPrefix')]",
"maxIntervalInSeconds": "[parameters('maxIntervalInSeconds')]"
},
"Strong": {
"defaultConsistencyLevel": "Strong"
}
},
"locations": [
{
"locationName": "[parameters('primaryRegion')]",
"failoverPriority": 0,
"isZoneRedundant": false
},
{
"locationName": "[parameters('secondaryRegion')]",
"failoverPriority": 1,
"isZoneRedundant": false
}
],
"throughputPolicy": {
"Manual": {
"throughput": "[parameters('manualProvisionedThroughput')]"
},
"Autoscale": {
"autoscaleSettings": {
"maxThroughput": "[parameters('autoscaleMaxThroughput')]"
}
}
},
"throughputPolicyToUse": "[if(equals(parameters('throughputPolicy'), 'Manual'), variables('throughputPolicy').Manual, variables('throughputPolicy').Autoscale)]"
},
"resources": [
{
"type": "Microsoft.DocumentDB/databaseAccounts",
"name": "[variables('accountName')]",
"apiVersion": "2020-04-01",
"kind": "GlobalDocumentDB",
"location": "[parameters('location')]",
"properties": {
"consistencyPolicy": "[variables('consistencyPolicy')[parameters('defaultConsistencyLevel')]]",
"locations": "[variables('locations')]",
"databaseAccountOfferType": "Standard",
"enableAutomaticFailover": "[parameters('automaticFailover')]"
}
},
{
"type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases",
"name": "[concat(variables('accountName'), '/', parameters('databaseName'))]",
"apiVersion": "2020-04-01",
"dependsOn": [
"[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('accountName'))]"
],
"properties":{
"resource":{
"id": "[parameters('databaseName')]"
}
}
},
{
"type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers",
"name": "[concat(variables('accountName'), '/', parameters('databaseName'), '/', parameters('containerName'))]",
"apiVersion": "2020-04-01",
"dependsOn": [
"[resourceId('Microsoft.DocumentDB/databaseAccounts/sqlDatabases', variables('accountName'), parameters('databaseName'))]"
],
"properties":
{
"resource":{
"id": "[parameters('containerName')]",
"partitionKey": {
"paths": [
"/myPartitionKey"
],
"kind": "Hash"
},
"indexingPolicy": {
"indexingMode": "consistent",
"includedPaths": [
{
"path": "/*"
}
],
"excludedPaths": [
{
"path": "/myPathToNotIndex/*"
}
],
"compositeIndexes":[
[
{
"path":"/name",
"order":"ascending"
},
{
"path":"/age",
"order":"descending"
}
]
],
"spatialIndexes": [
{
"path": "/path/to/geojson/property/?",
"types": [
"Point",
"Polygon",
"MultiPolygon",
"LineString"
]
}
]
},
"defaultTtl": 86400,
"uniqueKeyPolicy": {
"uniqueKeys": [
{
"paths": [
"/phoneNumber"
]
}
]
}
},
"options": "[variables('throughputPolicyToUse')]"
}
}
]
}
12 changes: 12 additions & 0 deletions 101-cosmosdb-sql-autoscale/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://aka.ms/azure-quickstart-templates-metadata-schema#",
"type": "QuickStart",
"itemDisplayName": "Create an Azure Cosmos DB account SQL API with autoscale",
"description": "This template creates an Azure Cosmos account for Core (SQL) API with a database and container with autoscale throughput with multiple other options.",
"summary": "This template creates an Azure Cosmos account for Core (SQL) API with a database and container with autoscale throughput with multiple other options.",
"githubUsername": "markjbrown",
"dateUpdated": "2020-05-19",
"environments": [
"AzureCloud"
]
}

0 comments on commit 6ff6311

Please sign in to comment.