infra: stats

This commit is contained in:
Frank
2026-06-02 02:41:33 -04:00
parent 6a5ef7f2ea
commit 90d85636e0
3 changed files with 49 additions and 9 deletions

View File

@@ -268,6 +268,7 @@ export const lakeIngest = new sst.Linkable("LakeIngest", {
secret: ingestSecret.result,
},
})
export const lakeIngestSecret = new sst.Secret("LakeIngestSecret", ingestSecret.result)
export const lakeQueryPermissions = [
{
@@ -320,3 +321,39 @@ export const lakeQueryPermissions = [
resources: ["*"],
},
]
////////////////
// S3 Tables
////////////////
const modelsNamespace = new aws.s3tables.Namespace("LakeModelsNamespace", {
namespace: "models",
tableBucketArn: tableBucket.arn,
})
new aws.s3tables.Table(
"LakeModelsEventTable",
{
name: "hit",
namespace: modelsNamespace.namespace,
tableBucketArn: modelsNamespace.tableBucketArn,
format: "ICEBERG",
metadata: {
iceberg: {
schema: {
fields: [
{ name: "event_timestamp", type: "string", required: false },
{ name: "event_date", type: "string", required: false },
{ name: "event_type", type: "string", required: false },
{ name: "country", type: "string", required: false },
{ name: "user_agent", type: "string", required: false },
{ name: "ip", type: "string", required: false },
{ name: "ip_prefix", type: "string", required: false },
{ name: "path", type: "string", required: false },
],
},
},
},
},
{ deleteBeforeReplace: $app.stage !== "production" },
)

View File

@@ -1,11 +1,6 @@
import { lakeAthenaWorkgroup, lakeCatalog, lakeCluster, lakeQueryPermissions, lakeRegion, tableBucket } from "./lake"
import { EMAILOCTOPUS_API_KEY } from "./app"
const domain = (() => {
if ($app.stage === "production") return "stats.opencode.ai"
if ($app.stage === "dev") return "stats.dev.opencode.ai"
return `stats.${$app.stage}.dev.opencode.ai`
})()
import { domain } from "./stage"
////////////////
// LAKE
@@ -42,6 +37,7 @@ const inferenceEventTable = new aws.s3tables.Table(
{ name: "request_length", type: "long", required: false },
{ name: "status", type: "int", required: false },
{ name: "ip", type: "string", required: false },
{ name: "ip_prefix", type: "string", required: false },
{ name: "is_stream", type: "boolean", required: false },
{ name: "session", type: "string", required: false },
{ name: "request", type: "string", required: false },
@@ -167,10 +163,10 @@ new sst.x.DevCommand("StatsStudio", {
export const app = new sst.cloudflare.x.SolidStart("Stats", {
path: "packages/stats/app",
buildCommand: "bun run build",
domain,
domain: `stats.${domain}`,
link: [database, EMAILOCTOPUS_API_KEY],
environment: {
PUBLIC_URL: `https://${domain}/stats`,
PUBLIC_URL: `https://stats.${domain}/stats`,
},
})