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.

perf(infra): right-size idle ECS tasks and tier S3 storage (#8442)

Wolf Mermelstein80d95852a9a1
diff --git a/infra/packages/resources/src/resources/rds.ts b/infra/packages/resources/src/resources/rds.ts
index efc96d1d38..87ecd8c19c 100644
--- a/infra/packages/resources/src/resources/rds.ts
+++ b/infra/packages/resources/src/resources/rds.ts
@@ -116,7 +116,7 @@ export class Database extends pulumi.ComponentResource {
parameterGroupName: 'default.postgres16',
enabledCloudwatchLogsExports: ['postgresql', 'upgrade'],
password: args.dbArgs.password,
- multiAz: true,
+ multiAz: stack === 'prod',
storageEncrypted: true,
backupRetentionPeriod: 7, // Number of days to retain backups
backupWindow: '03:00-04:00', // UTC time
diff --git a/infra/stacks/bulk-upload/upload-bucket.test.ts b/infra/stacks/bulk-upload/upload-bucket.test.ts
index 7e48abdf34..9bddc61c20 100644
--- a/infra/stacks/bulk-upload/upload-bucket.test.ts
+++ b/infra/stacks/bulk-upload/upload-bucket.test.ts
@@ -45,7 +45,7 @@ function resource(type: string): pulumi.runtime.MockResourceArgs {
}
describe('Slack import staging protections', () => {
- test('one helper-owned lifecycle rule expires only the Slack prefix after 14 days', () => {
+ test('helper-owned lifecycle rules expire Slack imports after 14 days and zips after 21', () => {
const lifecycle = resource(
'aws:s3/bucketLifecycleConfigurationV2:BucketLifecycleConfigurationV2'
);
@@ -57,6 +57,13 @@ describe('Slack import staging protections', () => {
filter: { prefix: 'slack-import/' },
expiration: { days: 14 },
},
+ {
+ id: 'extract-cleanup',
+ status: 'Enabled',
+ filter: { prefix: 'extract/' },
+ expiration: { days: 21 },
+ abortIncompleteMultipartUpload: { daysAfterInitiation: 1 },
+ },
]);
});
diff --git a/infra/stacks/bulk-upload/upload-bucket.ts b/infra/stacks/bulk-upload/upload-bucket.ts
index 0bd96abd34..0baf3ef3be 100644
--- a/infra/stacks/bulk-upload/upload-bucket.ts
+++ b/infra/stacks/bulk-upload/upload-bucket.ts
@@ -45,6 +45,14 @@ export class BulkUploadBucket extends pulumi.ComponentResource {
filter: { prefix: 'slack-import/' },
expiration: { days: 14 },
},
+ // Outlives the 14-day DLQ, so a redriven extraction still finds its zip
+ {
+ id: 'extract-cleanup',
+ status: 'Enabled',
+ filter: { prefix: 'extract/' },
+ expiration: { days: 21 },
+ abortIncompleteMultipartUpload: { daysAfterInitiation: 1 },
+ },
],
// The helper owns CORS: PUT and allowedHeaders ['*'] already permit
// If-None-Match and x-amz-checksum-sha256 without a second CORS resource.
diff --git a/infra/stacks/call-recording/index.ts b/infra/stacks/call-recording/index.ts
index b188c48d24..0fa83f83b6 100644
--- a/infra/stacks/call-recording/index.ts
+++ b/infra/stacks/call-recording/index.ts
@@ -22,6 +22,15 @@ const callRecordingBucket = createBucket({
bucketName: `macro-call-recording-${stack}`,
transferAcceleration: stack === 'prod',
enableVersioning: false,
+ lifecycleRules: [
+ {
+ id: `intelligent-tiering-${stack}`,
+ enabled: true,
+ transitions: [{ days: 0, storageClass: 'INTELLIGENT_TIERING' }],
+ // LiveKit egress uploads multipart and can die mid-recording
+ abortIncompleteMultipartUploadDays: 3,
+ },
+ ],
exposeHeaders: ['Content-Length', 'Content-Range'],
tags,
});
diff --git a/infra/stacks/connection-gateway/connection_gateway.ts b/infra/stacks/connection-gateway/connection_gateway.ts
index 30471b0beb..083ea83f51 100644
--- a/infra/stacks/connection-gateway/connection_gateway.ts
+++ b/infra/stacks/connection-gateway/connection_gateway.ts
@@ -208,8 +208,8 @@ export class ConnectionGateway extends pulumi.ComponentResource {
name: BASE_NAME,
image: image.image.imageUri,
stopTimeout: 10, // 10 seconds to force kill the task
- cpu: 4096,
- memory: 8192,
+ cpu: stack === 'prod' ? 1024 : 512,
+ memory: stack === 'prod' ? 3584 : 2560,
environment: [...(containerEnvVars ?? [])],
secrets: [...dopplerEcsEnvironment.containerSecrets],
logConfiguration: {
@@ -301,8 +301,7 @@ export class ConnectionGateway extends pulumi.ComponentResource {
`${BASE_NAME}-service-scalable-target-${stack}`,
{
maxCapacity: stack === 'prod' ? 15 : 3,
- // TODO: reset min capacity to 1 for dev, after testing
- minCapacity: stack === 'prod' ? 3 : 3,
+ minCapacity: stack === 'prod' ? 3 : 1,
resourceId: pulumi.interpolate`service/${this.cloudStorageClusterName}/${this.service.service.name}`,
scalableDimension: 'ecs:service:DesiredCount',
serviceNamespace: 'ecs',
diff --git a/infra/stacks/convert-service/service.ts b/infra/stacks/convert-service/service.ts
index cfd2b8135a..392c6f9839 100644
--- a/infra/stacks/convert-service/service.ts
+++ b/infra/stacks/convert-service/service.ts
@@ -214,8 +214,8 @@ export class ConvertService extends pulumi.ComponentResource {
name: BASE_NAME,
image: image.image.imageUri,
stopTimeout: 10, // 10 seconds to force kill the task
- cpu: 4096,
- memory: 8192,
+ cpu: stack === 'prod' ? 4096 : 512,
+ memory: stack === 'prod' ? 8192 : 3072,
environment: [
...containerEnvVars,
{
diff --git a/infra/stacks/document-cognition-service/document-cognition-service.ts b/infra/stacks/document-cognition-service/document-cognition-service.ts
index 3436247ad6..65353b7d24 100644
--- a/infra/stacks/document-cognition-service/document-cognition-service.ts
+++ b/infra/stacks/document-cognition-service/document-cognition-service.ts
@@ -298,8 +298,8 @@ export class DocumentCognitionService extends pulumi.ComponentResource {
name: BASE_NAME,
image: image.image.imageUri,
stopTimeout: 10, // 10 seconds to force kill the task
- cpu: 4096,
- memory: 8192,
+ cpu: stack === 'prod' ? 2048 : 512,
+ memory: stack === 'prod' ? 3584 : 1024,
environment: [...(containerEnvVars ?? [])],
secrets: [...dopplerEcsEnvironment.containerSecrets],
logConfiguration: {
@@ -334,7 +334,7 @@ export class DocumentCognitionService extends pulumi.ComponentResource {
}`,
},
},
- desiredCount: stack === 'prod' ? 4 : 1,
+ desiredCount: stack === 'prod' ? 2 : 1,
},
{
parent: this,
@@ -498,7 +498,7 @@ export class DocumentCognitionService extends pulumi.ComponentResource {
`${BASE_NAME}-service-scalable-target-${stack}`,
{
maxCapacity: stack === 'prod' ? 10 : 3,
- minCapacity: stack === 'prod' ? 4 : 1,
+ minCapacity: stack === 'prod' ? 2 : 1,
resourceId: pulumi.interpolate`service/${this.cloudStorageClusterName}/${this.service.service.name}`,
scalableDimension: 'ecs:service:DesiredCount',
serviceNamespace: 'ecs',
diff --git a/infra/stacks/document-storage/index.ts b/infra/stacks/document-storage/index.ts
index 3e3aa92934..240c8cb2ee 100644
--- a/infra/stacks/document-storage/index.ts
+++ b/infra/stacks/document-storage/index.ts
@@ -38,6 +38,14 @@ const documentStorageBucket = createBucket({
days: 30,
},
},
+ // Only the automatic tiers: CloudFront and GetObject can't read objects in
+ // the opt-in archive tiers
+ {
+ id: `intelligent-tiering-${stack}`,
+ enabled: true,
+ transitions: [{ days: 0, storageClass: 'INTELLIGENT_TIERING' }],
+ abortIncompleteMultipartUploadDays: 7,
+ },
],
exposeHeaders: ['Content-Length', 'Content-Range'],
});
@@ -65,7 +73,7 @@ new aws.s3.BucketReplicationConfig(
},
destination: {
bucket: replication.bucket.arn,
- storageClass: 'STANDARD',
+ storageClass: 'INTELLIGENT_TIERING',
},
},
],
diff --git a/infra/stacks/document-storage/replication-bucket.ts b/infra/stacks/document-storage/replication-bucket.ts
index 2af2313711..4a505a662b 100644
--- a/infra/stacks/document-storage/replication-bucket.ts
+++ b/infra/stacks/document-storage/replication-bucket.ts
@@ -124,6 +124,7 @@ export function setupReplicationBucket() {
's3:GetReplicationConfiguration',
's3:PutReplicationConfiguration',
's3:GetLifecycleConfiguration',
+ 's3:PutLifecycleConfiguration',
's3:GetAccountPublicAccessBlock',
's3:GetBucketOwnershipControls',
's3:GetBucketAcl',
@@ -173,6 +174,44 @@ export function setupReplicationBucket() {
)
);
+ // Lifecycle expirations on the source bucket are not replicated, so the
+ // replica needs its own. Admins may only put lifecycle rules once the policy
+ // above allows it.
+ new aws.s3.BucketLifecycleConfiguration(
+ 'replication-bucket-lifecycle',
+ {
+ bucket: replicationBucket.id,
+ rules: [
+ {
+ id: 'temp-cleanup',
+ status: 'Enabled',
+ filter: { prefix: 'temp_files/' },
+ expiration: { days: 1 },
+ },
+ {
+ id: 'delete-marked-files',
+ status: 'Enabled',
+ filter: {},
+ expiration: { expiredObjectDeleteMarker: true },
+ },
+ {
+ id: 'noncurrent-version-cleanup',
+ status: 'Enabled',
+ filter: {},
+ noncurrentVersionExpiration: { noncurrentDays: 30 },
+ },
+ {
+ id: 'intelligent-tiering',
+ status: 'Enabled',
+ filter: {},
+ transitions: [{ days: 0, storageClass: 'INTELLIGENT_TIERING' }],
+ abortIncompleteMultipartUpload: { daysAfterInitiation: 7 },
+ },
+ ],
+ },
+ { provider: replicationRegion, dependsOn: bucketPolicy }
+ );
+
return {
bucket: replicationBucket,
role: replicationRole,
diff --git a/infra/stacks/email-service/service.ts b/infra/stacks/email-service/service.ts
index 76df1b507e..fe6f11d0f1 100644
--- a/infra/stacks/email-service/service.ts
+++ b/infra/stacks/email-service/service.ts
@@ -148,8 +148,8 @@ export class EmailService extends pulumi.ComponentResource {
name: BASE_NAME,
image: image.image.imageUri,
stopTimeout: 10, // 10 seconds to force kill the task
- cpu: stack === 'prod' ? 1024 : 256,
- memory: stack === 'prod' ? 4096 : 717,
+ cpu: stack === 'prod' ? 512 : 256,
+ memory: stack === 'prod' ? 1024 : 717,
environment: [...containerEnvVars],
secrets: [...dopplerEcsEnvironment.containerSecrets],
logConfiguration: {
diff --git a/infra/stacks/fusion-auth/database.ts b/infra/stacks/fusion-auth/database.ts
index 66c180bdb9..7e5abd6724 100644
--- a/infra/stacks/fusion-auth/database.ts
+++ b/infra/stacks/fusion-auth/database.ts
@@ -119,7 +119,7 @@ export class Database extends pulumi.ComponentResource {
parameterGroupName: 'default.postgres16',
enabledCloudwatchLogsExports: ['postgresql', 'upgrade'],
password,
- multiAz: true,
+ multiAz: stack === 'prod',
tags,
},
{ parent: this }
diff --git a/infra/stacks/preview-gateway/index.ts b/infra/stacks/preview-gateway/index.ts
index 269fe27734..222f131b23 100644
--- a/infra/stacks/preview-gateway/index.ts
+++ b/infra/stacks/preview-gateway/index.ts
@@ -290,8 +290,8 @@ const service = new awsx.ecs.FargateService(
service: {
name: 'service',
image: image.image.imageUri,
- cpu: 1024,
- memory: 2048,
+ cpu: 256,
+ memory: 512,
essential: true,
stopTimeout: 30,
secrets: doppler.containerSecrets,
diff --git a/infra/stacks/static-file-service/static-file-service.ts b/infra/stacks/static-file-service/static-file-service.ts
index 777cb07be4..48cc712ddb 100644
--- a/infra/stacks/static-file-service/static-file-service.ts
+++ b/infra/stacks/static-file-service/static-file-service.ts
@@ -134,6 +134,11 @@ export class StaticFileService extends pulumi.ComponentResource {
expiredObjectDeleteMarker: true,
},
},
+ {
+ enabled: true,
+ transitions: [{ days: 0, storageClass: 'INTELLIGENT_TIERING' }],
+ abortIncompleteMultipartUploadDays: 7,
+ },
],
corsRules: [
{