Skip to content

Commit 3ed479b

Browse files
authored
feat: ECS Fargate APM Profiling (#19)
* Fix outdated example for secret arn * Add profiling into terraform interface * Make examples more clear that dummy apps are not datadog * Update smoke tests
1 parent 8a24581 commit 3ed479b

File tree

6 files changed

+29
-12
lines changed

6 files changed

+29
-12
lines changed

examples/ecs_fargate/main.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ module "datadog_ecs_fargate_task" {
3232
}
3333

3434
dd_apm = {
35-
enabled = true,
35+
enabled = true,
36+
profiling = true,
3637
}
3738

3839
dd_log_collection = {
@@ -44,20 +45,20 @@ module "datadog_ecs_fargate_task" {
4445
}
4546

4647
# Configure Task Definition
47-
family = "datadog-terraform-app"
48+
family = "dummy-terraform-app"
4849
container_definitions = jsonencode([
4950
{
50-
name = "datadog-dogstatsd-app",
51+
name = "dummy-dogstatsd-app",
5152
image = "ghcr.io/datadog/apps-dogstatsd:main",
5253
essential = false,
5354
},
5455
{
55-
name = "datadog-apm-app",
56+
name = "dummy-apm-app",
5657
image = "ghcr.io/datadog/apps-tracegen:main",
5758
essential = true,
5859
},
5960
{
60-
name = "datadog-cws-app",
61+
name = "dummy-cws-app",
6162
image = "public.ecr.aws/ubuntu/ubuntu:22.04_stable",
6263
essential = false,
6364
entryPoint = [

modules/ecs_fargate/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ module "ecs_fargate_task" {
2222
version = "1.0.0"
2323
2424
# Datadog Configuration
25-
dd_api_key_secret_arn = "arn:aws:secretsmanager:us-east-1:0000000000:secret:example-secret"
26-
dd_tags = "team:cont-p, owner:container-monitoring"
25+
dd_api_key_secret = {
26+
arn = "arn:aws:secretsmanager:us-east-1:0000000000:secret:example-secret"
27+
}
28+
dd_tags = "team:cont-p, owner:container-monitoring"
2729
2830
dd_dogstatsd = {
2931
enabled = true
@@ -227,7 +229,7 @@ No modules.
227229
| <a name="input_cpu"></a> [cpu](#input\_cpu) | Number of cpu units used by the task. If the `requires_compatibilities` is `FARGATE` this field is required | `number` | `256` | no |
228230
| <a name="input_dd_api_key"></a> [dd\_api\_key](#input\_dd\_api\_key) | Datadog API Key | `string` | `null` | no |
229231
| <a name="input_dd_api_key_secret"></a> [dd\_api\_key\_secret](#input\_dd\_api\_key\_secret) | Datadog API Key Secret ARN | <pre>object({<br/> arn = string<br/> })</pre> | `null` | no |
230-
| <a name="input_dd_apm"></a> [dd\_apm](#input\_dd\_apm) | Configuration for Datadog APM | <pre>object({<br/> enabled = optional(bool, true)<br/> socket_enabled = optional(bool, true)<br/> })</pre> | <pre>{<br/> "enabled": true,<br/> "socket_enabled": true<br/>}</pre> | no |
232+
| <a name="input_dd_apm"></a> [dd\_apm](#input\_dd\_apm) | Configuration for Datadog APM | <pre>object({<br/> enabled = optional(bool, true)<br/> socket_enabled = optional(bool, true)<br/> profiling = optional(bool, false)<br/> })</pre> | <pre>{<br/> "enabled": true,<br/> "profiling": false,<br/> "socket_enabled": true<br/>}</pre> | no |
231233
| <a name="input_dd_checks_cardinality"></a> [dd\_checks\_cardinality](#input\_dd\_checks\_cardinality) | Datadog Agent checks cardinality | `string` | `null` | no |
232234
| <a name="input_dd_cluster_name"></a> [dd\_cluster\_name](#input\_dd\_cluster\_name) | Datadog cluster name | `string` | `null` | no |
233235
| <a name="input_dd_cpu"></a> [dd\_cpu](#input\_dd\_cpu) | Datadog Agent container CPU units | `number` | `null` | no |

modules/ecs_fargate/datadog.tf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ locals {
118118
] : [],
119119
)
120120

121+
application_env_vars = concat(
122+
var.dd_apm.profiling != null ? [
123+
{
124+
name = "DD_PROFILING_ENABLED"
125+
value = tostring(var.dd_apm.profiling)
126+
}
127+
] : [],
128+
)
129+
121130
agent_dependency = var.dd_is_datadog_dependency_enabled && try(var.dd_health_check.command != null, false) ? [
122131
{
123132
containerName = "datadog-agent"
@@ -151,6 +160,7 @@ locals {
151160
local.apm_socket_var,
152161
local.dsd_port_var,
153162
local.ust_env_vars,
163+
local.application_env_vars,
154164
),
155165
# Append new volume mounts to any existing mountPoints.
156166
mountPoints = concat(
@@ -238,7 +248,7 @@ locals {
238248
{ key = "DD_SITE", value = var.dd_site },
239249
{ key = "DD_DOGSTATSD_TAG_CARDINALITY", value = var.dd_dogstatsd.dogstatsd_cardinality },
240250
{ key = "DD_TAGS", value = var.dd_tags },
241-
{ key = "DD_CLUSTER_NAME", value = var.dd_cluster_name }
251+
{ key = "DD_CLUSTER_NAME", value = var.dd_cluster_name },
242252
] : { name = pair.key, value = pair.value } if pair.value != null
243253
]
244254

modules/ecs_fargate/variables.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,12 @@ variable "dd_apm" {
165165
type = object({
166166
enabled = optional(bool, true)
167167
socket_enabled = optional(bool, true)
168+
profiling = optional(bool, false)
168169
})
169170
default = {
170171
enabled = true
171172
socket_enabled = true
173+
profiling = false
172174
}
173175
validation {
174176
condition = var.dd_apm != null

smoke_tests/ecs_fargate/all-dd-inputs.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module "dd_task_all_dd_inputs" {
3535
dd_apm = {
3636
enabled = true,
3737
socket_enabled = true,
38+
profiling = true,
3839
}
3940

4041
dd_log_collection = {

tests/all_dd_inputs_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ func (s *ECSFargateSuite) TestAllDDInputs() {
115115
s.True(found, "Container datadog-apm-app not found in definitions")
116116
s.Equal("ghcr.io/datadog/apps-tracegen:main", *apmAppContainer.Image)
117117
expectedApmDsdEnvVars := map[string]string{
118-
"DD_SERVICE": "test-service",
119-
"DD_TRACE_AGENT_URL": "unix:///var/run/datadog/apm.socket",
120-
"DD_AGENT_HOST": "127.0.0.1",
118+
"DD_SERVICE": "test-service",
119+
"DD_TRACE_AGENT_URL": "unix:///var/run/datadog/apm.socket",
120+
"DD_AGENT_HOST": "127.0.0.1",
121+
"DD_PROFILING_ENABLED": "true",
121122
}
122123
AssertEnvVars(s.T(), apmAppContainer, expectedApmDsdEnvVars)
123124
AssertMountPoint(s.T(), apmAppContainer, MountDdSocket)

0 commit comments

Comments
 (0)