Skip to content

Commit 834cbdb

Browse files
committed
update validator test cases for new metric rollups
1 parent 1bb9d6b commit 834cbdb

File tree

15 files changed

+496
-65
lines changed

15 files changed

+496
-65
lines changed

validator/src/main/java/com/amazon/aoc/App.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public class App implements Callable<Integer> {
7575
@CommandLine.Option(names = {"--remote-service-deployment-name"})
7676
private String remoteServiceDeploymentName;
7777

78+
@CommandLine.Option(names = {"--remote-target-name"})
79+
private String remoteTargetName;
80+
7881
@CommandLine.Option(names = {"--endpoint"})
7982
private String endpoint;
8083

@@ -160,6 +163,7 @@ public Integer call() throws Exception {
160163
context.setServiceName(this.serviceName);
161164
context.setRemoteServiceName(this.remoteServiceName);
162165
context.setRemoteServiceDeploymentName(this.remoteServiceDeploymentName);
166+
context.setRemoteTargetName(this.remoteTargetName);
163167
context.setEndpoint(this.endpoint);
164168
context.setRequestBody(this.requestBody);
165169
context.setLogGroup(this.logGroup);

validator/src/main/java/com/amazon/aoc/models/Context.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public class Context {
4949

5050
private String remoteServiceDeploymentName;
5151

52+
private String remoteTargetName;
53+
5254
private String endpoint;
5355

5456
private String requestBody;

validator/src/main/java/com/amazon/aoc/services/CloudWatchService.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828
import com.amazonaws.services.logs.model.OutputLogEvent;
2929
import java.util.Date;
3030
import java.util.List;
31+
import java.util.stream.Collectors;
32+
import kotlin.Pair;
3133
import lombok.extern.log4j.Log4j2;
3234

3335
/** a wrapper of cloudwatch client. */
3436
@Log4j2
3537
public class CloudWatchService {
3638
public static final String SERVICE_DIMENSION = "Service";
3739
public static final String REMOTE_SERVICE_DIMENSION = "RemoteService";
40+
public static final String REMOTE_TARGET_DIMENSION = "RemoteTarget";
3841

3942
private static final int MAX_QUERY_PERIOD = 60;
4043
private static final String REQUESTER = "integrationTest";
@@ -62,15 +65,20 @@ public CloudWatchService(String region) {
6265
public List<Metric> listMetrics(
6366
final String namespace,
6467
final String metricName,
65-
final String dimensionKey,
66-
final String dimensionValue) {
67-
final DimensionFilter dimensionFilter =
68-
new DimensionFilter().withName(dimensionKey).withValue(dimensionValue);
68+
final List<Pair<String, String>> dimensionList) {
69+
final List<DimensionFilter> dimensionFilters =
70+
dimensionList.stream()
71+
.map(
72+
dimension ->
73+
new DimensionFilter()
74+
.withName(dimension.getFirst())
75+
.withValue(dimension.getSecond()))
76+
.collect(Collectors.toList());
6977
final ListMetricsRequest listMetricsRequest =
7078
new ListMetricsRequest()
7179
.withNamespace(namespace)
7280
.withMetricName(metricName)
73-
.withDimensions(dimensionFilter)
81+
.withDimensions(dimensionFilters)
7482
.withRecentlyActive("PT3H");
7583
return amazonCloudWatch.listMetrics(listMetricsRequest).getMetrics();
7684
}

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

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@
3030
import com.google.common.collect.Lists;
3131
import java.io.IOException;
3232
import java.util.ArrayList;
33+
import java.util.Arrays;
3334
import java.util.Comparator;
3435
import java.util.HashMap;
3536
import java.util.HashSet;
3637
import java.util.List;
3738
import java.util.Set;
3839
import java.util.TreeSet;
40+
import kotlin.Pair;
3941
import lombok.extern.log4j.Log4j2;
4042

4143
@Log4j2
4244
public class CWMetricValidator implements IValidator {
43-
private static int DEFAULT_MAX_RETRY_COUNT = 80;
45+
private static int DEFAULT_MAX_RETRY_COUNT = 10;
4446

4547
private MustacheHelper mustacheHelper = new MustacheHelper();
4648
private ICaller caller;
@@ -103,16 +105,30 @@ public void validate() throws Exception {
103105
}
104106

105107
List<Metric> actualMetricList = Lists.newArrayList();
106-
addMetrics(
107-
CloudWatchService.SERVICE_DIMENSION,
108-
serviceNames,
109-
expectedMetricList,
110-
actualMetricList);
111-
addMetrics(
112-
CloudWatchService.REMOTE_SERVICE_DIMENSION,
113-
remoteServiceNames,
114-
expectedMetricList,
115-
actualMetricList);
108+
109+
// Add sets of dimesion filters to use for each query to CloudWatch
110+
List<List<Pair<String, String>>> dimensionLists = Lists.newArrayList();
111+
// Query metrics for rolled up into the [serviceDimension] dimension
112+
for (String serviceName : serviceNames) {
113+
dimensionLists.add(
114+
Arrays.asList(new Pair<>(CloudWatchService.SERVICE_DIMENSION, serviceName)));
115+
}
116+
// Query metrics for rolled up into the [remoteServiceDimension] dimension
117+
for (String remoteServiceName : remoteServiceNames) {
118+
dimensionLists.add(
119+
Arrays.asList(
120+
new Pair<>(CloudWatchService.REMOTE_SERVICE_DIMENSION, remoteServiceName)));
121+
}
122+
// Query metrics for rolled up into the [remoteServiceDimension, remoteTargetDemsion] dimensions
123+
dimensionLists.add(
124+
Arrays.asList(
125+
new Pair<>(CloudWatchService.REMOTE_SERVICE_DIMENSION, "AWS.SDK.S3"),
126+
new Pair<>(CloudWatchService.REMOTE_TARGET_DIMENSION, context.getRemoteTargetName())));
127+
128+
// Populate actualMetricList with metrics that pass through one of the dimension filters
129+
for (List<Pair<String, String>> dimensionList : dimensionLists) {
130+
addMetrics(dimensionList, expectedMetricList, actualMetricList);
131+
}
116132

117133
// remove the skip dimensions
118134
log.info("dimensions to be skipped in validation: {}", skippedDimensionNameList);
@@ -132,16 +148,12 @@ public void validate() throws Exception {
132148
}
133149

134150
private void addMetrics(
135-
String dimensionName,
136-
List<String> dimensionValues,
151+
List<Pair<String, String>> dimensionList,
137152
List<Metric> expectedMetricList,
138153
List<Metric> actualMetricList)
139154
throws Exception {
140-
for (String dimensionValue : dimensionValues) {
141-
actualMetricList.addAll(
142-
this.listMetricFromCloudWatch(
143-
cloudWatchService, expectedMetricList, dimensionName, dimensionValue));
144-
}
155+
actualMetricList.addAll(
156+
this.listMetricFromCloudWatch(cloudWatchService, expectedMetricList, dimensionList));
145157
}
146158

147159
/**
@@ -194,8 +206,7 @@ private void compareMetricLists(List<Metric> toBeCheckedMetricList, List<Metric>
194206
private List<Metric> listMetricFromCloudWatch(
195207
CloudWatchService cloudWatchService,
196208
List<Metric> expectedMetricList,
197-
String dimensionKey,
198-
String dimensionValue)
209+
List<Pair<String, String>> dimensionList)
199210
throws IOException {
200211
// put namespace into the map key, so that we can use it to search metric
201212
HashMap<String, String> metricNameMap = new HashMap<>();
@@ -207,8 +218,7 @@ private List<Metric> listMetricFromCloudWatch(
207218
List<Metric> result = new ArrayList<>();
208219
for (String metricName : metricNameMap.keySet()) {
209220
result.addAll(
210-
cloudWatchService.listMetrics(
211-
metricNameMap.get(metricName), metricName, dimensionKey, dimensionValue));
221+
cloudWatchService.listMetrics(metricNameMap.get(metricName), metricName, dimensionList));
212222
}
213223
return result;
214224
}

validator/src/main/resources/expected-data-template/ec2/aws-sdk-call-metric.mustache

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
value: AWS.SDK.S3
9696
-
9797
name: RemoteTarget
98-
value: ::s3:::e2e-test-bucket-name
98+
value: ::s3:::e2e-test-bucket-name-{{testingId}}
9999

100100
-
101101
metricName: Latency
@@ -115,7 +115,35 @@
115115
value: AWS.SDK.S3
116116
-
117117
name: RemoteTarget
118-
value: ::s3:::e2e-test-bucket-name
118+
value: ::s3:::e2e-test-bucket-name-{{testingId}}
119+
120+
-
121+
metricName: Latency
122+
namespace: {{metricNamespace}}
123+
dimensions:
124+
-
125+
name: Service
126+
value: {{serviceName}}
127+
-
128+
name: HostedIn.Environment
129+
value: EC2
130+
-
131+
name: RemoteService
132+
value: AWS.SDK.S3
133+
-
134+
name: RemoteTarget
135+
value: ::s3:::e2e-test-bucket-name-{{testingId}}
136+
137+
-
138+
metricName: Latency
139+
namespace: {{metricNamespace}}
140+
dimensions:
141+
-
142+
name: RemoteService
143+
value: AWS.SDK.S3
144+
-
145+
name: RemoteTarget
146+
value: ::s3:::e2e-test-bucket-name-{{testingId}}
119147

120148
-
121149
metricName: Error
@@ -214,7 +242,7 @@
214242
value: AWS.SDK.S3
215243
-
216244
name: RemoteTarget
217-
value: ::s3:::e2e-test-bucket-name
245+
value: ::s3:::e2e-test-bucket-name-{{testingId}}
218246

219247
-
220248
metricName: Error
@@ -234,7 +262,35 @@
234262
value: AWS.SDK.S3
235263
-
236264
name: RemoteTarget
237-
value: ::s3:::e2e-test-bucket-name
265+
value: ::s3:::e2e-test-bucket-name-{{testingId}}
266+
267+
-
268+
metricName: Error
269+
namespace: {{metricNamespace}}
270+
dimensions:
271+
-
272+
name: Service
273+
value: {{serviceName}}
274+
-
275+
name: HostedIn.Environment
276+
value: EC2
277+
-
278+
name: RemoteService
279+
value: AWS.SDK.S3
280+
-
281+
name: RemoteTarget
282+
value: ::s3:::e2e-test-bucket-name-{{testingId}}
283+
284+
-
285+
metricName: Error
286+
namespace: {{metricNamespace}}
287+
dimensions:
288+
-
289+
name: RemoteService
290+
value: AWS.SDK.S3
291+
-
292+
name: RemoteTarget
293+
value: ::s3:::e2e-test-bucket-name-{{testingId}}
238294

239295
-
240296
metricName: Fault
@@ -333,7 +389,7 @@
333389
value: AWS.SDK.S3
334390
-
335391
name: RemoteTarget
336-
value: ::s3:::e2e-test-bucket-name
392+
value: ::s3:::e2e-test-bucket-name-{{testingId}}
337393

338394
-
339395
metricName: Fault
@@ -353,6 +409,33 @@
353409
value: AWS.SDK.S3
354410
-
355411
name: RemoteTarget
356-
value: ::s3:::e2e-test-bucket-name
412+
value: ::s3:::e2e-test-bucket-name-{{testingId}}
413+
414+
-
415+
metricName: Fault
416+
namespace: {{metricNamespace}}
417+
dimensions:
418+
-
419+
name: Service
420+
value: {{serviceName}}
421+
-
422+
name: HostedIn.Environment
423+
value: EC2
424+
-
425+
name: RemoteService
426+
value: AWS.SDK.S3
427+
-
428+
name: RemoteTarget
429+
value: ::s3:::e2e-test-bucket-name-{{testingId}}
357430

431+
-
432+
metricName: Fault
433+
namespace: {{metricNamespace}}
434+
dimensions:
435+
-
436+
name: RemoteService
437+
value: AWS.SDK.S3
438+
-
439+
name: RemoteTarget
440+
value: ::s3:::e2e-test-bucket-name-{{testingId}}
358441

0 commit comments

Comments
 (0)