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): deploy calendar_service dormant on the shared gateway (#6623)

gbirman3518ad65de72
diff --git a/.github/services-config.json b/.github/services-config.json
index 8776abd879..c76e2fa358 100644
--- a/.github/services-config.json
+++ b/.github/services-config.json
@@ -58,6 +58,15 @@
"call_recording_preview_handler"
]
},
+ "calendar-service": {
+ "source_paths": [
+ "services/calendar_service/**"
+ ],
+ "stack_path": "infra/stacks/calendar-service/**",
+ "deploy_binaries": [
+ "calendar_service"
+ ]
+ },
"connection-gateway": {
"source_paths": [
"services/connection_gateway/**"
diff --git a/infra/bun.lock b/infra/bun.lock
index 50800cb015..a852f1f779 100644
--- a/infra/bun.lock
+++ b/infra/bun.lock
@@ -64,6 +64,10 @@
"stacks/bulk-upload": {
"name": "bulk-upload-stack",
},
+ "stacks/calendar-service": {
+ "name": "calendar-service-stack",
+ "version": "0.0.0",
+ },
"stacks/call-recording": {
"name": "call-recording-stack",
"version": "0.0.0",
@@ -499,6 +503,8 @@
"cacache": ["[email protected]", "", { "dependencies": { "@npmcli/fs": "^5.0.0", "fs-minipass": "^3.0.0", "glob": "^13.0.0", "lru-cache": "^11.1.0", "minipass": "^7.0.3", "minipass-collect": "^2.0.1", "minipass-flush": "^1.0.5", "minipass-pipeline": "^1.2.4", "p-map": "^7.0.2", "ssri": "^13.0.0" } }, "sha512-M3Lab8NPYlZU2exsL3bMVvMrMqgwCnMWfdZbK28bn3pK6APT/Te/I8hjRPNu1uwORY9a1eEQoifXbKPQMfMTOA=="],
+ "calendar-service-stack": ["calendar-service-stack@workspace:stacks/calendar-service"],
+
"call-recording-stack": ["call-recording-stack@workspace:stacks/call-recording"],
"chownr": ["[email protected]", "", {}, "sha512-+IxzY9BZOQd/XuYPRmrvEVjF/nqj5kgT4kEq7VofrDoM1MxoRjEWkrCC3EtLi59TVawxTAn+orJwFQcrqEN1+g=="],
diff --git a/infra/packages/shared/src/gateway_priorities.ts b/infra/packages/shared/src/gateway_priorities.ts
index 4d37aa9d62..8ffdaa360e 100644
--- a/infra/packages/shared/src/gateway_priorities.ts
+++ b/infra/packages/shared/src/gateway_priorities.ts
@@ -8,6 +8,7 @@ export enum GatewayService {
CONVERT_SERVICE = 'CONVERT_SERVICE',
NOTIFICATION_SERVICE = 'NOTIFICATION_SERVICE',
CONTACTS_SERVICE = 'CONTACTS_SERVICE',
+ CALENDAR_SERVICE = 'CALENDAR_SERVICE',
SEARCH_PROCESSING_SERVICE = 'SEARCH_PROCESSING_SERVICE',
IMAGE_PROXY_SERVICE = 'IMAGE_PROXY_SERVICE',
AGENT_HARNESS_SERVICE = 'AGENT_HARNESS_SERVICE',
@@ -44,6 +45,7 @@ export const GATEWAY_PRIORITIES: GatewayPriorityMap = {
[GatewayService.EMAIL_SERVICE]: 110,
[GatewayService.MCP_SERVER]: 130,
[GatewayService.DOCUMENT_COGNITION_SERVICE]: 120,
+ [GatewayService.CALENDAR_SERVICE]: 140,
[GatewayService.CONVERT_SERVICE]: 3000,
};
diff --git a/infra/stacks/calendar-service/Pulumi.dev.yaml b/infra/stacks/calendar-service/Pulumi.dev.yaml
new file mode 100644
index 0000000000..fdb204e0ca
--- /dev/null
+++ b/infra/stacks/calendar-service/Pulumi.dev.yaml
@@ -0,0 +1,7 @@
+config:
+ aws-native:region: us-east-1
+ aws:region: us-east-1
+ calendar-service:authentication_service_internal_api_key: authentication-service-internal-api-key-dev
+ calendar-service:jwt_secret_key: fusionauth-jwt-secret-dev
+ calendar-service:internal_auth_key: document-storage-service-auth-key-dev
+ calendar-service:macro_db_secret_key: macro-db-dev
diff --git a/infra/stacks/calendar-service/Pulumi.prod.yaml b/infra/stacks/calendar-service/Pulumi.prod.yaml
new file mode 100644
index 0000000000..896aa12154
--- /dev/null
+++ b/infra/stacks/calendar-service/Pulumi.prod.yaml
@@ -0,0 +1,7 @@
+config:
+ aws-native:region: us-east-1
+ aws:region: us-east-1
+ calendar-service:authentication_service_internal_api_key: authentication-service-internal-api-key-prod
+ calendar-service:jwt_secret_key: fusionauth-jwt-secret-prod
+ calendar-service:internal_auth_key: document-storage-service-auth-key-prod
+ calendar-service:macro_db_secret_key: macro-db-prod
diff --git a/infra/stacks/calendar-service/Pulumi.yaml b/infra/stacks/calendar-service/Pulumi.yaml
new file mode 100644
index 0000000000..8d48a35a33
--- /dev/null
+++ b/infra/stacks/calendar-service/Pulumi.yaml
@@ -0,0 +1,3 @@
+name: calendar-service
+runtime: nodejs
+description: Macro Calendar Service
diff --git a/infra/stacks/calendar-service/index.ts b/infra/stacks/calendar-service/index.ts
new file mode 100644
index 0000000000..f19bd49917
--- /dev/null
+++ b/infra/stacks/calendar-service/index.ts
@@ -0,0 +1,135 @@
+import * as aws from '@pulumi/aws';
+import * as pulumi from '@pulumi/pulumi';
+import { Queue, Redis } from '../../packages/resources';
+import {
+ BASE_DOMAIN,
+ config,
+ getMacroApiToken,
+ stack,
+} from '../../packages/shared';
+import { get_coparse_api_vpc } from '../../packages/vpc';
+import { CalendarService } from './service';
+
+const tags = {
+ environment: stack,
+ tech_lead: 'gab',
+ project: 'calendar-service',
+};
+
+export const coparse_api_vpc = get_coparse_api_vpc();
+
+const AUTHENTICATION_SERVICE_INTERNAL_API_KEY = config.require(
+ `authentication_service_internal_api_key`
+);
+const JWT_SECRET_KEY = config.require(`jwt_secret_key`);
+const INTERNAL_AUTH_KEY = config.require(`internal_auth_key`);
+const MACRO_DB_URL_SECRET_NAME = config.require(`macro_db_secret_key`);
+
+const authenticationServiceInternalApiKeyArn: pulumi.Output<string> =
+ aws.secretsmanager
+ .getSecretVersionOutput({
+ secretId: AUTHENTICATION_SERVICE_INTERNAL_API_KEY,
+ })
+ .apply((secret) => secret.arn);
+
+const jwtSecretKeyArn: pulumi.Output<string> = aws.secretsmanager
+ .getSecretVersionOutput({ secretId: JWT_SECRET_KEY })
+ .apply((secret) => secret.arn);
+
+const internalAuthKeyArn: pulumi.Output<string> = aws.secretsmanager
+ .getSecretVersionOutput({ secretId: INTERNAL_AUTH_KEY })
+ .apply((secret) => secret.arn);
+
+const macroDbUrlArn: pulumi.Output<string> = aws.secretsmanager
+ .getSecretVersionOutput({ secretId: MACRO_DB_URL_SECRET_NAME })
+ .apply((secret) => secret.arn);
+
+const MACRO_API_TOKENS = getMacroApiToken();
+
+const cloudStorageStack = new pulumi.StackReference('cloud-storage-stack', {
+ name: `macro-inc/document-storage/${stack}`,
+});
+
+const cloudStorageClusterArn: pulumi.Output<string> = cloudStorageStack
+ .getOutput('cloudStorageClusterArn')
+ .apply((arn) => arn as string);
+
+const cloudStorageClusterName: pulumi.Output<string> = cloudStorageStack
+ .getOutput('cloudStorageClusterName')
+ .apply((arn) => arn as string);
+
+const calendarServiceRedis = new Redis('calendar-service-redis', {
+ vpc: coparse_api_vpc,
+ tags,
+ redisArgs: {
+ // Dormant service: a small node in both stacks. Resize at cutover.
+ nodeType: 'cache.t3.micro',
+ port: 6379,
+ engineVersion: '7.1',
+ },
+});
+
+// Exported so the operator can point the calendar-service Doppler `REDIS_URI`
+// at this endpoint before the service is enabled. Config is loaded from
+// `APP_SECRETS_JSON` (Doppler), so the endpoint cannot be injected as a plain
+// container env var — it flows through Doppler, exactly like email-service.
+export const calendarServiceRedisEndpoint = calendarServiceRedis.endpoint;
+
+// Calendar's own backfill queue. The `Queue` construct appends
+// `-queue-${stack}`, producing `calendar-service-backfill-queue-{dev,prod}`,
+// which is exactly the name the Rust side expects
+// (`macro_queues::CalendarServiceBackfillQueue`).
+const backfillQueue = new Queue('calendar-service-backfill', {
+ tags,
+ maxReceiveCount: 20,
+ visibilityTimeoutSeconds: 60,
+ alarm: {
+ approximateAgeOfOldestMessageThreshold: 600, // 10 minutes
+ },
+});
+
+export const calendarBackfillQueueArn = pulumi.interpolate`${backfillQueue.queue.arn}`;
+export const calendarBackfillQueueName = pulumi.interpolate`${backfillQueue.queue.name}`;
+
+const secretKeyArns = [
+ authenticationServiceInternalApiKeyArn,
+ jwtSecretKeyArn,
+ internalAuthKeyArn,
+ macroDbUrlArn,
+ MACRO_API_TOKENS.macroApiTokenPublicKeyArn,
+];
+
+const containerEnvVars = [
+ {
+ name: 'ENVIRONMENT',
+ value: stack,
+ },
+ { name: 'DOPPLER_PROJECT', value: 'calendar_service' },
+ {
+ name: 'DD_SERVICE',
+ value: 'calendar-service',
+ },
+ {
+ name: 'DD_ENV',
+ value: stack,
+ },
+];
+
+const calendarService = new CalendarService('calendar-service', {
+ calendarBackfillQueueArn,
+ vpc: coparse_api_vpc,
+ tags,
+ containerEnvVars,
+ platform: { family: 'linux', architecture: 'amd64' },
+ serviceContainerPort: 8080,
+ healthCheckPath: '/health',
+ ecsClusterArn: cloudStorageClusterArn,
+ cloudStorageClusterName,
+ secretKeyArns,
+});
+
+export const calendarServiceUrl = calendarService.domain;
+
+export const calendarServiceGatewayUrl = `https://${
+ stack === 'prod' ? '' : `${stack}-`
+}gateway.${BASE_DOMAIN}/calendar-service`;
diff --git a/infra/stacks/calendar-service/package.json b/infra/stacks/calendar-service/package.json
new file mode 100644
index 0000000000..67984359fb
--- /dev/null
+++ b/infra/stacks/calendar-service/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "calendar-service-stack",
+ "version": "0.0.0",
+ "private": true,
+ "license": "MIT",
+ "main": "index.ts"
+}
diff --git a/infra/stacks/calendar-service/service.ts b/infra/stacks/calendar-service/service.ts
new file mode 100644
index 0000000000..332a7c42a0
--- /dev/null
+++ b/infra/stacks/calendar-service/service.ts
@@ -0,0 +1,497 @@
+import * as aws from '@pulumi/aws';
+import * as awsx from '@pulumi/awsx';
+import * as pulumi from '@pulumi/pulumi';
+import {
+ DATADOG_API_KEY,
+ DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ EcsDeploymentFailureAlarm,
+ datadogAgentContainer,
+ fargateLogRouterSidecarContainer,
+ ServiceTargetGroup,
+} from '../../packages/resources';
+import { EcrImage } from '../../packages/service';
+import {
+ BASE_DOMAIN,
+ CLOUD_TRAIL_SNS_TOPIC_ARN,
+ DopplerEcsEnvironment,
+ getGatewayAlb,
+ getKafkaClusterPolicy,
+ GatewayService,
+ stack,
+} from '../../packages/shared';
+
+const gatewayLoadBalancer = getGatewayAlb();
+
+const BASE_NAME = pulumi.getProject();
+const REPO_ROOT = '../../..';
+
+type CreateCalendarServiceArgs = {
+ calendarBackfillQueueArn: pulumi.Output<string> | string;
+ vpc: {
+ vpcId: pulumi.Output<string> | string;
+ privateSubnetIds: pulumi.Output<string[]> | string[];
+ };
+ tags: { [key: string]: string };
+ containerEnvVars: { name: string; value: pulumi.Output<string> | string }[];
+ platform: { family: string; architecture: 'amd64' | 'arm64' };
+ serviceContainerPort: number;
+ healthCheckPath: string;
+ ecsClusterArn: pulumi.Output<string> | string;
+ cloudStorageClusterName: pulumi.Output<string> | string;
+ secretKeyArns: (pulumi.Output<string> | string)[];
+};
+
+export class CalendarService extends pulumi.ComponentResource {
+ public role: aws.iam.Role;
+ public ecr: awsx.ecr.Repository;
+ public serviceSg: aws.ec2.SecurityGroup;
+ public domain: string;
+ public tags: { [key: string]: string };
+ public targetGroup: aws.lb.TargetGroup;
+ public service: awsx.ecs.FargateService;
+ public cloudStorageClusterName: pulumi.Output<string> | string;
+
+ constructor(
+ name: string,
+ {
+ calendarBackfillQueueArn,
+ vpc,
+ tags,
+ platform,
+ serviceContainerPort,
+ healthCheckPath,
+ ecsClusterArn,
+ containerEnvVars,
+ cloudStorageClusterName,
+ secretKeyArns,
+ }: CreateCalendarServiceArgs,
+ opts?: pulumi.ComponentResourceOptions
+ ) {
+ super('my:components:CalendarService', name, {}, opts);
+ this.domain = `https://${
+ stack === 'prod' ? '' : `${stack}-`
+ }gateway.${BASE_DOMAIN}/calendar-service`;
+ this.tags = tags;
+ this.cloudStorageClusterName = cloudStorageClusterName;
+
+ const secretsManagerPolicy = new aws.iam.Policy(
+ `${BASE_NAME}-secrets-manager-policy`,
+ {
+ name: `${BASE_NAME}-secrets-manager-policy-${stack}`,
+ policy: {
+ Version: '2012-10-17',
+ Statement: [
+ {
+ Action: [
+ 'secretsmanager:GetSecretValue',
+ 'secretsmanager:DescribeSecret',
+ ],
+ Resource: [...secretKeyArns],
+ Effect: 'Allow',
+ },
+ ],
+ },
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
+ const queuePolicy = new aws.iam.Policy(
+ `${BASE_NAME}-sqs-policy`,
+ {
+ name: `${BASE_NAME}-sqs-policy-${stack}`,
+ policy: {
+ Version: '2012-10-17',
+ Statement: [
+ {
+ Action: [
+ 'sqs:SendMessage',
+ 'sqs:ReceiveMessage',
+ 'sqs:DeleteMessage',
+ ],
+ Resource: [pulumi.interpolate`${calendarBackfillQueueArn}`],
+ Effect: 'Allow',
+ },
+ ],
+ },
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
+ this.role = new aws.iam.Role(
+ `${BASE_NAME}-role`,
+ {
+ name: `${BASE_NAME}-role-${stack}`,
+ assumeRolePolicy: {
+ Version: '2012-10-17',
+ Statement: [
+ {
+ Action: 'sts:AssumeRole',
+ Principal: {
+ Service: 'ecs-tasks.amazonaws.com',
+ },
+ Effect: 'Allow',
+ Sid: '',
+ },
+ ],
+ },
+ tags: this.tags,
+ managedPolicyArns: [
+ secretsManagerPolicy.arn,
+ queuePolicy.arn,
+ getKafkaClusterPolicy(),
+ ],
+ },
+ { parent: this }
+ );
+
+ // ecr image
+ const image = new EcrImage(
+ `${BASE_NAME}-ecr-image-${stack}`,
+ {
+ repositoryId: `${BASE_NAME}-ecr-${stack}`,
+ repositoryName: `${BASE_NAME}-${stack}`,
+ imageId: `${BASE_NAME}-image-${stack}`,
+ imagePath: REPO_ROOT,
+ dockerfile: 'docker/Dockerfile',
+ platform,
+ buildArgs: {
+ SERVICE_NAME: 'calendar_service',
+ },
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+ this.ecr = image.ecr;
+
+ // Security groups
+ this.serviceSg = this.initializeSecurityGroups({ vpcId: vpc.vpcId });
+
+ const gatewayTargetGroup = new ServiceTargetGroup(
+ `${stack}-${BASE_NAME}`,
+ {
+ tags: this.tags,
+ listenerArn: gatewayLoadBalancer.httpsListenerArn,
+ vpcId: vpc.vpcId,
+ containerPort: serviceContainerPort,
+ service: GatewayService.CALENDAR_SERVICE,
+ healthCheckPath,
+ // calendar-service does NOT own `/calendar` yet — email-service keeps
+ // that route until cutover. This temporary prefix keeps the dormant
+ // service reachable for health checks without shadowing email.
+ pathPatterns: ['/calendar-service', '/calendar-service/*'],
+ serviceSecurityGroupId: this.serviceSg.id,
+ albSecurityGroupId: gatewayLoadBalancer.albSecurityGroupId,
+ },
+ { parent: this }
+ );
+
+ this.targetGroup = gatewayTargetGroup.target_group;
+
+ const dopplerEcsEnvironment = new DopplerEcsEnvironment(
+ BASE_NAME,
+ { tags: this.tags },
+ { parent: this }
+ );
+
+ // Fargate Service
+ const service = new awsx.ecs.FargateService(
+ `${BASE_NAME}`,
+ {
+ tags,
+ cluster: ecsClusterArn,
+ networkConfiguration: {
+ subnets: vpc.privateSubnetIds,
+ securityGroups: [this.serviceSg.id],
+ },
+ continueBeforeSteadyState: DEFAULT_CONTINUE_BEFORE_STEADY_STATE,
+ deploymentCircuitBreaker: {
+ enable: true,
+ rollback: true,
+ },
+ // Register tasks only with the shared gateway.
+ loadBalancers: [
+ {
+ targetGroupArn: gatewayTargetGroup.target_group.arn,
+ containerName: 'service',
+ containerPort: serviceContainerPort,
+ },
+ ],
+ taskDefinitionArgs: {
+ taskRole: {
+ roleArn: this.role.arn,
+ },
+ executionRole: {
+ roleArn: dopplerEcsEnvironment.executionRole.arn,
+ },
+ containers: {
+ log_router: fargateLogRouterSidecarContainer,
+ datadog_agent: datadogAgentContainer,
+ service: {
+ name: 'service',
+ image: image.image.imageUri,
+ stopTimeout: 10, // 10 seconds to force kill the task
+ cpu: stack === 'prod' ? 512 : 256,
+ memory: stack === 'prod' ? 1024 : 512,
+ environment: [
+ ...containerEnvVars,
+ {
+ name: 'BASE_URL',
+ value: this.domain,
+ },
+ {
+ name: 'RUST_BACKTRACE',
+ value: '1',
+ },
+ ],
+ secrets: [...dopplerEcsEnvironment.containerSecrets],
+ logConfiguration: {
+ logDriver: 'awsfirelens',
+ options: {
+ Name: 'datadog',
+ Host: 'http-intake.logs.us5.datadoghq.com',
+ apikey: DATADOG_API_KEY,
+ dd_service: 'calendar-service',
+ dd_source: 'fargate',
+ dd_tags: `project:cloudstorage, env:${stack}`,
+ provider: 'ecs',
+ },
+ },
+ portMappings: [
+ {
+ appProtocol: 'http',
+ name: `${BASE_NAME}-tcp-${stack}`,
+ hostPort: serviceContainerPort,
+ containerPort: serviceContainerPort,
+ targetGroup: this.targetGroup,
+ },
+ ],
+ },
+ },
+ runtimePlatform: {
+ operatingSystemFamily: `${platform.family.toUpperCase()}`,
+ cpuArchitecture: `${
+ platform.architecture === 'amd64'
+ ? 'X86_64'
+ : platform.architecture.toUpperCase()
+ }`,
+ },
+ },
+ desiredCount: 1,
+ },
+ {
+ parent: this,
+ // ECS refuses a service whose target group is not yet associated with
+ // a load balancer; it is the listener rule that creates that
+ // association
+ dependsOn: [gatewayTargetGroup.listener_rule],
+ }
+ );
+ this.service = service;
+
+ // auto-scaling and alarm notifications
+ this.setupAutoScaling({
+ gatewayAlbArnSuffix: gatewayLoadBalancer.albArnSuffix,
+ gatewayTargetGroup: gatewayTargetGroup.target_group,
+ });
+ this.setupServiceAlarms();
+ }
+
+ initializeSecurityGroups({
+ vpcId,
+ }: {
+ vpcId: pulumi.Output<string> | string;
+ }) {
+ const serviceSg = new aws.ec2.SecurityGroup(
+ `${BASE_NAME}-sg-${stack}`,
+ {
+ name: `${BASE_NAME}-sg-${stack}`,
+ vpcId,
+ description: `${BASE_NAME} security group that is attached directly to the service`,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
+ new aws.vpc.SecurityGroupEgressRule(
+ `${BASE_NAME}-all-out`,
+ {
+ securityGroupId: serviceSg.id,
+ description: 'Allow all outbound',
+ cidrIpv4: '0.0.0.0/0',
+ ipProtocol: '-1',
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
+ return serviceSg;
+ }
+
+ setupAutoScaling({
+ gatewayAlbArnSuffix,
+ gatewayTargetGroup,
+ }: {
+ gatewayAlbArnSuffix: pulumi.Output<string>;
+ gatewayTargetGroup: aws.lb.TargetGroup;
+ }) {
+ if (!this.service) return;
+
+ const serviceScalableTarget = new aws.appautoscaling.Target(
+ `${BASE_NAME}-service-scalable-target-${stack}`,
+ {
+ maxCapacity: stack === 'prod' ? 3 : 2,
+ minCapacity: 1,
+ resourceId: pulumi.interpolate`service/${this.cloudStorageClusterName}/${this.service.service.name}`,
+ scalableDimension: 'ecs:service:DesiredCount',
+ serviceNamespace: 'ecs',
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
+ const resourceLabel = pulumi.interpolate`${gatewayAlbArnSuffix}/${gatewayTargetGroup.arnSuffix}`;
+
+ // Create an Auto Scaling policy for request count.
+ new aws.appautoscaling.Policy(
+ `${BASE_NAME}-scaling-policy-request-count-${stack}`,
+ {
+ policyType: 'TargetTrackingScaling',
+ resourceId: serviceScalableTarget.resourceId,
+ scalableDimension: serviceScalableTarget.scalableDimension,
+ serviceNamespace: serviceScalableTarget.serviceNamespace,
+ targetTrackingScalingPolicyConfiguration: {
+ targetValue: 1000,
+ predefinedMetricSpecification: {
+ predefinedMetricType: 'ALBRequestCountPerTarget',
+ resourceLabel,
+ },
+ scaleInCooldown: 60,
+ scaleOutCooldown: 120,
+ },
+ },
+ { parent: this }
+ );
+
+ // Create an Auto Scaling policy for CPU utilization.
+ new aws.appautoscaling.Policy(
+ `${BASE_NAME}-scaling-policy-cpu-${stack}`,
+ {
+ policyType: 'TargetTrackingScaling',
+ resourceId: serviceScalableTarget.resourceId,
+ scalableDimension: serviceScalableTarget.scalableDimension,
+ serviceNamespace: serviceScalableTarget.serviceNamespace,
+ targetTrackingScalingPolicyConfiguration: {
+ targetValue: 70.0,
+ predefinedMetricSpecification: {
+ predefinedMetricType: 'ECSServiceAverageCPUUtilization',
+ },
+ scaleInCooldown: 100,
+ scaleOutCooldown: 300,
+ },
+ },
+ { parent: this }
+ );
+
+ new aws.appautoscaling.Policy(
+ `${BASE_NAME}-scaling-policy-memory-${stack}`,
+ {
+ policyType: 'TargetTrackingScaling',
+ resourceId: serviceScalableTarget.resourceId,
+ scalableDimension: serviceScalableTarget.scalableDimension,
+ serviceNamespace: serviceScalableTarget.serviceNamespace,
+ targetTrackingScalingPolicyConfiguration: {
+ targetValue: 70.0,
+ predefinedMetricSpecification: {
+ predefinedMetricType: 'ECSServiceAverageMemoryUtilization',
+ },
+ scaleInCooldown: 100,
+ scaleOutCooldown: 300,
+ },
+ },
+ { parent: this }
+ );
+ }
+
+ 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`,
+ {
+ name: `${BASE_NAME}-high-cpu-alarm-${stack}`,
+ metricName: 'CPUUtilization',
+ namespace: 'AWS/ECS',
+ statistic: 'Average',
+ period: 180,
+ evaluationPeriods: 1,
+ threshold: 80,
+ comparisonOperator: 'GreaterThanThreshold',
+ dimensions: {
+ ClusterName: this.cloudStorageClusterName,
+ ServiceName: this.service.service.name,
+ },
+ alarmDescription: `High CPU usage alarm for ${BASE_NAME} service.`,
+ actionsEnabled: true,
+ alarmActions: [CLOUD_TRAIL_SNS_TOPIC_ARN],
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
+ new aws.cloudwatch.MetricAlarm(
+ `${BASE_NAME}-high-mem-alarm`,
+ {
+ name: `${BASE_NAME}-high-mem-alarm-${stack}`,
+ metricName: 'MemoryUtilization',
+ namespace: 'AWS/ECS',
+ statistic: 'Average',
+ period: 180,
+ evaluationPeriods: 1,
+ threshold: 80,
+ comparisonOperator: 'GreaterThanThreshold',
+ dimensions: {
+ ClusterName: this.cloudStorageClusterName,
+ ServiceName: this.service.service.name,
+ },
+ alarmDescription: `High Memory usage alarm for ${BASE_NAME} service.`,
+ actionsEnabled: true,
+ alarmActions: [CLOUD_TRAIL_SNS_TOPIC_ARN],
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
+ new aws.cloudwatch.MetricAlarm(
+ `${BASE_NAME}-http-5xx-alarm`,
+ {
+ name: `${BASE_NAME}-http-5xx-${stack}`,
+ metricName: 'HTTPCode_Target_5XX_Count',
+ namespace: 'AWS/ApplicationELB',
+ statistic: 'Sum',
+ period: 180,
+ evaluationPeriods: 1,
+ threshold: 25,
+ comparisonOperator: 'GreaterThanOrEqualToThreshold',
+ dimensions: {
+ LoadBalancer: gatewayLoadBalancer.albArnSuffix,
+ TargetGroup: this.targetGroup.arnSuffix,
+ },
+ alarmDescription: `High HTTP 5XX count alarm for ${BASE_NAME} gateway target group.`,
+ actionsEnabled: true,
+ alarmActions: [CLOUD_TRAIL_SNS_TOPIC_ARN],
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+ }
+}
diff --git a/infra/stacks/calendar-service/tsconfig.json b/infra/stacks/calendar-service/tsconfig.json
new file mode 100644
index 0000000000..6f83eb665f
--- /dev/null
+++ b/infra/stacks/calendar-service/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "extends": "../../tsconfig.json",
+}
diff --git a/infra/stacks/doppler-projects/index.ts b/infra/stacks/doppler-projects/index.ts
index 38f0bbec1e..88a2a915ec 100644
--- a/infra/stacks/doppler-projects/index.ts
+++ b/infra/stacks/doppler-projects/index.ts
@@ -5,6 +5,7 @@ const SERVICE_NAMES = [
'convert-service',
'notification-service',
'contacts-service',
+ 'calendar-service',
'cloud-storage-service',
'search-processing-service',
'unfurl-service',