3737import java .util .Arrays ;
3838import java .util .Comparator ;
3939import java .util .HashMap ;
40+ import java .util .HashSet ;
4041import java .util .List ;
4142import java .util .Set ;
4243import java .util .TreeSet ;
@@ -54,7 +55,21 @@ public class MetricValidator implements IValidator {
5455 @ Override
5556 public void validate () throws Exception {
5657 log .info ("Start metric validating" );
58+ // get expected metrics and remove the to be skipped dimensions
5759 final List <Metric > expectedMetricList = this .getExpectedMetricList (context );
60+ Set <String > skippedDimensionNameList = new HashSet <>();
61+ for (Metric metric : expectedMetricList ){
62+ for (Dimension dimension : metric .getDimensions ()){
63+ if (dimension .getValue ().equals ("SKIP" )){
64+ skippedDimensionNameList .add (dimension .getName ());
65+ }
66+ }
67+ }
68+ for (Metric metric : expectedMetricList ) {
69+ metric .getDimensions ().removeIf ((dimension ) -> skippedDimensionNameList .contains (dimension .getName ()));
70+ }
71+
72+ // get metric from cloudwatch
5873 CloudWatchService cloudWatchService = new CloudWatchService (context .getRegion ());
5974 RetryHelper .retry (
6075 MAX_RETRY_COUNT ,
@@ -63,11 +78,9 @@ public void validate() throws Exception {
6378 this .listMetricFromCloudWatch (cloudWatchService , expectedMetricList );
6479
6580 // remove the skip dimensions
66- for (Metric metric : expectedMetricList ) {
67- metric .getDimensions ().removeIf (dimension -> dimension .getValue ().equals ("SKIP" ));
68- }
81+ log .info ("dimensions to be skipped in validation: {}" , skippedDimensionNameList );
6982 for (Metric metric : metricList ) {
70- metric .getDimensions ().removeIf (dimension -> dimension . getValue (). equals ( "SKIP" ));
83+ metric .getDimensions ().removeIf (( dimension ) -> skippedDimensionNameList . contains ( dimension . getName () ));
7184 }
7285
7386 log .info ("check if all the expected metrics are found" );
0 commit comments