refactor(relay): group assignment cleanup and diagnostics (#31871)

This commit is contained in:
Neil
2026-10-22 00:21:02 -07:00
committed by GitHub
parent 3d1b8e396e
commit 005060ac7a
14 changed files with 26 additions and 20 deletions
@@ -1,5 +1,5 @@
import { readdirSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import { join, sep } from 'node:path'
import { fileURLToPath } from 'node:url'
import ts from 'typescript-api'
import { afterEach, describe, expect, it } from 'vitest'
@@ -44,7 +44,7 @@ const ACTIVITY_LEASE_READERS: Record<string, string> = {
// One host's rows under lock; each caller is classified in the reserve-mode census.
'assignment-store.ts:lockAssignmentActivities': 'host-lock',
// Metrics and previews: they report, and act on nothing.
'assignment-inventory-snapshot.ts:readAssignmentInventorySnapshot': 'report-only',
'assignment/assignment-inventory-snapshot.ts:readAssignmentInventorySnapshot': 'report-only',
'region-correction-preview.ts:previewRegionalRehomeEligibility': 'report-only',
'registered-migration-inventory.ts:readRegisteredMigrationInventory': 'report-only',
// Step 5's existing-only stranded release, fixed separately in #30609 before the first flip.
@@ -147,7 +147,8 @@ function activityLeaseReaders(): { readers: string[]; bareTableNames: string[] }
const files = readdirSync(directory, { recursive: true, encoding: 'utf8' }).filter(
(file) => file.endsWith('.ts') && !file.includes('.test.') && !file.split(/[\\/]/).includes('test-fixtures')
)
for (const file of files) {
for (const relativeFile of files) {
const file = relativeFile.split(sep).join('/')
const text = readFileSync(join(directory, file), 'utf8')
if (!text.includes(LEASE_TABLE)) continue
const source = ts.createSourceFile(file, text, ts.ScriptTarget.ES2022, true)
+1 -2
View File
@@ -38,7 +38,7 @@ import {
type ResolvedRelayAssignment
} from './assignment-store.js'
import { ASSIGNMENT_LEASE_AUDIENCE, assignmentLeaseKeyId } from './assignment-lease.js'
import { AssignmentRejectionLogWindow } from './assignment-rejection-log-window.js'
import { AssignmentRejectionLogWindow } from './assignment/assignment-rejection-log-window.js'
import { CELL_ADMISSION_STATES } from './cell-admission-selector.js'
import { registerCellSeatFeedRoute } from './cell-seat-feed-route.js'
import { ReservePaceError, type ReserveAssignment, type ReservePlan } from './reserve-assignment.js'
@@ -2375,7 +2375,6 @@ function operationError(error: unknown): string {
return error instanceof Error ? error.message : 'operation_failed'
}
export { relayHostLogDigest }
// `suppressed` is present only on a window-closing line, and counts the rejections
// that line stands for beyond the one already logged when the window opened.
@@ -1,4 +1,4 @@
import { runRelayBackgroundOperation } from './relay-background-operation.js'
import { runRelayBackgroundOperation } from '../relay-background-operation.js'
// The twelve periodic assignment sweeps the director runs every 30s. Each step
// re-derives its state from the database and is idempotent, so they carry no
@@ -3,7 +3,7 @@ import {
formatAssignmentInventorySnapshot,
readAssignmentInventorySnapshot
} from './assignment-inventory-snapshot.js'
import { openInMemoryRelayDatabase } from './database.js'
import { openInMemoryRelayDatabase } from '../database.js'
describe('assignment inventory snapshot', () => {
it('reports per-cell counters, lease backlog, and reservation debt', async () => {
@@ -1,6 +1,6 @@
import { RELAY_DEFAULT_REGION } from '@orca-cloud/relay-contract'
import type { RelayDatabase, SqlRow } from './database.js'
import { REGIONAL_REHOME_ABORT_REPORT_WINDOW_MS } from './regional-rehome-abort-reason.js'
import type { RelayDatabase, SqlRow } from '../database.js'
import { REGIONAL_REHOME_ABORT_REPORT_WINDOW_MS } from '../regional-rehome-abort-reason.js'
export type CellInventorySnapshotRow = {
cellId: string
@@ -1,6 +1,6 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { RelayHomeCellUnavailableError, type RelayAssignment } from './assignment-store.js'
import type { RelayConfig } from './config.js'
import { RelayHomeCellUnavailableError, type RelayAssignment } from '../assignment-store.js'
import type { RelayConfig } from '../config.js'
const fakes = vi.hoisted(() => ({
verifyRelayToken: vi.fn(async (token: string) => ({
@@ -9,12 +9,13 @@ const fakes = vi.hoisted(() => ({
}))
}))
vi.mock('./relay-token-verifier.js', () => ({
vi.mock('../relay-token-verifier.js', () => ({
createRelayTokenVerifier: () => fakes.verifyRelayToken,
readBearer: (value: string | undefined) => value?.replace(/^Bearer /, '') ?? null
}))
import { createRelayApp, relayHostLogDigest } from './app.js'
import { createRelayApp } from '../app.js'
import { relayHostLogDigest } from '../relay-host-log-digest.js'
describe('assignment rejection logging', () => {
afterEach(() => {
@@ -35,8 +35,13 @@ const COMPILER_OPTIONS: ts.CompilerOptions = {
}
function productionFiles(): string[] {
return readdirSync(sourceDirectory)
.filter((entry) => entry.endsWith('.ts') && !entry.endsWith('.test.ts'))
return readdirSync(sourceDirectory, { recursive: true, encoding: 'utf8' })
.filter(
(entry) =>
entry.endsWith('.ts') &&
!entry.endsWith('.test.ts') &&
!entry.split(/[\\/]/).includes('test-fixtures')
)
.map((entry) => join(sourceDirectory, entry))
}
+2 -2
View File
@@ -1,7 +1,7 @@
import {
formatAssignmentInventorySnapshot,
readAssignmentInventorySnapshot
} from './assignment-inventory-snapshot.js'
} from './assignment/assignment-inventory-snapshot.js'
import { readRegionCorrectionOutcomes } from './region-correction-outcomes.js'
import { RelayAssignmentStore } from './assignment-store.js'
import { loadRelayConfig } from './config.js'
@@ -24,7 +24,7 @@ import {
consumeRelayDatabasePoolPressure,
readRelayDatabasePoolPressure
} from './database.js'
import { runAssignmentCleanup } from './assignment-cleanup-steps.js'
import { runAssignmentCleanup } from './assignment/assignment-cleanup-steps.js'
import { runRelayBackgroundOperation } from './relay-background-operation.js'
import { readPostgresLockWaitSample } from './postgres-lock-wait-sample.js'
import { jitteredSweepIntervalMs } from './relay-sweep-schedule.js'
+1 -1
View File
@@ -1,4 +1,4 @@
import { AssignmentRejectionLogWindow } from './assignment-rejection-log-window.js'
import { AssignmentRejectionLogWindow } from './assignment/assignment-rejection-log-window.js'
import { relayHostLogDigest } from './relay-host-log-digest.js'
// Phone-connection anomalies that repeat per dial (a stuck database, a lost ledger write, a
+1 -1
View File
@@ -1,4 +1,4 @@
import { AssignmentRejectionLogWindow } from './assignment-rejection-log-window.js'
import { AssignmentRejectionLogWindow } from './assignment/assignment-rejection-log-window.js'
import { printableCloseReason } from './control-close-reason-text.js'
import { relayHostLogDigest } from './relay-host-log-digest.js'
import type { RelayRuntimeObserver } from './relay-observability.js'
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { readAssignmentInventorySnapshot } from './assignment-inventory-snapshot.js'
import { readAssignmentInventorySnapshot } from './assignment/assignment-inventory-snapshot.js'
import { REGIONAL_REHOME_ARRIVAL_WINDOW_MS } from './regional-rehome-abort-reason.js'
import {
RelayAssignmentStore as BaseRelayAssignmentStore,