From 8d3e01e87cad299fec1d7b192839cba770e6bdd1 Mon Sep 17 00:00:00 2001 From: ssupecial Date: Mon, 12 Aug 2024 03:32:07 +0000 Subject: [PATCH 1/7] feat(infra): add managed scaling option to ecs capacity provider --- .../codedang/modules/cluster_autoscaling/autoscaling.tf | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf b/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf index 82f59dc4c8..2ab9e00c23 100644 --- a/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf +++ b/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf @@ -66,5 +66,12 @@ resource "aws_ecs_capacity_provider" "this" { auto_scaling_group_provider { auto_scaling_group_arn = aws_autoscaling_group.this.arn managed_termination_protection = "ENABLED" + + managed_scaling { + maximum_scaling_step_size = 5 + minimum_scaling_step_size = 1 + status = "ENABLED" + target_capacity = 90 + } } } From 2eabe5b6a3720025b07536b46f84ab7c6bc4fba5 Mon Sep 17 00:00:00 2001 From: ssupecial Date: Mon, 12 Aug 2024 03:35:59 +0000 Subject: [PATCH 2/7] feat(infra): modify api service desired count to zero to apply ecs cluster auto scaling --- apps/infra/production/codedang/codedang_service_admin.tf | 2 +- apps/infra/production/codedang/codedang_service_client.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/infra/production/codedang/codedang_service_admin.tf b/apps/infra/production/codedang/codedang_service_admin.tf index 0a0c36a895..1b70f17a46 100644 --- a/apps/infra/production/codedang/codedang_service_admin.tf +++ b/apps/infra/production/codedang/codedang_service_admin.tf @@ -55,7 +55,7 @@ module "admin_api" { ecs_service = { name = "Codedang-Admin-Api-Service" cluster_arn = module.codedang_api.ecs_cluster.arn - desired_count = 1 + desired_count = 0 load_balancer = { container_name = "Codedang-Admin-Api" container_port = 3000 diff --git a/apps/infra/production/codedang/codedang_service_client.tf b/apps/infra/production/codedang/codedang_service_client.tf index 2080dd9e3a..1454650aad 100644 --- a/apps/infra/production/codedang/codedang_service_client.tf +++ b/apps/infra/production/codedang/codedang_service_client.tf @@ -85,7 +85,7 @@ module "client_api" { ecs_service = { name = "Codedang-Client-Api-Service" cluster_arn = module.codedang_api.ecs_cluster.arn - desired_count = 1 + desired_count = 0 load_balancer = { container_name = "Codedang-Client-Api" container_port = 4000 From 3810c4f5f2b132eacbf8ac8d092679c1a83fb149 Mon Sep 17 00:00:00 2001 From: ssupecial Date: Mon, 12 Aug 2024 03:47:26 +0000 Subject: [PATCH 3/7] feat(infra): restore ecs api soft limit --- .../production/codedang/container_definitions/admin_api.json | 2 +- .../production/codedang/container_definitions/client_api.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/infra/production/codedang/container_definitions/admin_api.json b/apps/infra/production/codedang/container_definitions/admin_api.json index 22bb4c03bd..31f7c5b145 100644 --- a/apps/infra/production/codedang/container_definitions/admin_api.json +++ b/apps/infra/production/codedang/container_definitions/admin_api.json @@ -1,7 +1,7 @@ { "name": "Codedang-Admin-Api", "image": "${ecr_uri}", - "cpu": 600, + "cpu": 924, "memoryReservation": 512, "essential": true, "portMappings": [ diff --git a/apps/infra/production/codedang/container_definitions/client_api.json b/apps/infra/production/codedang/container_definitions/client_api.json index 1fc90fd910..9a69015f95 100644 --- a/apps/infra/production/codedang/container_definitions/client_api.json +++ b/apps/infra/production/codedang/container_definitions/client_api.json @@ -1,7 +1,7 @@ { "name": "Codedang-Client-Api", "image": "${ecr_uri}", - "cpu": 600, + "cpu": 924, "memoryReservation": 512, "essential": true, "portMappings": [ From e653408ae9cb8c1404b5503888b35ec60059edaa Mon Sep 17 00:00:00 2001 From: ssupecial Date: Mon, 12 Aug 2024 04:06:57 +0000 Subject: [PATCH 4/7] feat(infra): modify ecs auto scaling target capacity to 100 --- .../codedang/modules/cluster_autoscaling/autoscaling.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf b/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf index 2ab9e00c23..7dad6e8635 100644 --- a/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf +++ b/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf @@ -71,7 +71,7 @@ resource "aws_ecs_capacity_provider" "this" { maximum_scaling_step_size = 5 minimum_scaling_step_size = 1 status = "ENABLED" - target_capacity = 90 + target_capacity = 100 } } } From 82c3a3e6b5665fd26cec52ebe7dbb9e19140ff6a Mon Sep 17 00:00:00 2001 From: ssupecial Date: Mon, 12 Aug 2024 15:44:40 +0000 Subject: [PATCH 5/7] fix(infra): modify desired capacity to zero, not service desired count --- apps/infra/production/codedang/codedang_service_admin.tf | 2 +- apps/infra/production/codedang/codedang_service_client.tf | 2 +- .../codedang/modules/cluster_autoscaling/autoscaling.tf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/infra/production/codedang/codedang_service_admin.tf b/apps/infra/production/codedang/codedang_service_admin.tf index 1b70f17a46..0a0c36a895 100644 --- a/apps/infra/production/codedang/codedang_service_admin.tf +++ b/apps/infra/production/codedang/codedang_service_admin.tf @@ -55,7 +55,7 @@ module "admin_api" { ecs_service = { name = "Codedang-Admin-Api-Service" cluster_arn = module.codedang_api.ecs_cluster.arn - desired_count = 0 + desired_count = 1 load_balancer = { container_name = "Codedang-Admin-Api" container_port = 3000 diff --git a/apps/infra/production/codedang/codedang_service_client.tf b/apps/infra/production/codedang/codedang_service_client.tf index 1454650aad..2080dd9e3a 100644 --- a/apps/infra/production/codedang/codedang_service_client.tf +++ b/apps/infra/production/codedang/codedang_service_client.tf @@ -85,7 +85,7 @@ module "client_api" { ecs_service = { name = "Codedang-Client-Api-Service" cluster_arn = module.codedang_api.ecs_cluster.arn - desired_count = 0 + desired_count = 1 load_balancer = { container_name = "Codedang-Client-Api" container_port = 4000 diff --git a/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf b/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf index 7dad6e8635..caf1484289 100644 --- a/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf +++ b/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf @@ -28,7 +28,7 @@ resource "aws_autoscaling_group" "this" { name = var.autoscaling_group.name vpc_zone_identifier = [for key in keys(var.subnets) : aws_subnet.this[key].id] - desired_capacity = 1 + desired_capacity = 0 min_size = 1 max_size = var.autoscaling_group.max_size From 03f66a1327b1d30e22be7d218b732a4f7fd578fd Mon Sep 17 00:00:00 2001 From: ssupecial Date: Tue, 13 Aug 2024 13:25:07 +0000 Subject: [PATCH 6/7] fix(infra): modify asg min size to zero to allow desired size --- .../codedang/modules/cluster_autoscaling/autoscaling.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf b/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf index caf1484289..1418966588 100644 --- a/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf +++ b/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf @@ -29,7 +29,7 @@ resource "aws_autoscaling_group" "this" { vpc_zone_identifier = [for key in keys(var.subnets) : aws_subnet.this[key].id] desired_capacity = 0 - min_size = 1 + min_size = 0 max_size = var.autoscaling_group.max_size mixed_instances_policy { From 862278c66c3a66a76e75a611c60d3434f9590bb1 Mon Sep 17 00:00:00 2001 From: ssupecial Date: Tue, 13 Aug 2024 14:14:44 +0000 Subject: [PATCH 7/7] fix(infra): restore asg min and desired size --- .../codedang/modules/cluster_autoscaling/autoscaling.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf b/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf index 1418966588..7dad6e8635 100644 --- a/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf +++ b/apps/infra/production/codedang/modules/cluster_autoscaling/autoscaling.tf @@ -28,8 +28,8 @@ resource "aws_autoscaling_group" "this" { name = var.autoscaling_group.name vpc_zone_identifier = [for key in keys(var.subnets) : aws_subnet.this[key].id] - desired_capacity = 0 - min_size = 0 + desired_capacity = 1 + min_size = 1 max_size = var.autoscaling_group.max_size mixed_instances_policy {