abstract List getExpectedMetrics()

in validator/src/main/java/com/amazon/aoc/validators/AbstractCWMetricsValidator.java [66:99]


  abstract List<Metric> getExpectedMetrics(
      Context context,
      FileConfig expectedDataTemplate
  ) throws Exception;

  @Override
  public void validate() throws Exception {
    log.info("[ContainerInsight] start validating metrics, pause 60s for metric collection");
    TimeUnit.SECONDS.sleep(initialSleepTime);
    log.info("[ContainerInsight] resume validation");

    RetryHelper.retry(maxRetryCount, CHECK_INTERVAL_IN_MILLI, true, () -> {
      Instant startTime = Instant.now().minusSeconds(CHECK_DURATION_IN_SECONDS)
              .truncatedTo(ChronoUnit.MINUTES);
      Instant endTime = startTime.plusSeconds(CHECK_DURATION_IN_SECONDS);

      for (Metric expectedMetric : expectedMetrics) {
        List<MetricDataResult> batchResult = cloudWatchService.getMetricData(expectedMetric,
                Date.from(startTime), Date.from(endTime));
        boolean found = false;
        for (MetricDataResult result : batchResult) {
          if (result.getValues().size() > 0) {
            found = true;
          }
        }
        if (!found) {
          throw new BaseException(ExceptionCode.EXPECTED_METRIC_NOT_FOUND,
                  String.format("[ContainerInsight] metric %s not found with dimension %s",
                          expectedMetric.getMetricName(), stringifyDimension(expectedMetric)));
        }
      }
    });
    log.info("[ContainerInsight] finish validation successfully");
  }