PR 4 du chantier admin. Board de sante temps reel des dependances.
- POST /internal/tech-steps/heartbeat (requireInternalWorker) ->
recordWorkerHeartbeat : upsert WorkerHeartbeat (cle fixe
"tech-step-llm-worker"), lastRunAt/lastResult pour un ping "job".
Schema workerHeartbeatSchema dans packages/shared.
- services/tech-step-llm-worker : api-client.postHeartbeat (best-effort,
ne throw jamais) appele au boot (index.ts), a chaque tick et apres
chaque job (scheduler.ts, avec job/ok/counts).
- admin-monitoring.service.ts + GET /admin/monitoring (requireAdmin) :
sonde active bornee (~2 s) de Postgres (SELECT 1), l'API (uptime/RSS),
tech-step-intent-service (/health), et le worker via son heartbeat.
Statut up/degraded/down/unknown ; une sonde down ne casse ni les autres
ni l'endpoint. Seuils worker : > 8 j degraded, > 21 j down.
- MonitoringView / ServiceHealthView dans packages/shared.
- Front : MonitoringPage (grille de cartes coloree par statut, re-poll
15 s), logique pure monitoring.ts, i18n admin.monitoring.*,
AdminApiClient.getMonitoring.
- Tests : Mocha admin-monitoring.test.ts (heartbeat 401/400/upsert
job+boot ; GET /admin/monitoring 401, board 4 cibles, worker unknown
sans heartbeat puis up apres) ; Cypress monitoring.cy.ts (2 verts).
Worker mocha : 6/6 toujours verts.
- specs/backend-architecture.md : section monitoring. .gitignore :
apps/admin-web/cypress/{screenshots,videos,downloads}.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
83 lines
2.4 KiB
TypeScript
83 lines
2.4 KiB
TypeScript
// Mocks the admin API via cy.intercept — no live backend.
|
|
|
|
const adminBody = {
|
|
id: 1,
|
|
email: "ops@example.com",
|
|
name: "Ops",
|
|
createdAt: "2026-08-01T00:00:00.000Z",
|
|
lastLoginAt: "2026-08-28T09:00:00.000Z",
|
|
};
|
|
|
|
function monitoringFixture() {
|
|
return {
|
|
generatedAt: "2026-08-28T09:15:00.000Z",
|
|
services: [
|
|
{
|
|
key: "postgres",
|
|
status: "up",
|
|
latencyMs: 3.2,
|
|
detail: null,
|
|
checkedAt: "2026-08-28T09:15:00.000Z",
|
|
},
|
|
{
|
|
key: "api",
|
|
status: "up",
|
|
latencyMs: 0,
|
|
detail: "uptime 3 h 12 min · RSS 120 Mo",
|
|
checkedAt: "2026-08-28T09:15:00.000Z",
|
|
},
|
|
{
|
|
key: "intent-service",
|
|
status: "down",
|
|
latencyMs: null,
|
|
detail: "fetch failed",
|
|
checkedAt: "2026-08-28T09:15:00.000Z",
|
|
},
|
|
{
|
|
key: "tech-step-llm-worker",
|
|
status: "degraded",
|
|
latencyMs: null,
|
|
detail: "dernier battement il y a 9 j",
|
|
checkedAt: "2026-08-28T09:15:00.000Z",
|
|
lastRunAt: "2026-08-19T03:00:00.000Z",
|
|
lastResult: { job: "audit-low-confidence", ok: true, counts: { suggestions: 2 } },
|
|
},
|
|
],
|
|
};
|
|
}
|
|
|
|
describe("Admin monitoring", () => {
|
|
beforeEach(() => {
|
|
cy.viewport(1400, 900);
|
|
cy.intercept("GET", "**/admin/auth/me", { statusCode: 200, body: adminBody });
|
|
});
|
|
|
|
it("renders one card per service with its status and details", () => {
|
|
cy.intercept("GET", "**/admin/monitoring", { statusCode: 200, body: monitoringFixture() }).as(
|
|
"getMonitoring",
|
|
);
|
|
cy.visit("/monitoring");
|
|
cy.wait("@getMonitoring");
|
|
|
|
cy.get(".monitoring-card").should("have.length", 4);
|
|
|
|
cy.contains(".monitoring-card", "Base de données")
|
|
.should("have.class", "monitoring-card--up")
|
|
.and("contain.text", "3.2 ms");
|
|
cy.contains(".monitoring-card", "Service NLP (spaCy)")
|
|
.should("have.class", "monitoring-card--down")
|
|
.and("contain.text", "Hors service");
|
|
cy.contains(".monitoring-card", "Worker LLM")
|
|
.should("have.class", "monitoring-card--degraded")
|
|
.and("contain.text", "audit-low-confidence");
|
|
});
|
|
|
|
it("shows an error state when the request fails", () => {
|
|
cy.intercept("GET", "**/admin/monitoring", {
|
|
statusCode: 500,
|
|
body: { code: 5000, message: "x" },
|
|
});
|
|
cy.visit("/monitoring");
|
|
cy.contains("Impossible de charger").should("be.visible");
|
|
});
|
|
});
|