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

feat: base impl for ecs fargate cdk #371

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
48 changes: 48 additions & 0 deletions src/ecs/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed
* under the Apache License Version 2.0.
*
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2021 Datadog, Inc.
*/

import { Duration } from "aws-cdk-lib";
import { DatadogECSBaseProps, Cardinality } from "./interfaces";

/**
* Default props for the Datadog ECS Fargate construct
*/
export const DatadogEcsBaseDefaultProps: DatadogECSBaseProps = {
registry: "public.ecr.aws/datadog/agent",
imageVersion: "latest",
memoryLimitMiB: 1024,

site: "datadoghq.com",
logLevel: "INFO",

enableAPM: true,
enableAPMSocket: true,

enableDogstatsd: true,
enableDogstatsdSocket: true,
enableDogstatsdOriginDetection: false,
dogstatsdCardinality: Cardinality.LOW,

enableLogCollection: false,
enableASM: false,
enableCWS: false,

isHealthCheckEnabled: true,
datadogHealthCheck: {
command: ["agent", "health"],
interval: Duration.seconds(5),
retries: 3,
startPeriod: Duration.seconds(15),
timeout: Duration.seconds(5),
},
};

/**
* Default CWS entrypoint prefix for application containers
*/
export const entryPointPrefixCWS = ["/cws-instrumentation-volume/cws-instrumentation", "trace", "--"];
70 changes: 70 additions & 0 deletions src/ecs/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed
* under the Apache License Version 2.0.
*
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2021 Datadog, Inc.
*/

export class EnvVarManager {
private envVars: Record<string, string> = {};
private overwrittenKeys: Set<string> = new Set();

constructor(defaultEnvVars: Record<string, string> = {}) {
this.addAll(defaultEnvVars);
}

/**
* Adds an environment variable if the value is not undefined.
* If the key already exists, it records that it has been overwritten.
*/
add(key: string, value: string | undefined): void {
if (value === undefined) {
return;
}
if (this.envVars.hasOwnProperty(key)) {
this.overwrittenKeys.add(key);
}
this.envVars[key] = value;
}

/**
* Adds all environment variables from a record.
*/
addAll(envVars: Record<string, string> | undefined): void {
if (envVars === undefined) {
return;
}
for (const [key, value] of Object.entries(envVars)) {
this.add(key, value);
}
}

/**
* Retrieves an environment variable by key.
*/
retrieve(key: string): string | undefined {
return this.envVars[key];
}

/**
* Returns all stored environment variables.
*/
retrieveAll(): Record<string, string> {
return { ...this.envVars };
}

/**
* Returns a list of keys that have been overwritten.
*/
retrieveOverwrittenKeys(): string[] {
return Array.from(this.overwrittenKeys);
}

/**
* Returns a string representation of the environment variables.
*/
toString(): string {
return JSON.stringify(this.envVars);
}
}
44 changes: 44 additions & 0 deletions src/ecs/fargate/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed
* under the Apache License Version 2.0.
*
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2021 Datadog, Inc.
*/

import { Duration } from "aws-cdk-lib";
import { DatadogECSFargateLogDriverProps, DatadogECSFargateProps } from "./interfaces";
import { DatadogEcsBaseDefaultProps } from "../constants";

/**
* Default log driver configuration for ECS Fargate
*/
export const DatadogECSFargateLogDriverDefaultProps: DatadogECSFargateLogDriverProps = {
hostEndpoint: "http-intake.logs.datadoghq.com",
registry: "public.ecr.aws/aws-observability/aws-for-fluent-bit",
imageVersion: "stable",
};

/**
* Default environment variables for the Agent in Fargate Tasks
*/
export const FargateDefaultEnvVars = {
DD_ECS_TASK_COLLECTION_ENABLED: "true",
ECS_FARGATE: "true",
};

/**
* Default props for the Datadog ECS Fargate construct
*/
export const DatadogEcsFargateDefaultProps: DatadogECSFargateProps = {
...DatadogEcsBaseDefaultProps,
logDriverConfiguration: DatadogECSFargateLogDriverDefaultProps,
isLogRouterHealthCheckEnabled: false,
logRouterHealthCheck: {
command: ["curl -f http://127.0.0.1:2020/api/v1/health || exit 1"],
interval: Duration.seconds(5),
retries: 3,
startPeriod: Duration.seconds(15),
timeout: Duration.seconds(5),
},
};
Loading
Loading