Skip to content

Commit

Permalink
Added support for streaming metrics (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
BSick7 authored Jun 4, 2024
1 parent 2091b6b commit 6aa1b2f
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 9 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
shell: bash

steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3

Expand All @@ -26,9 +25,9 @@ jobs:

- name: Find version
id: version
run: echo ::set-output name=tag::${GITHUB_REF#refs/tags/v}
run: echo "MODULE_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV

- id: publish
name: Publish
run: |
nullstone modules publish --version=${{ steps.version.outputs.tag }}
nullstone modules publish --version=${{ env.MODULE_VERSION }}
123 changes: 123 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 0.1.0 (Jun 04, 2024)
* Initial release
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lock-providers:
terraform providers lock -platform=linux_amd64 -platform=linux_arm64 -platform=darwin_amd64 -platform=darwin_arm64 -platform=windows_amd64
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
# aws-datadog-fargate
Capability to report logs and metrics for an AWS fargate service to Datadog
# Datadog Logs/Metrics for ECS/Fargate

This capability sends application logs and metrics to Datadog for ECS (Fargate-based or EC2-based).

## Logs

Application logs are configured to send to Datadog in near real-time. (<1 min latency)
These logs are tagged with `stack`, `block`, and `env`.

The application logs are immediately sent to Cloudwatch and transmitted to Datadog via Kinesis Firehose.

## Metrics

The Datadog agent is added to your application as a sidecar container.
This agent collects metrics from AWS and custom metrics from your application and sends them to Datadog in near real-time.

### OpenTelemetry

The Datadog agent is configured as an OpenTelemetry agent with a gRPC listener on port 4317 and HTTP listener on port 4318.
This module automatically injects `OTEL_EXPORTER_OTLP_ENDPOINT` environment variable into the app.
This endpoint refers to the HTTP listener.
44 changes: 44 additions & 0 deletions agent.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
locals {
sidecar_name = "datadog-agent"
agent_sidecar = {
name = "datadog-agent"
image = "public.ecr.aws/datadog/agent:latest"
essential = true
portMappings = jsonencode([
{ protocol = "tcp", containerPort = 4317 },
{ protocol = "tcp", containerPort = 4318 },
{ protocol = "tcp", containerPort = 8126 },
])
environment = jsonencode([
{ name = "ECS_FARGATE", value = "true" },
{ name = "DD_APM_ENABLED", value = "true" },
{ name = "DD_SITE", value = "datadoghq.com" },
{ name = "DD_OTLP_CONFIG_RECEIVER_PROTOCOLS_GRPC_ENDPOINT", value = "0.0.0.0:4317" },
{ name = "DD_OTLP_CONFIG_RECEIVER_PROTOCOLS_HTTP_ENDPOINT", value = "0.0.0.0:4318" }
])
secrets = jsonencode([{ name = "DD_API_KEY", valueFrom = local.api_key_secret_id }])
}
}

resource "aws_iam_role_policy_attachment" "execution-datadog" {
role = local.execution_role_name
policy_arn = aws_iam_policy.datadog.arn
}

resource "aws_iam_policy" "datadog" {
name = "${local.resource_name}-datadog"
policy = data.aws_iam_policy_document.datadog.json
}

data "aws_iam_policy_document" "datadog" {
statement {
sid = "AllowReadDatadogApiKey"
effect = "Allow"
resources = [local.api_key_secret_id]

actions = [
"secretsmanager:GetSecretValue",
"kms:Decrypt"
]
}
}
2 changes: 1 addition & 1 deletion datadog.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ data "ns_connection" "datadog" {
}

locals {
delivery_stream_arn = data.ns_connection.datadog.outputs.delivery_stream_arn
delivery_stream_arn = data.ns_connection.datadog.outputs.logs_delivery_stream_arn
delivery_role_arn = data.ns_connection.datadog.outputs.delivery_role_arn
datadog_region = data.ns_connection.datadog.outputs.datadog_region
api_key_secret_id = data.ns_connection.datadog.outputs.api_key_secret_id
Expand Down
15 changes: 13 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
output "noop" {
value = []
output "env" {
value = [
{
name = "OTEL_EXPORTER_OTLP_ENDPOINT"
value = "http://localhost:4318"
}
]
}

output "sidecars" {
value = [
local.agent_sidecar
]
}
3 changes: 2 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ EOF
}

locals {
log_group_name = var.app_metadata["log_group_name"]
log_group_name = var.app_metadata["log_group_name"]
execution_role_name = var.app_metadata["execution_role_name"]
}

0 comments on commit 6aa1b2f

Please sign in to comment.