Skip to content

Commit a8ba54d

Browse files
committed
test
1 parent ac89581 commit a8ba54d

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

validator/src/main/java/com/amazon/aoc/validators/CWMetricValidator.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,12 @@ public void validate() throws Exception {
9292
maxRetryCount,
9393
() -> {
9494

95-
// Special handling for Genesis path - just check if any metrics exist in namespace
96-
// since ADOT will just capture any OTel Metrics emitted and convert them into EMF metrics, it's impossible to create
95+
// Special handling for Genesis path - just check if any metrics exists in namespace
96+
// since ADOT will just capture any OTel Metrics from the emitted from the instrumentation library
97+
// and convert them into EMF metrics, it's impossible to create
9798
// a validation template for this.
9899
if (validationConfig.getHttpPath().contains("ai-chat")) {
99-
100-
List<Metric> allMetricsInNamespace = cloudWatchService.listMetrics(context.getMetricNamespace(), null, null, null);
101-
log.info("Found {} metrics in namespace {}", allMetricsInNamespace.size(), context.getMetricNamespace());
102-
if (allMetricsInNamespace.isEmpty()) {
103-
throw new BaseException(ExceptionCode.EXPECTED_METRIC_NOT_FOUND, "No metrics found in namespace: " + context.getMetricNamespace());
104-
}
105-
log.info("validation is passed for path {}", validationConfig.getHttpPath());
100+
validateAnyMetricExists();
106101
return;
107102
}
108103
// We will query the Service, RemoteService, and RemoteTarget dimensions to ensure we
@@ -224,6 +219,17 @@ private void compareMetricLists(List<Metric> expectedMetricList, List<Metric> ac
224219
matchAny.stream().findAny().get(), actualMetricSnapshot));
225220
}
226221
}
222+
223+
private void validateAnyMetricExists() throws Exception {
224+
// This will grab all metrics from last 3 hours
225+
// See: https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_ListMetrics.html
226+
List<Metric> allMetricsInNamespace = cloudWatchService.listMetrics(context.getMetricNamespace(), null, null, null);
227+
log.info("Found {} metrics in namespace {}", allMetricsInNamespace.size(), context.getMetricNamespace());
228+
if (allMetricsInNamespace.isEmpty()) {
229+
throw new BaseException(ExceptionCode.EXPECTED_METRIC_NOT_FOUND, "No metrics found in namespace: " + context.getMetricNamespace());
230+
}
231+
log.info("validation is passed for path {}", validationConfig.getHttpPath());
232+
}
227233

228234
private List<Metric> listMetricFromCloudWatch(
229235
CloudWatchService cloudWatchService,

0 commit comments

Comments
 (0)