Skip to content

Commit b348b7d

Browse files
authored
Merge pull request #28 from wyTrivail/terraform
support ecs context and skipping dimension
2 parents 59e4e70 + ee40820 commit b348b7d

File tree

8 files changed

+79
-35
lines changed

8 files changed

+79
-35
lines changed

terraform/ecs/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ output "rendered" {
7272
}
7373

7474
resource "aws_ecs_task_definition" "aoc" {
75-
family = "aoc-task-def-${module.common.testing_id}"
75+
family = "taskdef-${module.common.testing_id}"
7676
container_definitions = data.template_file.task_def.rendered
7777
network_mode = "awsvpc"
7878
requires_compatibilities = ["EC2", "FARGATE"]
@@ -136,7 +136,7 @@ resource "aws_lb_listener" "aoc_lb_listener" {
136136
resource "aws_ecs_service" "aoc" {
137137
# don't do lb if the sample app is not callable
138138
count = var.sample_app_callable ? 1 : 0
139-
name = "aoctaskdef-${module.common.testing_id}"
139+
name = "aocservice-${module.common.testing_id}"
140140
cluster = module.ecs_cluster.cluster_id
141141
task_definition = aws_ecs_task_definition.aoc.arn
142142
desired_count = 1
@@ -162,7 +162,7 @@ resource "aws_ecs_service" "aoc" {
162162
# remove lb since there's no callable sample app, some test cases will drop in here, for example, ecsmetadata receiver test
163163
resource "aws_ecs_service" "aoc_without_sample_app" {
164164
count = !var.sample_app_callable ? 1 : 0
165-
name = "aoc"
165+
name = "aocservice-${module.common.testing_id}"
166166
cluster = module.ecs_cluster.cluster_id
167167
task_definition = aws_ecs_task_definition.aoc.arn
168168
desired_count = 1
@@ -175,7 +175,7 @@ resource "aws_ecs_service" "aoc_without_sample_app" {
175175

176176
provisioner "local-exec" {
177177
working_dir = "../../"
178-
command = "${module.common.validator_path} --args='-c ${var.validation_config} -t ${module.common.testing_id} --region ${var.region} --metric-namespace ${module.common.otel_service_namespace}/${module.common.otel_service_name}'"
178+
command = "${module.common.validator_path} --args='-c ${var.validation_config} -t ${module.common.testing_id} --region ${var.region} --metric-namespace ${module.common.otel_service_namespace}/${module.common.otel_service_name} --ecs-context ecsClusterName=${module.ecs_cluster.cluster_name} --ecs-context ecsTaskArn=${aws_ecs_task_definition.aoc.arn} --ecs-context ecsTaskDefFamily=${aws_ecs_task_definition.aoc.family} --ecs-context ecsTaskDefVersion=${aws_ecs_task_definition.aoc.revision}'"
179179
}
180180
}
181181

terraform/testing-suites/xrayreceiver-ecs.tfvars

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ validation_config="xrayreceiver-trace-validation.yml"
77
data_emitter_image="josephwy/integ-test-emitter:xrayreceiver"
88

99
# todo this is config needs to be removed once we have statsd built in the aoc image
10-
aoc_image_repo="johnwu20/aocimage"
10+
aoc_image_repo="josephwy/awscollector"
1111

1212
# todo this version needs to be removed, instead version should be received from workflow
13-
aoc_version="v0.1.0"
13+
aoc_version="xray"
1414

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import com.amazon.aoc.helpers.ConfigLoadHelper;
44
import com.amazon.aoc.models.Context;
5+
import com.amazon.aoc.models.ECSContext;
56
import com.amazon.aoc.models.ValidationConfig;
67
import com.amazon.aoc.validators.ValidatorFactory;
8+
import com.fasterxml.jackson.databind.ObjectMapper;
79
import lombok.extern.log4j.Log4j2;
810
import picocli.CommandLine;
911

1012
import java.util.List;
13+
import java.util.Map;
1114
import java.util.concurrent.Callable;
1215

1316
@CommandLine.Command(name = "e2etest", mixinStandardHelpOptions = true, version = "1.0")
@@ -35,6 +38,12 @@ public class App implements Callable<Integer> {
3538
defaultValue = "us-west-2")
3639
private String region;
3740

41+
@CommandLine.Option(
42+
names = {"--ecs-context"},
43+
description = "eg, --ecs-context ecsCluster=xxx --ecs-context ecsTaskArn=xxxx"
44+
)
45+
private Map<String, String> ecsContexts;
46+
3847
public static void main(String[] args) throws Exception {
3948
int exitCode = new CommandLine(new App()).execute(args);
4049
System.exit(exitCode);
@@ -49,6 +58,8 @@ public Integer call() throws Exception {
4958
// build context
5059
Context context = new Context(this.testingId, this.metricNamespace, this.region);
5160
context.setEndpoint(this.endpoint);
61+
context.setEcsContext(buildECSContext(ecsContexts));
62+
5263
log.info(context);
5364

5465
// run validation
@@ -58,4 +69,11 @@ public Integer call() throws Exception {
5869
}
5970
return null;
6071
}
72+
73+
private ECSContext buildECSContext(Map<String, String> ecsContextMap){
74+
if(ecsContextMap == null) {
75+
return null;
76+
}
77+
return new ObjectMapper().convertValue(ecsContextMap, ECSContext.class);
78+
}
6179
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ public class Context {
2727
@NonNull private String region;
2828

2929
private String endpoint;
30+
31+
private ECSContext ecsContext;
3032
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.amazon.aoc.models;
2+
3+
import lombok.Data;
4+
5+
@Data
6+
public class ECSContext {
7+
// ecs related context
8+
private String ecsClusterName;
9+
private String ecsTaskArn;
10+
private String ecsTaskDefFamily;
11+
private String ecsTaskDefVersion;
12+
}

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

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,15 @@ private void compareMetricLists(List<Metric> toBeCheckedMetricList, List<Metric>
9898
// sort and check dimensions
9999
List<Dimension> dimensionList1 = o1.getDimensions();
100100
List<Dimension> dimensionList2 = o2.getDimensions();
101+
102+
// remove the skipped dimension
103+
dimensionList1.removeIf( dimension -> dimension.getValue().equals("SKIP"));
104+
dimensionList2.removeIf( dimension -> dimension.getValue().equals("SKIP"));
105+
106+
// sort
101107
dimensionList1.sort(Comparator.comparing(Dimension::getName));
102108
dimensionList2.sort(Comparator.comparing(Dimension::getName));
109+
103110
return dimensionList1.toString().compareTo(dimensionList2.toString());
104111
});
105112
for (Metric metric : baseMetricList) {
@@ -158,40 +165,54 @@ private List<Metric> rollupMetric(List<Metric> metricList) {
158165
for (Metric metric : metricList) {
159166
// get otellib dimension out
160167
// assuming the first dimension is otellib, if not the validation fails
161-
Dimension otellibDimension = metric.getDimensions().remove(0);
162-
assert otellibDimension.getName().equals(DEFAULT_DIMENSION_NAME);
168+
Dimension otellibDimension = metric.getDimensions().get(0);
169+
boolean otelLibDimensionExisted = otellibDimension.getName().equals(DEFAULT_DIMENSION_NAME);
170+
if(otelLibDimensionExisted) {
171+
metric.getDimensions().remove(0);
172+
}
163173

164174
// all dimension rollup
165175
Metric allDimensionsMetric = new Metric();
166176
allDimensionsMetric.setMetricName(metric.getMetricName());
167177
allDimensionsMetric.setNamespace(metric.getNamespace());
168178
allDimensionsMetric.setDimensions(metric.getDimensions());
169-
allDimensionsMetric
170-
.getDimensions()
171-
.add(new Dimension()
172-
.withName(otellibDimension.getName()).withValue(otellibDimension.getValue()));
179+
180+
if (otelLibDimensionExisted) {
181+
allDimensionsMetric
182+
.getDimensions()
183+
.add(
184+
new Dimension()
185+
.withName(otellibDimension.getName())
186+
.withValue(otellibDimension.getValue()));
187+
}
173188
rollupMetricList.add(allDimensionsMetric);
174189

175190
// zero dimension rollup
176191
Metric zeroDimensionMetric = new Metric();
177192
zeroDimensionMetric.setNamespace(metric.getNamespace());
178193
zeroDimensionMetric.setMetricName(metric.getMetricName());
179-
zeroDimensionMetric.setDimensions(
180-
Arrays.asList(
181-
new Dimension()
182-
.withName(otellibDimension.getName()).withValue(otellibDimension.getValue())));
194+
195+
if (otelLibDimensionExisted) {
196+
zeroDimensionMetric.setDimensions(
197+
Arrays.asList(
198+
new Dimension()
199+
.withName(otellibDimension.getName())
200+
.withValue(otellibDimension.getValue())));
201+
}
183202
rollupMetricList.add(zeroDimensionMetric);
184203

185204
// single dimension rollup
186205
for (Dimension dimension : metric.getDimensions()) {
187206
Metric singleDimensionMetric = new Metric();
188207
singleDimensionMetric.setNamespace(metric.getNamespace());
189208
singleDimensionMetric.setMetricName(metric.getMetricName());
190-
singleDimensionMetric.setDimensions(
191-
Arrays.asList(
192-
new Dimension()
193-
.withName(otellibDimension.getName())
194-
.withValue(otellibDimension.getValue())));
209+
if (otelLibDimensionExisted) {
210+
singleDimensionMetric.setDimensions(
211+
Arrays.asList(
212+
new Dimension()
213+
.withName(otellibDimension.getName())
214+
.withValue(otellibDimension.getValue())));
215+
}
195216
singleDimensionMetric.getDimensions().add(dimension);
196217
rollupMetricList.add(singleDimensionMetric);
197218
}

validator/src/main/resources/expected-data-template/ecsContainerExpectedMetric.mustache

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@
22
metricName: ecs.task.memory.utilized_{{testingId}}
33
namespace: default
44
dimensions:
5-
-
6-
name: OTelLib
7-
value: Undefined
85
-
96
name: ecs.cluster
10-
value: "{{ecsClusterName}}"
7+
value: "{{ecsContext.ecsClusterName}}"
118
-
129
name: ecs.service
1310
value: "undefined"
1411
-
1512
name: ecs.task-arn
16-
value: "{{ecsTaskArn}}"
13+
value: "{{ecsContext.ecsTaskArn}}"
1714
-
1815
name: ecs.task-definition-family
19-
value: "{{ecsTaskDefFamily}}"
16+
value: "{{ecsContext.ecsTaskDefFamily}}"
2017
-
2118
name: ecs.task-definition-version
22-
value: "{{ecsTaskDefVersion}}"
19+
value: "{{ecsContext.ecsTaskDefVersion}}"
2320
-
2421
name: ecs.task-id
25-
value: "{{ecsTaskId}}"
22+
value: "SKIP"

validator/src/main/resources/expected-data-template/statsdExpectedMetric.mustache

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
metricName: testCounter.metric_{{testingId}}
33
namespace: {{metricNamespace}}
44
dimensions:
5-
-
6-
name: OTelLib
7-
value: Undefined
85
-
96
name: key
107
value: val
@@ -16,9 +13,6 @@
1613
metricName: testGauge.metric_{{testingId}}
1714
namespace: {{metricNamespace}}
1815
dimensions:
19-
-
20-
name: OTelLib
21-
value: Undefined
2216
-
2317
name: keyg
2418
value: valg

0 commit comments

Comments
 (0)