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

Support autoscaling Cosmos DB databases and containers #7773

Merged
merged 25 commits into from
Sep 14, 2020
Merged

Support autoscaling Cosmos DB databases and containers #7773

merged 25 commits into from
Sep 14, 2020

Conversation

marc-sensenich
Copy link
Contributor

@marc-sensenich marc-sensenich commented Jul 16, 2020

Adds support for enabling autoscaling Cosmos DB databases and containers

Depends on fix for issue #7825 for testing
Depends on #7597 (merged in v2.20.0)
Closes #6164
Closes #7315

Example Usage

resource "azurerm_cosmosdb_sql_database" "autoscale" {
  account_name        = "myaccount"
  name                = "mydb"
  resource_group_name = "myrg"

  autoscale_settings {
    max_throughput = 4000
  }
}

Test Status

Run with commit 324d259

Passing

--- PASS: TestAccAzureRMCosmosDbCassandraKeyspace_basic (1330.26s)
--- PASS: TestAccAzureRMCosmosDbCassandraKeyspace_complete (1525.71s)
--- PASS: TestAccAzureRMCosmosDbCassandraKeyspace_update (1582.38s)
--- PASS: TestAccAzureRMCosmosDbCassandraKeyspace_autoscale (1778.28s)
--- PASS: TestAccAzureRMCosmosGremlinDatabase_requiresImport (1376.95s)
--- PASS: TestAccAzureRMCosmosGremlinDatabase_basic (1422.04s)
--- PASS: TestAccAzureRMCosmosGremlinDatabase_complete (1563.30s)
--- PASS: TestAccAzureRMCosmosGremlinDatabase_autoscale (1735.37s)
--- PASS: TestAccAzureRMCosmosDbGremlinGraph_requiresImport (1466.30s)
--- PASS: TestAccAzureRMCosmosDbGremlinGraph_customConflictResolutionPolicy (1498.55s)
--- PASS: TestAccAzureRMCosmosDbGremlinGraph_basic (1548.04s)
--- PASS: TestAccAzureRMCosmosDbGremlinGraph_indexPolicy (1610.39s)
--- PASS: TestAccAzureRMCosmosDbGremlinGraph_autoscale (1739.45s)
--- PASS: TestAccAzureRMCosmosDbGremlinGraph_update (1777.58s)
--- PASS: TestAccAzureRMCosmosDbMongoCollection_basic (1413.85s)
--- PASS: TestAccAzureRMCosmosDbMongoCollection_throughput (1624.28s)
--- PASS: TestAccAzureRMCosmosDbMongoCollection_autoscale (1744.72s)
--- PASS: TestAccAzureRMCosmosDbMongoDatabase_complete (1302.42s)
--- PASS: TestAccAzureRMCosmosDbMongoDatabase_basic (1307.51s)
--- PASS: TestAccAzureRMCosmosDbMongoDatabase_autoscale (1618.07s)
--- PASS: TestAccAzureRMCosmosDbSqlDatabase_basic (1350.69s)
--- PASS: TestAccAzureRMCosmosDbSqlDatabase_update (1500.18s)
--- PASS: TestAccAzureRMCosmosDbSqlDatabase_autoscale (1728.33s)
--- PASS: TestAccAzureRMCosmosDbSqlContainer_complete (1426.93s)
--- PASS: TestAccAzureRMCosmosDbSqlContainer_basic (1427.35s)
--- PASS: TestAccAzureRMCosmosDbSqlContainer_update (1572.95s)
--- PASS: TestAccAzureRMCosmosDbSqlContainer_autoscale (1734.78s)
--- PASS: TestAccAzureRMCosmosDbTable_basic (1380.36s)
--- PASS: TestAccAzureRMCosmosDbTable_autoscale (1788.62s)
--- PASS: TestAccAzureRMCosmosDbTable_update (1918.18s)

Failing

These failing tests are related to #7825

--- FAIL: TestAccAzureRMCosmosDbMongoCollection_complete (1459.93s)
--- FAIL: TestAccAzureRMCosmosDbMongoCollection_withIndex (1502.19s)
--- FAIL: TestAccAzureRMCosmosDbMongoCollection_update (1639.81s)

@ghost ghost added the size/XXL label Jul 16, 2020
@marc-sensenich marc-sensenich marked this pull request as draft July 16, 2020 02:43
@marc-sensenich marc-sensenich marked this pull request as ready for review July 21, 2020 10:52

func CheckForChangeFromAutoscaleAndManualThroughput(d *schema.ResourceData) error {
if d.HasChange("throughput") && d.HasChange("autoscale_settings") {
return fmt.Errorf("Switching between autoscale and manual provisioned throughput is not supported at this time.")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From https://docs.microsoft.com/en-us/azure/cosmos-db/autoscale-faq#can-i-enable-autoscale-on-an-existing-database-or-a-container

Yes. You can also switch between autoscale and standard (manual) provisioned throughput as needed. Currently, for all APIs, you can only use the Azure portal to do these operations.

Based on this and no clear documented API for toggling back and forth, I've decided to not allow this operation

Copy link
Contributor

Choose a reason for hiding this comment

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

There are some documented endpoints for migrating between autoscale and manual throughput (e.g. https://docs.microsoft.com/en-us/rest/api/cosmos-db-resource-provider/2020-04-01/tableresources/migratetabletoautoscale) however I couldn't find SDK support, so this seems fine 👍

@simongottschlag
Copy link

How is this PR going? 👍

@nadworny
Copy link

nadworny commented Aug 6, 2020

Does this PR also apply for azurerm_cosmosdb_mongo_database or only sql?

@marc-sensenich
Copy link
Contributor Author

marc-sensenich commented Aug 6, 2020

@simongottschlag this PR is complete and just awaiting review from an approver based on their priorities

@nadworny this PR covers all Cosmos APIs that are supported by Terraform today

@WodansSon WodansSon added this to the v2.24.0 milestone Aug 14, 2020
@WodansSon WodansSon requested a review from katbyte August 14, 2020 22:46
Copy link
Collaborator

@WodansSon WodansSon left a comment

Choose a reason for hiding this comment

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

@marc-sensenich, thank you so much for submitting this PR. It's looking really good I just left a few minor comments that I would like your input on. Once the changes are made this will LGTM! 🚀

@@ -42,3 +42,24 @@ func CosmosThroughput(v interface{}, k string) (warnings []string, errors []erro

return warnings, errors
}

func CosmosMaxThroughput(v interface{}, k string) (warnings []string, errors []error) {
value := v.(int)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we validate the type here to avoid a panic if the wrong type is passed?

Suggested change
value := v.(int)
v, ok := i.(int)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %q to be int", k))
return
}

@@ -42,3 +42,24 @@ func CosmosThroughput(v interface{}, k string) (warnings []string, errors []erro

return warnings, errors
}

func CosmosMaxThroughput(v interface{}, k string) (warnings []string, errors []error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we change v to be i to be consistent with the rest of the provider code?

Suggested change
func CosmosMaxThroughput(v interface{}, k string) (warnings []string, errors []error) {
func CosmosMaxThroughput(i interface{}, k string) (warnings []string, errors []error) {

func CosmosMaxThroughput(v interface{}, k string) (warnings []string, errors []error) {
value := v.(int)

if value < 4000 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we switch all of the value variables to be v as well?

Suggested change
if value < 4000 {
if v < 4000 {

@marc-sensenich
Copy link
Contributor Author

@WodansSon I've made the requested changes in 7684202.

@tombuildsstuff tombuildsstuff modified the milestones: v2.24.0, v2.25.0 Aug 20, 2020
@marc-sensenich
Copy link
Contributor Author

@WodansSon or @katbyte are there any further changes you'd like to see in this PR?

@tombuildsstuff tombuildsstuff modified the milestones: v2.25.0, v2.26.0 Aug 27, 2020
@joshatcaper
Copy link

Hey @tombuildsstuff it looks like this is tagged for v2.26.0 and that seems to be due tomorrow. Is this going to make the merge window for that? I have a lot of use cases that could benefit from this and I'm really hoping we can start making use of this.

@tombuildsstuff tombuildsstuff modified the milestones: v2.26.0, v2.27.0 Sep 3, 2020
marc-sensenich and others added 19 commits September 11, 2020 13:26
@marc-sensenich
Copy link
Contributor Author

@manicminer I've addressed your most recent comments. I'll run the full test-suite for Cosmos DB this evening and update this PR with the results

@marc-sensenich
Copy link
Contributor Author

@manicminer Cosmos DB database and collection acceptance tests have been run from 324d259 and are passing as noted in the initial PR message

@manicminer
Copy link
Contributor

Test results:

Autoscaling:
Screenshot 2020-09-14 at 09 06 58

All (3 unrelated failures):
Screenshot 2020-09-14 at 09 08 12

@manicminer manicminer merged commit 0c2aab3 into hashicorp:master Sep 14, 2020
manicminer added a commit that referenced this pull request Sep 14, 2020
@jonnekleijer
Copy link

@marc-sensenich

Hi Marc, thanks for doing this great work! Does this mean we can already use this functionality in Azure? I was looking at the documentation and there the autoscale option was not (yet) added.

@marc-sensenich
Copy link
Contributor Author

marc-sensenich commented Sep 16, 2020

@jonnekleijer this functionality will be available in the AzureRM provider in the yet to be released 2.28.0 version

@ghost
Copy link

ghost commented Sep 17, 2020

This has been released in version 2.28.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.28.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Oct 14, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Oct 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable autoscaling for azurerm_cosmosdb_gremlin_graph Support for cosmos db autopilot container
9 participants