Skip to content

Commit

Permalink
Add back ECS fargate
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhntd committed May 4, 2022
1 parent 4f3eb4c commit ada9cd7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ release: clean test build package-rpm package-deb package-win package-darwin

nightly-release: release

build: check_secrets cwagent-otel-collector amazon-cloudwatch-agent config-translator start-amazon-cloudwatch-agent amazon-cloudwatch-agent-config-wizard config-downloader
build: check_secrets cwagent-otel-collector amazon-cloudwatch-agent config-translator start-amazon-cloudwatch-agent amazon-cloudwatch-agent-config-wizard config-downloader

check_secrets::
if grep --exclude-dir=build --exclude-dir=vendor -E "(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}|(\"|')?(AWS|aws|Aws)?_?(SECRET|secret|Secret)?_?(ACCESS|access|Access)?_?(KEY|key|Key)(\"|')?\\s*(:|=>|=)\\s*(\"|')?[A-Za-z0-9/\\+=]{40}(\"|')?" -Rn .; then echo "check_secrets failed"; exit 1; fi;
Expand Down
2 changes: 1 addition & 1 deletion integration/generator/test_case_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var osToTestDirMap = map[string][]string{
"ec2_windows": {""},
"ec2_mac": {},
"ecs_fargate": {
"../../../test/ecs/ecs_metadata",
"./integration/test/ecs/ecs_metadata",
},
}

Expand Down
15 changes: 13 additions & 2 deletions integration/terraform/ecs/linux/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
Running ECS Fargate Integration Tests
=========================

# 1. Setup resources
## 1. How ECS Fargate are set up?
**Step 1:** Create a Fargate ECS Cluster with the default VPC Network.
**Step 2:** Create a security group to assign to the service in step 5 which allows all inbound
traffics and outbound traffics
**Step 3:** Create a IAM Role and IAM Execution Role for the containers to pull the image and
execute their purposes
**Step 4:** Create a [task definition](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definitions.html)
to decide which containers serve a specific task and assign the IAM roles in step 3 to the containers
**Step 5:** Create a [service](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_services.html) which configure
how many tasks are running in parallel and ensure availability of the task.

## 2. Setup resources
By running `terraform apply -auto-approve -lock=false`,
you agree to setup the following resources:
* 1 IAM Task Role and 1 Execution Task Role (similar to [these IAM Roles](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/deploy_servicelens_CloudWatch_agent_deploy_ECS.html))
Expand Down Expand Up @@ -41,7 +52,7 @@ To be more specifically,
* **CloudWatchAgent Parameter Store:** Store CloudWatchAgent's configuration and CloudWatchAgent will pull the config from there. [Example configuration](default_resources/default_amazon_cloudwatch_agent.json)
* **Prometheus Parameter Store:** Store Prometheus's configuration and CloudWatchAgent will pull the config from there. [Example configuration](default_resources/default_ecs_prometheus.tpl)

# 2. Run tests in your AWS account
## 3. Run tests in your AWS account
````
cd integration/terraform/ecs && terraform init && terraform apply -auto-approve \
-var="test_dir={{your test case folder name}} \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,6 @@
"^redis_memory_used_bytes$",
"^redis_connected_clients$"
]
},
{
"source_labels": ["container_name"],
"label_matcher": "^redis-exporter-.*$",
"dimensions": [["ClusterName","TaskDefinitionFamily","cmd"]],
"metric_selectors": [
"^redis_commands_total$"
]
},
{
"source_labels": ["container_name"],
"label_matcher": "^redis-exporter-.*$",
"dimensions": [["ClusterName","TaskDefinitionFamily","db"]],
"metric_selectors": [
"^redis_db_keys$"
]
}
]
}
Expand Down
9 changes: 5 additions & 4 deletions integration/terraform/ecs/linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ resource "aws_cloudwatch_log_group" "log_group" {
##########################################

locals {
cwagent_config = fileexists("${var.test_dir}/resources/config.json") ? "${var.test_dir}/resources/config.json" : "./default_resources/default_amazon_cloudwatch_agent.json"
cwagent_ecs_taskdef = fileexists("${var.test_dir}/resources/ecs_taskdef.tpl") ? "${var.test_dir}/resources/ecs_taskdef.tpl" : "./default_resources/default_ecs_taskdef.tpl"
prometheus_config = fileexists("${var.test_dir}/resources/ecs_prometheus.tpl") ? "${var.test_dir}/resources/ecs_prometheus.tpl" : "./default_resources/default_ecs_prometheus.tpl"
extra_apps_ecs_taskdef = fileexists("${var.test_dir}/resources/extra_apps.tpl") ? "${var.test_dir}/resources/extra_apps.tpl" : "./default_resources/default_extra_apps.tpl"
cwagent_config = fileexists("../../../../${var.test_dir}/resources/config.json") ? "../../../../${var.test_dir}/resources/config.json" : "./default_resources/default_amazon_cloudwatch_agent.json"
cwagent_ecs_taskdef = fileexists("../../../../${var.test_dir}/resources/ecs_taskdef.tpl") ? "../../../../${var.test_dir}/resources/ecs_taskdef.tpl" : "./default_resources/default_ecs_taskdef.tpl"
prometheus_config = fileexists("../../../../${var.test_dir}/resources/ecs_prometheus.tpl") ? "../../../../${var.test_dir}/resources/ecs_prometheus.tpl" : "./default_resources/default_ecs_prometheus.tpl"
extra_apps_ecs_taskdef = fileexists("../../../../${var.test_dir}/resources/extra_apps.tpl") ? "../../../../${var.test_dir}/resources/extra_apps.tpl" : "./default_resources/default_extra_apps.tpl"
}

data "template_file" "cwagent_config" {
Expand Down Expand Up @@ -134,6 +134,7 @@ resource "null_resource" "validator" {
provisioner "local-exec" {
command = <<-EOT
echo "Validating metrics/logs"
cd ../../../..
go test ${var.test_dir} -clusterName=${aws_ecs_cluster.cluster.name} --tags=integration
EOT
}
Expand Down
6 changes: 3 additions & 3 deletions integration/terraform/ecs/linux/variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
variable "region" {
type = string
default = "us-east-2"
default = "us-west-2"
}

variable "cwagent_image_repo" {
Expand All @@ -9,11 +9,11 @@ variable "cwagent_image_repo" {
}

variable "cwagent_image_tag" {
type = string
type = string
default = "latest"
}

variable "test_dir" {
type = string
default = "../../../test/ecs/ecs_metadata"
default = "./integration/test/ecs/ecs_metadata"
}

0 comments on commit ada9cd7

Please sign in to comment.