Skip to content

Commit d0199f1

Browse files
committed
fix: datadog 에이전트를 사이드카로 수정
1 parent 33bdd3d commit d0199f1

File tree

2 files changed

+86
-118
lines changed

2 files changed

+86
-118
lines changed

terraform/dev/locals.tf

Lines changed: 65 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -63,57 +63,71 @@ locals {
6363
}
6464

6565
container_definitions_map = {
66-
for svc, def in local.task_definitions_with_roles : svc => [
67-
{
68-
name = svc
69-
image = svc == "api-dev" ? "${local.ecr_repo_urls["dev"]}:placeholder" : def.container_image
70-
cpu = def.cpu
71-
memory = def.memory
72-
essential = true
73-
stopTimeout = lookup(def, "stop_timeout", 30)
74-
command = svc == "api-dev" ? [
75-
"java",
76-
"-javaagent:/dd-java-agent.jar",
77-
"-Ddd.logs.injection=true",
78-
"-Ddd.runtime-metrics.enabled=true",
79-
"-Ddd.service=eatda-api",
80-
"-Ddd.env=dev",
81-
"-Ddd.version=v1",
82-
"-Ddd.agent.host=10.0.7.245",
83-
"-Dspring.profiles.active=dev",
84-
"-jar",
85-
"/api.jar"
86-
] : null
87-
portMappings = [
88-
for m in lookup(def, "port_mappings", []) : {
89-
name = "${svc}-${m.container_port}-${m.protocol}"
90-
containerPort = m.container_port
91-
hostPort = m.host_port
92-
protocol = m.protocol
93-
}
94-
]
95-
environment = [for k, v in lookup(def, "environment", {}) : { name = k, value = v }]
96-
secrets = svc == "datadog-agent-task" ? [
97-
{ name = "DD_API_KEY", valueFrom = "/dev/DD_API_KEY" }
98-
] : (svc == "mysql-dev" ? [
99-
{ name = "MYSQL_USER", valueFrom = "/dev/MYSQL_USER_NAME" },
100-
{ name = "MYSQL_ROOT_PASSWORD", valueFrom = "/dev/MYSQL_ROOT_PASSWORD" },
101-
{ name = "MYSQL_PASSWORD", valueFrom = "/dev/MYSQL_PASSWORD" }
102-
] : [
103-
for s in lookup(def, "secrets", []) : {
104-
name = s.name
105-
valueFrom = s.valueFrom
106-
}
107-
])
108-
mountPoints = [
109-
for vol in lookup(def, "volumes", []) : {
110-
sourceVolume = vol.name
111-
containerPath = vol.containerPath
112-
readOnly = vol.readOnly
113-
}
114-
]
115-
}
116-
]
66+
for svc, task_def in local.task_definitions_with_roles : svc =>
67+
(svc == "api-dev" ?
68+
[
69+
{
70+
name = "api-dev"
71+
image = "${local.ecr_repo_urls["dev"]}:placeholder"
72+
cpu = task_def.cpu
73+
memory = contains(keys(task_def), "memory") ? task_def.memory : null
74+
essential = true
75+
command = [
76+
"java", "-javaagent:/dd-java-agent.jar",
77+
"-Ddd.logs.injection=true", "-Ddd.runtime-metrics.enabled=true",
78+
"-Ddd.service=eatda-api", "-Ddd.env=dev", "-Ddd.version=v1",
79+
"-Ddd.agent.host=127.0.0.1",
80+
"-Dspring.profiles.active=dev", "-jar", "/api.jar"
81+
]
82+
portMappings = [{ containerPort = 8080, hostPort = 0, protocol = "tcp" }]
83+
mountPoints = [{ sourceVolume = "dev-api-volume", containerPath = "/logs", readOnly = false }]
84+
},
85+
{
86+
name = "datadog-agent"
87+
image = "public.ecr.aws/datadog/agent:latest"
88+
cpu = 256
89+
memory = 128
90+
essential = true
91+
environment = [
92+
{ name = "DD_SITE", value = "us5.datadoghq.com" },
93+
{ name = "DD_PROCESS_AGENT_ENABLED", value = "true" },
94+
{ name = "DD_APM_ENABLED", value = "true" },
95+
{ name = "DD_LOGS_ENABLED", value = "true" },
96+
{ name = "DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL", value = "true" },
97+
{ name = "DD_DOGSTATSD_NON_LOCAL_TRAFFIC", value = "false" },
98+
]
99+
secrets = [{ name = "DD_API_KEY", valueFrom = "/dev/DD_API_KEY" }]
100+
mountPoints = [
101+
{ sourceVolume = "docker_sock", containerPath = "/var/run/docker.sock", readOnly = true },
102+
{ sourceVolume = "proc", containerPath = "/host/proc", readOnly = true },
103+
{ sourceVolume = "cgroup", containerPath = "/host/sys/fs/cgroup", readOnly = true }
104+
]
105+
}
106+
]
107+
:
108+
[
109+
{
110+
name = svc
111+
image = task_def.container_image
112+
cpu = task_def.cpu
113+
memory = task_def.memory
114+
essential = true
115+
portMappings = [
116+
for m in lookup(task_def, "port_mappings", []) :
117+
{ containerPort = m.container_port, hostPort = m.host_port, protocol = m.protocol }
118+
]
119+
environment = [for k, v in lookup(task_def, "environment", {}) : { name = k, value = v }]
120+
secrets = [for s in lookup(task_def, "secrets", []) : { name = s.name, valueFrom = s.valueFrom }]
121+
mountPoints = [
122+
for vol in lookup(task_def, "volumes", []) : {
123+
sourceVolume = vol.name
124+
containerPath = (svc == "mysql-dev" && vol.name == "dev-mysql-volume") ? "/var/lib/mysql" :
125+
vol.containerPath
126+
readOnly = false
127+
}
128+
]
129+
}
130+
])
117131
}
118132

119133
final_ecs_definitions_for_module = {

terraform/dev/terraform.tfvars

Lines changed: 21 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,13 @@ ecs_services = {
1111
mysql-dev = {
1212
task_definition = "mysql"
1313
}
14-
15-
datadog-agent-task = {
16-
task_definition = "datadog-agent-task"
17-
scheduling_strategy = "DAEMON"
18-
}
1914
}
2015

2116
ecs_task_definitions_base = {
2217
api-dev = {
23-
cpu = 256
24-
memory = 256
25-
network_mode = "bridge"
18+
cpu = 512
19+
memoryReservation = 384
20+
network_mode = "bridge"
2621
requires_compatibilities = ["EC2"]
2722

2823
port_mappings = [
@@ -36,10 +31,24 @@ ecs_task_definitions_base = {
3631
environment = {}
3732
volumes = [
3833
{
39-
name = "dev-api-volume"
40-
host_path = "/home/ec2-user/logs/"
41-
containerPath = "/logs"
42-
readOnly = false
34+
name = "dev-api-volume"
35+
host_path = "/home/ec2-user/logs/"
36+
readOnly = false
37+
},
38+
{
39+
name = "docker_sock"
40+
host_path = "/var/run/docker.sock"
41+
readOnly = true
42+
},
43+
{
44+
name = "proc"
45+
host_path = "/proc/"
46+
readOnly = true
47+
},
48+
{
49+
name = "cgroup"
50+
host_path = "/sys/fs/cgroup/"
51+
readOnly = true
4352
}
4453
]
4554
}
@@ -86,59 +95,4 @@ ecs_task_definitions_base = {
8695
}
8796
]
8897
}
89-
90-
"datadog-agent-task" = {
91-
cpu = 256
92-
memory = 128
93-
network_mode = "bridge"
94-
requires_compatibilities = ["EC2"]
95-
container_image = "public.ecr.aws/datadog/agent:latest"
96-
97-
port_mappings = [
98-
{
99-
container_port = 8126,
100-
host_port = 8126,
101-
protocol = "tcp"
102-
},
103-
{
104-
container_port = 8125,
105-
host_port = 8125,
106-
protocol = "udp"
107-
}
108-
]
109-
110-
environment = {
111-
DD_SITE = "us5.datadoghq.com"
112-
DD_PROCESS_AGENT_ENABLED = "true"
113-
DD_APM_ENABLED = "true"
114-
DD_LOGS_ENABLED = "true"
115-
DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL = "true"
116-
DD_EC2_USE_IMDSV2 = "true"
117-
DD_DOGSTATSD_NON_LOCAL_TRAFFIC = "true"
118-
DD_SERVICE = "eatda-api"
119-
DD_ENV = "dev"
120-
DD_VERSION = "v1"
121-
}
122-
123-
volumes = [
124-
{
125-
name = "docker_sock"
126-
host_path = "/var/run/docker.sock"
127-
containerPath = "/var/run/docker.sock"
128-
readOnly = true
129-
},
130-
{
131-
name = "proc"
132-
host_path = "/proc/"
133-
containerPath = "/host/proc"
134-
readOnly = true
135-
},
136-
{
137-
name = "cgroup"
138-
host_path = "/sys/fs/cgroup/"
139-
containerPath = "/host/sys/fs/cgroup"
140-
readOnly = true
141-
}
142-
]
143-
}
14498
}

0 commit comments

Comments
 (0)