Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(infra): add in deployment failure alarm for ecs services (#3839)

Will Hutchinsonec7372f392ad
diff --git a/infra/packages/resources/src/index.ts b/infra/packages/resources/src/index.ts
index 7119bbf88d..d1679a0e40 100644
--- a/infra/packages/resources/src/index.ts
+++ b/infra/packages/resources/src/index.ts
@@ -13,6 +13,10 @@ export {
DEFAULT_DEREGISTRATION_DELAY_SECONDS,
DEFAULT_TARGET_GROUP_HEALTH_CHECK,
} from './resources/ecs_deployment_defaults';
+export {
+ EcsDeploymentFailureAlarm,
+ type EcsDeploymentFailureAlarmArgs,
+} from './resources/ecs_deployment_failure_alarm';
export {
attachFrecencyTablePolicy,
createFrecencyTablePolicy,
diff --git a/infra/packages/resources/src/resources/ecs_deployment_failure_alarm.ts b/infra/packages/resources/src/resources/ecs_deployment_failure_alarm.ts
new file mode 100644
index 0000000000..2b305f9ac5
--- /dev/null
+++ b/infra/packages/resources/src/resources/ecs_deployment_failure_alarm.ts
@@ -0,0 +1,85 @@
+import * as aws from '@pulumi/aws';
+import * as pulumi from '@pulumi/pulumi';
+import { CLOUD_TRAIL_SNS_TOPIC_ARN, stack } from '../../../shared';
+
+export type EcsDeploymentFailureAlarmArgs = {
+ serviceName: string;
+ serviceArn: pulumi.Input<string>;
+ tags: Record<string, string>;
+ alarmActions?: aws.cloudwatch.MetricAlarmArgs['alarmActions'];
+ period?: pulumi.Input<number>;
+ evaluationPeriods?: pulumi.Input<number>;
+ threshold?: pulumi.Input<number>;
+};
+
+export class EcsDeploymentFailureAlarm extends pulumi.ComponentResource {
+ eventRule: aws.cloudwatch.EventRule;
+ alarm: aws.cloudwatch.MetricAlarm;
+
+ constructor(
+ name: string,
+ args: EcsDeploymentFailureAlarmArgs,
+ opts?: pulumi.ComponentResourceOptions
+ ) {
+ super(
+ 'my:components:EcsDeploymentFailureAlarm',
+ name,
+ { tags: args.tags },
+ opts
+ );
+
+ const alarmActions = args.alarmActions ?? [CLOUD_TRAIL_SNS_TOPIC_ARN];
+ const period = args.period ?? 60;
+ const evaluationPeriods = args.evaluationPeriods ?? 1;
+ const threshold = args.threshold ?? 0;
+
+ const eventPattern = pulumi.output(args.serviceArn).apply((serviceArn) =>
+ JSON.stringify({
+ source: ['aws.ecs'],
+ 'detail-type': ['ECS Deployment State Change'],
+ detail: {
+ eventName: ['SERVICE_DEPLOYMENT_FAILED'],
+ },
+ resources: [serviceArn],
+ })
+ );
+
+ this.eventRule = new aws.cloudwatch.EventRule(
+ `${name}-event-rule`,
+ {
+ name: `${args.serviceName}-deployment-failure-${stack}`,
+ description: `Matches failed ECS deployments for ${args.serviceName}.`,
+ eventPattern,
+ tags: args.tags,
+ },
+ { parent: this }
+ );
+
+ this.alarm = new aws.cloudwatch.MetricAlarm(
+ `${name}-alarm`,
+ {
+ name: `${args.serviceName}-deployment-failure-alarm-${stack}`,
+ alarmDescription: `Alarm when an ECS deployment fails for ${args.serviceName}.`,
+ comparisonOperator: 'GreaterThanThreshold',
+ evaluationPeriods,
+ metricName: 'TriggeredRules',
+ namespace: 'AWS/Events',
+ period,
+ statistic: 'Sum',
+ threshold,
+ treatMissingData: 'notBreaching',
+ dimensions: {
+ RuleName: this.eventRule.name,
+ },
+ alarmActions,
+ tags: args.tags,
+ },
+ { parent: this }
+ );
+
+ this.registerOutputs({
+ eventRule: this.eventRule,
+ alarm: this.alarm,
+ });
+ }
+}
diff --git a/infra/packages/service/src/service.ts b/infra/packages/service/src/service.ts
index ea27c1dc99..f209bf697e 100644
--- a/infra/packages/service/src/service.ts
+++ b/infra/packages/service/src/service.ts
@@ -4,6 +4,7 @@ import * as pulumi from '@pulumi/pulumi';
import {
DATADOG_API_KEY,
DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ EcsDeploymentFailureAlarm,
datadogAgentContainer,
fargateLogRouterSidecarContainer,
} from '../../resources';
@@ -136,6 +137,16 @@ export class Service extends pulumi.ComponentResource {
}
);
+ new EcsDeploymentFailureAlarm(
+ `${serviceName}-deployment-failure`,
+ {
+ serviceName,
+ serviceArn: this.service.service.arn,
+ tags: args.tags,
+ },
+ { parent: this }
+ );
+
this.serviceName = this.service.service.name;
this.registerOutputs({
name: this.service.service.name,
diff --git a/infra/stacks/agent-schedule-service/service.ts b/infra/stacks/agent-schedule-service/service.ts
index 8c786294e5..c5016179cd 100644
--- a/infra/stacks/agent-schedule-service/service.ts
+++ b/infra/stacks/agent-schedule-service/service.ts
@@ -4,6 +4,7 @@ import * as pulumi from '@pulumi/pulumi';
import {
DATADOG_API_KEY,
DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ EcsDeploymentFailureAlarm,
datadogAgentContainer,
fargateLogRouterSidecarContainer,
serviceLoadBalancer,
@@ -442,6 +443,16 @@ export class AgentScheduleService extends pulumi.ComponentResource {
}
private setupServiceAlarms() {
+ new EcsDeploymentFailureAlarm(
+ `${BASE_NAME}-deployment-failure-alarm`,
+ {
+ serviceName: BASE_NAME,
+ serviceArn: this.service.service.arn,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
new aws.cloudwatch.MetricAlarm(
`${BASE_NAME}-service-cpu-alarm`,
{
diff --git a/infra/stacks/authentication-service/service.ts b/infra/stacks/authentication-service/service.ts
index bb253efc7e..e38dc0293e 100644
--- a/infra/stacks/authentication-service/service.ts
+++ b/infra/stacks/authentication-service/service.ts
@@ -4,6 +4,7 @@ import * as pulumi from '@pulumi/pulumi';
import {
DATADOG_API_KEY,
DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ EcsDeploymentFailureAlarm,
datadogAgentContainer,
fargateLogRouterSidecarContainer,
serviceLoadBalancer,
@@ -531,6 +532,16 @@ export class AuthenticationService extends pulumi.ComponentResource {
}
setupServiceAlarms() {
+ new EcsDeploymentFailureAlarm(
+ `${BASE_NAME}-deployment-failure-alarm`,
+ {
+ serviceName: BASE_NAME,
+ serviceArn: this.service.service.arn,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
new aws.cloudwatch.MetricAlarm(
`${BASE_NAME}-high-cpu-alarm`,
{
diff --git a/infra/stacks/cloud-storage-service/cloud-storage-service.ts b/infra/stacks/cloud-storage-service/cloud-storage-service.ts
index 8aff64df51..ec31cb2683 100644
--- a/infra/stacks/cloud-storage-service/cloud-storage-service.ts
+++ b/infra/stacks/cloud-storage-service/cloud-storage-service.ts
@@ -6,6 +6,7 @@ import {
createFrecencyTablePolicy,
DATADOG_API_KEY,
DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ EcsDeploymentFailureAlarm,
datadogAgentContainer,
fargateLogRouterSidecarContainer,
serviceLoadBalancer,
@@ -595,6 +596,16 @@ export class CloudStorageService extends pulumi.ComponentResource {
}
setupServiceAlarms() {
+ new EcsDeploymentFailureAlarm(
+ `${BASE_NAME}-deployment-failure-alarm`,
+ {
+ serviceName: BASE_NAME,
+ serviceArn: this.service.service.arn,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
new aws.cloudwatch.MetricAlarm(
`${BASE_NAME}-high-cpu-alarm`,
{
diff --git a/infra/stacks/connection-gateway/connection_gateway.ts b/infra/stacks/connection-gateway/connection_gateway.ts
index 59e98a95bd..51b0af4511 100644
--- a/infra/stacks/connection-gateway/connection_gateway.ts
+++ b/infra/stacks/connection-gateway/connection_gateway.ts
@@ -5,6 +5,7 @@ import {
createFrecencyTablePolicy,
DATADOG_API_KEY,
DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ EcsDeploymentFailureAlarm,
datadogAgentContainer,
fargateLogRouterSidecarContainer,
serviceLoadBalancer,
@@ -463,6 +464,16 @@ export class ConnectionGateway extends pulumi.ComponentResource {
}
setupServiceAlarms() {
+ new EcsDeploymentFailureAlarm(
+ `${BASE_NAME}-deployment-failure-alarm`,
+ {
+ serviceName: BASE_NAME,
+ serviceArn: this.service.service.arn,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
new aws.cloudwatch.MetricAlarm(
`${BASE_NAME}-high-cpu-alarm`,
{
diff --git a/infra/stacks/contacts-service/service.ts b/infra/stacks/contacts-service/service.ts
index 100bad55a6..0c72130db2 100644
--- a/infra/stacks/contacts-service/service.ts
+++ b/infra/stacks/contacts-service/service.ts
@@ -4,6 +4,7 @@ import * as pulumi from '@pulumi/pulumi';
import {
DATADOG_API_KEY,
DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ EcsDeploymentFailureAlarm,
datadogAgentContainer,
fargateLogRouterSidecarContainer,
serviceLoadBalancer,
@@ -477,6 +478,16 @@ export class ContactsService extends pulumi.ComponentResource {
}
setupServiceAlarms() {
+ new EcsDeploymentFailureAlarm(
+ `${BASE_NAME}-deployment-failure-alarm`,
+ {
+ serviceName: BASE_NAME,
+ serviceArn: this.service.service.arn,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
new aws.cloudwatch.MetricAlarm(
`${BASE_NAME}-high-cpu-alarm`,
{
diff --git a/infra/stacks/convert-service/service.ts b/infra/stacks/convert-service/service.ts
index a8eb0d3790..f1a29cd29c 100644
--- a/infra/stacks/convert-service/service.ts
+++ b/infra/stacks/convert-service/service.ts
@@ -4,6 +4,7 @@ import * as pulumi from '@pulumi/pulumi';
import {
DATADOG_API_KEY,
DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ EcsDeploymentFailureAlarm,
datadogAgentContainer,
fargateLogRouterSidecarContainer,
serviceLoadBalancer,
@@ -497,6 +498,16 @@ export class ConvertService extends pulumi.ComponentResource {
}
setupServiceAlarms() {
+ new EcsDeploymentFailureAlarm(
+ `${BASE_NAME}-deployment-failure-alarm`,
+ {
+ serviceName: BASE_NAME,
+ serviceArn: this.service.service.arn,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
new aws.cloudwatch.MetricAlarm(
`${BASE_NAME}-high-cpu-alarm`,
{
diff --git a/infra/stacks/document-cognition-service/document-cognition-service.ts b/infra/stacks/document-cognition-service/document-cognition-service.ts
index 2e9539f0e2..b45733e344 100644
--- a/infra/stacks/document-cognition-service/document-cognition-service.ts
+++ b/infra/stacks/document-cognition-service/document-cognition-service.ts
@@ -4,6 +4,7 @@ import * as pulumi from '@pulumi/pulumi';
import {
DATADOG_API_KEY,
DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ EcsDeploymentFailureAlarm,
DatadogServiceEntity,
datadogAgentContainer,
fargateLogRouterSidecarContainer,
@@ -532,6 +533,16 @@ export class DocumentCognitionService extends pulumi.ComponentResource {
}
setupServiceAlarms() {
+ new EcsDeploymentFailureAlarm(
+ `${BASE_NAME}-deployment-failure-alarm`,
+ {
+ serviceName: BASE_NAME,
+ serviceArn: this.service.service.arn,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
new aws.cloudwatch.MetricAlarm(
`${BASE_NAME}-high-cpu-alarm`,
{
diff --git a/infra/stacks/email-service/pubsub_workers.ts b/infra/stacks/email-service/pubsub_workers.ts
index 2a56874f9b..bea5cf54bd 100644
--- a/infra/stacks/email-service/pubsub_workers.ts
+++ b/infra/stacks/email-service/pubsub_workers.ts
@@ -4,6 +4,7 @@ import * as pulumi from '@pulumi/pulumi';
import {
DATADOG_API_KEY,
DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ EcsDeploymentFailureAlarm,
datadogAgentContainer,
fargateLogRouterSidecarContainer,
} from '../../packages/resources';
@@ -233,6 +234,16 @@ export class EmailPubSubWorkers extends pulumi.ComponentResource {
}
setupServiceAlarms() {
+ new EcsDeploymentFailureAlarm(
+ `${BASE_NAME}-deployment-failure-alarm`,
+ {
+ serviceName: BASE_NAME,
+ serviceArn: this.service.service.arn,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
new aws.cloudwatch.MetricAlarm(
`${BASE_NAME}-high-cpu-alarm`,
{
diff --git a/infra/stacks/email-service/service.ts b/infra/stacks/email-service/service.ts
index 76e15e802e..72f4ac9a24 100644
--- a/infra/stacks/email-service/service.ts
+++ b/infra/stacks/email-service/service.ts
@@ -4,6 +4,7 @@ import * as pulumi from '@pulumi/pulumi';
import {
DATADOG_API_KEY,
DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ EcsDeploymentFailureAlarm,
datadogAgentContainer,
fargateLogRouterSidecarContainer,
serviceLoadBalancer,
@@ -405,6 +406,16 @@ export class EmailService extends pulumi.ComponentResource {
}
setupServiceAlarms() {
+ new EcsDeploymentFailureAlarm(
+ `${BASE_NAME}-deployment-failure-alarm`,
+ {
+ serviceName: BASE_NAME,
+ serviceArn: this.service.service.arn,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
new aws.cloudwatch.MetricAlarm(
`${BASE_NAME}-high-cpu-alarm`,
{
diff --git a/infra/stacks/fusion-auth/fusionauth-service.ts b/infra/stacks/fusion-auth/fusionauth-service.ts
index 45f2d188f9..ed4977ee45 100644
--- a/infra/stacks/fusion-auth/fusionauth-service.ts
+++ b/infra/stacks/fusion-auth/fusionauth-service.ts
@@ -1,7 +1,10 @@
import * as aws from '@pulumi/aws';
import * as awsx from '@pulumi/awsx';
import * as pulumi from '@pulumi/pulumi';
-import { DEFAULT_CONTINUE_BEFORE_STEADY_STATE } from '../../packages/resources';
+import {
+ DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ EcsDeploymentFailureAlarm,
+} from '../../packages/resources';
import { serviceLoadBalancer } from './resources/load_balancer';
import {
BASE_DOMAIN,
@@ -301,6 +304,16 @@ export class FusionAuthService extends pulumi.ComponentResource {
}
setupServiceAlarms() {
+ new EcsDeploymentFailureAlarm(
+ `${BASE_NAME}-deployment-failure-alarm`,
+ {
+ serviceName: BASE_NAME,
+ serviceArn: this.service.service.arn,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
new aws.cloudwatch.MetricAlarm(
`${BASE_NAME}-high-cpu-alarm`,
{
diff --git a/infra/stacks/image-proxy-service/image-proxy-service.ts b/infra/stacks/image-proxy-service/image-proxy-service.ts
index d1cc22876d..917aec0208 100644
--- a/infra/stacks/image-proxy-service/image-proxy-service.ts
+++ b/infra/stacks/image-proxy-service/image-proxy-service.ts
@@ -4,6 +4,7 @@ import * as pulumi from '@pulumi/pulumi';
import {
DATADOG_API_KEY,
DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ EcsDeploymentFailureAlarm,
datadogAgentContainer,
fargateLogRouterSidecarContainer,
serviceLoadBalancer,
@@ -455,6 +456,16 @@ export class ImageProxyService extends pulumi.ComponentResource {
}
setupServiceAlarms() {
+ new EcsDeploymentFailureAlarm(
+ `${BASE_NAME}-deployment-failure-alarm`,
+ {
+ serviceName: BASE_NAME,
+ serviceArn: this.service.service.arn,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
new aws.cloudwatch.MetricAlarm(
`${BASE_NAME}-high-cpu-alarm`,
{
diff --git a/infra/stacks/mcp-server/mcp-server.ts b/infra/stacks/mcp-server/mcp-server.ts
index e432c0b9d7..f86bdbaecd 100644
--- a/infra/stacks/mcp-server/mcp-server.ts
+++ b/infra/stacks/mcp-server/mcp-server.ts
@@ -4,6 +4,7 @@ import * as pulumi from '@pulumi/pulumi';
import {
DATADOG_API_KEY,
DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ EcsDeploymentFailureAlarm,
datadogAgentContainer,
fargateLogRouterSidecarContainer,
serviceLoadBalancer,
@@ -504,6 +505,16 @@ export class McpServer extends pulumi.ComponentResource {
}
setupServiceAlarms() {
+ new EcsDeploymentFailureAlarm(
+ `${BASE_NAME}-deployment-failure-alarm`,
+ {
+ serviceName: BASE_NAME,
+ serviceArn: this.service.service.arn,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
new aws.cloudwatch.MetricAlarm(
`${BASE_NAME}-high-cpu-alarm`,
{
diff --git a/infra/stacks/notification-service/service.ts b/infra/stacks/notification-service/service.ts
index 5e3214a5ce..f6f025a9ae 100644
--- a/infra/stacks/notification-service/service.ts
+++ b/infra/stacks/notification-service/service.ts
@@ -4,6 +4,7 @@ import * as pulumi from '@pulumi/pulumi';
import {
DATADOG_API_KEY,
DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ EcsDeploymentFailureAlarm,
datadogAgentContainer,
fargateLogRouterSidecarContainer,
serviceLoadBalancer,
@@ -533,6 +534,16 @@ export class NotificationService extends pulumi.ComponentResource {
}
setupServiceAlarms() {
+ new EcsDeploymentFailureAlarm(
+ `${BASE_NAME}-deployment-failure-alarm`,
+ {
+ serviceName: BASE_NAME,
+ serviceArn: this.service.service.arn,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
new aws.cloudwatch.MetricAlarm(
`${BASE_NAME}-high-cpu-alarm`,
{
diff --git a/infra/stacks/search-processing-service/service.ts b/infra/stacks/search-processing-service/service.ts
index e322a1e4e4..040e6c5f1b 100644
--- a/infra/stacks/search-processing-service/service.ts
+++ b/infra/stacks/search-processing-service/service.ts
@@ -4,6 +4,7 @@ import * as pulumi from '@pulumi/pulumi';
import {
DATADOG_API_KEY,
DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ EcsDeploymentFailureAlarm,
datadogAgentContainer,
fargateLogRouterSidecarContainer,
serviceLoadBalancer,
@@ -498,6 +499,16 @@ export class SearchProcessingService extends pulumi.ComponentResource {
}
setupServiceAlarms() {
+ new EcsDeploymentFailureAlarm(
+ `${BASE_NAME}-deployment-failure-alarm`,
+ {
+ serviceName: BASE_NAME,
+ serviceArn: this.service.service.arn,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
new aws.cloudwatch.MetricAlarm(
`${BASE_NAME}-high-cpu-alarm`,
{
diff --git a/infra/stacks/static-file-service/static-file-service.ts b/infra/stacks/static-file-service/static-file-service.ts
index a81b135fb9..a0f5e2a0f5 100644
--- a/infra/stacks/static-file-service/static-file-service.ts
+++ b/infra/stacks/static-file-service/static-file-service.ts
@@ -6,6 +6,7 @@ import {
DATADOG_API_KEY,
DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
datadogAgentContainer,
+ EcsDeploymentFailureAlarm,
fargateLogRouterSidecarContainer,
QueueAlarms,
serviceLoadBalancer,
@@ -605,6 +606,17 @@ export class StaticFileService extends pulumi.ComponentResource {
);
this.service = service;
+
+ new EcsDeploymentFailureAlarm(
+ `${SERVICE_NAME}-deployment-failure-alarm`,
+ {
+ serviceName: SERVICE_NAME,
+ serviceArn: this.service.service.arn,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
this.domain = `https://${SERVICE_DOMAIN_NAME}`;
}
diff --git a/infra/stacks/unfurl-service/unfurl-service.ts b/infra/stacks/unfurl-service/unfurl-service.ts
index 60bffbeec2..d22fbf1fe7 100644
--- a/infra/stacks/unfurl-service/unfurl-service.ts
+++ b/infra/stacks/unfurl-service/unfurl-service.ts
@@ -4,6 +4,7 @@ import * as pulumi from '@pulumi/pulumi';
import {
DATADOG_API_KEY,
DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ EcsDeploymentFailureAlarm,
datadogAgentContainer,
fargateLogRouterSidecarContainer,
serviceLoadBalancer,
@@ -426,6 +427,16 @@ export class UnfurlService extends pulumi.ComponentResource {
}
setupServiceAlarms() {
+ new EcsDeploymentFailureAlarm(
+ `${BASE_NAME}-deployment-failure-alarm`,
+ {
+ serviceName: BASE_NAME,
+ serviceArn: this.service.service.arn,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
new aws.cloudwatch.MetricAlarm(
`${BASE_NAME}-high-cpu-alarm`,
{