Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add datadog-agent to ECS #244

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ module "apiary" {
apiary_log_bucket = "s3-logs-bucket"
db_instance_class = "db.t2.medium"
db_backup_retention = "7"

# Enable datadog for monitoring
datadog_key_secret_name = "datadog-secret-key-name"
include_datadog_agent = true

apiary_managed_schemas = [
{
schema_name = "db1",
Expand Down
6 changes: 6 additions & 0 deletions cloudwatch.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
* Licensed under the Apache License, Version 2.0 (the "License");
*/

resource "aws_cloudwatch_log_group" "ecs" {
count = var.hms_instance_type == "ecs" ? 1 : 0
name = local.instance_alias
tags = var.apiary_tags
}

data "template_file" "s3_widgets" {
count = length(local.schemas_info)

Expand Down
10 changes: 10 additions & 0 deletions common.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,13 @@ data "aws_route53_zone" "apiary_zone" {
name = var.apiary_domain_name
vpc_id = var.vpc_id
}

data "aws_secretsmanager_secret" "datadog_key" {
count = length(var.datadog_key_secret_name) == 0 ? 0 : 1
name = var.datadog_key_secret_name
}

data "aws_secretsmanager_secret_version" "datadog_key" {
count = length(var.datadog_key_secret_name) == 0 ? 0 : 1
secret_id = data.aws_secretsmanager_secret.datadog_key[0].id
}
14 changes: 14 additions & 0 deletions templates.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ locals{
mysql_permissions = "ALL"
mysql_master_cred_arn = var.external_database_host == "" ? aws_secretsmanager_secret.apiary_mysql_master_credentials[0].arn : null
mysql_user_cred_arn = data.aws_secretsmanager_secret.db_rw_user.arn

# Datadog vars
datadog_secret_key = jsondecode(data.aws_secretsmanager_secret_version.datadog_key[0].secret_string).api_key
wd_instance_type = var.hms_instance_type
metrics_port = var.datadog_metrics_port
datadog_agent_version = var.datadog_agent_version
include_datadog_agent = var.include_datadog_agent
})

hms_readonly_template = templatefile("${path.module}/templates/apiary-hms-readonly.json", {
Expand Down Expand Up @@ -104,5 +111,12 @@ locals{
mysql_write_db = "${var.external_database_host == "" ? join("", aws_rds_cluster.apiary_cluster.*.endpoint) : var.external_database_host}"
mysql_master_cred_arn = var.external_database_host == "" ? aws_secretsmanager_secret.apiary_mysql_master_credentials[0].arn : null
mysql_user_cred_arn = data.aws_secretsmanager_secret.db_ro_user.arn

# Datadog vars
datadog_secret_key = jsondecode(data.aws_secretsmanager_secret_version.datadog_key[0].secret_string).api_key
wd_instance_type = var.hms_instance_type
metrics_port = var.datadog_metrics_port
datadog_agent_version = var.datadog_agent_version
include_datadog_agent = var.include_datadog_agent
})
}
32 changes: 32 additions & 0 deletions templates/apiary-hms-readonly.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,36 @@
%{ endfor }
]
}
%{ if include_datadog_agent }
,{
"name": "datadog-agent",
"image": "public.ecr.aws/datadog/agent:${datadog_agent_version}",
"essential": true,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "${loggroup}",
"awslogs-region": "${region}",
"awslogs-stream-prefix": "/"
}
},
"environment": [
{
"name": "DD_API_KEY",
"value": "${datadog_secret_key}"
},
{
"name": "ECS_FARGATE",
"value": "true"
}
],
"healthCheck": {
"command": ["CMD-SHELL", "curl -f http://localhost:18000/actuator/health || exit 1"],
"interval": 5,
"retries": 3,
"startPeriod": 60,
"timeout": 5
}
}
%{ endif }
]
32 changes: 32 additions & 0 deletions templates/apiary-hms-readwrite.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,36 @@
%{ endfor }
]
}
%{ if include_datadog_agent }
,{
"name": "datadog-agent",
"image": "public.ecr.aws/datadog/agent:${datadog_agent_version}",
"essential": true,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "${loggroup}",
"awslogs-region": "${region}",
"awslogs-stream-prefix": "/"
}
},
"environment": [
{
"name": "DD_API_KEY",
"value": "${datadog_secret_key}"
},
{
"name": "ECS_FARGATE",
"value": "true"
}
],
"healthCheck": {
"command": ["CMD-SHELL", "curl -f http://localhost:18000/actuator/health || exit 1"],
"interval": 5,
"retries": 3,
"startPeriod": 60,
"timeout": 5
}
}
%{ endif }
]
18 changes: 18 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,24 @@ variable "datadog_metrics_port" {
default = "8080"
}

variable "datadog_key_secret_name" {
description = "Name of the secret containing the DataDog API key. This needs to be created manually in AWS secrets manager. This is only applicable to ECS deployments."
type = string
default = null
}

variable "datadog_agent_version" {
description = "Version of the Datadog Agent running in the ECS cluster. This is only applicable to ECS deployments."
type = string
default = "7.46.0-jmx"
}

variable "include_datadog_agent" {
description = "Whether to include the datadog-agent container. This is only applicable to ECS deployments."
type = bool
default = false
}

variable "hms_rw_request_partition_limit" {
description = "Read-write Hive metastore setting for size of the Hive metastore limit of request partitions."
type = string
Expand Down
Loading