Skip to content

Commit 9f23b86

Browse files
author
Aman Brar
authored
Make ec2 test compatible with prometheus (#144)
* added environment variables to EC2 AOC deployment * make env vars only on amazon linux * remove unneeded changes * made env vars command modular and added windows env vars * remove cortex instance endpoint var for backwards compatibility * ec2 working with windows
1 parent 9ca4f5f commit 9f23b86

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

terraform/ec2/amis.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ variable "ami_family" {
2222
otconfig_destination = "/tmp/ot-default.yml"
2323
download_command_pattern = "wget %s"
2424
install_command = "sudo dpkg -i aws-otel-collector.deb"
25+
set_env_var_command = "echo \"no env vars to assign values %s and %s to\""
2526
start_command = "sudo /opt/aws/aws-otel-collector/bin/aws-otel-collector-ctl -c /tmp/ot-default.yml -a start"
2627
connection_type = "ssh"
2728
user_data = ""
@@ -33,6 +34,7 @@ variable "ami_family" {
3334
otconfig_destination = "/tmp/ot-default.yml"
3435
download_command_pattern = "wget %s"
3536
install_command = "sudo rpm -Uvh aws-otel-collector.rpm"
37+
set_env_var_command = "sudo chmod 777 /opt/aws/aws-otel-collector/etc/.env && sudo echo 'SAMPLE_APP_HOST=%s' >> /opt/aws/aws-otel-collector/etc/.env && sudo echo 'SAMPLE_APP_PORT=%s' >> /opt/aws/aws-otel-collector/etc/.env"
3638
start_command = "sudo /opt/aws/aws-otel-collector/bin/aws-otel-collector-ctl -c /tmp/ot-default.yml -a start"
3739
connection_type = "ssh"
3840
user_data = ""
@@ -44,6 +46,7 @@ variable "ami_family" {
4446
otconfig_destination = "C:\\ot-default.yml"
4547
download_command_pattern = "powershell -command \"Invoke-WebRequest -Uri %s -OutFile C:\\aws-otel-collector.msi\""
4648
install_command = "msiexec /i C:\\aws-otel-collector.msi"
49+
set_env_var_command = "powershell \"[System.Environment]::SetEnvironmentVariable('SAMPLE_APP_HOST', '%s', [System.EnvironmentVariableTarget]::Machine); [System.Environment]::SetEnvironmentVariable('SAMPLE_APP_PORT', '%s', [System.EnvironmentVariableTarget]::Machine)\""
4750
start_command = "powershell \"& 'C:\\Program Files\\Amazon\\AwsOtelCollector\\aws-otel-collector-ctl.ps1' -ConfigLocation C:\\ot-default.yml -Action start\""
4851
connection_type = "winrm"
4952
user_data = <<EOF

terraform/ec2/main.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ resource "null_resource" "start_collector" {
224224
provisioner "remote-exec" {
225225
inline = [
226226
local.ami_family["install_command"],
227+
format(local.ami_family["set_env_var_command"], aws_instance.sidecar.public_ip, module.common.sample_app_lb_port),
227228
local.ami_family["start_command"],
228229
]
229230

@@ -361,10 +362,12 @@ module "validator" {
361362
canary = var.canary
362363
testcase = split("/", var.testcase)[2]
363364

365+
cortex_instance_endpoint = var.cortex_instance_endpoint
366+
364367
aws_access_key_id = var.aws_access_key_id
365368
aws_secret_access_key = var.aws_secret_access_key
366369

367-
depends_on = [null_resource.setup_sample_app_and_mock_server]
370+
depends_on = [null_resource.setup_sample_app_and_mock_server, null_resource.start_collector]
368371
}
369372

370373
output "public_ip" {

terraform/ec2/outputs.tf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,3 @@ output "sample_app_instance_id" {
2121
output "testing_id" {
2222
value = module.common.testing_id
2323
}
24-
25-

terraform/ec2/variables.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,5 @@ variable "canary" {
100100
}
101101

102102
variable "cortex_instance_endpoint" {
103-
# change to your cortex endpoint
104103
default = ""
105104
}

terraform/testcases/prometheus_static/parameters.tfvars

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,4 @@ validation_config="prometheus-metric-validation.yml"
33

44
sample_app="prometheus"
55

6-
# change to your cortex endpoint
7-
cortex_instance_endpoint=""
8-
9-
sample_app_mode="pull"
6+
sample_app_mode="pull"

0 commit comments

Comments
 (0)