Medium35 training campaign monitor in cockpit-admin#78
Merged
Conversation
Context: the gateway exposes /admin/training/{status,start,abort,log}
endpoints that drive the medium35 training campaign across 28+
hardware-first and generalist domains. Operators had no UI to drive
them — only curl with an X-Admin-Token header.
Approach: proxy the four endpoints through cockpit-api so the admin
token stays server-side, then build a dedicated /training/campaign
page in cockpit-admin with live status, controls, and log tail.
Changes:
- apps/api: services/gateway_admin.py async httpx client with
X-Admin-Token injection, shared AsyncClient, upstream-status
HTTPException remap.
- apps/api: routers/admin/campaign.py FastAPI router gated by
require_tailscale_user (matches existing admin pattern).
- apps/api: 7 new tests covering status / start / abort / log paths
including tail clamping and auth gating.
- apps/cockpit-admin: 4 TanStack Query hooks (status auto-refresh
30s, log auto-refresh 30s skipped when no current domain, plus
start/abort mutations).
- apps/cockpit-admin: CampaignStatusCard (progress bars overall +
current), CampaignDomainGrid (verdict badges), CampaignControls
(Start modal with 28-domain checkbox, Abort confirm dialog).
- apps/cockpit-admin: /training/campaign route reusing LogTail for
the live tail of the current domain.
- deploy: COCKPIT_AILIANCE_ADMIN_TOKEN piped from host env into api
container (never hardcoded).
Impact: operators can launch, monitor, and abort medium35 training
campaigns from admin.ailiance.fr without shell access to the
gateway, and the X-Admin-Token never reaches the browser.
There was a problem hiding this comment.
Pull request overview
Adds a new cockpit-admin page for live monitoring and control of the gateway-orchestrated “medium35” training campaign, backed by new cockpit-api proxy endpoints that inject the admin token server-side (so the browser never sees it).
Changes:
- Added FastAPI proxy router + async gateway client for
/admin/training/*campaign endpoints (status/start/abort/log), protected by existing Tailscale auth. - Added new cockpit-admin route
/training/campaignwith status, per-domain verdict table, start/abort controls, and log tail display (auto-refresh). - Added unit tests covering the new campaign proxy endpoints.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| deploy/docker-compose.yml | Adds COCKPIT_AILIANCE_ADMIN_TOKEN env wiring for the API container. |
| apps/cockpit-admin/src/routeTree.gen.ts | Registers the new /training/campaign route (generated). |
| apps/cockpit-admin/src/routes/training.index.tsx | Adds a link from training runs to the new campaign page. |
| apps/cockpit-admin/src/routes/training.campaign.tsx | New campaign monitoring page (status + verdicts + log tail). |
| apps/cockpit-admin/src/hooks/useStartCampaign.ts | React Query mutation to start the campaign. |
| apps/cockpit-admin/src/hooks/useCampaignStatus.ts | React Query polling for campaign status. |
| apps/cockpit-admin/src/hooks/useCampaignLog.ts | React Query polling for plain-text log tail. |
| apps/cockpit-admin/src/hooks/useAbortCampaign.ts | React Query mutation to abort the campaign. |
| apps/cockpit-admin/src/components/CampaignStatusCard.tsx | UI card for campaign status + progress bars. |
| apps/cockpit-admin/src/components/CampaignDomainGrid.tsx | Verdict table for per-domain results (and active domain). |
| apps/cockpit-admin/src/components/CampaignControls.tsx | Start/abort controls with dialogs and domain selection. |
| apps/api/tests/unit/test_admin_campaign.py | New unit tests for the campaign proxy router. |
| apps/api/src/ailiance_demo/services/gateway_admin.py | New async client to call gateway admin campaign endpoints. |
| apps/api/src/ailiance_demo/routers/admin/campaign.py | New authenticated proxy router under /api/admin/training/campaign. |
| apps/api/src/ailiance_demo/main.py | Wires the new router into the FastAPI app. |
Comments suppressed due to low confidence (1)
apps/cockpit-admin/src/components/CampaignControls.tsx:121
- For accessibility, the
role="dialog"/aria-modalshould describe the dialog surface, not the full-screen overlay (which also has click-to-dismiss). Move the dialog role attributes onto the inner panel and wirearia-labelledbyto the dialog title so screen readers announce it correctly (same applies to the abort dialog below).
<div
role="dialog"
aria-modal="true"
className="fixed inset-0 z-40 flex items-center justify-center bg-black/50"
onClick={() => setStartOpen(false)}
>
<div
className="max-h-[80vh] w-full max-w-2xl overflow-y-auto rounded bg-white p-6 shadow-lg"
onClick={(e) => e.stopPropagation()}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+42
to
+45
| @router.get("/log/{domain}", response_class=PlainTextResponse) | ||
| async def get_domain_log(domain: str, tail: int = 100) -> str: | ||
| tail = max(1, min(tail, 1000)) | ||
| return await gateway_admin.get_domain_log(domain, tail) |
Comment on lines
+32
to
+39
| # Shared async client. Reused across calls to keep connection pooling. | ||
| _client: httpx.AsyncClient | None = None | ||
|
|
||
|
|
||
| def _get_client() -> httpx.AsyncClient: | ||
| global _client | ||
| if _client is None: | ||
| _client = httpx.AsyncClient(base_url=_GATEWAY_URL.rstrip("/")) |
Comment on lines
+86
to
+94
| <button | ||
| type="button" | ||
| onClick={() => setStartOpen(true)} | ||
| disabled={startDisabled} | ||
| title={startDisabled ? 'campagne déjà active' : 'Démarrer la campagne'} | ||
| className="inline-flex items-center gap-2 rounded bg-emerald-600 px-3 py-1 text-sm text-white hover:bg-emerald-500 disabled:cursor-not-allowed disabled:bg-slate-300" | ||
| > | ||
| <Play size={14} /> Start | ||
| </button> |
Comment on lines
+13
to
+14
| const url = `/api/admin/training/campaign/log/${domain}?tail=${tail}`; | ||
| const response = await fetch(url, { signal }); |
Comment on lines
+24
to
+32
| function ProgressBar({ value, max }: { value: number; max: number }) { | ||
| const pct = max > 0 ? Math.min(100, Math.round((value / max) * 100)) : 0; | ||
| return ( | ||
| <div className="h-2 rounded bg-slate-200 overflow-hidden" aria-label={`${pct}%`}> | ||
| <div | ||
| className="h-full bg-violet-500 transition-all" | ||
| style={{ width: `${pct}%` }} | ||
| /> | ||
| </div> |
|
|
||
| router = APIRouter( | ||
| prefix="/api/admin/training/campaign", | ||
| tags=["campaign"], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
New page
admin.ailiance.fr/training/campaignto monitor and control thegateway-orchestrated medium35 training campaign live.
apps/api/src/.../routers/admin/campaign.py+services/gateway_admin.py): proxies the gateway's/admin/training/*endpoints behind the existing
require_tailscale_userauth. Admin tokenread from env (
COCKPIT_AILIANCE_ADMIN_TOKEN), never exposed to thebrowser.
apps/cockpit-admin/src/routes/training.campaign.tsx):live status card (auto-refresh 30s), per-domain verdict grid, Start dialog
with multi-select of the 28 hardware-first domains, Abort confirm, log
tail of the current domain via the existing
LogTailcomponent.ailiance/ailiancePR #113 adds the gateway log endpointthis page consumes.
Known follow-up
The 28-domain list is hardcoded in
CampaignControls.tsx. A future smalladdition could expose the list via the gateway and fetch it dynamically.
Test plan
pnpm -F cockpit-admin buildclean