Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(unfurl): migrate unfurl-service onto the shared gateway (#6128)
Will Hutchinson0fa70da650e3
diff --git a/apps/web/scripts/services.ts b/apps/web/scripts/services.tsindex 83ee56a3f7..26bd757c97 100644--- a/apps/web/scripts/services.ts+++ b/apps/web/scripts/services.ts@@ -82,8 +82,8 @@ export const services: Service[] = [},{name: "unfurl-service",- dev: "https://unfurl-service-dev.macro.com/api-doc/openapi.json",- prod: "https://unfurl-service.macro.com/api-doc/openapi.json",+ dev: "https://dev-gateway.macro.com/unfurl/api-doc/openapi.json",+ prod: "https://gateway.macro.com/unfurl/api-doc/openapi.json",local: "http://localhost:8095/api-doc/openapi.json",output: "../src/lib/service-clients/service-unfurl/",orvalKey: "unfurlService",diff --git a/apps/web/src/lib/core/constant/servers.ts b/apps/web/src/lib/core/constant/servers.tsindex dabbd8156a..7a830a7eee 100644--- a/apps/web/src/lib/core/constant/servers.ts+++ b/apps/web/src/lib/core/constant/servers.ts@@ -18,9 +18,9 @@ const serverHostLocal: Servers = {const devServerSuffix = import.meta.env.MODE === 'development' ? '-dev' : '';-// The shared gateway ALB fronts DSS under a `/dss` path prefix. Unlike the-// other services it is named with a `dev-` prefix rather than a `-dev` suffix,-// so it cannot reuse `devServerSuffix`.+// The shared gateway ALB fronts DSS (`/dss`) and unfurl (`/unfurl`). Unlike+// the other services it is named with a `dev-` prefix rather than a `-dev`+// suffix, so it cannot reuse `devServerSuffix`.const gatewayHost =import.meta.env.MODE === 'development'? 'https://dev-gateway.macro.com'@@ -41,7 +41,7 @@ const serverHostRemote = {'connection-gateway': `wss://connection-gateway${devServerSuffix}.macro.com`,'notification-service': `https://notifications${devServerSuffix}.macro.com`,'static-file': `https://static-file-service${devServerSuffix}.macro.com`,- 'unfurl-service': `https://unfurl-service${devServerSuffix}.macro.com`,+ 'unfurl-service': `${gatewayHost}/unfurl`,contacts: `https://contacts${devServerSuffix}.macro.com`,'email-service': `https://email-service${devServerSuffix}.macro.com`,'image-proxy-service': `https://image-proxy${devServerSuffix}.macro.com`,diff --git a/crates/macro_service_urls/src/lib.rs b/crates/macro_service_urls/src/lib.rsindex 9ded44ead0..48ee282daa 100644--- a/crates/macro_service_urls/src/lib.rs+++ b/crates/macro_service_urls/src/lib.rs@@ -546,8 +546,8 @@ service_url! {/// Link unfurl service API URL.pub UnfurlServiceUrl {local: "http://localhost:8095",- dev: "https://unfurl-service-dev.macro.com",- prod: "https://unfurl-service.macro.com",+ dev: "https://dev-gateway.macro.com/unfurl",+ prod: "https://gateway.macro.com/unfurl",},/// Contacts service API URL.pub ContactsServiceUrl {diff --git a/crates/macro_service_urls/src/test.rs b/crates/macro_service_urls/src/test.rsindex 2f6cf0bfb0..3cc7044841 100644--- a/crates/macro_service_urls/src/test.rs+++ b/crates/macro_service_urls/src/test.rs@@ -319,7 +319,7 @@ fn exported_service_urls_match_dev_values() {);assert_eq!(service_urls.unfurl_service_url.as_ref(),- "https://unfurl-service-dev.macro.com",+ "https://dev-gateway.macro.com/unfurl",);assert_eq!(service_urls.contacts_service_url.as_ref(),@@ -374,7 +374,7 @@ fn exported_service_urls_match_prod_values() {);assert_eq!(service_urls.unfurl_service_url.as_ref(),- "https://unfurl-service.macro.com",+ "https://gateway.macro.com/unfurl",);assert_eq!(service_urls.contacts_service_url.as_ref(),diff --git a/docs/AGENT_GUIDE/observability.md b/docs/AGENT_GUIDE/observability.mdindex ef213f6835..d16f5473ff 100644--- a/docs/AGENT_GUIDE/observability.md+++ b/docs/AGENT_GUIDE/observability.md@@ -32,13 +32,14 @@ attribute.separate tiny traces for the same path — prefer the trace whose root is `web-app`.URL prefix → service mapping: `/dss/*` → document_storage_service,-`/cognition/*` → document_cognition_service, `/auth/*` → authentication_service,-`/email/*` → email_service. Frontend OTel exports to `/i/otlp/v1/{traces,logs}`.+`/unfurl/*` → unfurl_service, `/cognition/*` → document_cognition_service,+`/auth/*` → authentication_service, `/email/*` → email_service. Frontend OTel+exports to `/i/otlp/v1/{traces,logs}`.The local Caddy proxy strips these prefixes before forwarding, so `span.url.path` is-unprefixed locally. The deployed gateway ALB does **not** strip `/dss` — DSS serves the-same routes at both `/` and `/dss` — so in dev and prod `span.url.path` includes the-prefix. Query both forms when a search comes back empty.+unprefixed locally. The deployed gateway ALB does **not** strip `/dss` or `/unfurl` —+those services serve the same routes at both `/` and the prefix — so in dev and prod+`span.url.path` includes the prefix. Query both forms when a search comes back empty.## Logs (Loki)diff --git a/infra/packages/shared/src/gateway_priorities.ts b/infra/packages/shared/src/gateway_priorities.tsindex 3cef2d5b6a..da442dd587 100644--- a/infra/packages/shared/src/gateway_priorities.ts+++ b/infra/packages/shared/src/gateway_priorities.ts@@ -4,6 +4,7 @@*/export enum GatewayService {DOCUMENT_STORAGE_SERVICE = 'DOCUMENT_STORAGE_SERVICE',+ UNFURL_SERVICE = 'UNFURL_SERVICE',}/**@@ -17,6 +18,7 @@ type GatewayPriorityMap = { [K in GatewayService]: number };*/export const GATEWAY_PRIORITIES: GatewayPriorityMap = {[GatewayService.DOCUMENT_STORAGE_SERVICE]: 10,+ [GatewayService.UNFURL_SERVICE]: 20,};const assigned = Object.values(GATEWAY_PRIORITIES);diff --git a/infra/packages/shared/src/service_urls.ts b/infra/packages/shared/src/service_urls.tsindex d775d73e91..d2c4ed0fca 100644--- a/infra/packages/shared/src/service_urls.ts+++ b/infra/packages/shared/src/service_urls.ts@@ -13,6 +13,7 @@ export enum ServiceUrl {CONNECTION_GATEWAY_URL = 'CONNECTION_GATEWAY_URL',DOCUMENT_COGNITION_SERVICE_URL = 'DOCUMENT_COGNITION_SERVICE_URL',LEXICAL_SERVICE_URL = 'LEXICAL_SERVICE_URL',+ UNFURL_SERVICE_URL = 'UNFURL_SERVICE_URL',}/**@@ -41,6 +42,7 @@ const DEV_SERVICE_URLS: ServiceUrlMap = {'https://document-cognition-dev.macro.com',[ServiceUrl.LEXICAL_SERVICE_URL]:'https://lexical-service-dev.macroverse.workers.dev',+ [ServiceUrl.UNFURL_SERVICE_URL]: 'https://dev-gateway.macro.com/unfurl',};/**@@ -59,6 +61,7 @@ const PROD_SERVICE_URLS: ServiceUrlMap = {'https://document-cognition.macro.com',[ServiceUrl.LEXICAL_SERVICE_URL]:'https://lexical-service-prod.macroverse.workers.dev',+ [ServiceUrl.UNFURL_SERVICE_URL]: 'https://gateway.macro.com/unfurl',};/**diff --git a/infra/stacks/unfurl-service/index.ts b/infra/stacks/unfurl-service/index.tsindex f3db71601d..d3c1e89a94 100644--- a/infra/stacks/unfurl-service/index.ts+++ b/infra/stacks/unfurl-service/index.ts@@ -1,5 +1,5 @@import * as pulumi from '@pulumi/pulumi';-import { stack } from '../../packages/shared';+import { getServiceUrl, ServiceUrl, stack } from '../../packages/shared';import { get_coparse_api_vpc } from '../../packages/vpc';import { UnfurlService } from './unfurl-service';@@ -54,4 +54,4 @@ const unfurlService = new UnfurlService(`unfurl-service-${stack}`, {export const unfurlServiceSgId = unfurlService.serviceSg.id;export const unfurlServiceAlbSgId = unfurlService.serviceAlbSg.id;-export const unfurlServiceUrl = pulumi.interpolate`${unfurlService.domain}`;+export const unfurlServiceUrl = getServiceUrl(ServiceUrl.UNFURL_SERVICE_URL);diff --git a/infra/stacks/unfurl-service/unfurl-service.ts b/infra/stacks/unfurl-service/unfurl-service.tsindex 736db36883..347ced5836 100644--- a/infra/stacks/unfurl-service/unfurl-service.ts+++ b/infra/stacks/unfurl-service/unfurl-service.ts@@ -8,15 +8,20 @@ import {datadogAgentContainer,fargateLogRouterSidecarContainer,serviceLoadBalancer,+ ServiceTargetGroup,} from '../../packages/resources';import { EcrImage } from '../../packages/service';import {BASE_DOMAIN,CLOUD_TRAIL_SNS_TOPIC_ARN,DopplerEcsEnvironment,+ getGatewayAlb,+ GatewayService,stack,} from '../../packages/shared';+const gatewayLoadBalancer = getGatewayAlb();+const BASE_NAME = pulumi.getProject();const REPO_ROOT = '../../..';@@ -100,6 +105,22 @@ export class UnfurlService 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,+ service: GatewayService.UNFURL_SERVICE,+ healthCheckPath,+ pathPatterns: ['/unfurl', '/unfurl/*'],+ serviceSecurityGroupId: this.serviceSg.id,+ albSecurityGroupId: gatewayLoadBalancer.albSecurityGroupId,+ },+ { parent: this }+ );+// lbconst { targetGroup, lb, listener } = serviceLoadBalancer(this, {serviceName: BASE_NAME, // service name@@ -159,6 +180,18 @@ export class UnfurlService extends pulumi.ComponentResource {enable: true,rollback: true,},+ loadBalancers: [+ {+ targetGroupArn: targetGroup.arn,+ containerName: 'service',+ containerPort: serviceContainerPort,+ },+ {+ targetGroupArn: gatewayTargetGroup.target_group.arn,+ containerName: 'service',+ containerPort: serviceContainerPort,+ },+ ],taskDefinitionArgs: {taskRole: {roleArn: this.role.arn,@@ -214,6 +247,7 @@ export class UnfurlService extends pulumi.ComponentResource {},{parent: this,+ dependsOn: [gatewayTargetGroup.listener_rule],});diff --git a/packages/sdk/src/config.ts b/packages/sdk/src/config.tsindex edfe2927f2..5660fb9542 100644--- a/packages/sdk/src/config.ts+++ b/packages/sdk/src/config.ts@@ -37,7 +37,7 @@ export const HOSTS: Record<Env, Record<ServiceName, string>> = {'static-files': 'https://static-file-service-dev.macro.com',connection: 'https://connection-gateway-dev.macro.com',contacts: 'https://contacts-dev.macro.com',- unfurl: 'https://unfurl-service-dev.macro.com',+ unfurl: 'https://dev-gateway.macro.com/unfurl',},prod: {'agent-harness': 'https://agent-harness.macro.com',@@ -52,7 +52,7 @@ export const HOSTS: Record<Env, Record<ServiceName, string>> = {'static-files': 'https://static-file-service.macro.com',connection: 'https://connection-gateway.macro.com',contacts: 'https://contacts.macro.com',- unfurl: 'https://unfurl-service.macro.com',+ unfurl: 'https://gateway.macro.com/unfurl',},local: {'agent-harness': 'http://localhost:8101',diff --git a/services/notification_service/examples/send_push_notification.rs b/services/notification_service/examples/send_push_notification.rsindex 80a3eb4826..ef8f75a105 100644--- a/services/notification_service/examples/send_push_notification.rs+++ b/services/notification_service/examples/send_push_notification.rs@@ -1,9 +1,7 @@use anyhow::Context;-use aws_sdk_sns::types::MessageAttributeValue;use macro_entrypoint::MacroEntrypoint;use serde::Serialize;use sns_client::{APNSPushNotification, Alert, AlertDictionary, Aps, MessageAttributes, SnsTarget};-use std::collections::HashMap;/// Sends a push notification to the provided ENDPOINT_ARN environment variable#[tokio::main]diff --git a/services/unfurl_service/src/api.rs b/services/unfurl_service/src/api.rsindex 0be0b41736..d32135b98c 100644--- a/services/unfurl_service/src/api.rs+++ b/services/unfurl_service/src/api.rs@@ -26,11 +26,13 @@ wherelet cors = macro_cors::cors_layer();let env = state.environment;- let app = api_router(unfurl_state)- .with_state(state)- .merge(health::router())+ let app = app_router(state, unfurl_state).layer(cors)- .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("/unfurl/docs")+ .url("/unfurl/api-doc/openapi.json", swagger::ApiDoc::openapi()),+ );let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{}", port)).await@@ -57,6 +59,17 @@ where.nest("/proxy", proxy::router())}+fn app_router<F>(state: ApiContext, unfurl_state: UnfurlRouterState<UnfurlServiceImpl<F>>) -> Router+where+ F: UnfurlFetcher,+ anyhow::Error: From<F::Err>,+{+ let inner = api_router(unfurl_state)+ .with_state(state)+ .merge(health::router());+ Router::new().merge(inner.clone()).nest("/unfurl", inner)+}+#[cfg(test)]mod tests {use crate::api::unfurl::get_unfurl::{GetUnfurlBulkBody, GetUnfurlBulkResponse};@@ -105,6 +118,63 @@ mod tests {assert!(body.is_empty());}+ async fn health_body(app: Router, uri: &str) -> (StatusCode, String) {+ let response = app+ .oneshot(+ Request::builder()+ .uri(uri)+ .method("GET")+ .body(Body::empty())+ .unwrap(),+ )+ .await+ .unwrap();+ let status = response.status();+ let body = String::from_utf8(+ response+ .into_body()+ .collect()+ .await+ .unwrap()+ .to_bytes()+ .to_vec(),+ )+ .unwrap();+ (status, body)+ }++ #[tokio::test]+ async fn test_health_is_served_at_root_and_gateway_prefix() {+ let (root_status, root_body) =+ health_body(app_router(test_state(), test_unfurl_state()), "/health").await;+ assert_eq!(root_status, StatusCode::OK);+ assert_eq!(root_body, "healthy");++ let (prefixed_status, prefixed_body) = health_body(+ app_router(test_state(), test_unfurl_state()),+ "/unfurl/health",+ )+ .await;+ assert_eq!(prefixed_status, StatusCode::OK);+ assert_eq!(prefixed_body, "healthy");+ }++ #[tokio::test]+ async fn test_gateway_prefixed_unfurl_path_is_reachable() {+ let api = app_router(test_state(), test_unfurl_state());++ let response = api+ .oneshot(+ Request::builder()+ .uri("/unfurl/unfurl?url=https://doesnotexist.com")+ .body(Body::empty())+ .unwrap(),+ )+ .await+ .unwrap();+ assert_eq!(response.status(), StatusCode::INTERNAL_SERVER_ERROR);+ }+#[tokio::test]async fn test_unfurl_url_nonexistent() {let api = api_router(test_unfurl_state()).with_state(test_state());