From 747f022afc2d2506f4908033303986802b3490b1 Mon Sep 17 00:00:00 2001 From: Ying Wang Date: Tue, 20 Oct 2020 11:51:23 -0700 Subject: [PATCH] fix the skip dimension validation issue --- .../aoc/validators/MetricValidator.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/validator/src/main/java/com/amazon/aoc/validators/MetricValidator.java b/validator/src/main/java/com/amazon/aoc/validators/MetricValidator.java index 0c1341df4..54652155e 100644 --- a/validator/src/main/java/com/amazon/aoc/validators/MetricValidator.java +++ b/validator/src/main/java/com/amazon/aoc/validators/MetricValidator.java @@ -37,6 +37,7 @@ import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -54,7 +55,21 @@ public class MetricValidator implements IValidator { @Override public void validate() throws Exception { log.info("Start metric validating"); + // get expected metrics and remove the to be skipped dimensions final List expectedMetricList = this.getExpectedMetricList(context); + Set skippedDimensionNameList = new HashSet<>(); + for(Metric metric: expectedMetricList){ + for(Dimension dimension: metric.getDimensions()){ + if(dimension.getValue().equals("SKIP")){ + skippedDimensionNameList.add(dimension.getName()); + } + } + } + for (Metric metric : expectedMetricList) { + metric.getDimensions().removeIf((dimension) -> skippedDimensionNameList.contains(dimension.getName())); + } + + // get metric from cloudwatch CloudWatchService cloudWatchService = new CloudWatchService(context.getRegion()); RetryHelper.retry( MAX_RETRY_COUNT, @@ -63,11 +78,9 @@ public void validate() throws Exception { this.listMetricFromCloudWatch(cloudWatchService, expectedMetricList); // remove the skip dimensions - for (Metric metric : expectedMetricList) { - metric.getDimensions().removeIf(dimension -> dimension.getValue().equals("SKIP")); - } + log.info("dimensions to be skipped in validation: {}", skippedDimensionNameList); for (Metric metric : metricList) { - metric.getDimensions().removeIf(dimension -> dimension.getValue().equals("SKIP")); + metric.getDimensions().removeIf((dimension) -> skippedDimensionNameList.contains(dimension.getName())); } log.info("check if all the expected metrics are found");