fleet(tower): 0.18 — Tasks-View (Spool/Dead-Letter/Alarm) + Task-Detail-Modal + /healthz + /api/status; Fleet-Views 0.13-0.18 erstmals versioniert
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import {
|
||||
loadOrg,
|
||||
loadSandboxFacts,
|
||||
loadHeartbeatAges,
|
||||
cached,
|
||||
} from "@/app/lib/fleet/fleetSource"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
/**
|
||||
* GET /api/fleet/sandboxes — fleet-native Sandbox-View (Kernfeature-Ergänzung,
|
||||
* Design §2 Datenquellen-Adapter). Zeigt die K8s-Realität der 9 Agenten-Sandboxes:
|
||||
* Phase, Restarts, Age, Node, Requests, Image-Digest (kube-state-metrics via
|
||||
* Prometheus) + Worker-/Heartbeat-Status aus Spool/Beacon.
|
||||
* KEIN kubectl / KEINE Host-CLI im Tower (macOS-Design des Upstream ersetzt).
|
||||
* Fail-loud: tote Quelle -> 500 mit Klartext, kein stilles Leeren (§5.5).
|
||||
* Cache 2 s (View pollt 5 s -> max 1 Upstream-Call je Quelle je Zyklus).
|
||||
*/
|
||||
export async function GET() {
|
||||
try {
|
||||
const data = await cached("fleet-sandboxes", 2000, async () => {
|
||||
const [org, facts, hearts] = await Promise.all([
|
||||
loadOrg(),
|
||||
loadSandboxFacts(),
|
||||
loadHeartbeatAges(),
|
||||
])
|
||||
const sandboxByAgent = new Map(facts.sandboxes.map((s) => [s.agent_id, s]))
|
||||
const agents = org.members.map((m) => {
|
||||
const sb = sandboxByAgent.get(m.agent_id)
|
||||
const hbAge = hearts[m.agent_id]
|
||||
return {
|
||||
agent_id: m.agent_id,
|
||||
role: m.role,
|
||||
title: m.title ?? null,
|
||||
exists: Boolean(sb),
|
||||
phase: sb?.phase ?? null,
|
||||
ready: sb?.ready ?? null,
|
||||
restarts: sb?.restarts ?? null,
|
||||
pod_age_s: sb?.pod_age_s ?? null,
|
||||
node: sb?.node ?? null,
|
||||
cpu_request_milli: sb?.cpu_request_milli ?? null,
|
||||
mem_request_mb: sb?.mem_request_mb ?? null,
|
||||
image_digest: sb?.image_digest ?? null,
|
||||
heartbeat_age_s: typeof hbAge === "number" ? hbAge : null,
|
||||
}
|
||||
})
|
||||
const healthy =
|
||||
facts.sandboxes.length === org.members.length &&
|
||||
facts.sandboxes.every((s) => s.phase === "Running" && s.ready)
|
||||
return {
|
||||
agents,
|
||||
fleet_image_digest: facts.fleet_image_digest,
|
||||
all_running: healthy,
|
||||
generated_at: new Date().toISOString(),
|
||||
}
|
||||
})
|
||||
return NextResponse.json(data, { headers: { "Cache-Control": "no-store" } })
|
||||
} catch (err) {
|
||||
return NextResponse.json(
|
||||
{ error: `FLEET_SANDBOXES_FAILED: ${err instanceof Error ? err.message : String(err)}` },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user