Skip to content

Commit ee7a588

Browse files
authored
feat: added dynatrace oneagent - RK-19751 (#64)
* feat: added dynatrace oneagent * add tags * fix: dt env id variable
1 parent 04ed663 commit ee7a588

File tree

5 files changed

+185
-5
lines changed

5 files changed

+185
-5
lines changed

controller.tf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ locals {
2929
controller_version = var.controller_version
3030
controller_image = var.controller_image
3131
enforce_token = "${var.enforce_token}"
32+
deploy_dynatrace_agent = var.deploy_dynatrace_agent
33+
dynatrace_pass_token = var.dynatrace_pass_token
34+
environment = var.environment
35+
dynatrace_environment_id = var.dynatrace_environment_id
3236
})
3337

3438
}
3539

3640

3741
resource "aws_ecs_task_definition" "controller" {
3842

39-
family = "${local.controller_settings.container_name}-${var.environment}"
43+
family = "${local.controller_settings.container_name}"
4044
requires_compatibilities = ["FARGATE"]
4145
network_mode = "awsvpc"
4246
cpu = local.controller_settings.task_cpu
@@ -45,6 +49,13 @@ resource "aws_ecs_task_definition" "controller" {
4549
task_role_arn = var.custom_iam_task_exec_role_arn == "" ? aws_iam_role.task_exec_role[0].arn : var.custom_iam_task_exec_role_arn
4650
container_definitions = local.controller_definition
4751

52+
dynamic "volume" {
53+
for_each = var.deploy_dynatrace_agent ? [1] : []
54+
content {
55+
name = "oneagent"
56+
}
57+
}
58+
4859
}
4960

5061
resource "aws_ecs_service" "controller" {

datastore.tf

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
locals {
2-
datastore_settings = { # TODO: configure
2+
datastore_settings = {
33
container_name = "${var.environment}-datastore"
44
task_cpu = var.datastore_resource.cpu
55
task_memory = var.datastore_resource.memory
@@ -10,7 +10,6 @@ locals {
1010
container_memory = var.datastore_resource.memory
1111
container_port = 8080
1212
load_balancer_port = 8080
13-
storage_size = 21
1413
datastore_in_memory_db = true
1514
}
1615

@@ -30,6 +29,10 @@ locals {
3029
additional_env_vars = var.additional_datastore_env_vars
3130
datastore_version = var.datastore_version
3231
datastore_image = var.datastore_image
32+
deploy_dynatrace_agent = var.deploy_dynatrace_agent
33+
dynatrace_pass_token = var.dynatrace_pass_token
34+
environment = var.environment
35+
dynatrace_environment_id = var.dynatrace_environment_id
3336
})
3437

3538
}
@@ -46,8 +49,11 @@ resource "aws_ecs_task_definition" "datastore" {
4649
task_role_arn = var.custom_iam_task_exec_role_arn == "" ? aws_iam_role.task_exec_role[0].arn : var.custom_iam_task_exec_role_arn
4750
container_definitions = local.datastore_definition
4851

49-
ephemeral_storage {
50-
size_in_gib = local.datastore_settings.storage_size
52+
dynamic "volume" {
53+
for_each = var.deploy_dynatrace_agent ? [1] : []
54+
content {
55+
name = "oneagent"
56+
}
5157
}
5258

5359
}

templates/controller_task_def.tpl

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,37 @@
66
"memory": ${memory},
77
"memoryReservation": ${memory},
88
"essential": true,
9+
%{ if deploy_dynatrace_agent }
10+
"mountPoints": [
11+
{
12+
"sourceVolume": "oneagent",
13+
"containerPath": "/opt/dynatrace/oneagent",
14+
"readOnly": false
15+
}
16+
],
17+
"dependsOn": [
18+
{
19+
"containerName": "install-oneagent",
20+
"condition": "COMPLETE"
21+
}
22+
],
23+
%{ endif ~}
924
"portMappings": [
1025
{
1126
"containerPort": ${port}
1227
}
1328
],
1429
"environment": [
30+
%{ if deploy_dynatrace_agent }
31+
{
32+
"name": "LD_PRELOAD",
33+
"value": "/opt/dynatrace/oneagent/agent/lib64/liboneagentproc.so"
34+
},
35+
{
36+
"name": "DT_TAGS",
37+
"value": "Service=rookout.controller ECS=true env=${environment}"
38+
},
39+
%{ endif ~}
1540
{
1641
"name": "ROOKOUT_DOP_NO_SSL_VERIFY",
1742
"value": "${dop_no_ssl_verify}"
@@ -58,4 +83,51 @@
5883
"startPeriod": null
5984
}
6085
}
86+
%{ if deploy_dynatrace_agent }
87+
,{
88+
"name": "install-oneagent",
89+
"image": "alpine:3",
90+
"cpu": 0,
91+
"portMappings": [],
92+
"essential": false,
93+
"entryPoint": [
94+
"/bin/sh",
95+
"-c"
96+
],
97+
"command": [
98+
"ARCHIVE=$(mktemp) && wget -O $ARCHIVE \"$DT_API_URL/v1/deployment/installer/agent/unix/paas/latest?Api-Token=$DT_PAAS_TOKEN&$DT_ONEAGENT_OPTIONS\" && unzip -o -d /opt/dynatrace/oneagent $ARCHIVE && rm -f $ARCHIVE"
99+
],
100+
"environment": [
101+
{
102+
"name": "DT_PAAS_TOKEN",
103+
"value": "${dynatrace_pass_token}"
104+
},
105+
{
106+
"name": "DT_ONEAGENT_OPTIONS",
107+
"value": "flavor=musl&include=go"
108+
},
109+
{
110+
"name": "DT_API_URL",
111+
"value": "https://${dynatrace_environment_id}.live.dynatrace.com/api"
112+
}
113+
],
114+
"environmentFiles": [],
115+
"mountPoints": [
116+
{
117+
"sourceVolume": "oneagent",
118+
"containerPath": "/opt/dynatrace/oneagent",
119+
"readOnly": false
120+
}
121+
],
122+
"volumesFrom": [],
123+
"logConfiguration": {
124+
"logDriver": "awslogs",
125+
"options": {
126+
"awslogs-group": "${log_group}",
127+
"awslogs-region": "${aws_region}",
128+
"awslogs-stream-prefix": "${log_stream}"
129+
}
130+
}
131+
}
132+
%{ endif ~}
61133
]

templates/datastore_task_def.tpl

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,37 @@
66
"memory": ${memory},
77
"memoryReservation": ${memory},
88
"essential": true,
9+
%{ if deploy_dynatrace_agent }
10+
"mountPoints": [
11+
{
12+
"sourceVolume": "oneagent",
13+
"containerPath": "/opt/dynatrace/oneagent",
14+
"readOnly": false
15+
}
16+
],
17+
"dependsOn": [
18+
{
19+
"containerName": "install-oneagent",
20+
"condition": "COMPLETE"
21+
}
22+
],
23+
%{ endif ~}
924
"portMappings": [
1025
{
1126
"containerPort": ${port}
1227
}
1328
],
1429
"environment": [
30+
%{ if deploy_dynatrace_agent }
31+
{
32+
"name": "LD_PRELOAD",
33+
"value": "/opt/dynatrace/oneagent/agent/lib64/liboneagentproc.so"
34+
},
35+
{
36+
"name": "DT_TAGS",
37+
"value": "Service=rookout.datastore ECS=true env=${environment}"
38+
},
39+
%{ endif ~}
1540
{
1641
"name": "ROOKOUT_DOP_SERVER_MODE",
1742
"value": "${datastore_server_mode}"
@@ -59,4 +84,51 @@
5984
"startPeriod": null
6085
}
6186
}
87+
%{ if deploy_dynatrace_agent }
88+
,{
89+
"name": "install-oneagent",
90+
"image": "alpine:3",
91+
"cpu": 0,
92+
"portMappings": [],
93+
"essential": false,
94+
"entryPoint": [
95+
"/bin/sh",
96+
"-c"
97+
],
98+
"command": [
99+
"ARCHIVE=$(mktemp) && wget -O $ARCHIVE \"$DT_API_URL/v1/deployment/installer/agent/unix/paas/latest?Api-Token=$DT_PAAS_TOKEN&$DT_ONEAGENT_OPTIONS\" && unzip -o -d /opt/dynatrace/oneagent $ARCHIVE && rm -f $ARCHIVE"
100+
],
101+
"environment": [
102+
{
103+
"name": "DT_PAAS_TOKEN",
104+
"value": "${dynatrace_pass_token}"
105+
},
106+
{
107+
"name": "DT_ONEAGENT_OPTIONS",
108+
"value": "flavor=musl&include=go"
109+
},
110+
{
111+
"name": "DT_API_URL",
112+
"value": "https://${dynatrace_environment_id}.live.dynatrace.com/api"
113+
}
114+
],
115+
"environmentFiles": [],
116+
"mountPoints": [
117+
{
118+
"sourceVolume": "oneagent",
119+
"containerPath": "/opt/dynatrace/oneagent",
120+
"readOnly": false
121+
}
122+
],
123+
"volumesFrom": [],
124+
"logConfiguration": {
125+
"logDriver": "awslogs",
126+
"options": {
127+
"awslogs-group": "${log_group}",
128+
"awslogs-region": "${aws_region}",
129+
"awslogs-stream-prefix": "${log_stream}"
130+
}
131+
}
132+
}
133+
%{ endif ~}
62134
]

variables.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,23 @@ variable "demo_app_alb_sg_igress_cidr_blocks" {
270270
type = list(string)
271271
default = ["0.0.0.0/0"]
272272
description = "Ingress CIDRs datastore's ALB security group"
273+
}
274+
275+
variable "deploy_dynatrace_agent" {
276+
type = bool
277+
default = false
278+
description = "Flag to deploy dynatrace oneagent inside the application"
279+
}
280+
281+
variable "dynatrace_pass_token" {
282+
type = string
283+
default = ""
284+
sensitive = true
285+
description = "Dynatrace pass token"
286+
}
287+
288+
variable "dynatrace_environment_id" {
289+
type = string
290+
default = ""
291+
description = "Dynatrace environment id"
273292
}

0 commit comments

Comments
 (0)