diff --git a/ai b/ai index bf528179e..e66bb8079 160000 --- a/ai +++ b/ai @@ -1 +1 @@ -Subproject commit bf528179eb36bf0de11f6aa3e146b4199c588771 +Subproject commit e66bb80796bf8387e4fbcc550f9d520eaa182f6e diff --git a/server/.env.example b/server/.env.example index 3cb56059e..c621748a0 100644 --- a/server/.env.example +++ b/server/.env.example @@ -65,9 +65,6 @@ SVIX_API_KEY= # This is used to generate singular / plural names for your features, which are used when in the dashboard and when you use Autumn UI components ANTHROPIC_API_KEY= -# TINYBIRD US-EAST CLICKHOUSE (required for analytics paths that hit ClickHouse-direct) -# During the us-west → us-east cutover, ClickHouse-direct reads (revenue -# analytics, getCountAndSum, etc.) are routed to the us-east workspace via -# this URL plus TINYBIRD_US_EAST_TOKEN. Legacy TINYBIRD_CLICKHOUSE_URL is -# ignored at runtime. +# TINYBIRD +# ClickHouse endpoint for the us-east workspace (primary after cutover). TINYBIRD_US_EAST_CLICKHOUSE_URL= diff --git a/server/src/external/tinybird/initClickhouse.ts b/server/src/external/tinybird/initClickhouse.ts index 2987effbc..16e84bc9b 100644 --- a/server/src/external/tinybird/initClickhouse.ts +++ b/server/src/external/tinybird/initClickhouse.ts @@ -1,18 +1,5 @@ import { type ClickHouseClient, createClient } from "@clickhouse/client"; -/** - * ClickHouse-direct client for Tinybird (used by analytics paths like - * revenue analytics, getCountAndSum, getTopEventNames, etc.). During the - * us-west → us-east cutover transition this reads from the us-east - * workspace's ClickHouse endpoint and admin token. The legacy - * `TINYBIRD_CLICKHOUSE_URL` / `TINYBIRD_TOKEN` env vars are ignored at - * runtime — primary moved to TINYBIRD_US_EAST_* in `tinybirdUtils.ts` and - * this client follows it. - * - * Tinybird URL pattern reference: - * API: https://api..aws.tinybird.co - * ClickHouse: https://clickhouse..aws.tinybird.co - */ const primaryClickhouseUrl = process.env.TINYBIRD_US_EAST_CLICKHOUSE_URL; const primaryToken = process.env.TINYBIRD_US_EAST_TOKEN; diff --git a/server/src/external/tinybird/initTinybird.ts b/server/src/external/tinybird/initTinybird.ts index d6efe3f8f..d90790a1f 100644 --- a/server/src/external/tinybird/initTinybird.ts +++ b/server/src/external/tinybird/initTinybird.ts @@ -8,13 +8,7 @@ import { createListEventsPaginatedPipe } from "./pipes/listEventsPaginatedPipe.j import { tinybirdConfig } from "./tinybirdUtils.js"; import { z } from "./tinybirdZod.js"; -/** - * Primary Tinybird REST API client — handles reads (pipes) and primary - * writes (ingest). Configured from `TINYBIRD_US_EAST_*` env vars during the - * us-west → us-east cutover transition (see `tinybirdUtils.ts`). The - * dual-write safety-net secondary lives in `initTinybirdV2.ts` and - * reads the legacy `TINYBIRD_API_URL` / `TINYBIRD_TOKEN` vars. - */ +/** Primary Tinybird client — reads (pipes) and primary writes (ingest). */ const tinybirdClient: Tinybird | null = tinybirdConfig ? new Tinybird(tinybirdConfig) : null; diff --git a/server/src/external/tinybird/initTinybirdV2.ts b/server/src/external/tinybird/initTinybirdV2.ts index 82297b8e3..24620b84a 100644 --- a/server/src/external/tinybird/initTinybirdV2.ts +++ b/server/src/external/tinybird/initTinybirdV2.ts @@ -1,14 +1,8 @@ import { createTinybirdApi } from "@tinybirdco/sdk"; -/** - * Secondary Tinybird API client for dual-write safety net during the - * us-west → us-east region cutover. Reads from the legacy `TINYBIRD_API_URL` - * / `TINYBIRD_TOKEN` env vars, which point at us-west during the transition. - * Primary lives on `TINYBIRD_US_EAST_*` (see `tinybirdUtils.ts`). Once - * us-east is stable, delete this file + the dual-write logic in - * `sendEvents.ts`, and remove `TINYBIRD_API_URL` / `TINYBIRD_TOKEN` from - * Infisical. - */ +// Dual-write safety net during the us-east cutover. Reads the legacy +// us-west env vars; delete with the dual-write logic in `sendEvents.ts` +// once us-east is stable. const secondaryApiUrl = process.env.TINYBIRD_API_URL; const secondaryToken = process.env.TINYBIRD_TOKEN; diff --git a/server/src/external/tinybird/sendEvents/sendEvents.ts b/server/src/external/tinybird/sendEvents/sendEvents.ts index 3969d981d..80c23cbd4 100644 --- a/server/src/external/tinybird/sendEvents/sendEvents.ts +++ b/server/src/external/tinybird/sendEvents/sendEvents.ts @@ -11,13 +11,7 @@ const generateErrorId = (): string => { return `TB_ERR_${crypto.randomBytes(8).toString("hex").toUpperCase()}`; }; -/** - * Send EventInsert[] to Tinybird primary and (if configured) the secondary - * dual-write safety-net client. Each path is fired independently so a missing - * or broken primary doesn't disable the secondary. Does not throw — failures - * are logged and captured in Sentry with `tinybird_region=primary|secondary` - * (the tag name is legacy from when the second client was region-specific). - */ +/** Dual-write to Tinybird primary + secondary. Failures logged, never thrown. */ export const sendEventsToTinybird = async ({ events, logger, @@ -29,10 +23,7 @@ export const sendEventsToTinybird = async ({ return; } - // During the region cutover, primary (us-east via TINYBIRD_US_EAST_*) and - // secondary (us-west via legacy TINYBIRD_API_URL/TOKEN) are independent. - // If primary is misconfigured or down, the secondary safety net must - // still fire — that's the whole point of dual-write. + // Gate on either being configured — a broken primary must not silence the secondary. if (!tinybirdIngest && !tinybirdSecondaryApi) { logger?.debug( "Tinybird not configured (neither primary nor secondary), skipping event send", diff --git a/server/src/external/tinybird/tinybirdUtils.ts b/server/src/external/tinybird/tinybirdUtils.ts index 5827babf6..7abe97e29 100644 --- a/server/src/external/tinybird/tinybirdUtils.ts +++ b/server/src/external/tinybird/tinybirdUtils.ts @@ -1,14 +1,8 @@ import { ErrCode, RecaseError } from "@autumn/shared"; import { StatusCodes } from "http-status-codes"; -/** - * Primary Tinybird config — reads from `TINYBIRD_US_EAST_API_URL` / - * `TINYBIRD_US_EAST_TOKEN` during the us-west → us-east cutover transition. - * The legacy `TINYBIRD_API_URL` / `TINYBIRD_TOKEN` env vars now feed the - * dual-write *secondary* client (`initTinybirdV2.ts`) as a safety net - * during the transition. After cutover stabilises, the secondary client and - * legacy env vars get removed in a follow-up cleanup. - */ +// Primary points at us-east during the cutover; legacy us-west vars feed +// the dual-write secondary in `initTinybirdV2.ts`. const primaryApiUrl = process.env.TINYBIRD_US_EAST_API_URL; const primaryToken = process.env.TINYBIRD_US_EAST_TOKEN;