mirror of
https://github.com/stablyai/orca.git
synced 2026-10-03 00:02:19 +00:00
* feat(relay): declare US cells c32 and c33 at the 3,000-host shape Declares two us-central1 cells at the Asia shape (cap 3000, 6000 request units, e2-standard-4) with the US default pool of 10, and generalises the Asia topology and admission ladder to derive each wave's region from its reviewed zone, leaving every Asia wave's behaviour unchanged. Claude-Session: ced32ebb-7155-4413-adad-1eccd14c2010 * docs(relay): note the US canary tie-break and leave the fleet pool list to promotion Claude-Session: ced32ebb-7155-4413-adad-1eccd14c2010 * fix(relay): plan C32 and C33 as one topology wave The live-image overlay refuses a declared non-target cell with no template, so a lone C32 plan would fail on C33. Registration and promotion stay one cell at a time. Claude-Session: ced32ebb-7155-4413-adad-1eccd14c2010
174 lines
6.0 KiB
JavaScript
174 lines
6.0 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import { readFileSync } from 'node:fs'
|
|
import test from 'node:test'
|
|
import {
|
|
calculateRelayCloudSqlConnectionBudget,
|
|
readRelayCloudSqlConnectionBudget
|
|
} from './relay-cloud-sql-connection-budget.mjs'
|
|
|
|
test('production shared consumers keep allowance and reserve below the ceiling', () => {
|
|
// cells: 22 pools at 10 (220, C32/C33 included) + the five asia-east2 pools at 16 (80).
|
|
const report = readRelayCloudSqlConnectionBudget()
|
|
|
|
assert.deepEqual(report.consumers, { cells: 300, directors: 15, auth: 20, api: 50 })
|
|
assert.deepEqual(report.asia, { cells: 5, poolMax: 16 })
|
|
assert.equal(report.configuredMaximum, 385)
|
|
assert.equal(report.rolloutOverlap.relayDirectorCandidate, 30)
|
|
assert.equal(report.rolloutOverlap.apiCandidate, 65)
|
|
assert.equal(report.rolloutOverlap.authCandidate, 35)
|
|
assert.equal(report.rolloutOverlap.relayCells, 15)
|
|
assert.equal(report.rolloutOverlap.retainedDirectorRollback, 15)
|
|
assert.equal(report.rolloutOverlap.maximum, 65)
|
|
assert.equal(report.maintenanceAdminAllowance, 5)
|
|
assert.equal(report.explicitReserve, 10)
|
|
assert.equal(report.usableCeiling, 490)
|
|
assert.equal(report.operatingMaximum, 455)
|
|
assert.equal(report.remainingWithinUsableCeiling, 35)
|
|
assert.equal(report.budgetedTotal, 465)
|
|
assert.equal(report.unallocated, 35)
|
|
assert.equal(report.withinBudget, true)
|
|
})
|
|
|
|
test('fails closed when pool growth consumes the explicit reserve', () => {
|
|
const report = calculateRelayCloudSqlConnectionBudget({
|
|
cellPoolTotal: 200,
|
|
asiaCellCount: 3,
|
|
asiaPoolMax: 20,
|
|
directorInstances: 5,
|
|
directorPoolMax: 3,
|
|
authInstances: 2,
|
|
authPoolMax: 10,
|
|
apiInstances: 20,
|
|
apiPoolMax: 5,
|
|
maxConnections: 400,
|
|
maintenanceAdminAllowance: 5,
|
|
explicitReserve: 10
|
|
})
|
|
|
|
assert.equal(report.operatingMaximum, 515)
|
|
assert.equal(report.withinBudget, false)
|
|
})
|
|
|
|
test('excludes fenced cell pools and reads per-cell pool overrides', () => {
|
|
const report = readRelayCloudSqlConnectionBudget({
|
|
proposedAsiaCellCount: 1,
|
|
appConsumers: { authInstances: 1, authPoolMax: 10, apiInstances: 1, apiPoolMax: 5, maxConnections: 100 },
|
|
sources: {
|
|
productionTfvars: `
|
|
relay_max_instances = 1
|
|
relay_gce_fenced_cells = ["production-gce-c1"]
|
|
relay_gce_cells = {
|
|
"production-gce-c1" = { database_pool_max = 99
|
|
}
|
|
"production-gce-c2" = { database_pool_max = 4
|
|
}
|
|
}
|
|
`,
|
|
terraformVariables: [
|
|
'variable "relay_director_database_pool_max" { default = 3 }',
|
|
'variable "push_max_instances" { default = 1 }',
|
|
'variable "push_database_pool_max" { default = 2 }'
|
|
].join('\n'),
|
|
relayConfig: 'export const RELAY_DATABASE_POOL_MAX = 10'
|
|
},
|
|
maxConnections: 100,
|
|
maintenanceAdminAllowance: 1,
|
|
explicitReserve: 1
|
|
})
|
|
|
|
assert.equal(report.consumers.cells, 14)
|
|
assert.equal(report.operatingMaximum, 46)
|
|
assert.equal(report.budgetedTotal, 47)
|
|
})
|
|
|
|
test('refuses an Asia cell whose pool differs from its siblings', () => {
|
|
const budget = (c30PoolMax) => readRelayCloudSqlConnectionBudget({
|
|
appConsumers: { authInstances: 1, authPoolMax: 10, apiInstances: 1, apiPoolMax: 5, maxConnections: 500 },
|
|
sources: {
|
|
productionTfvars: `
|
|
relay_max_instances = 1
|
|
relay_gce_fenced_cells = []
|
|
relay_gce_cells = {
|
|
${['c27', 'c28', 'c29', 'c30'].map((hostname) => ` "production-gce-${hostname}" = {
|
|
region = "asia-east2"
|
|
database_pool_max = ${hostname === 'c30' ? c30PoolMax : 16}
|
|
}`).join('\n')}
|
|
}
|
|
`,
|
|
terraformVariables: [
|
|
'variable "relay_director_database_pool_max" { default = 3 }',
|
|
'variable "push_max_instances" { default = 1 }',
|
|
'variable "push_database_pool_max" { default = 2 }'
|
|
].join('\n'),
|
|
relayConfig: 'export const RELAY_DATABASE_POOL_MAX = 10'
|
|
},
|
|
maxConnections: 500
|
|
})
|
|
assert.deepEqual(budget(16).asia, { cells: 4, poolMax: 16 })
|
|
assert.throws(() => budget(10), /Asia Relay cells must use one checked pool maximum/)
|
|
})
|
|
|
|
test('dedicated push scaling does not consume shared capacity', () => {
|
|
const report = readRelayCloudSqlConnectionBudget({
|
|
proposedAsiaCellCount: 1,
|
|
appConsumers: { authInstances: 1, authPoolMax: 10, apiInstances: 1, apiPoolMax: 5, maxConnections: 100 },
|
|
sources: {
|
|
productionTfvars: `
|
|
relay_max_instances = 1
|
|
push_max_instances = 3
|
|
relay_gce_fenced_cells = []
|
|
relay_gce_cells = {
|
|
"production-gce-c2" = { database_pool_max = 4
|
|
}
|
|
}
|
|
`,
|
|
terraformVariables: [
|
|
'variable "relay_director_database_pool_max" { default = 3 }',
|
|
'variable "push_max_instances" { default = 1 }',
|
|
'variable "push_database_pool_max" { default = 2 }'
|
|
].join('\n'),
|
|
relayConfig: 'export const RELAY_DATABASE_POOL_MAX = 10'
|
|
},
|
|
maxConnections: 100,
|
|
maintenanceAdminAllowance: 1,
|
|
explicitReserve: 1
|
|
})
|
|
|
|
assert.equal(report.consumers.push, undefined)
|
|
assert.equal(report.rolloutOverlap.pushCandidate, undefined)
|
|
assert.equal(report.operatingMaximum, 46)
|
|
})
|
|
|
|
test('requires strict headroom below the physical ceiling', () => {
|
|
const report = calculateRelayCloudSqlConnectionBudget({
|
|
cellPoolTotal: 20,
|
|
asiaCellCount: 0,
|
|
asiaPoolMax: 10,
|
|
directorInstances: 1,
|
|
directorPoolMax: 3,
|
|
authInstances: 1,
|
|
authPoolMax: 10,
|
|
apiInstances: 1,
|
|
apiPoolMax: 5,
|
|
maxConnections: 50,
|
|
maintenanceAdminAllowance: 9,
|
|
explicitReserve: 3
|
|
})
|
|
|
|
assert.equal(report.budgetedTotal, 63)
|
|
assert.equal(report.withinBudget, false)
|
|
})
|
|
|
|
test('pages Relay channels when Cloud SQL backends consume headroom', () => {
|
|
const terraform = readFileSync(
|
|
new URL('../../infra/terraform/relay-observability.tf', import.meta.url),
|
|
'utf8'
|
|
)
|
|
const policy = terraform.match(
|
|
/resource "google_monitoring_alert_policy" "relay_cloud_sql_backends" \{([\s\S]*?)\n\}/
|
|
)?.[1]
|
|
|
|
assert.ok(policy)
|
|
assert.match(policy, /notification_channels\s*=\s*var\.relay_alert_notification_channels/)
|
|
})
|