Skip to content

Commit 6969da5

Browse files
committed
wip: stats
1 parent 8f37ded commit 6969da5

5 files changed

Lines changed: 74 additions & 25 deletions

File tree

infra/console.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { domain } from "./stage"
1+
import { deployAws, domain } from "./stage"
22
import { EMAILOCTOPUS_API_KEY } from "./app"
33
import { SECRET } from "./secret"
4-
import { lakeIngest } from "./lake"
4+
5+
const lake = deployAws ? await import("./lake") : undefined
56

67
////////////////
78
// DATABASE
@@ -241,7 +242,7 @@ const SALESFORCE_INSTANCE_URL = new sst.Secret("SALESFORCE_INSTANCE_URL")
241242

242243
const logProcessor = new sst.cloudflare.Worker("LogProcessor", {
243244
handler: "packages/console/function/src/log-processor.ts",
244-
link: [SECRET.HoneycombApiKey, lakeIngest],
245+
link: [SECRET.HoneycombApiKey, ...(lake?.lakeIngest ? [lake.lakeIngest] : [])],
245246
})
246247

247248
new sst.cloudflare.x.SolidStart("Console", {

infra/stage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const domain = (() => {
55
})()
66

77
export const zoneID = "430ba34c138cfb5360826c4909f99be8"
8+
export const deployAws = $app.stage === "production" || $app.stage === "dev" || $app.stage === "adam"
89

910
const githubActionsDeployRole = (() => {
1011
if ($app.stage !== "dev" && $app.stage !== "production") return

packages/console/function/src/log-processor.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export default {
5151
]
5252
console.log(JSON.stringify(data, null, 2))
5353

54+
const lakeIngest = getLakeIngest()
5455
const [honeycomb, lake] = await Promise.all([
5556
fetch("https://api.honeycomb.io/1/batch/zen", {
5657
method: "POST",
@@ -60,23 +61,37 @@ export default {
6061
},
6162
body: JSON.stringify(events),
6263
}),
63-
fetch(Resource.LakeIngest.url, {
64-
method: "POST",
65-
headers: {
66-
"Content-Type": "application/json",
67-
Authorization: `Bearer ${Resource.LakeIngest.secret}`,
68-
},
69-
body: JSON.stringify({ events: events.map((event) => toLakeEvent(event.time, event.data)) }),
70-
}),
64+
...(lakeIngest
65+
? [
66+
fetch(lakeIngest.url, {
67+
method: "POST",
68+
headers: {
69+
"Content-Type": "application/json",
70+
Authorization: `Bearer ${lakeIngest.secret}`,
71+
},
72+
body: JSON.stringify({ events: events.map((event) => toLakeEvent(event.time, event.data)) }),
73+
}),
74+
]
75+
: []),
7176
])
7277
console.log(honeycomb.status)
7378
console.log(await honeycomb.text())
74-
console.log(lake.status)
75-
console.log(await lake.text())
79+
if (lake) {
80+
console.log(lake.status)
81+
console.log(await lake.text())
82+
}
7683
}
7784
},
7885
}
7986

87+
function getLakeIngest(): { url: string; secret: string } | undefined {
88+
try {
89+
return Resource.LakeIngest
90+
} catch {
91+
return undefined
92+
}
93+
}
94+
8095
function toLakeEvent(time: string, data: Record<string, unknown>) {
8196
return {
8297
_datalake_key: "inference.event",

packages/stats/server/Dockerfile

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,35 @@ ENV BUN_RUNTIME_TRANSPILER_CACHE_PATH=0
77

88
COPY package.json bun.lock ./
99
COPY patches ./patches
10-
COPY packages ./packages
10+
COPY packages/app/package.json ./packages/app/package.json
11+
COPY packages/console/app/package.json ./packages/console/app/package.json
12+
COPY packages/console/core/package.json ./packages/console/core/package.json
13+
COPY packages/console/function/package.json ./packages/console/function/package.json
14+
COPY packages/console/mail/package.json ./packages/console/mail/package.json
15+
COPY packages/console/resource/package.json ./packages/console/resource/package.json
16+
COPY packages/core/package.json ./packages/core/package.json
17+
COPY packages/desktop/package.json ./packages/desktop/package.json
18+
COPY packages/effect-drizzle-sqlite/package.json ./packages/effect-drizzle-sqlite/package.json
19+
COPY packages/enterprise/package.json ./packages/enterprise/package.json
20+
COPY packages/function/package.json ./packages/function/package.json
21+
COPY packages/http-recorder/package.json ./packages/http-recorder/package.json
22+
COPY packages/llm/package.json ./packages/llm/package.json
23+
COPY packages/opencode/package.json ./packages/opencode/package.json
24+
COPY packages/plugin/package.json ./packages/plugin/package.json
25+
COPY packages/script/package.json ./packages/script/package.json
26+
COPY packages/sdk/js/package.json ./packages/sdk/js/package.json
27+
COPY packages/slack/package.json ./packages/slack/package.json
28+
COPY packages/stats/app/package.json ./packages/stats/app/package.json
29+
COPY packages/stats/core/package.json ./packages/stats/core/package.json
30+
COPY packages/stats/server/package.json ./packages/stats/server/package.json
31+
COPY packages/storybook/package.json ./packages/storybook/package.json
32+
COPY packages/ui/package.json ./packages/ui/package.json
33+
COPY packages/web/package.json ./packages/web/package.json
1134

1235
RUN bun install --frozen-lockfile --production --ignore-scripts
1336

37+
COPY packages ./packages
38+
1439
WORKDIR /app/packages/stats/server
1540

1641
EXPOSE 3000

sst.config.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@
22

33
export default $config({
44
app(input) {
5+
const deployAws = input.stage === "production" || input.stage === "dev" || input.stage === "adam"
56
return {
67
name: "opencode",
78
removal: input?.stage === "production" ? "retain" : "remove",
89
protect: ["production"].includes(input?.stage),
910
home: "cloudflare",
1011
providers: {
11-
aws: {
12-
version: "7.30.0",
13-
region: "us-east-1",
14-
profile: process.env.GITHUB_ACTIONS
15-
? undefined
16-
: input.stage === "production"
17-
? "opencode-production"
18-
: "opencode-dev",
19-
},
12+
...(deployAws
13+
? {
14+
aws: {
15+
version: "7.30.0",
16+
region: "us-east-1",
17+
profile: process.env.GITHUB_ACTIONS
18+
? undefined
19+
: input.stage === "production"
20+
? "opencode-production"
21+
: "opencode-dev",
22+
},
23+
}
24+
: {}),
2025
stripe: {
2126
version: "0.0.28",
2227
apiKey: process.env.STRIPE_SECRET_KEY!,
@@ -30,8 +35,10 @@ export default $config({
3035
async run() {
3136
const stage = await import("./infra/stage.js")
3237
await import("./infra/app.js")
33-
await import("./infra/lake.js")
34-
await import("./infra/stats.js")
38+
if (stage.deployAws) {
39+
await import("./infra/lake.js")
40+
await import("./infra/stats.js")
41+
}
3542
const { stat } = await import("./infra/console.js")
3643
await import("./infra/enterprise.js")
3744
if ($app.stage === "production" || $app.stage === "vimtor") {

0 commit comments

Comments
 (0)