From c35aaac30161d61772e574f48e1023e605395a2c Mon Sep 17 00:00:00 2001 From: Christos Arvanitis Date: Thu, 12 Dec 2024 20:10:32 +0200 Subject: [PATCH] fix(ecs): Cloudwatch alarms cleanup on destroy ecs group (#6315) --- .../ecs/services/EcsCloudMetricService.java | 2 +- .../ecs/services/EcsCloudMetricServiceSpec.groovy | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/clouddriver-ecs/src/main/java/com/netflix/spinnaker/clouddriver/ecs/services/EcsCloudMetricService.java b/clouddriver-ecs/src/main/java/com/netflix/spinnaker/clouddriver/ecs/services/EcsCloudMetricService.java index 07af7889e0..3f434037a6 100644 --- a/clouddriver-ecs/src/main/java/com/netflix/spinnaker/clouddriver/ecs/services/EcsCloudMetricService.java +++ b/clouddriver-ecs/src/main/java/com/netflix/spinnaker/clouddriver/ecs/services/EcsCloudMetricService.java @@ -46,7 +46,7 @@ public class EcsCloudMetricService { public void deleteMetrics( String serviceName, String account, String region, String ecsClusterName) { List metricAlarms = - metricAlarmCacheClient.getMetricAlarms(ecsClusterName, serviceName, account, region); + metricAlarmCacheClient.getMetricAlarms(serviceName, account, region, ecsClusterName); if (metricAlarms.isEmpty()) { return; diff --git a/clouddriver-ecs/src/test/groovy/com/netflix/spinnaker/clouddriver/ecs/services/EcsCloudMetricServiceSpec.groovy b/clouddriver-ecs/src/test/groovy/com/netflix/spinnaker/clouddriver/ecs/services/EcsCloudMetricServiceSpec.groovy index 090d7be0b7..bbc46348f9 100644 --- a/clouddriver-ecs/src/test/groovy/com/netflix/spinnaker/clouddriver/ecs/services/EcsCloudMetricServiceSpec.groovy +++ b/clouddriver-ecs/src/test/groovy/com/netflix/spinnaker/clouddriver/ecs/services/EcsCloudMetricServiceSpec.groovy @@ -19,6 +19,7 @@ package com.netflix.spinnaker.clouddriver.ecs.services import com.amazonaws.services.applicationautoscaling.AWSApplicationAutoScaling import com.amazonaws.services.applicationautoscaling.model.* import com.amazonaws.services.cloudwatch.AmazonCloudWatch +import com.amazonaws.services.cloudwatch.model.DeleteAlarmsRequest import com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult import com.amazonaws.services.cloudwatch.model.Dimension import com.amazonaws.services.cloudwatch.model.MetricAlarm @@ -409,16 +410,19 @@ class EcsCloudMetricServiceSpec extends Specification { 5.times { metricAlarms << new EcsMetricAlarm( accountName: targetAccountName, - region: targetRegion + region: targetRegion, + alarmName: "alarm-name-${it}" ) } - metricAlarmCacheClient.getMetricAlarms(_, _,_ ,_) >> metricAlarms + metricAlarmCacheClient.getMetricAlarms(targetServiceName,targetAccountName,targetRegion,clusterName) >> metricAlarms when: service.deleteMetrics(targetServiceName, targetAccountName, targetRegion, clusterName) then: - 1 * targetCloudWatch.deleteAlarms(_) + 1 * targetCloudWatch.deleteAlarms({ DeleteAlarmsRequest request -> + request.alarmNames.sort() == metricAlarms*.alarmName.sort() + }) } }