@caelo-cms/provisioning 0.12.10 → 0.12.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/dist/agent-db.js +51 -2
  2. package/dist/cli.js +23 -2
  3. package/dist/cli.js.map +1 -1
  4. package/dist/collection-stores.d.ts +5 -0
  5. package/dist/collection-stores.d.ts.map +1 -0
  6. package/dist/collection-stores.js +21 -0
  7. package/dist/collection-stores.js.map +1 -0
  8. package/dist/collections-setup.d.ts +66 -0
  9. package/dist/collections-setup.d.ts.map +1 -0
  10. package/dist/collections-setup.js +252 -0
  11. package/dist/collections-setup.js.map +1 -0
  12. package/dist/compose.d.ts +27 -0
  13. package/dist/compose.d.ts.map +1 -1
  14. package/dist/compose.js +52 -1
  15. package/dist/compose.js.map +1 -1
  16. package/dist/gateway-edge.d.ts +13 -0
  17. package/dist/gateway-edge.d.ts.map +1 -1
  18. package/dist/gateway-edge.js +22 -0
  19. package/dist/gateway-edge.js.map +1 -1
  20. package/dist/gcp-names.d.ts +18 -48
  21. package/dist/gcp-names.d.ts.map +1 -1
  22. package/dist/gcp-names.js +11 -69
  23. package/dist/gcp-names.js.map +1 -1
  24. package/dist/infra-contract.d.ts +1 -1
  25. package/dist/infra-contract.d.ts.map +1 -1
  26. package/dist/infra-contract.js +35 -1
  27. package/dist/infra-contract.js.map +1 -1
  28. package/dist/reporting-job-catalog.d.ts +111 -0
  29. package/dist/reporting-job-catalog.d.ts.map +1 -0
  30. package/dist/reporting-job-catalog.js +306 -0
  31. package/dist/reporting-job-catalog.js.map +1 -0
  32. package/dist/reporting-job-setup.d.ts +11 -68
  33. package/dist/reporting-job-setup.d.ts.map +1 -1
  34. package/dist/reporting-job-setup.js +44 -100
  35. package/dist/reporting-job-setup.js.map +1 -1
  36. package/dist/runtime-secrets.d.ts +25 -0
  37. package/dist/runtime-secrets.d.ts.map +1 -1
  38. package/dist/runtime-secrets.js +34 -0
  39. package/dist/runtime-secrets.js.map +1 -1
  40. package/dist/self-hosted-backup.d.ts.map +1 -1
  41. package/dist/self-hosted-backup.js +18 -6
  42. package/dist/self-hosted-backup.js.map +1 -1
  43. package/dist/stack-contract.d.ts +75 -22
  44. package/dist/stack-contract.d.ts.map +1 -1
  45. package/dist/stack-contract.js +142 -51
  46. package/dist/stack-contract.js.map +1 -1
  47. package/dist/stack-converge.d.ts +20 -1
  48. package/dist/stack-converge.d.ts.map +1 -1
  49. package/dist/stack-converge.js +105 -2
  50. package/dist/stack-converge.js.map +1 -1
  51. package/dist/staging-gateway-setup.d.ts.map +1 -1
  52. package/dist/staging-gateway-setup.js +10 -5
  53. package/dist/staging-gateway-setup.js.map +1 -1
  54. package/dist/upgrade/admin-image-jobs.d.ts +4 -3
  55. package/dist/upgrade/admin-image-jobs.d.ts.map +1 -1
  56. package/dist/upgrade/admin-image-jobs.js +9 -16
  57. package/dist/upgrade/admin-image-jobs.js.map +1 -1
  58. package/dist/upgrade/app-roll.d.ts +16 -0
  59. package/dist/upgrade/app-roll.d.ts.map +1 -1
  60. package/dist/upgrade/app-roll.js +35 -23
  61. package/dist/upgrade/app-roll.js.map +1 -1
  62. package/dist/upgrade/converge.d.ts +1 -1
  63. package/dist/upgrade/converge.d.ts.map +1 -1
  64. package/dist/upgrade/converge.js +83 -87
  65. package/dist/upgrade/converge.js.map +1 -1
  66. package/dist/upgrade/upgrade.d.ts +7 -5
  67. package/dist/upgrade/upgrade.d.ts.map +1 -1
  68. package/dist/upgrade/upgrade.js +31 -14
  69. package/dist/upgrade/upgrade.js.map +1 -1
  70. package/dist/upgrader-iam-preflight.d.ts.map +1 -1
  71. package/dist/upgrader-iam-preflight.js +8 -18
  72. package/dist/upgrader-iam-preflight.js.map +1 -1
  73. package/dist/upgrader-setup.d.ts.map +1 -1
  74. package/dist/upgrader-setup.js +7 -15
  75. package/dist/upgrader-setup.js.map +1 -1
  76. package/dist/visitor-query-logs.d.ts +40 -0
  77. package/dist/visitor-query-logs.d.ts.map +1 -0
  78. package/dist/visitor-query-logs.js +41 -0
  79. package/dist/visitor-query-logs.js.map +1 -0
  80. package/dist/wizards/gcp-cost.d.ts.map +1 -1
  81. package/dist/wizards/gcp-cost.js +17 -9
  82. package/dist/wizards/gcp-cost.js.map +1 -1
  83. package/dist/wizards/gcp.d.ts.map +1 -1
  84. package/dist/wizards/gcp.js +45 -35
  85. package/dist/wizards/gcp.js.map +1 -1
  86. package/package.json +2 -2
  87. package/src/admin-memory.test.ts +57 -1
  88. package/src/cli.ts +23 -1
  89. package/src/collection-stores.ts +28 -0
  90. package/src/collections-setup.test.ts +237 -0
  91. package/src/collections-setup.ts +317 -0
  92. package/src/compose.ts +54 -1
  93. package/src/gateway-edge.test.ts +28 -0
  94. package/src/gateway-edge.ts +24 -0
  95. package/src/gateway-env-isolation.test.ts +141 -3
  96. package/src/gcp-names.ts +28 -84
  97. package/src/infra-contract.test.ts +5 -3
  98. package/src/infra-contract.ts +35 -1
  99. package/src/remote-mcp.test.ts +13 -1
  100. package/src/reporting-job-catalog.test.ts +156 -0
  101. package/src/reporting-job-catalog.ts +426 -0
  102. package/src/reporting-job-setup.test.ts +119 -6
  103. package/src/reporting-job-setup.ts +51 -158
  104. package/src/runtime-secrets.test.ts +19 -4
  105. package/src/runtime-secrets.ts +42 -0
  106. package/src/self-hosted-backup.test.ts +2 -2
  107. package/src/self-hosted-backup.ts +18 -6
  108. package/src/self-hosted-compose.test.ts +9 -3
  109. package/src/stack-contract.test.ts +62 -4
  110. package/src/stack-contract.ts +172 -59
  111. package/src/stack-converge-secrets.test.ts +4 -0
  112. package/src/stack-converge.test.ts +81 -3
  113. package/src/stack-converge.ts +124 -3
  114. package/src/staging-gateway-setup.test.ts +4 -0
  115. package/src/staging-gateway-setup.ts +16 -6
  116. package/src/upgrade/admin-image-jobs.ts +13 -25
  117. package/src/upgrade/app-roll.ts +54 -28
  118. package/src/upgrade/converge.ts +100 -122
  119. package/src/upgrade/upgrade.test.ts +159 -6
  120. package/src/upgrade/upgrade.ts +46 -32
  121. package/src/upgrader-iam-preflight.ts +7 -20
  122. package/src/upgrader-job.test.ts +3 -0
  123. package/src/upgrader-setup.test.ts +3 -0
  124. package/src/upgrader-setup.ts +6 -17
  125. package/src/visitor-query-logs.ts +46 -0
  126. package/src/wizards/gcp-cost.ts +19 -9
  127. package/src/wizards/gcp.ts +51 -45
  128. package/stacks/aws/index.ts +18 -9
  129. package/stacks/azure/index.ts +19 -8
  130. package/stacks/gcp/index.ts +54 -1
  131. package/stacks/gcp-firebase/index.ts +28 -1
@@ -51,12 +51,9 @@
51
51
 
52
52
  import { z } from "zod";
53
53
  import {
54
- auditRunnerServiceAccountEmail,
55
54
  auditServiceAccountEmail,
56
- buildCarrierServiceAccountEmail,
57
55
  captureServiceAccountEmail,
58
56
  gatewayServiceAccountEmail,
59
- importCrawlServiceAccountEmail,
60
57
  mcpAuthProxyServiceAccountEmail,
61
58
  mcpIapServiceAccountEmail,
62
59
  runServiceAccountEmail,
@@ -64,6 +61,7 @@ import {
64
61
  upgraderJobName,
65
62
  upgraderServiceAccountEmail,
66
63
  } from "./gcp-names.js";
64
+ import { REPORTING_JOB_CATALOG, reportingJobServiceAccountEmail } from "./reporting-job-catalog.js";
67
65
  import type { HttpFetch } from "./runtime-secrets.js";
68
66
  import { OPS_INSTALL_PREFIX, opsBucketName } from "./state-backend.js";
69
67
  import { RELEASE_REGISTRY } from "./upgrade/release-images.js";
@@ -262,24 +260,13 @@ export function upgraderAccessChecks(target: {
262
260
  resource: sa(captureServiceAccountEmail(projectId, env)),
263
261
  permissions: ["iam.serviceAccounts.actAs"],
264
262
  },
265
- {
266
- // #1359 — so does the quality-audit runner.
267
- need: "run the quality-audit runner as its service account after moving it",
268
- resource: sa(auditRunnerServiceAccountEmail(projectId, env)),
269
- permissions: ["iam.serviceAccounts.actAs"],
270
- },
271
- {
272
- // #1360 — and the site-import crawler.
273
- need: "run the site-import crawler as its service account after moving it",
274
- resource: sa(importCrawlServiceAccountEmail(projectId, env)),
263
+ // #1359, #1360, #1574, epic #1644 — and every reporting job
264
+ // (reporting-job-catalog.ts).
265
+ ...REPORTING_JOB_CATALOG.map((e) => ({
266
+ need: `run the ${e.label} as its service account after moving it`,
267
+ resource: sa(reportingJobServiceAccountEmail(e, projectId, env)),
275
268
  permissions: ["iam.serviceAccounts.actAs"],
276
- },
277
- {
278
- // #1574 — and the build carrier.
279
- need: "run the build carrier as its service account after moving it",
280
- resource: sa(buildCarrierServiceAccountEmail(projectId, env)),
281
- permissions: ["iam.serviceAccounts.actAs"],
282
- },
269
+ })),
283
270
  {
284
271
  need: "keep the upgrader job running as its own service account after it moves onto a release",
285
272
  resource: sa(upgraderServiceAccountEmail(projectId, env)),
@@ -522,6 +522,9 @@ describe("runUpgraderJob", () => {
522
522
  "iam projects/acme/serviceAccounts/caelo-production-capture@acme.iam.gserviceaccount.com",
523
523
  "iam projects/acme/serviceAccounts/caelo-production-gateway-sa@acme.iam.gserviceaccount.com",
524
524
  "iam projects/acme/serviceAccounts/caelo-production-import@acme.iam.gserviceaccount.com",
525
+ // Epic #1644 — the collection index job and the plugin batch job.
526
+ "iam projects/acme/serviceAccounts/caelo-production-index@acme.iam.gserviceaccount.com",
527
+ "iam projects/acme/serviceAccounts/caelo-production-plugin-batch@acme.iam.gserviceaccount.com",
525
528
  "iam projects/acme/serviceAccounts/caelo-production-mcp-proxy-sa@acme.iam.gserviceaccount.com",
526
529
  "iam projects/acme/serviceAccounts/caelo-production-run-sa@acme.iam.gserviceaccount.com",
527
530
  "iam projects/acme/serviceAccounts/caelo-production-stg-gw-sa@acme.iam.gserviceaccount.com",
@@ -96,6 +96,9 @@ describe("ensureUpgraderJob", () => {
96
96
  "iam service-accounts add-iam-policy-binding caelo-production-import@acme.iam.gserviceaccount.com → roles/iam.serviceAccountUser",
97
97
  // #1574 — and the build carrier.
98
98
  "iam service-accounts add-iam-policy-binding caelo-production-build@acme.iam.gserviceaccount.com → roles/iam.serviceAccountUser",
99
+ // Epic #1644 — and the collection index job and the plugin batch job.
100
+ "iam service-accounts add-iam-policy-binding caelo-production-index@acme.iam.gserviceaccount.com → roles/iam.serviceAccountUser",
101
+ "iam service-accounts add-iam-policy-binding caelo-production-plugin-batch@acme.iam.gserviceaccount.com → roles/iam.serviceAccountUser",
99
102
  "storage buckets add-iam-policy-binding gs://acme-caelo-ops → roles/storage.objectUser",
100
103
  "storage buckets add-iam-policy-binding gs://acme-caelo-ops → projects/acme/roles/caeloUpgraderOpsList",
101
104
  ].sort(),
@@ -80,12 +80,9 @@ import { ensureCloudSqlIamUser } from "./cloudsql-iam-user.js";
80
80
  import { gcloud as defaultGcloud, type GcloudResult } from "./gcloud.js";
81
81
  import { type GcloudRunner, realSleep, runWithRetry, type Sleep } from "./gcloud-retry.js";
82
82
  import {
83
- auditRunnerServiceAccountEmail,
84
83
  auditServiceAccountEmail,
85
- buildCarrierServiceAccountEmail,
86
84
  captureServiceAccountEmail,
87
85
  gatewayServiceAccountEmail,
88
- importCrawlServiceAccountEmail,
89
86
  mcpAuthProxyServiceAccountEmail,
90
87
  mcpIapServiceAccountEmail,
91
88
  runServiceAccountEmail,
@@ -96,6 +93,7 @@ import {
96
93
  } from "./gcp-names.js";
97
94
  import { readAdminConfig } from "./migration-runner.js";
98
95
  import { type CustomRoleSpec, customRoleName, ensureCustomRole } from "./operator-access.js";
96
+ import { REPORTING_JOB_CATALOG, reportingJobServiceAccountEmail } from "./reporting-job-catalog.js";
99
97
  import { OPS_INSTALL_PREFIX, opsBucketName } from "./state-backend.js";
100
98
 
101
99
  /** Cloud SQL backups for the pre-upgrade backup — nothing else on the instance. */
@@ -291,21 +289,12 @@ export function upgraderAccountGrants(projectId: string, env: string): UpgraderA
291
289
  role: "roles/iam.serviceAccountUser",
292
290
  why: "the app-roll moves the capture job, which runs as it, onto the new image",
293
291
  },
294
- {
295
- account: auditRunnerServiceAccountEmail(projectId, env),
296
- role: "roles/iam.serviceAccountUser",
297
- why: "the app-roll moves the quality-audit runner, which runs as it, onto the new image",
298
- },
299
- {
300
- account: importCrawlServiceAccountEmail(projectId, env),
292
+ // #1359, #1360, #1574, epic #1644 — every reporting job (reporting-job-catalog.ts).
293
+ ...REPORTING_JOB_CATALOG.map((e) => ({
294
+ account: reportingJobServiceAccountEmail(e, projectId, env),
301
295
  role: "roles/iam.serviceAccountUser",
302
- why: "the app-roll moves the site-import crawler, which runs as it, onto the new image",
303
- },
304
- {
305
- account: buildCarrierServiceAccountEmail(projectId, env),
306
- role: "roles/iam.serviceAccountUser",
307
- why: "the app-roll moves the build carrier, which runs as it, onto the new image",
308
- },
296
+ why: `the app-roll moves the ${e.label}, which runs as it, onto the new image`,
297
+ })),
309
298
  {
310
299
  account: mcpIapServiceAccountEmail(projectId),
311
300
  role: "roles/iam.serviceAccountTokenCreator",
@@ -0,0 +1,46 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+
3
+ /**
4
+ * Epic #1644 (#1649) — visitors' search queries stay out of the install's
5
+ * logs. A declared collection operation (search, suggest, read) answers a
6
+ * GET whose query string carries what the visitor typed:
7
+ * `/api/plugin/<slug>/<op>?q=…&lang=…`. The gateway itself never logs it
8
+ * (its `gateway_request_log` row has the operation, not the query), but
9
+ * Google Cloud writes a request log entry for every request a Cloud Run
10
+ * service, the load balancer or Firebase Hosting serves, with the full URL
11
+ * in `httpRequest.requestUrl`. A visitor's query is personal data the
12
+ * install has no use for in its logs.
13
+ *
14
+ * So every Google Cloud install excludes those entries from every sink the
15
+ * install routes logs through: `_Default` (the project's own log bucket)
16
+ * and, on `gcp`, the edge log sink to BigQuery (the stack declares the same
17
+ * exclusion there). A sink exclusion drops the entry before it is stored,
18
+ * so nothing is kept anywhere. The rest of the request's record stays: the
19
+ * gateway's own request log row (operation, status, duration).
20
+ *
21
+ * The filter matches by method and URL shape only, never by service or
22
+ * resource type: whichever Google service logged the request (Cloud Run,
23
+ * the load balancer, Firebase Hosting's optional Cloud Logging
24
+ * integration), an entry with such a URL is dropped. Only collection
25
+ * operations are GETs under `/api/plugin/` (plugin operations are POSTs),
26
+ * so no other request disappears from the logs.
27
+ *
28
+ * Pure module: the stacks import it from `dist/`; collections-setup.ts
29
+ * applies it with gcloud on install and converge.
30
+ */
31
+
32
+ /**
33
+ * The Cloud Logging query of the exclusion. `=~` is an RE2 match anywhere in
34
+ * the value; `[?]` is a literal question mark without an escape the query
35
+ * language would read first. A route without a query string (the uncached
36
+ * `/release` lookup) carries nothing of the visitor's and stays logged.
37
+ */
38
+ export const VISITOR_QUERY_LOG_FILTER =
39
+ 'httpRequest.requestMethod="GET" AND httpRequest.requestUrl=~"/api/plugin/[a-z][a-z0-9-]*/[a-z_][a-z0-9_]*[?]"';
40
+
41
+ /** The exclusion's description, as the Cloud Console shows it. */
42
+ export const VISITOR_QUERY_LOG_DESCRIPTION =
43
+ "Caelo: visitors' search queries (GET /api/plugin/<slug>/<op>?...) are not stored (epic #1644)";
44
+
45
+ /** The sink every Google Cloud project routes its logs through by default. */
46
+ export const DEFAULT_LOG_SINK = "_Default";
@@ -14,6 +14,7 @@
14
14
  import { GATEWAY_ARMOR_BILLED_RULES } from "../gateway-edge.js";
15
15
  import {
16
16
  ADMIN_MEMORY_DEFAULT,
17
+ GATEWAY_MEMORY_DEFAULT,
17
18
  memoryQuantityMiB,
18
19
  parseSchedulerIntervalMinutes,
19
20
  RUNTIME_SECRETS,
@@ -230,6 +231,15 @@ export function estimateGcpCost(inputs: CostEstimateInputs): {
230
231
  notes:
231
232
  "one small container per such build for the build's length (1 vCPU / 512 MiB, waiting for the admin's answer): ~$0.001 per build minute, a 2-minute Stage ~$0.002; mostly in the free tier",
232
233
  },
234
+ {
235
+ // Epic #1644 — a Stage whose plugin collections changed (a site
236
+ // search's pages) builds their new index in its own job; nothing runs
237
+ // without a plugin that declares collections.
238
+ name: "Search indexes (Cloud Run collection index job)",
239
+ monthlyUsd: 0,
240
+ notes:
241
+ "one container per Stage whose plugin collections changed (2 vCPU / 4 GiB): a delta of 1,000 pages ~30 s (~$0.002), a full 50,000-page rebuild a few minutes (~$0.01-0.02); nothing without such a plugin; mostly in the free tier",
242
+ },
233
243
  {
234
244
  name: "Screenshots (Cloud Run capture job)",
235
245
  monthlyUsd: 1,
@@ -243,8 +253,8 @@ export function estimateGcpCost(inputs: CostEstimateInputs): {
243
253
  monthlyUsd: inputs.gatewayMinInstances === 0 ? 1 : 1 + inputs.gatewayMinInstances * 15,
244
254
  notes:
245
255
  inputs.gatewayMinInstances === 0
246
- ? "scale-to-zero; ~$1/mo light traffic"
247
- : `${inputs.gatewayMinInstances} min-instance${inputs.gatewayMinInstances > 1 ? "s" : ""}`,
256
+ ? `scale-to-zero, ${GATEWAY_MEMORY_DEFAULT} (search indexes cached in memory, #1644); ~$1/mo light traffic`
257
+ : `${inputs.gatewayMinInstances} min-instance${inputs.gatewayMinInstances > 1 ? "s" : ""}, ${GATEWAY_MEMORY_DEFAULT}`,
248
258
  },
249
259
  {
250
260
  // #1330 — the staging gateway serves the staged site behind the
@@ -253,8 +263,7 @@ export function estimateGcpCost(inputs: CostEstimateInputs): {
253
263
  // answers a fixed 404 while no staging host is set.
254
264
  name: "Cloud Run staging gateway",
255
265
  monthlyUsd: 0,
256
- notes:
257
- "scale-to-zero, request-based CPU; only the team's visits to staging wake it, mostly in the free tier",
266
+ notes: `scale-to-zero, request-based CPU, ${GATEWAY_MEMORY_DEFAULT}; only the team's visits to staging wake it, mostly in the free tier`,
258
267
  },
259
268
  {
260
269
  // #1328 — remote MCP's sign-in service, its own service on every
@@ -281,7 +290,8 @@ export function estimateGcpCost(inputs: CostEstimateInputs): {
281
290
  {
282
291
  name: "Cloud CDN cache",
283
292
  monthlyUsd: 1,
284
- notes: "Free egress at edge cache hits",
293
+ notes:
294
+ "Free egress at edge cache hits; also caches visitor search answers on the gateway backend (#1644): ~$0.0075 per 10,000 lookups",
285
295
  },
286
296
  {
287
297
  // #1339 — the gateway's policy (src/gateway-edge.ts): its rules
@@ -305,10 +315,10 @@ export function estimateGcpCost(inputs: CostEstimateInputs): {
305
315
  "own policy ($5) with 2 rules ($2): per-IP throttle for remote MCP clients; requests ~$0",
306
316
  },
307
317
  {
308
- name: "Cloud Storage (static + media + staging)",
318
+ name: "Cloud Storage (static + media + staging + collection stores)",
309
319
  monthlyUsd: 1,
310
320
  notes:
311
- "~5 GB storage + low egress; the staging bucket holds two complete builds (#1330 A/B slots); growth roughly $0.02/GB",
321
+ "~5 GB storage + low egress; the staging bucket holds two complete builds (#1330 A/B slots); a 50,000-page site search index ~350 MB per environment (#1644); growth roughly $0.02/GB",
312
322
  },
313
323
  {
314
324
  name: "BigQuery edge log sink",
@@ -324,10 +334,10 @@ export function estimateGcpCost(inputs: CostEstimateInputs): {
324
334
  "Free tier: 10 GB storage + 360 MB/day egress; the staging site (#1330) only rewrites to the staging gateway and stores nothing",
325
335
  },
326
336
  {
327
- name: "Cloud Storage (media + staging)",
337
+ name: "Cloud Storage (media + staging + collection stores)",
328
338
  monthlyUsd: 1,
329
339
  notes:
330
- "~5 GB storage + low egress; static lives on Firebase; the private staging bucket holds two complete builds (#1330 A/B slots); growth roughly $0.02/GB",
340
+ "~5 GB storage + low egress; static lives on Firebase; the private staging bucket holds two complete builds (#1330 A/B slots); a 50,000-page site search index ~350 MB per environment (#1644); growth roughly $0.02/GB",
331
341
  },
332
342
  {
333
343
  name: "Cloud Logging (service logs, the edge log sink)",
@@ -44,6 +44,7 @@ import { ensureAuditJob, resolveAdminImage } from "../audit-job-setup.js";
44
44
  import { ensureCaptureJob } from "../capture-job-setup.js";
45
45
  import { CERT_WAIT_TIMEOUT_MS, lbCertProbe, waitForCert } from "../cert-wait.js";
46
46
  import { redactCredentials } from "../checkpoint-secrets.js";
47
+ import { ensureCollectionStores } from "../collections-setup.js";
47
48
  import { ensureConvergeJob } from "../converge-job-setup.js";
48
49
  import { removeDefaultFirewallRules } from "../default-firewall.js";
49
50
  import {
@@ -80,10 +81,7 @@ import {
80
81
  serviceAccountExists,
81
82
  } from "../gcloud.js";
82
83
  import {
83
- auditRunnerServiceAccountEmail,
84
- buildCarrierServiceAccountEmail,
85
84
  GCP_STACK_ENV,
86
- importCrawlServiceAccountEmail,
87
85
  schedulerServiceAccountEmail,
88
86
  upgraderServiceAccountEmail,
89
87
  } from "../gcp-names.js";
@@ -136,10 +134,11 @@ import {
136
134
  resolveStackRemoteMcpIdentity,
137
135
  } from "../remote-mcp.js";
138
136
  import {
139
- ensureAuditRunnerJob,
140
- ensureBuildCarrierJob,
141
- ensureImportCrawlJob,
142
- } from "../reporting-job-setup.js";
137
+ REPORTING_JOB_CATALOG,
138
+ type ReportingJobKindEntry,
139
+ reportingJobServiceAccounts,
140
+ } from "../reporting-job-catalog.js";
141
+ import { ensureReportingJobKind } from "../reporting-job-setup.js";
143
142
  import type { RunMode } from "../run-mode.js";
144
143
  import { ensureSchedulerTick } from "../scheduler-setup.js";
145
144
  import { selfCommand } from "../self-command.js";
@@ -631,30 +630,19 @@ export async function runGcpConverge(opts: GcpConvergeOpts): Promise<void> {
631
630
  // Before the upgrader, which gets actAs on the job's service account.
632
631
  await stepAuditJob(projectId, region, provider);
633
632
 
634
- // === 11.32. The quality-audit runner: a Stage's audit in its own job (#1359) ===
635
- // After the audit job (it starts its Lighthouse tasks), before the
636
- // upgrader (actAs on its account) and operator access (keeps it on IAP).
637
- await stepReportingJob(projectId, region, provider, ownerEmail, {
638
- starting: "Setting up the quality-audit runner (audits outside the admin)...",
639
- ready: "Quality-audit runner ready",
640
- ensure: ensureAuditRunnerJob,
641
- });
642
-
643
- // === 11.33. The site-import crawler: a site import's crawl in its own job (#1360) ===
644
- // Before the upgrader and operator access, for the same reasons.
645
- await stepReportingJob(projectId, region, provider, ownerEmail, {
646
- starting: "Setting up the site-import crawler (crawls outside the admin)...",
647
- ready: "Site-import crawler ready",
648
- ensure: ensureImportCrawlJob,
649
- });
633
+ // === 11.32. The collection stores + the search-query log exclusion (epic #1644) ===
634
+ // After the staging gateway (its account reads the staging store), before
635
+ // the collection index job (it writes there).
636
+ await stepCollectionStores(projectId, region, provider);
650
637
 
651
- // === 11.34. The build carrier: holds the request a build nobody waits for runs in (#1574) ===
652
- // Before the upgrader and operator access, for the same reasons.
653
- await stepReportingJob(projectId, region, provider, ownerEmail, {
654
- starting: "Setting up the build carrier (builds that outlast their request)...",
655
- ready: "Build carrier ready",
656
- ensure: ensureBuildCarrierJob,
657
- });
638
+ // === 11.33. Every reporting job of the catalog (#1359, #1360, #1574, epic #1644) ===
639
+ // In catalog order, each after what it needs: the quality-audit runner
640
+ // after the audit job (it starts its Lighthouse tasks), the collection
641
+ // index job after the stores. All before the upgrader (actAs on their
642
+ // accounts) and operator access (keeps them on IAP).
643
+ for (const entry of REPORTING_JOB_CATALOG) {
644
+ await stepReportingJob(projectId, region, provider, ownerEmail, entry);
645
+ }
658
646
 
659
647
  // === 11.35. The capture job: server-side screenshots outside the admin (#1217) ===
660
648
  // Before the upgrader as well, which gets actAs on its service account.
@@ -689,10 +677,8 @@ export async function runGcpConverge(opts: GcpConvergeOpts): Promise<void> {
689
677
  keepSigner ? [`serviceAccount:${upgraderServiceAccountEmail(projectId, GCP_STACK_ENV)}`] : [],
690
678
  [
691
679
  ...(keepScheduler ? [schedulerServiceAccountEmail(projectId, GCP_STACK_ENV)] : []),
692
- // #1359 / #1360 / #1574 — set up above (a failure stops the wizard there).
693
- auditRunnerServiceAccountEmail(projectId, GCP_STACK_ENV),
694
- importCrawlServiceAccountEmail(projectId, GCP_STACK_ENV),
695
- buildCarrierServiceAccountEmail(projectId, GCP_STACK_ENV),
680
+ // Every reporting job: set up above (a failure stops the wizard there).
681
+ ...reportingJobServiceAccounts(projectId, GCP_STACK_ENV),
696
682
  ],
697
683
  );
698
684
 
@@ -1556,9 +1542,8 @@ async function stepAuditJob(
1556
1542
  }
1557
1543
 
1558
1544
  /**
1559
- * #1359 / #1360 — set up a reporting job (reporting-job-setup.ts) on the
1560
- * deployed admin's image: the quality-audit runner (a Stage's whole audit)
1561
- * or the site-import crawler (a site import's crawl), each reporting back
1545
+ * #1359 — set up one reporting job of the catalog (reporting-job-catalog.ts,
1546
+ * reporting-job-setup.ts) on the deployed admin's image, reporting back
1562
1547
  * through IAP. A failure stops the wizard: without it that work fails.
1563
1548
  * Idempotent, so it runs on every wizard pass.
1564
1549
  */
@@ -1567,14 +1552,10 @@ async function stepReportingJob(
1567
1552
  region: string,
1568
1553
  provider: "gcp" | "gcp-firebase",
1569
1554
  ownerEmail: string,
1570
- job: {
1571
- readonly starting: string;
1572
- readonly ready: string;
1573
- readonly ensure: typeof ensureAuditRunnerJob;
1574
- },
1555
+ entry: ReportingJobKindEntry,
1575
1556
  ): Promise<void> {
1576
1557
  const s = spinner();
1577
- s.start(job.starting);
1558
+ s.start(entry.wizard.starting);
1578
1559
  const image = await resolveAdminImage({ projectId, region, env: GCP_STACK_ENV });
1579
1560
  const resolved = image.ok
1580
1561
  ? await resolveOperatorAccessTarget({
@@ -1589,7 +1570,7 @@ async function stepReportingJob(
1589
1570
  ? { ok: false as const, done: [], error: image.error }
1590
1571
  : !resolved?.ok
1591
1572
  ? { ok: false as const, done: [], error: resolved?.error ?? "no IAP resource" }
1592
- : await job.ensure({
1573
+ : await ensureReportingJobKind(entry, {
1593
1574
  provider,
1594
1575
  projectId,
1595
1576
  region,
@@ -1603,7 +1584,32 @@ async function stepReportingJob(
1603
1584
  cancel("Aborted.");
1604
1585
  process.exit(1);
1605
1586
  }
1606
- s.stop(green(`${job.ready} (${r.done.length} steps)`));
1587
+ s.stop(green(`${entry.wizard.ready} (${r.done.length} steps)`));
1588
+ }
1589
+
1590
+ /**
1591
+ * Epic #1644 — the collection stores and who may read them, plus the log
1592
+ * exclusion for visitors' search queries (collections-setup.ts). A failure
1593
+ * stops the wizard: without the stores every Stage's plugin collections
1594
+ * fail. Idempotent, so it runs on every wizard pass. A staging gateway
1595
+ * whose setup failed above gets its read access from the next `upgrade`.
1596
+ */
1597
+ async function stepCollectionStores(
1598
+ projectId: string,
1599
+ region: string,
1600
+ provider: "gcp" | "gcp-firebase",
1601
+ ): Promise<void> {
1602
+ const s = spinner();
1603
+ s.start("Setting up the collection stores (plugin indexes such as site search)...");
1604
+ const r = await ensureCollectionStores({ provider, projectId, region, env: GCP_STACK_ENV });
1605
+ if (!r.ok) {
1606
+ s.stop(red(`Failed: ${r.error}`));
1607
+ log.error("Re-run the wizard once the cause is fixed (this step is idempotent).");
1608
+ cancel("Aborted.");
1609
+ process.exit(1);
1610
+ }
1611
+ s.stop(green(`Collection stores ready (${r.done.length} steps)`));
1612
+ for (const p of r.pending) log.warn(` ${p}`);
1607
1613
  }
1608
1614
 
1609
1615
  /**
@@ -455,15 +455,24 @@ new aws.cloudwatch.LogDelivery(
455
455
  // (quality/lighthouse-runner-select.ts) instead of measuring on its own
456
456
  // shared CPU. Nothing is staged on AWS before #749 either.
457
457
  //
458
- // FIXME(issue #749): no reporting-job task yet (#1359, #1360, #1574). On GCP
459
- // a Stage's whole quality audit and a site import's crawl each run in their
460
- // own job that reports back to the admin, and the build carrier holds the
461
- // request a build nobody else waits for runs in (src/reporting-job-setup.ts);
462
- // the AWS equivalent is an ECS task per audit, crawl or carried build behind
463
- // admin-core reporting-jobs/launcher.ts `JobLauncher`, reporting through the
464
- // ALB's Cognito gate. Until it exists the admin records every audit, every
465
- // site import and every carried build as failed with that gap instead of
466
- // running it on its own CPU.
458
+ // FIXME(issue #749): no reporting-job task yet (#1359, #1360, #1574, epic
459
+ // #1644). On GCP a Stage's whole quality audit, a site import's crawl, a
460
+ // Stage's collection index and a plugin's batch run each run in their own
461
+ // job that reports back to the admin, and the build carrier holds the
462
+ // request a build nobody else waits for runs in (src/reporting-job-catalog.ts);
463
+ // the AWS equivalent is an ECS task per kind behind admin-core
464
+ // reporting-jobs/launcher.ts `JobLauncher`, reporting through the ALB's
465
+ // Cognito gate. Until it exists the admin records every such run as failed
466
+ // with that gap instead of running it on its own CPU.
467
+ //
468
+ // FIXME(issue #749): no collection store yet (epic #1644). On GCP plugin
469
+ // collections (a site search's index) live in two private buckets, staging
470
+ // and live, each gateway reading only its own (src/collections-setup.ts);
471
+ // the AWS equivalent is two private S3 buckets with the same per-task
472
+ // grants and CAELO_COLLECTIONS_{STAGING,LIVE}_STORE on the tasks. Until it
473
+ // exists no task gets a store: a plugin's collection write fails with this
474
+ // gap (plugin-host collections-host.ts), the Stage records its collections
475
+ // as failed, and Publish live refuses until the plugin is deactivated.
467
476
  //
468
477
  // FIXME(issue #749): no capture task definition yet. On GCP every
469
478
  // server-side browser render (screenshots, external page renders, the
@@ -433,14 +433,25 @@ const logWorkspace = new azure.operationalinsights.Workspace(`${namePrefix}-logs
433
433
  // before #750 either.
434
434
  //
435
435
  // FIXME(issue #750): no reporting-job Container Apps job yet (#1359, #1360,
436
- // #1574). On GCP a Stage's whole quality audit and a site import's crawl each
437
- // run in their own job that reports back to the admin, and the build carrier
438
- // holds the request a build nobody else waits for runs in
439
- // (src/reporting-job-setup.ts); the Azure equivalent is a Container Apps job
440
- // execution per audit, crawl or carried build behind admin-core
441
- // reporting-jobs/launcher.ts `JobLauncher`, reporting through Easy Auth.
442
- // Until it exists the admin records every audit, every site import and every
443
- // carried build as failed with that gap instead of running it on its own CPU.
436
+ // #1574, epic #1644). On GCP a Stage's whole quality audit, a site import's
437
+ // crawl, a Stage's collection index and a plugin's batch run each run in
438
+ // their own job that reports back to the admin, and the build carrier holds
439
+ // the request a build nobody else waits for runs in
440
+ // (src/reporting-job-catalog.ts); the Azure equivalent is a Container Apps
441
+ // job execution per kind behind admin-core reporting-jobs/launcher.ts
442
+ // `JobLauncher`, reporting through Easy Auth. Until it exists the admin
443
+ // records every such run as failed with that gap instead of running it on
444
+ // its own CPU.
445
+ //
446
+ // FIXME(issue #750): no collection store yet (epic #1644). On GCP plugin
447
+ // collections (a site search's index) live in two private buckets, staging
448
+ // and live, each gateway reading only its own (src/collections-setup.ts);
449
+ // the Azure equivalent is two private Blob containers with the same
450
+ // per-app role assignments and CAELO_COLLECTIONS_{STAGING,LIVE}_STORE on the
451
+ // apps. Until it exists no app gets a store: a plugin's collection write
452
+ // fails with this gap (plugin-host collections-host.ts), the Stage records
453
+ // its collections as failed, and Publish live refuses until the plugin is
454
+ // deactivated.
444
455
  //
445
456
  // FIXME(issue #750): no capture Container Apps job yet. On GCP every
446
457
  // server-side browser render (screenshots, external page renders, the
@@ -35,6 +35,7 @@ import {
35
35
  runServiceAccountId,
36
36
  stagingGatewayServiceAccountId,
37
37
  staticPublisherServiceAccountId,
38
+ visitorQueryLogExclusionName,
38
39
  } from "../../dist/gcp-names.js";
39
40
  import { createSiteUrlMap } from "../../dist/gcp-url-map.js";
40
41
  import {
@@ -59,6 +60,8 @@ import {
59
60
  cloudSqlPrivateDnsName,
60
61
  databaseUrls,
61
62
  defaultStagingHost,
63
+ GATEWAY_CDN_POLICY,
64
+ GATEWAY_MEMORY_DEFAULT,
62
65
  gatewayEnvContract,
63
66
  REMOTE_MCP_IDENTITY_CONFIG,
64
67
  type RuntimeSecret,
@@ -70,6 +73,10 @@ import {
70
73
  } from "../../dist/stack-contract.js";
71
74
  import { DEPLOY_GATEWAYS_CONFIG, parseDeployGateways } from "../../dist/stack-gateways.js";
72
75
  import { GCP_STATIC_RESPONSE_HEADERS } from "../../dist/static-security-headers.js";
76
+ import {
77
+ VISITOR_QUERY_LOG_DESCRIPTION,
78
+ VISITOR_QUERY_LOG_FILTER,
79
+ } from "../../dist/visitor-query-logs.js";
73
80
 
74
81
  const cfg = new pulumi.Config();
75
82
  const domain = cfg.require("domain");
@@ -300,6 +307,9 @@ const runtimeSecretIds: Record<RuntimeSecret, pulumi.Input<string>> = {
300
307
  // then; IAP login, IAP programmatic access and the remote-MCP broker) and
301
308
  // the broker's seal key, both CLI-generated.
302
309
  "operator-oauth-client": gcpSecretId(env, "operator-oauth-client"),
310
+ // #1654 — the visitor AI's key per environment, CLI-generated as `{}`.
311
+ "visitor-ai-key": gcpSecretId(env, "visitor-ai-key"),
312
+ "visitor-ai-staging-key": gcpSecretId(env, "visitor-ai-staging-key"),
303
313
  "mcp-oauth-seal-key": gcpSecretId(env, "mcp-oauth-seal-key"),
304
314
  };
305
315
 
@@ -635,6 +645,28 @@ new gcp.secretmanager.SecretIamMember(
635
645
  opts,
636
646
  );
637
647
 
648
+ // #1654 — the Owner's visitor-AI keys, one secret per environment, the same
649
+ // add-version-only grant: the admin stores or removes a key, never reads
650
+ // one; each gateway reads only its own (stack-contract.ts GCP_COMMON).
651
+ new gcp.secretmanager.SecretIamMember(
652
+ `${namePrefix}-admin-visitor-ai-key-version-adder`,
653
+ {
654
+ secretId: runtimeSecretIds["visitor-ai-key"],
655
+ role: "roles/secretmanager.secretVersionAdder",
656
+ member: pulumi.interpolate`serviceAccount:${runSa.email}`,
657
+ },
658
+ opts,
659
+ );
660
+ new gcp.secretmanager.SecretIamMember(
661
+ `${namePrefix}-admin-visitor-ai-staging-key-version-adder`,
662
+ {
663
+ secretId: runtimeSecretIds["visitor-ai-staging-key"],
664
+ role: "roles/secretmanager.secretVersionAdder",
665
+ member: pulumi.interpolate`serviceAccount:${runSa.email}`,
666
+ },
667
+ opts,
668
+ );
669
+
638
670
  new gcp.storage.BucketIAMMember(
639
671
  `${namePrefix}-media-rw`,
640
672
  {
@@ -976,7 +1008,8 @@ const gatewaySvc = deployGateways
976
1008
  serviceName: "gateway",
977
1009
  minInstances: gatewayMinInstances,
978
1010
  maxInstances: gatewayMaxInstances,
979
- memory: "512Mi",
1011
+ // Epic #1644 — collection index files are cached in memory.
1012
+ memory: GATEWAY_MEMORY_DEFAULT,
980
1013
  // Visitor requests only (#1328 moved remote MCP's long streams to the
981
1014
  // MCP-Auth-Proxy): Cloud Run's default.
982
1015
  timeout: "300s",
@@ -1086,6 +1119,16 @@ function gatewayBackend(service: gcp.cloudrunv2.Service): gcp.compute.BackendSer
1086
1119
  backends: [{ group: gatewayNeg.id }],
1087
1120
  loadBalancingScheme: "EXTERNAL_MANAGED",
1088
1121
  securityPolicy: wafPolicy.id,
1122
+ // Epic #1644 — a collection operation's answer for the release it
1123
+ // names is cacheable; everything else the gateway says is no-store
1124
+ // (stack-contract.ts GATEWAY_CDN_POLICY, converged by upgrade).
1125
+ enableCdn: true,
1126
+ cdnPolicy: {
1127
+ cacheMode: GATEWAY_CDN_POLICY.cacheMode,
1128
+ negativeCaching: GATEWAY_CDN_POLICY.negativeCaching,
1129
+ serveWhileStale: GATEWAY_CDN_POLICY.serveWhileStale,
1130
+ cacheKeyPolicy: { ...GATEWAY_CDN_POLICY.cacheKeyPolicy },
1131
+ },
1089
1132
  },
1090
1133
  opts,
1091
1134
  );
@@ -1396,6 +1439,16 @@ const loggingSink = new gcp.logging.ProjectSink(
1396
1439
  ? pulumi.interpolate`(resource.type="cloud_run_revision" AND resource.labels.service_name="${gatewaySvc.name}") OR (resource.type="cloud_run_revision" AND resource.labels.service_name="${adminSvc.name}" AND severity>=WARNING)`
1397
1440
  : pulumi.interpolate`resource.type="cloud_run_revision" AND resource.labels.service_name="${adminSvc.name}" AND severity>=WARNING`,
1398
1441
  uniqueWriterIdentity: true,
1442
+ // Epic #1644 — visitors' search queries ride in the URL of a gateway
1443
+ // request log; they are never exported (visitor-query-logs.ts; the CLI
1444
+ // puts the same exclusion on _Default).
1445
+ exclusions: [
1446
+ {
1447
+ name: visitorQueryLogExclusionName(env),
1448
+ description: VISITOR_QUERY_LOG_DESCRIPTION,
1449
+ filter: VISITOR_QUERY_LOG_FILTER,
1450
+ },
1451
+ ],
1399
1452
  },
1400
1453
  opts,
1401
1454
  );
@@ -76,6 +76,7 @@ import {
76
76
  databaseUrls,
77
77
  defaultStagingHost,
78
78
  fixedCloudRunServiceName,
79
+ GATEWAY_MEMORY_DEFAULT,
79
80
  gatewayEnvContract,
80
81
  MCP_AUTH_PROXY_TIMEOUT_SECONDS,
81
82
  mcpAuthProxyEnvContract,
@@ -287,6 +288,9 @@ const runtimeSecretIds: Record<RuntimeSecret, pulumi.Input<string>> = {
287
288
  // then; IAP login, IAP programmatic access and the remote-MCP broker) and
288
289
  // the broker's seal key, both CLI-generated.
289
290
  "operator-oauth-client": gcpSecretId(env, "operator-oauth-client"),
291
+ // #1654 — the visitor AI's key per environment, CLI-generated as `{}`.
292
+ "visitor-ai-key": gcpSecretId(env, "visitor-ai-key"),
293
+ "visitor-ai-staging-key": gcpSecretId(env, "visitor-ai-staging-key"),
290
294
  "mcp-oauth-seal-key": gcpSecretId(env, "mcp-oauth-seal-key"),
291
295
  };
292
296
 
@@ -552,6 +556,28 @@ new gcp.secretmanager.SecretIamMember(
552
556
  opts,
553
557
  );
554
558
 
559
+ // #1654 — the Owner's visitor-AI keys, one secret per environment, the same
560
+ // add-version-only grant: the admin stores or removes a key, never reads
561
+ // one; each gateway reads only its own (stack-contract.ts GCP_COMMON).
562
+ new gcp.secretmanager.SecretIamMember(
563
+ `${namePrefix}-admin-visitor-ai-key-version-adder`,
564
+ {
565
+ secretId: runtimeSecretIds["visitor-ai-key"],
566
+ role: "roles/secretmanager.secretVersionAdder",
567
+ member: pulumi.interpolate`serviceAccount:${runSa.email}`,
568
+ },
569
+ opts,
570
+ );
571
+ new gcp.secretmanager.SecretIamMember(
572
+ `${namePrefix}-admin-visitor-ai-staging-key-version-adder`,
573
+ {
574
+ secretId: runtimeSecretIds["visitor-ai-staging-key"],
575
+ role: "roles/secretmanager.secretVersionAdder",
576
+ member: pulumi.interpolate`serviceAccount:${runSa.email}`,
577
+ },
578
+ opts,
579
+ );
580
+
555
581
  new gcp.storage.BucketIAMMember(
556
582
  `${namePrefix}-media-rw`,
557
583
  {
@@ -861,7 +887,8 @@ const gatewaySvc = deployGateways
861
887
  resourceName: `${namePrefix}-data-gateway`,
862
888
  minInstances: gatewayMinInstances,
863
889
  maxInstances: gatewayMaxInstances,
864
- memory: "512Mi",
890
+ // Epic #1644 — collection index files are cached in memory.
891
+ memory: GATEWAY_MEMORY_DEFAULT,
865
892
  // Firebase Hosting cuts a rewritten request at 60 s anyway.
866
893
  timeout: "300s",
867
894
  // All traffic: the Firebase rewrite arrives from Google's edge, and it is