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(dss): Add in DSS to the gateway (#5501)

Will Hutchinson7fc5fdc692b6
diff --git a/infra/packages/resources/src/index.ts b/infra/packages/resources/src/index.ts
index 447b1a47d7..68aeeef900 100644
--- a/infra/packages/resources/src/index.ts
+++ b/infra/packages/resources/src/index.ts
@@ -36,3 +36,4 @@ export {
} from './resources/role';
export type { TopicArgs } from './resources/kafka-cluster';
export { KafkaCluster } from './resources/kafka-cluster';
+export { ServiceTargetGroup } from './resources/service_target_group';
diff --git a/infra/packages/resources/src/resources/service_target_group.ts b/infra/packages/resources/src/resources/service_target_group.ts
new file mode 100644
index 0000000000..4a4becd4bf
--- /dev/null
+++ b/infra/packages/resources/src/resources/service_target_group.ts
@@ -0,0 +1,137 @@
+import * as aws from '@pulumi/aws';
+import * as pulumi from '@pulumi/pulumi';
+import {
+ DEFAULT_DEREGISTRATION_DELAY_SECONDS,
+ DEFAULT_TARGET_GROUP_HEALTH_CHECK,
+} from './ecs_deployment_defaults';
+
+type ServiceTargetGroupArgs = {
+ // AWS resource tags
+ tags: { [key: string]: string };
+ // Listener arn
+ listenerArn: pulumi.Output<string>;
+ // Vpc id
+ vpcId: pulumi.Output<string> | string;
+ // Container port
+ containerPort: number;
+ // Health check
+ healthCheckPath: string;
+ // Path patterns
+ pathPatterns: string[];
+ // Priority **MUST BE UNIQUE**
+ priority: number;
+ // Health check
+ healthCheck?: Partial<aws.types.input.lb.TargetGroupHealthCheck>;
+ // Deregistration delay
+ deregistrationDelay?: number;
+ // Service security group id
+ serviceSecurityGroupId: pulumi.Output<string>;
+ // Application load balancer security group id
+ albSecurityGroupId: pulumi.Output<string>;
+};
+
+/**
+ * @description creates a service target group.
+ */
+export class ServiceTargetGroup extends pulumi.ComponentResource {
+ tags: { [key: string]: string };
+ public readonly target_group: aws.lb.TargetGroup;
+ public readonly listener_rule: aws.lb.ListenerRule;
+ constructor(
+ name: string,
+ args: ServiceTargetGroupArgs,
+ opts?: pulumi.ComponentResourceOptions
+ ) {
+ super('my:components:ServiceTargetGroup', name, {}, opts);
+
+ this.tags = args.tags;
+
+ this.target_group = new aws.lb.TargetGroup(
+ `${name}-target-group`,
+ {
+ name: `${name}-tg`,
+ port: args.containerPort,
+ protocol: 'HTTP',
+ targetType: 'ip',
+ vpcId: args.vpcId,
+
+ deregistrationDelay:
+ args.deregistrationDelay ?? DEFAULT_DEREGISTRATION_DELAY_SECONDS,
+
+ healthCheck: {
+ path: args.healthCheckPath,
+ protocol: 'HTTP',
+ ...DEFAULT_TARGET_GROUP_HEALTH_CHECK,
+ ...args.healthCheck,
+ },
+
+ tags: args.tags,
+ },
+ {
+ parent: this,
+ }
+ );
+
+ this.listener_rule = new aws.lb.ListenerRule(
+ `${name}-listener-rule`,
+ {
+ listenerArn: args.listenerArn,
+ priority: args.priority,
+
+ conditions: [
+ {
+ pathPattern: {
+ values: args.pathPatterns,
+ },
+ },
+ ],
+
+ actions: [
+ {
+ type: 'forward',
+ targetGroupArn: this.target_group.arn,
+ },
+ ],
+
+ tags: args.tags,
+ },
+ {
+ parent: this,
+ }
+ );
+
+ // Update service and alb security groups to support traffic
+ new aws.vpc.SecurityGroupIngressRule(
+ `${name}-security-group-ingress-service-to-alb`,
+ {
+ securityGroupId: args.serviceSecurityGroupId,
+ description: 'Allow inbound traffic from ALB',
+ referencedSecurityGroupId: args.albSecurityGroupId,
+ fromPort: args.containerPort,
+ toPort: args.containerPort,
+ ipProtocol: 'tcp',
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
+ new aws.vpc.SecurityGroupEgressRule(
+ `${name}-security-group-egress-alb-to-service`,
+ {
+ description: `Allow traffic to ${name}`,
+ securityGroupId: args.albSecurityGroupId,
+ referencedSecurityGroupId: args.serviceSecurityGroupId,
+ fromPort: args.containerPort,
+ ipProtocol: 'tcp',
+ toPort: args.containerPort,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
+ this.registerOutputs({
+ targetGroupArn: this.target_group.arn,
+ listenerRuleArn: this.listener_rule.arn,
+ });
+ }
+}
diff --git a/infra/stacks/cloud-storage-service/cloud-storage-service.ts b/infra/stacks/cloud-storage-service/cloud-storage-service.ts
index a6db3ece89..8237952cac 100644
--- a/infra/stacks/cloud-storage-service/cloud-storage-service.ts
+++ b/infra/stacks/cloud-storage-service/cloud-storage-service.ts
@@ -10,6 +10,7 @@ import {
datadogAgentContainer,
fargateLogRouterSidecarContainer,
serviceLoadBalancer,
+ ServiceTargetGroup,
} from '../../packages/resources';
import { EcrImage } from '../../packages/service';
import {
@@ -19,8 +20,11 @@ import {
DopplerEcsEnvironment,
getKafkaClusterPolicy,
stack,
+ getGatewayAlb,
} from '../../packages/shared';
+const gatewayLoadBalancer = getGatewayAlb();
+
const BASE_NAME = pulumi.getProject();
const REPO_ROOT = '../../..';
@@ -304,6 +308,22 @@ export class CloudStorageService extends pulumi.ComponentResource {
this.serviceAlbSg = sg.serviceAlbSg;
this.serviceSg = sg.serviceSg;
+ const gatewayTargetGroup = new ServiceTargetGroup(
+ `${stack}-${BASE_NAME}`,
+ {
+ tags: this.tags,
+ listenerArn: gatewayLoadBalancer.httpsListenerArn,
+ vpcId: vpc.vpcId,
+ containerPort: serviceContainerPort,
+ priority: 10,
+ healthCheckPath,
+ pathPatterns: ['/dss', '/dss/*'],
+ serviceSecurityGroupId: this.serviceSg.id,
+ albSecurityGroupId: gatewayLoadBalancer.albSecurityGroupId,
+ },
+ { parent: this }
+ );
+
// lb
const { targetGroup, lb, listener } = serviceLoadBalancer(this, {
serviceName: BASE_NAME, // service name
@@ -339,6 +359,23 @@ export class CloudStorageService extends pulumi.ComponentResource {
enable: true,
rollback: true,
},
+ // Register tasks in both the legacy ALB's target group and the gateway
+ // target group while we migrate to the gateway. An explicit
+ // `loadBalancers` replaces the list awsx derives from
+ // `portMappings.targetGroup`, so the legacy entry must be listed here
+ // too.
+ loadBalancers: [
+ {
+ targetGroupArn: targetGroup.arn,
+ containerName: 'service',
+ containerPort: serviceContainerPort,
+ },
+ {
+ targetGroupArn: gatewayTargetGroup.target_group.arn,
+ containerName: 'service',
+ containerPort: serviceContainerPort,
+ },
+ ],
taskDefinitionArgs: {
taskRole: {
roleArn: this.role.arn,
@@ -393,6 +430,10 @@ export class CloudStorageService extends pulumi.ComponentResource {
},
{
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],
}
);
diff --git a/services/document_storage_service/src/api/mod.rs b/services/document_storage_service/src/api/mod.rs
index 0cfc1fa1d0..2b892f127a 100644
--- a/services/document_storage_service/src/api/mod.rs
+++ b/services/document_storage_service/src/api/mod.rs
@@ -50,7 +50,6 @@ pub const MACRO_INTERNAL_USER_ID: &str = "macro|[email protected]";
pub async fn setup_and_serve(state: ApiContext) -> anyhow::Result<()> {
let app = api_router(state.clone())
- .merge(health::router())
.layer(
ServiceBuilder::new()
.layer(MacroRequestIdAndTracingLayer::new(Duration::from_millis(200)).into_inner())
@@ -64,7 +63,11 @@ pub async fn setup_and_serve(state: ApiContext) -> anyhow::Result<()> {
.layer(CompressionLayer::new().gzip(true)),
)
// The health router is attached here so we don't attach the logging middleware to it
- .merge(SwaggerUi::new("/docs").url("/api-doc/openapi.json", swagger::ApiDoc::openapi()));
+ .merge(SwaggerUi::new("/docs").url("/api-doc/openapi.json", swagger::ApiDoc::openapi()))
+ .merge(
+ SwaggerUi::new("/dss/docs")
+ .url("/dss/api-doc/openapi.json", swagger::ApiDoc::openapi()),
+ );
let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{}", state.config.port))
.await
@@ -276,9 +279,14 @@ fn api_router(state: ApiContext) -> Router {
.nest("/recents", recents::router())
.nest("/saved_views", saved_views::router())
.with_state(state);
- Router::new()
+ let dss_router = Router::new()
.nest("/{version}", internal_router.clone())
.merge(internal_router)
.merge(webhook_router)
.merge(internal_call_router)
+ .merge(health::router());
+
+ Router::new()
+ .merge(dss_router.clone())
+ .nest("/dss", dss_router)
}