Skip to content

Commit

Permalink
fix the skip dimension validation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
wyTrivail committed Oct 20, 2020
1 parent e55ce3e commit 747f022
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Metric> expectedMetricList = this.getExpectedMetricList(context);
Set<String> 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,
Expand All @@ -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");
Expand Down

0 comments on commit 747f022

Please sign in to comment.