Skip to content

Commit 27f1cb6

Browse files
author
Aman Brar
authored
removed env vars entirely and updated prometheus validator (#173)
1 parent 2b999b6 commit 27f1cb6

File tree

14 files changed

+56
-35
lines changed

14 files changed

+56
-35
lines changed

terraform/basic_components/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ data "template_file" "otconfig" {
7474
grpc_port = module.common.grpc_port
7575
udp_port = module.common.udp_port
7676
cortex_instance_endpoint = var.cortex_instance_endpoint
77+
sample_app_listen_address_host = var.sample_app_listen_address_host
78+
sample_app_listen_address_port = var.sample_app_listen_address_port
7779

7880
mock_endpoint = var.mocked_endpoint
7981
}

terraform/basic_components/variables.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ variable "sample_app" {
3232
variable "cortex_instance_endpoint" {
3333
default = ""
3434
}
35+
36+
variable "sample_app_listen_address_host" {
37+
default = ""
38+
}
39+
40+
variable "sample_app_listen_address_port" {
41+
default = ""
42+
}

terraform/canary/amis.tf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ variable "ami_family" {
77
otconfig_destination = "/tmp/ot-default.yml"
88
download_command_pattern = "wget %s"
99
install_command = "sudo rpm -Uvh aws-otel-collector.rpm"
10-
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"
1110
start_command = "sudo /opt/aws/aws-otel-collector/bin/aws-otel-collector-ctl -c /tmp/ot-default.yml -a start"
1211
connection_type = "ssh"
1312
user_data = ""
@@ -19,7 +18,6 @@ variable "ami_family" {
1918
otconfig_destination = "C:\\ot-default.yml"
2019
download_command_pattern = "powershell -command \"Invoke-WebRequest -Uri %s -OutFile C:\\aws-otel-collector.msi\""
2120
install_command = "msiexec /i C:\\aws-otel-collector.msi"
22-
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)\""
2321
start_command = "powershell \"& 'C:\\Program Files\\Amazon\\AwsOtelCollector\\aws-otel-collector-ctl.ps1' -ConfigLocation C:\\ot-default.yml -Action start\""
2422
connection_type = "winrm"
2523
user_data = <<EOF

terraform/ec2/amis.tf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ 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\""
2625
start_command = "sudo /opt/aws/aws-otel-collector/bin/aws-otel-collector-ctl -c /tmp/ot-default.yml -a start"
2726
connection_type = "ssh"
2827
user_data = ""
@@ -34,7 +33,6 @@ variable "ami_family" {
3433
otconfig_destination = "/tmp/ot-default.yml"
3534
download_command_pattern = "wget %s"
3635
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"
3836
start_command = "sudo /opt/aws/aws-otel-collector/bin/aws-otel-collector-ctl -c /tmp/ot-default.yml -a start"
3937
connection_type = "ssh"
4038
user_data = ""
@@ -46,7 +44,6 @@ variable "ami_family" {
4644
otconfig_destination = "C:\\ot-default.yml"
4745
download_command_pattern = "powershell -command \"Invoke-WebRequest -Uri %s -OutFile C:\\aws-otel-collector.msi\""
4846
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)\""
5047
start_command = "powershell \"& 'C:\\Program Files\\Amazon\\AwsOtelCollector\\aws-otel-collector-ctl.ps1' -ConfigLocation C:\\ot-default.yml -Action start\""
5148
connection_type = "winrm"
5249
user_data = <<EOF

terraform/ec2/main.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ module "basic_components" {
3333
sample_app = var.sample_app
3434

3535
cortex_instance_endpoint = var.cortex_instance_endpoint
36+
37+
sample_app_listen_address_host = aws_instance.sidecar.public_ip
38+
39+
sample_app_listen_address_port = module.common.sample_app_lb_port
3640
}
3741

3842
provider "aws" {
@@ -224,7 +228,6 @@ resource "null_resource" "start_collector" {
224228
provisioner "remote-exec" {
225229
inline = [
226230
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),
228231
local.ami_family["start_command"],
229232
]
230233

terraform/ec2_setup/amis.tf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ variable "ami_family" {
77
otconfig_destination = "/tmp/ot-default.yml"
88
download_command_pattern = "wget %s"
99
install_command = "sudo rpm -Uvh aws-otel-collector.rpm && sudo chmod 777 /opt/aws/aws-otel-collector/etc/.env && sudo echo 'GODEBUG=madvdontneed=1' >> /opt/aws/aws-otel-collector/etc/.env"
10-
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"
1110
start_command = "sudo /opt/aws/aws-otel-collector/bin/aws-otel-collector-ctl -c /tmp/ot-default.yml -a start"
1211
connection_type = "ssh"
1312
user_data = ""
@@ -27,7 +26,6 @@ variable "ami_family" {
2726
otconfig_destination = "C:\\ot-default.yml"
2827
download_command_pattern = "powershell -command \"Invoke-WebRequest -Uri %s -OutFile C:\\aws-otel-collector.msi\""
2928
install_command = "msiexec /i C:\\aws-otel-collector.msi"
30-
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)\""
3129
start_command = "powershell \"& 'C:\\Program Files\\Amazon\\AwsOtelCollector\\aws-otel-collector-ctl.ps1' -ConfigLocation C:\\ot-default.yml -Action start\""
3230
connection_type = "winrm"
3331
soaking_cwagent_config = "../templates/cwagent-config/soaking-linux.json.tpl"

terraform/eks/main.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ module "basic_components" {
3838
sample_app = var.sample_app
3939

4040
cortex_instance_endpoint = var.cortex_instance_endpoint
41+
42+
sample_app_listen_address_host = var.sample_app_mode == "pull" ? kubernetes_service.pull_mode_sample_app_service[0].load_balancer_ingress.0.hostname : ""
43+
44+
sample_app_listen_address_port = module.common.sample_app_lb_port
4145
}
4246

4347
locals {
@@ -389,13 +393,15 @@ resource "kubernetes_service" "mocked_server_service" {
389393

390394
# create service upon the sample app
391395
resource "kubernetes_service" "sample_app_service" {
396+
count = var.sample_app_mode == "push" ? 1 : 0
397+
392398
metadata {
393399
name = "sample-app"
394400
namespace = kubernetes_namespace.aoc_ns.metadata[0].name
395401
}
396402
spec {
397403
selector = {
398-
app = var.sample_app_mode == "push" ? kubernetes_deployment.sample_app_deployment[0].metadata[0].labels.app : kubernetes_deployment.pull_mode_sample_app_deployment[0].metadata[0].labels.app
404+
app = kubernetes_deployment.sample_app_deployment[0].metadata[0].labels.app
399405
}
400406

401407
type = "LoadBalancer"
@@ -417,7 +423,7 @@ module "validator" {
417423
region = var.region
418424
testing_id = module.common.testing_id
419425
metric_namespace = "${module.common.otel_service_namespace}/${module.common.otel_service_name}"
420-
sample_app_endpoint = "http://${kubernetes_service.sample_app_service.load_balancer_ingress.0.hostname}:${module.common.sample_app_lb_port}"
426+
sample_app_endpoint = "http://${var.sample_app_mode == "push" ? kubernetes_service.sample_app_service[0].load_balancer_ingress.0.hostname : kubernetes_service.pull_mode_sample_app_service[0].load_balancer_ingress.0.hostname}:${module.common.sample_app_lb_port}"
421427
mocked_server_validating_url = "http://${kubernetes_service.mocked_server_service.load_balancer_ingress.0.hostname}/check-data"
422428

423429
cortex_instance_endpoint = var.cortex_instance_endpoint

terraform/eks/pull_mode_deployment.tf

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,6 @@ resource "kubernetes_deployment" "pull_mode_aoc_deployment" {
8282
args = [
8383
"--config=/aoc/aoc-config.yml"]
8484

85-
env {
86-
name = "SAMPLE_APP_HOST"
87-
value = kubernetes_service.sample_app_service.load_balancer_ingress.0.hostname
88-
}
89-
90-
env {
91-
name = "SAMPLE_APP_PORT"
92-
value = module.common.sample_app_lb_port
93-
}
94-
9585
resources {
9686
requests {
9787
cpu = "0.2"
@@ -192,4 +182,26 @@ resource "kubernetes_deployment" "pull_mode_sample_app_deployment" {
192182
}
193183
}
194184
}
185+
}
186+
187+
# create service upon the sample app
188+
resource "kubernetes_service" "pull_mode_sample_app_service" {
189+
count = var.sample_app_mode == "pull" ? 1 : 0
190+
191+
metadata {
192+
name = "sample-app"
193+
namespace = kubernetes_namespace.aoc_ns.metadata[0].name
194+
}
195+
spec {
196+
selector = {
197+
app = kubernetes_deployment.pull_mode_sample_app_deployment[0].metadata[0].labels.app
198+
}
199+
200+
type = "LoadBalancer"
201+
202+
port {
203+
port = module.common.sample_app_lb_port
204+
target_port = module.common.sample_app_listen_address_port
205+
}
206+
}
195207
}

terraform/mock/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ data "template_file" "otconfig" {
4040
grpc_port = module.common.grpc_port
4141
udp_port = module.common.udp_port
4242
mock_endpoint = local.mock_endpoint
43+
sample_app_listen_address_host = "172.17.0.1"
44+
sample_app_listen_address_port = module.common.sample_app_listen_address_port
4345
}
4446
}
4547

terraform/templates/local/docker_compose.tpl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ services:
2626
- AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
2727
- AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
2828
- GODEBUG=x509ignoreCN=0
29-
- SAMPLE_APP_PORT=${sample_app_external_port}
30-
- SAMPLE_APP_HOST=172.17.0.1
3129
depends_on:
3230
- mocked-server
3331

0 commit comments

Comments
 (0)