in validator/src/main/java/com/amazon/aoc/validators/CWMetricValidator.java [123:162]
private void compareMetricLists(List<Metric> toBeCheckedMetricList, List<Metric> baseMetricList)
throws BaseException {
// load metrics into a hash set
Set<Metric> metricSet =
new TreeSet<>(
(Metric o1, Metric o2) -> {
// check namespace
if (!o1.getNamespace().equals(o2.getNamespace())) {
return o1.getNamespace().compareTo(o2.getNamespace());
}
// check metric name
if (!o1.getMetricName().equals(o2.getMetricName())) {
return o1.getMetricName().compareTo(o2.getMetricName());
}
// sort and check dimensions
List<Dimension> dimensionList1 = o1.getDimensions();
List<Dimension> dimensionList2 = o2.getDimensions();
// sort
dimensionList1.sort(Comparator.comparing(Dimension::getName));
dimensionList2.sort(Comparator.comparing(Dimension::getName));
return dimensionList1.toString().compareTo(dimensionList2.toString());
});
for (Metric metric : baseMetricList) {
metricSet.add(metric);
}
for (Metric metric : toBeCheckedMetricList) {
if (!metricSet.contains(metric)) {
throw new BaseException(
ExceptionCode.EXPECTED_METRIC_NOT_FOUND,
String.format(
"metric in toBeCheckedMetricList %s not found in baseMetricList: %s",
metric, metricSet));
}
}
}