Skip to content

Commit ca70fb6

Browse files
feat: Increase ECS autoscaling capacity (#907)
* feat: Increase ECS autoscaling capacity * chore: Add changeset * fix: Cpu low alarm and scaling adjustment as var * feat: Set ecs min and max capacity switch region workflow * fix: Set correct ecs scaling values --------- Co-authored-by: GNuccio96 <giuseppenuccio.crea@pagopa.it>
1 parent e1f9d75 commit ca70fb6

File tree

14 files changed

+47
-40
lines changed

14 files changed

+47
-40
lines changed

.changeset/quiet-birds-wait.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"infra": minor
3+
"oneidentity": minor
4+
---
5+
6+
Increased autoscaling capacity of ecs-core tasks for bonus elettrodomestici

.github/workflows/switch-region.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
--service-namespace ecs \
2929
--scalable-dimension ecs:service:DesiredCount \
3030
--resource-id service/$ECS_CLUSTER_NAME/$ECS_SERVICE_NAME \
31-
--min-capacity 3 \
31+
--min-capacity 60 --max-capacity 1000 \
3232
--region eu-central-1
3333
3434
@@ -38,7 +38,7 @@ jobs:
3838
aws ecs update-service \
3939
--cluster $ECS_CLUSTER_NAME \
4040
--service $ECS_SERVICE_NAME \
41-
--desired-count 3 \
41+
--desired-count 60 \
4242
--region eu-central-1
4343
4444
- name: Wait for ECS Service to stabilize

src/infra/dev/eu-south-1/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ module "backend" {
195195
vpc_cidr_block = module.network.vpc_cidr_block
196196

197197
service_core = {
198-
service_name = format("%s-core", local.project)
199-
200-
cpu = var.ecs_oneid_core.cpu
201-
memory = var.ecs_oneid_core.memory
198+
service_name = format("%s-core", local.project)
199+
cpu = var.ecs_oneid_core.cpu
200+
memory = var.ecs_oneid_core.memory
201+
cpu_high_scaling_adjustment = 2
202202

203203
container = {
204204
name = "oneid-core"

src/infra/dev/eu-south-1/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,8 @@ variable "ecs_alarms" {
475475
namespace = "AWS/ECS"
476476
evaluation_periods = 3
477477
comparison_operator = "LessThanOrEqualToThreshold"
478-
threshold = 20
479-
period = 900
478+
threshold = 5
479+
period = 300
480480
statistic = "Average"
481481
scaling_policy = "cpu_low"
482482
},

src/infra/modules/backend/ecs.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ module "ecs_core_service" {
426426
"adjustment_type" : "ChangeInCapacity"
427427
"step_adjustment" : [
428428
{
429-
"scaling_adjustment" : 2 # Add 2 tasks
429+
"scaling_adjustment" : var.service_core.cpu_high_scaling_adjustment # Add 10 tasks
430430
metric_interval_lower_bound = 0
431431
}
432432
]
@@ -439,11 +439,11 @@ module "ecs_core_service" {
439439
"adjustment_type" : "ChangeInCapacity"
440440
"step_adjustment" : [
441441
{
442-
"scaling_adjustment" : -1 # Add 2 tasks
442+
"scaling_adjustment" : -1 # Remove 1 task
443443
metric_interval_lower_bound = 0
444444
}
445445
]
446-
cooldown = 900
446+
cooldown = 300
447447
}
448448
}
449449
}

src/infra/modules/backend/variables.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ variable "fargate_capacity_providers" {
6666

6767
variable "service_core" {
6868
type = object({
69-
service_name = string
70-
cpu = number
71-
memory = number
72-
enable_execute_command = optional(bool, true)
69+
service_name = string
70+
cpu = number
71+
memory = number
72+
enable_execute_command = optional(bool, true)
73+
cpu_high_scaling_adjustment = number
7374
container = object({
7475
name = string
7576
cpu = number

src/infra/prod/eu-central-1/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ No outputs.
131131
| <a name="input_dns_record_ttl"></a> [dns\_record\_ttl](#input\_dns\_record\_ttl) | Dns record ttl (in sec) | `number` | `86400` | no |
132132
| <a name="input_ecs_alarms"></a> [ecs\_alarms](#input\_ecs\_alarms) | n/a | <pre>map(object({<br/> metric_name = string<br/> namespace = string<br/> threshold = optional(number)<br/> evaluation_periods = optional(number)<br/> period = optional(number)<br/> statistic = optional(string)<br/> comparison_operator = optional(string)<br/> scaling_policy = optional(string, null)<br/> }))</pre> | <pre>{<br/> "cpu_high": {<br/> "comparison_operator": "GreaterThanOrEqualToThreshold",<br/> "evaluation_periods": 1,<br/> "metric_name": "CPUUtilization",<br/> "namespace": "AWS/ECS",<br/> "period": 60,<br/> "scaling_policy": "cpu_high",<br/> "statistic": "Average",<br/> "threshold": 50<br/> },<br/> "cpu_low": {<br/> "comparison_operator": "LessThanOrEqualToThreshold",<br/> "evaluation_periods": 3,<br/> "metric_name": "CPUUtilization",<br/> "namespace": "AWS/ECS",<br/> "period": 900,<br/> "scaling_policy": "cpu_low",<br/> "statistic": "Average",<br/> "threshold": 20<br/> },<br/> "mem_high": {<br/> "comparison_operator": "GreaterThanOrEqualToThreshold",<br/> "evaluation_periods": 1,<br/> "metric_name": "MemoryUtilization",<br/> "namespace": "AWS/ECS",<br/> "period": 60,<br/> "statistic": "Average",<br/> "threshold": 70<br/> }<br/>}</pre> | no |
133133
| <a name="input_ecs_enable_container_insights"></a> [ecs\_enable\_container\_insights](#input\_ecs\_enable\_container\_insights) | Enable ecs cluster container inight. | `bool` | `true` | no |
134-
| <a name="input_ecs_oneid_core"></a> [ecs\_oneid\_core](#input\_ecs\_oneid\_core) | Oneidentity core backend configurations. | <pre>object({<br/> image_version = string<br/> cpu = number<br/> memory = number<br/> container_cpu = number<br/> container_memory = number<br/> autoscaling = object({<br/> enable = bool<br/> desired_count = number<br/> min_capacity = number<br/> max_capacity = number<br/> })<br/> logs_retention_days = number<br/> app_spid_test_enabled = optional(bool, false)<br/> })</pre> | <pre>{<br/> "autoscaling": {<br/> "desired_count": 1,<br/> "enable": true,<br/> "max_capacity": 12,<br/> "min_capacity": 1<br/> },<br/> "container_cpu": 2048,<br/> "container_memory": 4096,<br/> "cpu": 2048,<br/> "image_version": "05d9825a488fc80c2b8cd08d69e55732d4762977",<br/> "logs_retention_days": 30,<br/> "memory": 4096<br/>}</pre> | no |
134+
| <a name="input_ecs_oneid_core"></a> [ecs\_oneid\_core](#input\_ecs\_oneid\_core) | Oneidentity core backend configurations. | <pre>object({<br/> image_version = string<br/> cpu = number<br/> memory = number<br/> container_cpu = number<br/> container_memory = number<br/> autoscaling = object({<br/> enable = bool<br/> desired_count = number<br/> min_capacity = number<br/> max_capacity = number<br/> })<br/> logs_retention_days = number<br/> app_spid_test_enabled = optional(bool, false)<br/> })</pre> | <pre>{<br/> "autoscaling": {<br/> "desired_count": 40,<br/> "enable": true,<br/> "max_capacity": 80,<br/> "min_capacity": 40<br/> },<br/> "container_cpu": 2048,<br/> "container_memory": 4096,<br/> "cpu": 2048,<br/> "image_version": "05d9825a488fc80c2b8cd08d69e55732d4762977",<br/> "logs_retention_days": 30,<br/> "memory": 4096<br/>}</pre> | no |
135135
| <a name="input_enable_nat_gateway"></a> [enable\_nat\_gateway](#input\_enable\_nat\_gateway) | Create nat gateway(s) | `bool` | `false` | no |
136136
| <a name="input_env_short"></a> [env\_short](#input\_env\_short) | Environment short. | `string` | `"p"` | no |
137137
| <a name="input_idp_status_history_table"></a> [idp\_status\_history\_table](#input\_idp\_status\_history\_table) | IDP Status History configurations table. | <pre>object({<br/> point_in_time_recovery_enabled = optional(bool, false)<br/> })</pre> | <pre>{<br/> "point_in_time_recovery_enabled": false<br/>}</pre> | no |

src/infra/prod/eu-central-1/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ module "backend" {
111111
vpc_cidr_block = module.network.vpc_cidr_block
112112

113113
service_core = {
114-
service_name = format("%s-core", local.project)
115-
116-
cpu = var.ecs_oneid_core.cpu
117-
memory = var.ecs_oneid_core.memory
114+
service_name = format("%s-core", local.project)
115+
cpu_high_scaling_adjustment = 10
116+
cpu = var.ecs_oneid_core.cpu
117+
memory = var.ecs_oneid_core.memory
118118

119119
container = {
120120
name = "oneid-core"

src/infra/prod/eu-central-1/variables.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ variable "ecs_oneid_core" {
115115
container_memory = 4096
116116
autoscaling = {
117117
enable = true
118-
desired_count = 1
119-
min_capacity = 1
118+
desired_count = 3
119+
min_capacity = 3
120120
max_capacity = 12
121121
}
122122
logs_retention_days = 30
@@ -423,8 +423,8 @@ variable "ecs_alarms" {
423423
namespace = "AWS/ECS"
424424
evaluation_periods = 3
425425
comparison_operator = "LessThanOrEqualToThreshold"
426-
threshold = 20
427-
period = 900
426+
threshold = 5
427+
period = 300
428428
statistic = "Average"
429429
scaling_policy = "cpu_low"
430430
},

src/infra/prod/eu-south-1/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
| <a name="input_dns_record_ttl"></a> [dns\_record\_ttl](#input\_dns\_record\_ttl) | Dns record ttl (in sec) | `number` | `86400` | no |
155155
| <a name="input_ecs_alarms"></a> [ecs\_alarms](#input\_ecs\_alarms) | n/a | <pre>map(object({<br/> metric_name = string<br/> namespace = string<br/> threshold = optional(number)<br/> evaluation_periods = optional(number)<br/> period = optional(number)<br/> statistic = optional(string)<br/> comparison_operator = optional(string)<br/> scaling_policy = optional(string)<br/> }))</pre> | <pre>{<br/> "cpu_high": {<br/> "comparison_operator": "GreaterThanOrEqualToThreshold",<br/> "evaluation_periods": 1,<br/> "metric_name": "CPUUtilization",<br/> "namespace": "AWS/ECS",<br/> "period": 60,<br/> "scaling_policy": "cpu_high",<br/> "statistic": "Average",<br/> "threshold": 50<br/> },<br/> "cpu_low": {<br/> "comparison_operator": "LessThanOrEqualToThreshold",<br/> "evaluation_periods": 3,<br/> "metric_name": "CPUUtilization",<br/> "namespace": "AWS/ECS",<br/> "period": 900,<br/> "scaling_policy": "cpu_low",<br/> "statistic": "Average",<br/> "threshold": 20<br/> },<br/> "mem_high": {<br/> "comparison_operator": "GreaterThanOrEqualToThreshold",<br/> "evaluation_periods": 1,<br/> "metric_name": "MemoryUtilization",<br/> "namespace": "AWS/ECS",<br/> "period": 60,<br/> "statistic": "Average",<br/> "threshold": 70<br/> }<br/>}</pre> | no |
156156
| <a name="input_ecs_enable_container_insights"></a> [ecs\_enable\_container\_insights](#input\_ecs\_enable\_container\_insights) | Enable ecs cluster container inight. | `bool` | `true` | no |
157-
| <a name="input_ecs_oneid_core"></a> [ecs\_oneid\_core](#input\_ecs\_oneid\_core) | Oneidentity core backend configurations. | <pre>object({<br/> image_version = string<br/> cpu = number<br/> memory = number<br/> container_cpu = number<br/> container_memory = number<br/> autoscaling = object({<br/> enable = bool<br/> desired_count = number<br/> min_capacity = number<br/> max_capacity = number<br/> })<br/> logs_retention_days = number<br/> app_spid_test_enabled = optional(bool, false)<br/> })</pre> | <pre>{<br/> "autoscaling": {<br/> "desired_count": 3,<br/> "enable": true,<br/> "max_capacity": 12,<br/> "min_capacity": 3<br/> },<br/> "container_cpu": 2048,<br/> "container_memory": 4096,<br/> "cpu": 2048,<br/> "image_version": "05d9825a488fc80c2b8cd08d69e55732d4762977",<br/> "logs_retention_days": 30,<br/> "memory": 4096<br/>}</pre> | no |
157+
| <a name="input_ecs_oneid_core"></a> [ecs\_oneid\_core](#input\_ecs\_oneid\_core) | Oneidentity core backend configurations. | <pre>object({<br/> image_version = string<br/> cpu = number<br/> memory = number<br/> container_cpu = number<br/> container_memory = number<br/> autoscaling = object({<br/> enable = bool<br/> desired_count = number<br/> min_capacity = number<br/> max_capacity = number<br/> })<br/> logs_retention_days = number<br/> app_spid_test_enabled = optional(bool, false)<br/> })</pre> | <pre>{<br/> "autoscaling": {<br/> "desired_count": 40,<br/> "enable": true,<br/> "max_capacity": 80,<br/> "min_capacity": 40<br/> },<br/> "container_cpu": 2048,<br/> "container_memory": 4096,<br/> "cpu": 2048,<br/> "image_version": "05d9825a488fc80c2b8cd08d69e55732d4762977",<br/> "logs_retention_days": 30,<br/> "memory": 4096<br/>}</pre> | no |
158158
| <a name="input_enable_nat_gateway"></a> [enable\_nat\_gateway](#input\_enable\_nat\_gateway) | Create nat gateway(s) | `bool` | `false` | no |
159159
| <a name="input_env_short"></a> [env\_short](#input\_env\_short) | Environment short. | `string` | `"p"` | no |
160160
| <a name="input_idp_metadata_table"></a> [idp\_metadata\_table](#input\_idp\_metadata\_table) | IDP Metadata configurations table. | <pre>object({<br/> point_in_time_recovery_enabled = optional(bool, false)<br/> stream_enabled = optional(bool, false)<br/> stream_view_type = optional(string, null)<br/> deletion_protection_enabled = optional(bool, false)<br/> replication_regions = optional(list(object({<br/> region_name = string<br/> propagate_tags = optional(bool, true)<br/> point_in_time_recovery = optional(bool, true)<br/> })), [])<br/> })</pre> | <pre>{<br/> "deletion_protection_enabled": true,<br/> "point_in_time_recovery_enabled": true,<br/> "replication_regions": [<br/> {<br/> "propagate_tags": true,<br/> "region_name": "eu-central-1"<br/> }<br/> ],<br/> "stream_enabled": true,<br/> "stream_view_type": "NEW_AND_OLD_IMAGES"<br/>}</pre> | no |

0 commit comments

Comments
 (0)