问题描述
我们为ECS服务配置了自动缩放功能。自动缩放的工作流程应如下所示:
- 如果在1分钟内我们收到超过10个值,则需要按比例放大
- 等待10分钟
- 如果没有值,我们需要按比例缩小
按比例放大效果完美,但按比例缩小完全无效。我们得到这个:
Failed to execute action arn:aws:autoscaling:eu-central-1:BLA-BLA-BLA-fargate-scale-down. Received error: ""
可能是因为在resource "aws_appautoscaling_policy" "down"
的Terraform中,我们具有以下内容:
step_adjustment {
metric_interval_lower_bound = ""
metric_interval_upper_bound = 0
scaling_adjustment = -100
}
,它期望为“ 0”而不是没有数据。
在resource "aws_cloudwatch_metric_alarm" "cloudwatch_metric_alarm_down"
中:
treat_missing_data = "breaching"
insufficient_data_actions = [aws_appautoscaling_policy.down.arn]
对此有什么解决方案吗?除非每分钟手动发送“ 0”。
解决方法
解决方案是:
resource "aws_cloudwatch_metric_alarm" "cloudwatch_metric_alarm_down" {
alarm_name = "${local.name}-ecs-alarm-down"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = var.evaluation_periods_down
threshold = var.downscale_threshold
metric_query {
id = "e1"
expression = "FILL(m1,0)"
label = "0 if NoData"
return_data = "true"
}
metric_query {
id = "m1"
metric {
metric_name = var.metric_name
namespace = var.env_name
period = "60"
stat = var.metric_statistic
}
}
alarm_actions = [aws_appautoscaling_policy.down.arn]
depends_on = [aws_appautoscaling_policy.down]
}
有关FILL()的更多信息,请点击此处https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/using-metric-math.html#metric-math-syntax-functions-list