mirror of
https://github.com/stablyai/orca.git
synced 2026-09-29 16:02:50 +00:00
Copies the private repository's relay side: the IAM-only fence broker, the operations console and incident monitor, the relay Terraform root with its backend configuration and tfvars, and the deploy/capacity/admission/rehome/ monitoring scripts the workflows call, with their contract tests, contracts, and fixtures. The foundation and apps Terraform roots and the API and auth services stay private. Four surfaces that spanned both trees are narrowed to the relay side rather than left with a dangling read: the infra runner and the root-partition and workload-identity-condition renderers now declare only the relay root, and the Cloud SQL rollout census drops the six app workflows that are not here.
34 lines
1.6 KiB
JavaScript
34 lines
1.6 KiB
JavaScript
import { spawnSync } from 'node:child_process'
|
|
|
|
function accessToken() {
|
|
const result = spawnSync('gcloud', ['auth', 'print-access-token'], {
|
|
encoding: 'utf8', timeout: 30_000
|
|
})
|
|
const token = result.stdout.trim()
|
|
if (result.status !== 0 || token.length < 20) {
|
|
throw new Error('Google access token is unavailable')
|
|
}
|
|
return token
|
|
}
|
|
|
|
export async function readCloudSqlBackends(environment, startedAt, endedAt) {
|
|
const production = environment === 'production'
|
|
if (!production && environment !== 'staging') throw new Error('Cloud SQL environment is invalid')
|
|
const project = production ? 'onorca-cloud' : 'onorca-cloud-staging'
|
|
const instance = production ? 'orca-cloud-auth-db' : 'orca-cloud-staging-auth-db'
|
|
const url = new URL(`https://monitoring.googleapis.com/v3/projects/${project}/timeSeries`)
|
|
url.searchParams.set('filter', `metric.type = "cloudsql.googleapis.com/database/postgresql/num_backends" AND resource.labels.database_id = "${project}:${instance}"`)
|
|
url.searchParams.set('interval.startTime', startedAt)
|
|
url.searchParams.set('interval.endTime', endedAt)
|
|
url.searchParams.set('aggregation.alignmentPeriod', '60s')
|
|
url.searchParams.set('aggregation.perSeriesAligner', 'ALIGN_MAX')
|
|
url.searchParams.set('aggregation.crossSeriesReducer', 'REDUCE_MAX')
|
|
url.searchParams.set('view', 'FULL')
|
|
const response = await fetch(url, {
|
|
headers: { authorization: `Bearer ${accessToken()}` },
|
|
redirect: 'error', signal: AbortSignal.timeout(30_000)
|
|
})
|
|
if (!response.ok) throw new Error(`Cloud SQL metric query returned ${response.status}`)
|
|
return await response.json()
|
|
}
|