9cb3dcb07c
Adds the `ComputeWorkloadManager` for routing task execution through the compute gateway, including full checkpoint/restore support, OTel trace integration, and template pre-warming. ## Changes **Compute workload manager** (`apps/supervisor/src/workloadManager/compute.ts`) - Routes instance create, snapshot, delete, and restore through the compute gateway API - Wide event logging on create with full timing and context - Configurable gateway timeout, auth token, image digest stripping **Compute snapshot service** (`apps/supervisor/src/services/computeSnapshotService.ts`) - Timer wheel for delayed snapshot dispatch (avoids wasted work on short-lived waitpoints) - Configurable dispatch concurrency limit (`COMPUTE_SNAPSHOT_DISPATCH_LIMIT`) - Snapshot-complete callback handler with suspend completion reporting - Trace context management and OTel span emission for snapshot operations **OTel trace service** (`apps/supervisor/src/services/otlpTraceService.ts`) - Fire-and-forget OTLP span emission for compute operations (provision, restore, snapshot) - BigInt nanosecond conversion preserving sub-ms precision for span ordering **Template creation** (`apps/webapp/app/v3/services/computeTemplateCreation.server.ts`) - Three-mode rollout: required (MICROVM projects), shadow (feature flag / percentage), skip - Integrated into deploy finalize flow **Shared compute package** (`internal-packages/compute/`) - Gateway client with namespace-based API (instances, templates, snapshots) - Zod schemas for all gateway request/response types **Database** - `COMPUTE` variant added to `TaskRunCheckpointType` enum - `WorkloadType` enum and column on `WorkerInstanceGroup` - `hasComputeAccess` feature flag **Env / config** - Compute gateway URL, auth token, timeout - Snapshot enable flag, delay, dispatch limit - Dedicated OTLP endpoint for compute spans (`COMPUTE_TRACE_OTLP_ENDPOINT`)
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { isMacOS, isWindows } from "std-env";
|
|
|
|
export function normalizeDockerHostUrl(url: string) {
|
|
const $url = new URL(url);
|
|
|
|
if ($url.hostname === "localhost") {
|
|
$url.hostname = getDockerHostDomain();
|
|
}
|
|
|
|
return $url.toString();
|
|
}
|
|
|
|
export function getDockerHostDomain() {
|
|
return isMacOS || isWindows ? "host.docker.internal" : "localhost";
|
|
}
|
|
|
|
/** Extract the W3C traceparent string from an untyped trace context record */
|
|
export function extractTraceparent(traceContext?: Record<string, unknown>): string | undefined {
|
|
if (
|
|
traceContext &&
|
|
"traceparent" in traceContext &&
|
|
typeof traceContext.traceparent === "string"
|
|
) {
|
|
return traceContext.traceparent;
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
export function getRunnerId(runId: string, attemptNumber?: number) {
|
|
const parts = ["runner", runId.replace("run_", "")];
|
|
|
|
if (attemptNumber && attemptNumber > 1) {
|
|
parts.push(`attempt-${attemptNumber}`);
|
|
}
|
|
|
|
return parts.join("-");
|
|
}
|
|
|
|
/** Derive a unique runnerId for a restore cycle using the checkpoint suffix */
|
|
export function getRestoreRunnerId(runFriendlyId: string, checkpointId: string) {
|
|
const runIdShort = runFriendlyId.replace("run_", "");
|
|
const checkpointSuffix = checkpointId.slice(-8);
|
|
return `runner-${runIdShort}-${checkpointSuffix}`;
|
|
}
|