Files
floci-ui/packages/api/src/service/runtimeProbe.ts
T
Zakaria 91ce11274d
CI / checks (pull_request) Successful in 25m47s
chore: show TheCloud instead of Floci in console text and messages
Labels, empty states, error messages and defaults the console shows now name
TheCloud or its runtimes. Identifiers that must match the emulator (FLOCI_*
settings, the X-Floci-CSRF header, emulator-returned host names) are unchanged.
2026-10-24 14:30:44 -04:00

48 lines
1.8 KiB
TypeScript

import {RuntimeUnavailableError} from '../cloud-spi/errors'
import type {CloudProvider} from '../cloud-spi/types'
import {azure, azureEndpoint} from '../azure'
import {gcp, gcpEndpoint} from '../gcp'
/**
* Liveness probes per runtime.
*
* Cloud status used to be inferred from whether the *storage* adapter could list,
* which meant a cloud whose storage worked reported "reachable" no matter what
* else was broken, and a cloud with no storage adapter reported "coming_soon"
* even when its runtime was up. These probe the runtime itself.
*/
export type RuntimeProbe = () => Promise<void>
export const runtimeProbes: Record<CloudProvider, RuntimeProbe> = {
// Every runtime exposes a health endpoint, but under its own path: core and
// Floci-AZ use /_floci/health, Floci-GCP uses /_floci-gcp/health.
aws: () => probeHttp(`${awsEndpoint()}/_floci/health`, 'TheCloud AWS runtime'),
azure: async () => {
await azure.fetch('/_floci/health', {method: 'GET'})
},
gcp: () => gcp.health(),
}
export function endpointFor(cloud: CloudProvider): string | null {
if (cloud === 'aws') return awsEndpoint()
if (cloud === 'azure') return azureEndpoint()
if (cloud === 'gcp') return gcpEndpoint()
return null
}
export function awsEndpoint(): string {
return process.env.FLOCI_ENDPOINT ?? 'http://localhost:4566'
}
async function probeHttp(endpoint: string, label: string): Promise<void> {
let res: Response
try {
res = await globalThis.fetch(endpoint, {method: 'GET'})
} catch (error) {
throw new RuntimeUnavailableError(`Cannot reach ${label} at ${endpoint}`, {cause: error})
}
if (res.status >= 500) {
throw new RuntimeUnavailableError(`${label} at ${endpoint} returned HTTP ${res.status}`)
}
}