Skip to content

Commit e046ac3

Browse files
committed
Add retry loop around datapoint fetching for first metrics datapoints.
1 parent 9393659 commit e046ac3

File tree

1 file changed

+10
-4
lines changed
  • powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools

1 file changed

+10
-4
lines changed

powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/MetricsE2ET.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
import org.junit.jupiter.api.Test;
3535
import org.junit.jupiter.api.Timeout;
3636

37+
import software.amazon.lambda.powertools.testutils.DataNotReadyException;
3738
import software.amazon.lambda.powertools.testutils.Infrastructure;
39+
import software.amazon.lambda.powertools.testutils.RetryUtils;
3840
import software.amazon.lambda.powertools.testutils.lambda.InvocationResult;
3941
import software.amazon.lambda.powertools.testutils.metrics.MetricsFetcher;
4042

@@ -89,16 +91,20 @@ void test_recordMetrics() {
8991
{ "FunctionName", functionName },
9092
{ "Service", SERVICE } }).collect(Collectors.toMap(data -> data[0], data -> data[1])));
9193
assertThat(coldStart.get(0)).isEqualTo(1);
92-
List<Double> orderMetrics = metricsFetcher.fetchMetrics(invocationResult.getStart(), invocationResult.getEnd(),
93-
60, NAMESPACE,
94-
"orders", Collections.singletonMap("Environment", "test"));
94+
List<Double> orderMetrics = RetryUtils.withRetry(() -> {
95+
List<Double> metrics = metricsFetcher.fetchMetrics(invocationResult.getStart(), invocationResult.getEnd(),
96+
60, NAMESPACE, "orders", Collections.singletonMap("Environment", "test"));
97+
if (metrics.get(0) != 2.0) {
98+
throw new DataNotReadyException("Expected 2.0 orders but got " + metrics.get(0));
99+
}
100+
return metrics;
101+
}, "orderMetricsRetry", DataNotReadyException.class).get();
95102
assertThat(orderMetrics.get(0)).isEqualTo(2);
96103
List<Double> productMetrics = metricsFetcher.fetchMetrics(invocationResult.getStart(),
97104
invocationResult.getEnd(), 60, NAMESPACE,
98105
"products", Collections.singletonMap("Environment", "test"));
99106

100107
// When searching across a 1 minute time period with a period of 60 we find both metrics and the sum is 12
101-
102108
assertThat(productMetrics.get(0)).isEqualTo(12);
103109

104110
orderMetrics = metricsFetcher.fetchMetrics(invocationResult.getStart(), invocationResult.getEnd(), 60,

0 commit comments

Comments
 (0)