Skip to content

Commit 4393637

Browse files
author
Richard To
authored
Add integration tests for EKS Fargate Container Insights (#424)
1 parent f3bc116 commit 4393637

File tree

16 files changed

+334
-23
lines changed

16 files changed

+334
-23
lines changed

terraform/templates/defaults/validator_docker_compose.tpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,4 @@ services:
2626
- "--alarm-names=${cpu_alarm}"
2727
- "--alarm-names=${mem_alarm}"
2828
- "--alarm-names=${incoming_packets_alarm}"
29-
- "--cortex-instance-endpoint=${cortex_instance_endpoint}"
30-
29+
- "--cortex-instance-endpoint=${cortex_instance_endpoint}"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# this file is defined in validator/src/main/resources/validations
2+
validation_config = "eks-cw-container-insight.yml"
3+
4+
aoc_base_scenario = "infra"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# this file is defined in validator/src/main/resources/validations
2+
validation_config = "otelFargate-metric-validation.yml"
3+
4+
aoc_base_scenario = "infra"

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ public class App implements Callable<Integer> {
102102
description = "cortex instance validating url")
103103
private String cortexInstanceEndpoint;
104104

105+
@CommandLine.Option(
106+
names = {"--rollup"},
107+
defaultValue = "true")
108+
private boolean isRollup;
109+
105110
private static final String TEST_CASE_DIM_KEY = "testcase";
106111
private static final String CANARY_NAMESPACE = "Otel/Canary";
107112
private static final String CANARY_METRIC_NAME = "Success";
@@ -115,7 +120,7 @@ public static void main(String[] args) throws Exception {
115120
public Integer call() throws Exception {
116121
final Instant startTime = Instant.now();
117122
// build context
118-
Context context = new Context(this.testingId, this.region, this.isCanary);
123+
Context context = new Context(this.testingId, this.region, this.isCanary, this.isRollup);
119124
context.setAccountId(this.accountId);
120125
context.setAvailabilityZone(this.availabilityZone);
121126
context.setMetricNamespace(this.metricNamespace);

validator/src/main/java/com/amazon/aoc/fileconfigs/PredefinedExpectedTemplate.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public enum PredefinedExpectedTemplate implements FileConfig {
3535
"/expected-data-template/container-insight/eks/prometheus"),
3636
CONTAINER_INSIGHT_ECS_PROMETHEUS_METRIC(
3737
"/expected-data-template/container-insight/ecs/prometheus"),
38+
FARGATE_EXPECTED_METRIC("/expected-data-template/EKSFargateCWCIExpectedMetric.mustache"),
39+
3840

3941
/**
4042
* trace template, defined in resources.
@@ -80,8 +82,11 @@ public enum PredefinedExpectedTemplate implements FileConfig {
8082
"/expected-data-template/container-insight/ecs/ecs-instance"),
8183
CONTAINER_INSIGHT_ECS_PROMETHEUS_LOG(
8284
"/expected-data-template/container-insight/ecs/prometheus"),
85+
CONTAINER_INSIGHT_FARGATE_EKS_LOG(
86+
"/expected-data-template/container-insight/eks/fargate"),
8387
;
8488

89+
8590
private String path;
8691

8792
PredefinedExpectedTemplate(String path) {

validator/src/main/java/com/amazon/aoc/helpers/CWMetricHelper.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@ public class CWMetricHelper {
4242
* @param context testing context
4343
* @param expectedMetric expected template
4444
* @param caller http caller, none caller, could be null
45-
* @param rollup true then rollup metrics
4645
* @return list of metrics
4746
* @throws Exception when caller throws exception or template can not be found
4847
*/
4948
public List<Metric> listExpectedMetrics(
5049
Context context,
5150
FileConfig expectedMetric,
52-
ICaller caller,
53-
boolean rollup
51+
ICaller caller
5452
) throws Exception {
5553
// call endpoint
5654
if (caller != null) {
@@ -66,9 +64,10 @@ public List<Metric> listExpectedMetrics(
6664
yamlExpectedMetrics.getBytes(StandardCharsets.UTF_8),
6765
new TypeReference<List<Metric>>() {});
6866

69-
if (rollup) {
67+
if (context.getIsRollup()) {
7068
return this.rollupMetric(expectedMetricList);
7169
}
70+
7271
return expectedMetricList;
7372
}
7473

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public class Context {
3535
@NonNull
3636
private Boolean isCanary;
3737

38+
@NonNull
39+
private Boolean isRollup;
40+
3841
private String metricNamespace;
3942

4043
private String endpoint;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ public void validate() throws Exception {
6868
final List<Metric> expectedMetricList = cwMetricHelper.listExpectedMetrics(
6969
context,
7070
expectedMetric,
71-
caller,
72-
true
71+
caller
7372
);
7473
Set<String> skippedDimensionNameList = new HashSet<>();
7574
for (Metric metric : expectedMetricList) {
@@ -146,7 +145,6 @@ private void compareMetricLists(List<Metric> toBeCheckedMetricList, List<Metric>
146145
for (Metric metric : baseMetricList) {
147146
metricSet.add(metric);
148147
}
149-
150148
for (Metric metric : toBeCheckedMetricList) {
151149
if (!metricSet.contains(metric)) {
152150
throw new BaseException(
@@ -171,7 +169,6 @@ private List<Metric> listMetricFromCloudWatch(
171169
for (String metricName : metricNameMap.keySet()) {
172170
result.addAll(cloudWatchService.listMetrics(metricNameMap.get(metricName), metricName));
173171
}
174-
175172
return result;
176173
}
177174

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
import lombok.extern.log4j.Log4j2;
1010
import org.apache.commons.io.FilenameUtils;
1111

12+
import java.io.IOException;
1213
import java.time.Instant;
1314
import java.util.Arrays;
14-
import java.util.HashSet;
1515
import java.util.List;
16-
import java.util.Set;
1716

1817

1918
@Log4j2
@@ -46,8 +45,12 @@ void init(Context context, FileConfig expectedDataTemplate) throws Exception {
4645
FileConfig fileConfig = new LocalPathExpectedTemplate(FilenameUtils.concat(
4746
expectedDataTemplate.getPath().toString(),
4847
logType + ".json"));
49-
String templateInput = mustacheHelper.render(fileConfig, context);
50-
schemasToValidate.put(logType, parseJsonSchema(templateInput));
48+
try {
49+
String templateInput = mustacheHelper.render(fileConfig, context);
50+
schemasToValidate.put(logType, parseJsonSchema(templateInput));
51+
} catch (IOException e) {
52+
log.debug("The " + logType + " was not found for this expected template path.");
53+
}
5154
}
5255
}
5356

@@ -63,9 +66,9 @@ protected int getMaxRetryCount() {
6366

6467
@Override
6568
protected void fetchAndValidateLogs(Instant startTime) throws Exception {
66-
Set<String> logTypes = new HashSet<>(LOG_TYPE_TO_VALIDATE);
67-
log.info("Fetch and validate logs with types: " + String.join(", ", logTypes));
68-
for (String logType : logTypes) {
69+
log.info("Fetch and validate logs with types: "
70+
+ String.join(", ", schemasToValidate.keySet()));
71+
for (String logType : schemasToValidate.keySet()) {
6972
String filterPattern = String.format("{ $.Type = \"%s\"}", logType);
7073
List<FilteredLogEvent> logEvents = cloudWatchService.filterLogs(logGroupName, filterPattern,
7174
startTime.toEpochMilli(), QUERY_LIMIT);

0 commit comments

Comments
 (0)