Skip to content

Commit

Permalink
apps: workers support autoscaling (#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsomething authored Jan 6, 2025
1 parent dcdeef2 commit 035e137
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
14 changes: 14 additions & 0 deletions digitalocean/app/app_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,14 @@ func appSpecWorkerSchema() *schema.Resource {
Optional: true,
Description: "The amount of instances that this component should be scaled to.",
},
"autoscaling": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: appSpecAutoscalingSchema(),
},
},
}

for k, v := range appSpecComponentBase(workerComponent) {
Expand Down Expand Up @@ -2026,6 +2034,11 @@ func expandAppSpecWorkers(config []interface{}) []*godo.AppWorkerSpec {
s.LogDestinations = expandAppLogDestinations(logDestinations)
}

autoscaling := worker["autoscaling"].([]interface{})
if len(autoscaling) > 0 {
s.Autoscaling = expandAppAutoscaling(autoscaling)
}

appWorkers = append(appWorkers, s)
}

Expand Down Expand Up @@ -2053,6 +2066,7 @@ func flattenAppSpecWorkers(workers []*godo.AppWorkerSpec) []map[string]interface
r["environment_slug"] = w.EnvironmentSlug
r["alert"] = flattenAppAlerts(w.Alerts)
r["log_destination"] = flattenAppLogDestinations(w.LogDestinations)
r["autoscaling"] = flattenAppAutoscaling(w.Autoscaling)

result[i] = r
}
Expand Down
28 changes: 28 additions & 0 deletions digitalocean/app/resource_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,14 @@ func TestAccDigitalOceanApp_autoScale(t *testing.T) {
"digitalocean_app.foobar", "spec.0.service.0.autoscaling.0.max_instance_count", "4"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.service.0.autoscaling.0.metrics.0.cpu.0.percent", "60"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.worker.0.name", "go-worker"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.worker.0.autoscaling.0.min_instance_count", "1"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.worker.0.autoscaling.0.max_instance_count", "2"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.worker.0.autoscaling.0.metrics.0.cpu.0.percent", "80"),
),
},
},
Expand Down Expand Up @@ -1676,6 +1684,26 @@ resource "digitalocean_app" "foobar" {
}
}
}
worker {
name = "go-worker"
instance_size_slug = "apps-d-1vcpu-0.5gb"
git {
repo_clone_url = "https://github.com/digitalocean/sample-sleeper.git"
branch = "main"
}
autoscaling {
min_instance_count = 1
max_instance_count = 2
metrics {
cpu {
percent = 80
}
}
}
}
}
}`

Expand Down
6 changes: 6 additions & 0 deletions docs/data-sources/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ A `worker` can contain:
- `password` - Password for user defined in User. Is required when endpoint is set. Cannot be set if using a DigitalOcean DBaaS OpenSearch cluster.
- `index_name` - The index name to use for the logs. If not set, the default index name is `logs`.
- `cluster_name` - The name of a DigitalOcean DBaaS OpenSearch cluster to use as a log forwarding destination. Cannot be specified if endpoint is also specified.
* `autoscaling` - Configuration for automatically scaling this component based on metrics.
- `min_instance_count` - The minimum amount of instances for this component. Must be less than max_instance_count.
- `max_instance_count` - The maximum amount of instances for this component. Must be more than min_instance_count.
- `metrics` - The metrics that the component is scaled on.
- `cpu` - Settings for scaling the component based on CPU utilization.
- `percent` - The average target CPU utilization for the component.

A `job` can contain:

Expand Down
6 changes: 6 additions & 0 deletions docs/resources/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ A `worker` can contain:
- `password` - Password for user defined in User. Is required when endpoint is set. Cannot be set if using a DigitalOcean DBaaS OpenSearch cluster.
- `index_name` - The index name to use for the logs. If not set, the default index name is `logs`.
- `cluster_name` - The name of a DigitalOcean DBaaS OpenSearch cluster to use as a log forwarding destination. Cannot be specified if endpoint is also specified.
- `autoscaling` - Configuration for automatically scaling this component based on metrics.
- `min_instance_count` - The minimum amount of instances for this component. Must be less than max_instance_count.
- `max_instance_count` - The maximum amount of instances for this component. Must be more than min_instance_count.
- `metrics` - The metrics that the component is scaled on.
- `cpu` - Settings for scaling the component based on CPU utilization.
- `percent` - The average target CPU utilization for the component.

A `job` can contain:

Expand Down

0 comments on commit 035e137

Please sign in to comment.