@caelo-cms/provisioning 0.12.9 → 0.12.11

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 (123) hide show
  1. package/dist/agent-db.js +76 -3
  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.map +1 -1
  37. package/dist/runtime-secrets.js +3 -0
  38. package/dist/runtime-secrets.js.map +1 -1
  39. package/dist/self-hosted-backup.d.ts.map +1 -1
  40. package/dist/self-hosted-backup.js +18 -6
  41. package/dist/self-hosted-backup.js.map +1 -1
  42. package/dist/stack-contract.d.ts +75 -22
  43. package/dist/stack-contract.d.ts.map +1 -1
  44. package/dist/stack-contract.js +142 -51
  45. package/dist/stack-contract.js.map +1 -1
  46. package/dist/stack-converge.d.ts +20 -1
  47. package/dist/stack-converge.d.ts.map +1 -1
  48. package/dist/stack-converge.js +105 -2
  49. package/dist/stack-converge.js.map +1 -1
  50. package/dist/staging-gateway-setup.d.ts.map +1 -1
  51. package/dist/staging-gateway-setup.js +10 -5
  52. package/dist/staging-gateway-setup.js.map +1 -1
  53. package/dist/upgrade/admin-image-jobs.d.ts +4 -3
  54. package/dist/upgrade/admin-image-jobs.d.ts.map +1 -1
  55. package/dist/upgrade/admin-image-jobs.js +9 -16
  56. package/dist/upgrade/admin-image-jobs.js.map +1 -1
  57. package/dist/upgrade/app-roll.d.ts.map +1 -1
  58. package/dist/upgrade/app-roll.js +8 -7
  59. package/dist/upgrade/app-roll.js.map +1 -1
  60. package/dist/upgrade/converge.d.ts.map +1 -1
  61. package/dist/upgrade/converge.js +78 -50
  62. package/dist/upgrade/converge.js.map +1 -1
  63. package/dist/upgrader-iam-preflight.d.ts.map +1 -1
  64. package/dist/upgrader-iam-preflight.js +8 -18
  65. package/dist/upgrader-iam-preflight.js.map +1 -1
  66. package/dist/upgrader-setup.d.ts.map +1 -1
  67. package/dist/upgrader-setup.js +7 -15
  68. package/dist/upgrader-setup.js.map +1 -1
  69. package/dist/visitor-query-logs.d.ts +40 -0
  70. package/dist/visitor-query-logs.d.ts.map +1 -0
  71. package/dist/visitor-query-logs.js +41 -0
  72. package/dist/visitor-query-logs.js.map +1 -0
  73. package/dist/wizards/gcp-cost.d.ts.map +1 -1
  74. package/dist/wizards/gcp-cost.js +17 -9
  75. package/dist/wizards/gcp-cost.js.map +1 -1
  76. package/dist/wizards/gcp.d.ts.map +1 -1
  77. package/dist/wizards/gcp.js +45 -35
  78. package/dist/wizards/gcp.js.map +1 -1
  79. package/package.json +2 -2
  80. package/src/admin-memory.test.ts +57 -1
  81. package/src/cli.ts +23 -1
  82. package/src/collection-stores.ts +28 -0
  83. package/src/collections-setup.test.ts +237 -0
  84. package/src/collections-setup.ts +317 -0
  85. package/src/compose.ts +54 -1
  86. package/src/gateway-edge.test.ts +28 -0
  87. package/src/gateway-edge.ts +24 -0
  88. package/src/gateway-env-isolation.test.ts +141 -3
  89. package/src/gcp-names.ts +28 -84
  90. package/src/infra-contract.test.ts +5 -3
  91. package/src/infra-contract.ts +35 -1
  92. package/src/remote-mcp.test.ts +13 -1
  93. package/src/reporting-job-catalog.test.ts +156 -0
  94. package/src/reporting-job-catalog.ts +426 -0
  95. package/src/reporting-job-setup.test.ts +119 -6
  96. package/src/reporting-job-setup.ts +51 -158
  97. package/src/runtime-secrets.test.ts +19 -4
  98. package/src/runtime-secrets.ts +3 -0
  99. package/src/self-hosted-backup.test.ts +2 -2
  100. package/src/self-hosted-backup.ts +18 -6
  101. package/src/self-hosted-compose.test.ts +9 -3
  102. package/src/stack-contract.test.ts +62 -4
  103. package/src/stack-contract.ts +172 -59
  104. package/src/stack-converge-secrets.test.ts +4 -0
  105. package/src/stack-converge.test.ts +81 -3
  106. package/src/stack-converge.ts +124 -3
  107. package/src/staging-gateway-setup.test.ts +4 -0
  108. package/src/staging-gateway-setup.ts +16 -6
  109. package/src/upgrade/admin-image-jobs.ts +13 -25
  110. package/src/upgrade/app-roll.ts +7 -6
  111. package/src/upgrade/converge.ts +94 -77
  112. package/src/upgrade/upgrade.test.ts +97 -2
  113. package/src/upgrader-iam-preflight.ts +7 -20
  114. package/src/upgrader-job.test.ts +3 -0
  115. package/src/upgrader-setup.test.ts +3 -0
  116. package/src/upgrader-setup.ts +6 -17
  117. package/src/visitor-query-logs.ts +46 -0
  118. package/src/wizards/gcp-cost.ts +19 -9
  119. package/src/wizards/gcp.ts +51 -45
  120. package/stacks/aws/index.ts +18 -9
  121. package/stacks/azure/index.ts +19 -8
  122. package/stacks/gcp/index.ts +54 -1
  123. package/stacks/gcp-firebase/index.ts +28 -1
@@ -8,8 +8,11 @@
8
8
  * MCP access through IAP, the staging database and its gateway login
9
9
  * (#1329), the gateway logins' Cloud SQL role memberships (#633),
10
10
  * the gateway's and public_role's database logins, the operator-access sync
11
- * job, the quality-audit job (#875), the remote-MCP load-balancer rules and
12
- * identity env (#806), and dropping bindings nothing reads any more.
11
+ * job, the quality-audit job (#875), the reporting jobs (#1359, #1360,
12
+ * #1574, epic #1644's collection index job), the collection stores and the
13
+ * search-query log exclusion (epic #1644), the remote-MCP load-balancer
14
+ * rules and identity env (#806), and dropping bindings nothing reads any
15
+ * more.
13
16
  *
14
17
  * It needs the rights of whoever provisioned the install: `cms-provision
15
18
  * upgrade` runs it as the operator's own identity, and the converge job
@@ -37,27 +40,24 @@ import {
37
40
  liveDatabaseUrls,
38
41
  moveServicesToDnsHost,
39
42
  } from "../cloudsql-tls.js";
43
+ import { COLLECTIONS_LIVE_STORE_ENV, COLLECTIONS_STAGING_STORE_ENV } from "../collection-stores.js";
44
+ import { ensureCollectionStores } from "../collections-setup.js";
40
45
  import { ensureConvergeJob } from "../converge-job-setup.js";
41
46
  import { ensureGatewayArmorRules } from "../gateway-armor.js";
42
47
  import { findSqlInstance, planPublicRoleSwitch } from "../gateway-credentials.js";
43
48
  import type { GcloudRunner, Sleep } from "../gcloud-retry.js";
44
- import {
45
- auditRunnerServiceAccountEmail,
46
- buildCarrierServiceAccountEmail,
47
- importCrawlServiceAccountEmail,
48
- schedulerServiceAccountEmail,
49
- upgraderServiceAccountEmail,
50
- } from "../gcp-names.js";
49
+ import { schedulerServiceAccountEmail, upgraderServiceAccountEmail } from "../gcp-names.js";
51
50
  import type { InstallMetadata } from "../install-state.js";
52
51
  import { ensureMcpIapAccess, type IapResource } from "../mcp-iap.js";
53
52
  import { ensureOperatorAccessSync, resolveOperatorAccessTarget } from "../operator-access.js";
54
53
  import { revokePublicRoleMemberships } from "../public-role-isolation.js";
55
54
  import { ensureRemoteMcpEdge, resolveRemoteMcpIdentity } from "../remote-mcp.js";
56
55
  import {
57
- ensureAuditRunnerJob,
58
- ensureBuildCarrierJob,
59
- ensureImportCrawlJob,
60
- } from "../reporting-job-setup.js";
56
+ REPORTING_JOB_CATALOG,
57
+ type ReportingJobKindEntry,
58
+ reportingJobServiceAccountEmail,
59
+ } from "../reporting-job-catalog.js";
60
+ import { ensureReportingJobKind } from "../reporting-job-setup.js";
61
61
  import {
62
62
  ensureGatewayServiceAccount,
63
63
  ensureGeneratedSecrets,
@@ -70,17 +70,11 @@ import { selfCommand } from "../self-command.js";
70
70
  import {
71
71
  AUDIT_JOB_ENV_VAR,
72
72
  AUDIT_RESULTS_BUCKET_ENV_VAR,
73
- AUDIT_RUNNER_JOB_ENV_VAR,
74
- AUDIT_RUNNER_SERVICE_ACCOUNT_ENV_VAR,
75
- BUILD_CARRIER_JOB_ENV_VAR,
76
- BUILD_CARRIER_SERVICE_ACCOUNT_ENV_VAR,
77
73
  CAPTURE_BUCKET_ENV_VAR,
78
74
  CAPTURE_JOB_ENV_VAR,
79
75
  type CloudRunEnvVar,
80
76
  CONVERGE_JOB_ENV_VAR,
81
77
  DATABASE_URL_VARS,
82
- IMPORT_CRAWL_JOB_ENV_VAR,
83
- IMPORT_CRAWL_SERVICE_ACCOUNT_ENV_VAR,
84
78
  MCP_ENV_VAR,
85
79
  OPERATOR_ACCESS_JOB_ENV_VAR,
86
80
  parseSchedulerIntervalMinutes,
@@ -402,24 +396,23 @@ export function startConverge(
402
396
  }
403
397
 
404
398
  /**
405
- * Reporting jobs (#1359, #1360) set up this run, or whose account exists
406
- * from an earlier one: the operator-access sync keeps them on IAP.
399
+ * Reporting jobs (reporting-job-catalog.ts) set up this run, or whose
400
+ * account exists from an earlier one: the operator-access sync keeps them
401
+ * on IAP.
407
402
  */
408
403
  const reportingJobsOnIap: string[] = [];
409
404
 
410
- async function reportingJob(job: {
411
- readonly step: string;
412
- readonly ready: string;
413
- readonly label: string;
414
- readonly consequence: string;
415
- readonly ensure: typeof ensureAuditRunnerJob;
416
- readonly serviceAccount: string;
417
- readonly envVars: readonly string[];
418
- }): Promise<void> {
405
+ async function reportingJob(entry: ReportingJobKindEntry): Promise<void> {
419
406
  // A job that reports back to the admin through IAP
420
407
  // (reporting-job-setup.ts), deployed with the admin's CURRENT image like
421
408
  // the audit job: the app-roll moves them onto the new one. A failure
422
409
  // costs the work it runs, so it warns and the admin keeps its env.
410
+ const job = {
411
+ ...entry.converge,
412
+ label: `${entry.label.charAt(0).toUpperCase()}${entry.label.slice(1)}`,
413
+ serviceAccount: reportingJobServiceAccountEmail(entry, install.projectId, install.env),
414
+ envVars: [entry.jobEnvVar, entry.serviceAccountEnvVar],
415
+ };
423
416
  const s = r.step(job.step);
424
417
  const image = await resolveAdminImage(
425
418
  { projectId: install.projectId, region: install.region, env: install.env },
@@ -430,7 +423,8 @@ export function startConverge(
430
423
  ? { ok: false as const, done: [], error: image.error }
431
424
  : !resource
432
425
  ? { ok: false as const, done: [], error: "the admin's IAP resource was not found" }
433
- : await job.ensure(
426
+ : await ensureReportingJobKind(
427
+ entry,
434
428
  {
435
429
  provider: install.provider,
436
430
  projectId: install.projectId,
@@ -451,63 +445,87 @@ export function startConverge(
451
445
  r.warn(
452
446
  `The upgrade continues; ${job.consequence} until this succeeds. Re-run upgrade once the cause is fixed.`,
453
447
  );
454
- // An account set up by an earlier run keeps its IAP access, or the next
455
- // operator-access sync would cut off a job that still works.
448
+ await keepOnIapIfExists(job.serviceAccount);
449
+ incomplete = true;
450
+ leaveUntouched.push(...job.envVars);
451
+ }
452
+
453
+ /**
454
+ * An account set up by an earlier run keeps its IAP access, or the next
455
+ * operator-access sync would cut off a job that still works.
456
+ */
457
+ async function keepOnIapIfExists(serviceAccount: string): Promise<void> {
456
458
  const exists = await run([
457
459
  "iam",
458
460
  "service-accounts",
459
461
  "describe",
460
- job.serviceAccount,
462
+ serviceAccount,
461
463
  `--project=${install.projectId}`,
462
464
  "--format=value(email)",
463
465
  ]);
464
- if (exists.ok) reportingJobsOnIap.push(job.serviceAccount);
465
- incomplete = true;
466
- leaveUntouched.push(...job.envVars);
466
+ if (exists.ok) reportingJobsOnIap.push(serviceAccount);
467
467
  }
468
468
 
469
469
  /**
470
- * #1359 — the job a Stage's whole quality audit runs in. After the audit
471
- * job, on whose Lighthouse tasks it gets its run grant.
470
+ * Epic #1644 — the collection stores (collections-setup.ts) and the log
471
+ * exclusion for visitors' search queries. A failure costs plugin
472
+ * collections (a site search) only: it warns, and the admin and the
473
+ * gateways keep their env without the stores.
472
474
  */
473
- const auditRunnerJob = () =>
474
- reportingJob({
475
- step: "Ensuring the quality-audit runner (audits outside the admin)...",
476
- ready: "Quality-audit runner ready (Stage audits run in their own job)",
477
- label: "Quality-audit runner",
478
- consequence: "Stage audits fail after their last attempt",
479
- ensure: ensureAuditRunnerJob,
480
- serviceAccount: auditRunnerServiceAccountEmail(install.projectId, install.env),
481
- envVars: [AUDIT_RUNNER_JOB_ENV_VAR, AUDIT_RUNNER_SERVICE_ACCOUNT_ENV_VAR],
482
- });
483
-
484
- /** #1360 — the job a site import's crawl runs in. */
485
- const importCrawlJob = () =>
486
- reportingJob({
487
- step: "Ensuring the site-import crawler (crawls outside the admin)...",
488
- ready: "Site-import crawler ready (site imports crawl in their own job)",
489
- label: "Site-import crawler",
490
- consequence: "site imports fail after their last attempt",
491
- ensure: ensureImportCrawlJob,
492
- serviceAccount: importCrawlServiceAccountEmail(install.projectId, install.env),
493
- envVars: [IMPORT_CRAWL_JOB_ENV_VAR, IMPORT_CRAWL_SERVICE_ACCOUNT_ENV_VAR],
494
- });
475
+ let collectionStoresReady = false;
476
+ async function collectionStores(): Promise<void> {
477
+ const s = r.step(
478
+ "Ensuring the collection stores (plugin indexes such as site search) and the search-query log exclusion...",
479
+ );
480
+ const cs = await ensureCollectionStores(
481
+ {
482
+ provider: install.provider,
483
+ projectId: install.projectId,
484
+ region: install.region,
485
+ env: install.env,
486
+ },
487
+ runDeps,
488
+ );
489
+ for (const step of cs.done) r.info(` ${step}`);
490
+ if (cs.ok) {
491
+ collectionStoresReady = true;
492
+ for (const p of cs.pending) r.warn(` not yet: ${p}`);
493
+ if (cs.pending.length > 0) incomplete = true;
494
+ s.done("Collection stores ready (each gateway reads only its own index)");
495
+ return;
496
+ }
497
+ s.warned(`Collection stores not set up: ${cs.error}`);
498
+ r.warn(
499
+ "The upgrade continues; plugin collections (a site search) fail at every Stage until this succeeds. Re-run upgrade once the cause is fixed.",
500
+ );
501
+ incomplete = true;
502
+ // And the env of every job that works on the stores, which is not set up.
503
+ leaveUntouched.push(
504
+ COLLECTIONS_STAGING_STORE_ENV,
505
+ COLLECTIONS_LIVE_STORE_ENV,
506
+ ...REPORTING_JOB_CATALOG.filter((e) => e.prerequisite === "collection-stores").flatMap(
507
+ (e) => [e.jobEnvVar, e.serviceAccountEnvVar],
508
+ ),
509
+ );
510
+ }
495
511
 
496
512
  /**
497
- * #1574 — the job that holds the request a Stage, Publish live or
498
- * production build nobody else waits for runs in.
513
+ * Every reporting job of the catalog, in its order: each after what it
514
+ * needs (the audit runner after the audit job whose Lighthouse tasks it
515
+ * starts; the collection index job after the stores it writes, and not
516
+ * at all without them: its env stays untouched, collectionStores said so).
499
517
  */
500
- const buildCarrierJob = () =>
501
- reportingJob({
502
- step: "Ensuring the build carrier (builds that outlast their request)...",
503
- ready: "Build carrier ready (a build nobody waits for still ends)",
504
- label: "Build carrier",
505
- consequence:
506
- "an agent's Stage and every Stage or Publish live button fail at once with this reason",
507
- ensure: ensureBuildCarrierJob,
508
- serviceAccount: buildCarrierServiceAccountEmail(install.projectId, install.env),
509
- envVars: [BUILD_CARRIER_JOB_ENV_VAR, BUILD_CARRIER_SERVICE_ACCOUNT_ENV_VAR],
510
- });
518
+ async function reportingJobs(): Promise<void> {
519
+ for (const entry of REPORTING_JOB_CATALOG) {
520
+ if (entry.prerequisite === "collection-stores" && !collectionStoresReady) {
521
+ await keepOnIapIfExists(
522
+ reportingJobServiceAccountEmail(entry, install.projectId, install.env),
523
+ );
524
+ continue;
525
+ }
526
+ await reportingJob(entry);
527
+ }
528
+ }
511
529
 
512
530
  async function captureJob(): Promise<void> {
513
531
  // #1217 — the job every server-side browser render runs in, so no
@@ -1024,9 +1042,8 @@ export function startConverge(
1024
1042
  await mcpAccess();
1025
1043
  await urlMapRedirectsAccess();
1026
1044
  await auditJob();
1027
- await auditRunnerJob();
1028
- await importCrawlJob();
1029
- await buildCarrierJob();
1045
+ await collectionStores();
1046
+ await reportingJobs();
1030
1047
  await captureJob();
1031
1048
  await remoteMcpEdge();
1032
1049
  await gatewayArmor();
@@ -340,10 +340,11 @@ const ANY_WRITE =
340
340
  /**
341
341
  * #1328 — the only writes allowed before the backup: the MCP-Auth-Proxy's
342
342
  * account, its secretAccessor on its two secrets, and the services an older
343
- * install lacks (mcp-auth-proxy-setup.ts). Additive; nothing serves on them.
343
+ * install lacks (mcp-auth-proxy-setup.ts), with (#1654) the staging
344
+ * gateway's read of its own visitor-AI key. Additive; nothing serves on them.
344
345
  */
345
346
  const PRE_PLAN_WRITE =
346
- /^(iam service-accounts create caelo-production-(mcp-proxy-sa|stg-gw-sa) |secrets add-iam-policy-binding caelo-production-(mcp-oauth-seal-key|operator-oauth-client) .*--member=serviceAccount:caelo-production-mcp-proxy-sa@|secrets add-iam-policy-binding caelo-production-public-staging-role-password .*--member=serviceAccount:caelo-production-stg-gw-sa@|storage buckets (create|add-iam-policy-binding) gs:\/\/acme-caelo-production-staging |run services replace |run deploy caelo-production-(mcp-auth-proxy|staging-gateway) |run services add-iam-policy-binding caelo-production-staging-gateway .*--member=allUsers )/;
347
+ /^(iam service-accounts create caelo-production-(mcp-proxy-sa|stg-gw-sa) |secrets add-iam-policy-binding caelo-production-(mcp-oauth-seal-key|operator-oauth-client) .*--member=serviceAccount:caelo-production-mcp-proxy-sa@|secrets add-iam-policy-binding caelo-production-(public-staging-role-password|visitor-ai-staging-key) .*--member=serviceAccount:caelo-production-stg-gw-sa@|storage buckets (create|add-iam-policy-binding) gs:\/\/acme-caelo-production-staging |run services replace |run deploy caelo-production-(mcp-auth-proxy|staging-gateway) |run services add-iam-policy-binding caelo-production-staging-gateway .*--member=allUsers )/;
347
348
 
348
349
  const indexOf = (events: string[], pattern: RegExp): number => {
349
350
  const i = events.findIndex((e) => pattern.test(e));
@@ -595,6 +596,100 @@ describe("upgradeGcpInstall — converge, then app-roll", () => {
595
596
  ).toBe(false);
596
597
  });
597
598
 
599
+ it("epic #1644 — creates the collection stores, then the index job that writes the staging one, keeps it on IAP, tells the admin and both gateways", async () => {
600
+ const events: string[] = [];
601
+ const { deps, lines } = upgradeDeps(events, {
602
+ overrides: [
603
+ [/^storage buckets describe gs:\/\/acme-caelo-production-coll-/, fail("NOT_FOUND: 404")],
604
+ ],
605
+ });
606
+ expect(await upgradeGcpInstall(TARGET, deps)).toBe(true);
607
+ const index = "caelo-production-index@acme.iam.gserviceaccount.com";
608
+ const created = indexOf(
609
+ events,
610
+ /^gcloud storage buckets create gs:\/\/acme-caelo-production-coll-staging /,
611
+ );
612
+ const exclusion = indexOf(
613
+ events,
614
+ /^gcloud logging sinks update _Default .*--add-exclusion=\^;\^name=caelo-production-visitor-queries;/,
615
+ );
616
+ const write = indexOf(
617
+ events,
618
+ new RegExp(
619
+ `^gcloud storage buckets add-iam-policy-binding gs://acme-caelo-production-coll-staging --member=serviceAccount:${index} --role=roles/storage\\.objectCreator`,
620
+ ),
621
+ );
622
+ const deploy = indexOf(events, /^gcloud run jobs deploy caelo-production-index /);
623
+ const opAccess = indexOf(
624
+ events,
625
+ /^gcloud run jobs deploy caelo-production-operator-access-sync /,
626
+ );
627
+ const adminRoll = indexOf(events, new RegExp(`^gcloud run services update ${ADMIN} `));
628
+ const gatewayRoll = indexOf(events, new RegExp(`^gcloud run services update ${GATEWAY} `));
629
+ const move = indexOf(events, /^gcloud run jobs update caelo-production-index /);
630
+ expect(created < exclusion && exclusion < write && write < deploy).toBe(true);
631
+ expect(deploy < opAccess && opAccess < adminRoll && adminRoll < move).toBe(true);
632
+ expect(events[opAccess]).toContain(index);
633
+ expect(events[adminRoll]).toContain(
634
+ "CAELO_COLLECTION_INDEX_JOB=projects/acme/locations/europe-west1/jobs/caelo-production-index",
635
+ );
636
+ expect(events[adminRoll]).toContain(
637
+ "CAELO_COLLECTIONS_STAGING_STORE=gs://acme-caelo-production-coll-staging",
638
+ );
639
+ expect(events[adminRoll]).toContain(
640
+ "CAELO_COLLECTIONS_LIVE_STORE=gs://acme-caelo-production-coll-live",
641
+ );
642
+ // The live gateway learns the live store and nothing of staging.
643
+ expect(events[gatewayRoll]).toContain(
644
+ "CAELO_COLLECTIONS_LIVE_STORE=gs://acme-caelo-production-coll-live",
645
+ );
646
+ expect(events[gatewayRoll]).not.toContain("coll-staging");
647
+ // #1646 — and the plugin batch job, which holds the shared line only.
648
+ const batch = "caelo-production-plugin-batch@acme.iam.gserviceaccount.com";
649
+ expect(
650
+ indexOf(events, /^gcloud run jobs deploy caelo-production-plugin-batch /),
651
+ ).toBeGreaterThan(-1);
652
+ expect(
653
+ events.some(
654
+ (e) =>
655
+ e.includes(`--member=serviceAccount:${batch}`) &&
656
+ /(run jobs|storage buckets) add-iam-policy-binding/.test(e),
657
+ ),
658
+ ).toBe(false);
659
+ expect(events[opAccess]).toContain(batch);
660
+ expect(events[adminRoll]).toContain(`CAELO_PLUGIN_BATCH_SERVICE_ACCOUNT=${batch}`);
661
+ expect(lines).toContain(
662
+ "done: Collection stores ready (each gateway reads only its own index)",
663
+ );
664
+ expect(lines).toContain(
665
+ "done: Collection index job ready (a Stage's plugin indexes build in their own job)",
666
+ );
667
+ });
668
+
669
+ it("epic #1644 — failed collection stores skip the index job and leave every collection env untouched", async () => {
670
+ const events: string[] = [];
671
+ const { deps, recorded, lines } = upgradeDeps(events, {
672
+ overrides: [
673
+ [/^storage buckets describe gs:\/\/acme-caelo-production-coll-/, fail("NOT_FOUND: 404")],
674
+ [
675
+ /^storage buckets create gs:\/\/acme-caelo-production-coll-staging/,
676
+ fail("PERMISSION_DENIED"),
677
+ ],
678
+ ],
679
+ });
680
+ expect(await upgradeGcpInstall(TARGET, deps)).toBe(true);
681
+ expect(recorded.contract).toEqual([]);
682
+ expect(lines.some((l) => l.includes("Collection stores not set up"))).toBe(true);
683
+ expect(events.some((e) => e.startsWith("gcloud run jobs deploy caelo-production-index "))).toBe(
684
+ false,
685
+ );
686
+ expect(events.some((e) => /services update .*CAELO_COLLECTION/.test(e))).toBe(false);
687
+ // The other reporting jobs are untouched by it.
688
+ expect(
689
+ events.some((e) => e.startsWith("gcloud run jobs deploy caelo-production-plugin-batch ")),
690
+ ).toBe(true);
691
+ });
692
+
598
693
  it("sets up the capture job on the CURRENT admin image before the roll, then moves it with the admin (#1217)", async () => {
599
694
  const events: string[] = [];
600
695
  const { deps, lines } = upgradeDeps(events);
@@ -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)",