-
Notifications
You must be signed in to change notification settings - Fork 27
feat: Enable Cloud Connector ECS autoscaling based on RAM #157
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
Changes from all commits
e3d6ffc
36a8351
f5dbe3e
40aa8ce
664aad5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
resource "aws_appautoscaling_target" "ecs_target" { | ||
count = var.enable_autoscaling ? 1 : 0 | ||
|
||
max_capacity = var.max_replicas | ||
min_capacity = var.min_replicas | ||
resource_id = "service/${data.aws_ecs_cluster.this.cluster_name}/${aws_ecs_service.service.name}" | ||
scalable_dimension = "ecs:service:DesiredCount" | ||
service_namespace = "ecs" | ||
} | ||
|
||
resource "aws_appautoscaling_policy" "ecs_ram_policy" { | ||
count = var.enable_autoscaling ? 1 : 0 | ||
|
||
name = "scale-cloud-connector-ram-usage" | ||
policy_type = "StepScaling" | ||
resource_id = aws_appautoscaling_target.ecs_target[0].resource_id | ||
scalable_dimension = aws_appautoscaling_target.ecs_target[0].scalable_dimension | ||
service_namespace = aws_appautoscaling_target.ecs_target[0].service_namespace | ||
|
||
step_scaling_policy_configuration { | ||
adjustment_type = "ChangeInCapacity" | ||
cooldown = 30 | ||
metric_aggregation_type = "Average" | ||
|
||
# Scale down on Memory usage if it's below 40% usage | ||
step_adjustment { | ||
metric_interval_upper_bound = -10 | ||
scaling_adjustment = -1 | ||
} | ||
|
||
# Do not scale if Memory usage is between 40% and 60% usage | ||
step_adjustment { | ||
metric_interval_lower_bound = -10 | ||
metric_interval_upper_bound = 10 | ||
scaling_adjustment = 0 | ||
} | ||
|
||
# Scale up on Memory usage if it's above 60% usage | ||
step_adjustment { | ||
metric_interval_lower_bound = 10 | ||
scaling_adjustment = 1 | ||
} | ||
|
||
} | ||
} | ||
|
||
resource "aws_cloudwatch_metric_alarm" "ecs_ram_usage" { | ||
count = var.enable_autoscaling ? 1 : 0 | ||
|
||
alarm_name = "Step-Scaling-AlarmHigh-ECS:service/${data.aws_ecs_cluster.this.cluster_name}/${aws_ecs_service.service.name}" | ||
|
||
metric_name = "MemoryUtilization" | ||
namespace = "AWS/EC2" | ||
statistic = "Average" | ||
|
||
period = "30" | ||
evaluation_periods = "2" | ||
threshold = "50" | ||
|
||
comparison_operator = "GreaterThanOrEqualToThreshold" | ||
|
||
dimensions = { | ||
Name = data.aws_ecs_cluster.this.cluster_name, | ||
ServiceName = aws_ecs_service.service.name | ||
} | ||
|
||
alarm_actions = [aws_appautoscaling_policy.ecs_ram_policy[0].arn] | ||
|
||
alarm_description = "This metric monitors ECS Memory Utilization of Cloud Connector" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,10 @@ resource "aws_ecs_service" "service" { | |
task_definition = aws_ecs_task_definition.task_definition.arn | ||
wait_for_steady_state = true | ||
tags = var.tags | ||
|
||
lifecycle { | ||
ignore_changes = [desired_count] | ||
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the rationale on this? just curious :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to ignore the desired count because will be modified by the autoscaling and further |
||
} | ||
} | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,10 @@ terraform { | |
source = "sysdiglabs/sysdig" | ||
version = ">=0.5.33" | ||
} | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "<4.51.0" | ||
} | ||
Comment on lines
+7
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's clarify that this version has been pinned due to an error with latest aws version, reported by @tembleking |
||
} | ||
} | ||
|
||
|
@@ -22,4 +26,8 @@ module "cloudvision_aws_single_account_ecs" { | |
|
||
deploy_image_scanning_ecr = true | ||
deploy_image_scanning_ecs = true | ||
|
||
enable_autoscaling = true | ||
min_replicas = 2 | ||
max_replicas = 4 | ||
} |
Uh oh!
There was an error while loading. Please reload this page.