Skip to content

Commit

Permalink
Update main.yml (#263)
Browse files Browse the repository at this point in the history
* Update main.yml

* Add files via upload

* Add files via upload

* Add files via upload
  • Loading branch information
jinchuantang authored Feb 12, 2024
1 parent 123e041 commit 1b76717
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
# Runs a single command using the runners shell
- name: Build Drupal docker image
run: |
docker build . -t ${{ secrets.AWS_ECR_URI }}:${{ github.sha }} --build-arg TIMEOUT=3s --build-arg MAX_CHILDREN=350 --build-arg START_SERVERS=10 --build-arg MIN_SPARE=5 --build-arg MAX_SPARE=15 --build-arg SPAWN_RATE=32
docker build . -t ${{ secrets.AWS_ECR_URI }}:${{ github.sha }} --build-arg TIMEOUT=3s --build-arg MAX_CHILDREN=250 --build-arg START_SERVERS=10 --build-arg MIN_SPARE=5 --build-arg MAX_SPARE=15 --build-arg SPAWN_RATE=32
- name: Push Drupal docker image
run: |
docker push ${{ secrets.AWS_ECR_URI }}:${{ github.sha }}
Expand Down
4 changes: 2 additions & 2 deletions terraform/dev/autoscaling.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ resource "aws_appautoscaling_policy" "down" {
# CloudWatch alarm that triggers the autoscaling up policy
resource "aws_cloudwatch_metric_alarm" "service_memory_high" {
count = local.create_ecs_service
alarm_name = "ecs_memory_utilization_high"
alarm_name = "ecs_memory_utilization_high_cdq"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "MemoryUtilization"
Expand All @@ -78,7 +78,7 @@ resource "aws_cloudwatch_metric_alarm" "service_memory_high" {
# CloudWatch alarm that triggers the autoscaling down policy
resource "aws_cloudwatch_metric_alarm" "service_memory_low" {
count = local.create_ecs_service
alarm_name = "ecs_memory_utilization_low"
alarm_name = "ecs_memory_utilization_low_cdq"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "MemoryUtilization"
Expand Down
98 changes: 98 additions & 0 deletions terraform/prod/autoscaling.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# auto_scaling.tf

resource "aws_appautoscaling_target" "ecs" {
count = local.create_ecs_service
service_namespace = "ecs"
resource_id = "service/${aws_ecs_cluster.main.name}/${aws_ecs_service.main[count.index].name}"
scalable_dimension = "ecs:service:DesiredCount"
min_capacity = 1
max_capacity = 6
}

# Automatically scale capacity up by one
resource "aws_appautoscaling_policy" "up" {
count = local.create_ecs_service
name = "auto_scale_up"
service_namespace = aws_appautoscaling_target.ecs[count.index].service_namespace
resource_id = aws_appautoscaling_target.ecs[count.index].resource_id
scalable_dimension = aws_appautoscaling_target.ecs[count.index].scalable_dimension

step_scaling_policy_configuration {
adjustment_type = "ChangeInCapacity"
cooldown = 60
metric_aggregation_type = "Maximum"

step_adjustment {
metric_interval_lower_bound = 0
scaling_adjustment = 1
}
}

depends_on = [aws_appautoscaling_target.ecs]
}

# Automatically scale capacity down by one
resource "aws_appautoscaling_policy" "down" {
count = local.create_ecs_service
name = "auto_scale_down"
service_namespace = aws_appautoscaling_target.ecs[count.index].service_namespace
resource_id = aws_appautoscaling_target.ecs[count.index].resource_id
scalable_dimension = aws_appautoscaling_target.ecs[count.index].scalable_dimension

step_scaling_policy_configuration {
adjustment_type = "ChangeInCapacity"
cooldown = 60
metric_aggregation_type = "Maximum"

step_adjustment {
metric_interval_upper_bound = 0
scaling_adjustment = -1
}
}

depends_on = [aws_appautoscaling_target.ecs]
}

# CloudWatch alarm that triggers the autoscaling up policy
resource "aws_cloudwatch_metric_alarm" "service_memory_high" {
count = local.create_ecs_service
alarm_name = "ecs_memory_utilization_high_cdq"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "MemoryUtilization"
namespace = "AWS/ECS"
period = "30"
statistic = "Average"
threshold = "75"

dimensions = {
ClusterName = aws_ecs_cluster.main.name
ServiceName = aws_ecs_service.main[count.index].name
}

alarm_actions = [aws_appautoscaling_policy.up[count.index].arn]

tags = var.common_tags
}

# CloudWatch alarm that triggers the autoscaling down policy
resource "aws_cloudwatch_metric_alarm" "service_memory_low" {
count = local.create_ecs_service
alarm_name = "ecs_memory_utilization_low_cdq"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "MemoryUtilization"
namespace = "AWS/ECS"
period = "30"
statistic = "Average"
threshold = "10"

dimensions = {
ClusterName = aws_ecs_cluster.main.name
ServiceName = aws_ecs_service.main[count.index].name
}

alarm_actions = [aws_appautoscaling_policy.down[count.index].arn]

tags = var.common_tags
}
98 changes: 98 additions & 0 deletions terraform/test/autoscaling.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# auto_scaling.tf

resource "aws_appautoscaling_target" "ecs" {
count = local.create_ecs_service
service_namespace = "ecs"
resource_id = "service/${aws_ecs_cluster.main.name}/${aws_ecs_service.main[count.index].name}"
scalable_dimension = "ecs:service:DesiredCount"
min_capacity = 1
max_capacity = 6
}

# Automatically scale capacity up by one
resource "aws_appautoscaling_policy" "up" {
count = local.create_ecs_service
name = "auto_scale_up"
service_namespace = aws_appautoscaling_target.ecs[count.index].service_namespace
resource_id = aws_appautoscaling_target.ecs[count.index].resource_id
scalable_dimension = aws_appautoscaling_target.ecs[count.index].scalable_dimension

step_scaling_policy_configuration {
adjustment_type = "ChangeInCapacity"
cooldown = 60
metric_aggregation_type = "Maximum"

step_adjustment {
metric_interval_lower_bound = 0
scaling_adjustment = 1
}
}

depends_on = [aws_appautoscaling_target.ecs]
}

# Automatically scale capacity down by one
resource "aws_appautoscaling_policy" "down" {
count = local.create_ecs_service
name = "auto_scale_down"
service_namespace = aws_appautoscaling_target.ecs[count.index].service_namespace
resource_id = aws_appautoscaling_target.ecs[count.index].resource_id
scalable_dimension = aws_appautoscaling_target.ecs[count.index].scalable_dimension

step_scaling_policy_configuration {
adjustment_type = "ChangeInCapacity"
cooldown = 60
metric_aggregation_type = "Maximum"

step_adjustment {
metric_interval_upper_bound = 0
scaling_adjustment = -1
}
}

depends_on = [aws_appautoscaling_target.ecs]
}

# CloudWatch alarm that triggers the autoscaling up policy
resource "aws_cloudwatch_metric_alarm" "service_memory_high" {
count = local.create_ecs_service
alarm_name = "ecs_memory_utilization_high_cdq"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "MemoryUtilization"
namespace = "AWS/ECS"
period = "30"
statistic = "Average"
threshold = "75"

dimensions = {
ClusterName = aws_ecs_cluster.main.name
ServiceName = aws_ecs_service.main[count.index].name
}

alarm_actions = [aws_appautoscaling_policy.up[count.index].arn]

tags = var.common_tags
}

# CloudWatch alarm that triggers the autoscaling down policy
resource "aws_cloudwatch_metric_alarm" "service_memory_low" {
count = local.create_ecs_service
alarm_name = "ecs_memory_utilization_low_cdq"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "MemoryUtilization"
namespace = "AWS/ECS"
period = "30"
statistic = "Average"
threshold = "10"

dimensions = {
ClusterName = aws_ecs_cluster.main.name
ServiceName = aws_ecs_service.main[count.index].name
}

alarm_actions = [aws_appautoscaling_policy.down[count.index].arn]

tags = var.common_tags
}

0 comments on commit 1b76717

Please sign in to comment.