fix ssh tcp pool transient diagnostics
This commit is contained in:
@@ -130,6 +130,75 @@ export async function debugHealth(config: UniDeskConfig): Promise<unknown> {
|
||||
};
|
||||
}
|
||||
|
||||
function recordValue(value: unknown): Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value) ? value as Record<string, unknown> : {};
|
||||
}
|
||||
|
||||
function arrayValue(value: unknown): unknown[] {
|
||||
return Array.isArray(value) ? value : [];
|
||||
}
|
||||
|
||||
function stringValue(value: unknown): string | null {
|
||||
return typeof value === "string" ? value : null;
|
||||
}
|
||||
|
||||
export async function debugSshPool(_config: UniDeskConfig, providerId: string): Promise<unknown> {
|
||||
const nodesResponse = await coreInternalFetch("/api/nodes");
|
||||
const body = recordValue(recordValue(nodesResponse).body);
|
||||
const nodes = arrayValue(body.nodes);
|
||||
const node = nodes
|
||||
.map((item) => recordValue(item))
|
||||
.find((item) => item.providerId === providerId) ?? null;
|
||||
if (node === null) {
|
||||
return {
|
||||
ok: false,
|
||||
providerId,
|
||||
degradedReason: "provider-not-found",
|
||||
nodesFetch: nodesResponse,
|
||||
next: { fullHealth: "bun scripts/cli.ts debug health" },
|
||||
};
|
||||
}
|
||||
const labels = recordValue(node.labels);
|
||||
const pool = {
|
||||
transport: stringValue(labels.providerGatewaySshDataTransport),
|
||||
host: stringValue(labels.providerGatewaySshDataHost),
|
||||
port: labels.providerGatewaySshDataPort ?? null,
|
||||
desired: labels.providerGatewaySshDataPoolDesired ?? null,
|
||||
total: labels.providerGatewaySshDataPoolTotal ?? null,
|
||||
ready: labels.providerGatewaySshDataPoolReady ?? null,
|
||||
claimed: labels.providerGatewaySshDataPoolClaimed ?? null,
|
||||
connecting: labels.providerGatewaySshDataPoolConnecting ?? null,
|
||||
lastError: labels.providerGatewaySshDataPoolLastError ?? null,
|
||||
};
|
||||
const ready = Number(pool.ready ?? 0);
|
||||
const claimed = Number(pool.claimed ?? 0);
|
||||
const desired = Number(pool.desired ?? 0);
|
||||
const ok = pool.transport === "tcp-pool" && Number.isFinite(ready) && ready > 0;
|
||||
return {
|
||||
ok,
|
||||
providerId,
|
||||
node: {
|
||||
providerId: node.providerId,
|
||||
name: node.name,
|
||||
status: node.status,
|
||||
lastHeartbeat: node.lastHeartbeat ?? null,
|
||||
updatedAt: node.updatedAt ?? null,
|
||||
},
|
||||
pool,
|
||||
classification: ok
|
||||
? "ssh-tcp-pool-ready"
|
||||
: pool.transport !== "tcp-pool"
|
||||
? "provider-gateway-upgrade-required"
|
||||
: desired > 0 && claimed >= desired
|
||||
? "provider-data-pool-exhausted"
|
||||
: "provider-data-pool-not-ready",
|
||||
next: {
|
||||
smoke: `trans ${providerId} argv true`,
|
||||
fullHealth: "bun scripts/cli.ts debug health",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function waitForTask(taskId: string, timeoutMs: number): Promise<unknown> {
|
||||
const started = Date.now();
|
||||
let latest: unknown = null;
|
||||
|
||||
Reference in New Issue
Block a user