Dependency map, impact preview in maintenance, and a calmer Alerts page
- Map: a Dependencies view showing what would go down with a picked box and what it relies on - Maintenance: lists what depends on a target and can silence those too (same time, audited); the recurring form and update drawer show the same note - Alerts: a headline on where things stand, held-back alerts nested under their cause, severity edge on rows; caused-by now carries the explaining alert's id Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ec9c2f73f0
commit
9caa414829
19 files changed
+944
-40
No files matched your search
@@ -2,11 +2,14 @@ import { Router } from "express";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { z } from "zod";
|
||||
import { db } from "../db/client.js";
|
||||
import { dependencies } from "../db/schema.js";
|
||||
import { dependencies, servers } from "../db/schema.js";
|
||||
import { requireAuth, requireRole } from "../auth/middleware.js";
|
||||
import { recordAudit } from "../services/audit.js";
|
||||
import { invalidateAlertsCache } from "../services/alerts.js";
|
||||
import { loadGraph, nodeKey, nodeTypes, wouldLoop } from "../services/dependencies.js";
|
||||
import { dependentsOf, impactOf, loadGraph, nodeKey, nodeTypes, wouldLoop } from "../services/dependencies.js";
|
||||
import { getSettings } from "../services/settingsStore.js";
|
||||
import { getSourceStatus } from "../services/integrationHealthMonitor.js";
|
||||
import { serverStatus, type MapStatus } from "../services/topology.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
|
||||
export const dependenciesRouter = Router();
|
||||
@@ -41,6 +44,56 @@ dependenciesRouter.get("/", asyncHandler(async (_req, res) => {
|
||||
});
|
||||
}));
|
||||
|
||||
// What a thing would take with it, and what it needs itself: for the maintenance and update pages, which say so before it is done.
|
||||
dependenciesRouter.get("/impact", asyncHandler(async (req, res) => {
|
||||
const type = nodeTypes.find((t) => t === req.query.type);
|
||||
const id = typeof req.query.id === "string" && /^\d+$/.test(req.query.id) ? Number(req.query.id) : NaN;
|
||||
if (!type || !Number.isInteger(id)) return res.status(400).json({ error: "invalid_query", message: "Say which server or integration." });
|
||||
const impact = await impactOf(type, id);
|
||||
if (!impact) return res.status(404).json({ error: "not_found" });
|
||||
res.json(impact);
|
||||
}));
|
||||
|
||||
// The graph for the Map page: the servers and integrations that take part in any dependency, how each is doing, and who needs whom. An edge runs
|
||||
// from the thing that is needed to the thing that needs it, so the foundations come first.
|
||||
dependenciesRouter.get("/graph", asyncHandler(async (_req, res) => {
|
||||
const graph = await loadGraph();
|
||||
const written = new Set(graph.rows.map((r) => `${nodeKey(r.fromType, r.fromId)}>${nodeKey(r.toType, r.toId)}`));
|
||||
const edges: { from: string; to: string; kind: "written" | "runs-on" }[] = [];
|
||||
const taking = new Set<string>();
|
||||
for (const [needing, needed] of graph.edges) {
|
||||
for (const n of needed) {
|
||||
edges.push({ from: n, to: needing, kind: written.has(`${needing}>${n}`) ? "written" : "runs-on" });
|
||||
taking.add(needing);
|
||||
taking.add(n);
|
||||
}
|
||||
}
|
||||
const { healthChecks } = await getSettings();
|
||||
const now = new Date();
|
||||
const serverRows = await db.select({ id: servers.id, lastSeenAt: servers.lastSeenAt, thresholds: servers.thresholds }).from(servers);
|
||||
const serverById = new Map(serverRows.map((s) => [s.id, s]));
|
||||
const intById = new Map(graph.intRows.map((i) => [i.id, i]));
|
||||
const nodes = [...taking]
|
||||
.map((key) => {
|
||||
const [type, rawId] = key.split(":");
|
||||
const id = Number(rawId);
|
||||
let status: MapStatus = "unknown";
|
||||
if (type === "server") {
|
||||
const s = serverById.get(id);
|
||||
if (s) status = serverStatus(s, healthChecks.serverOfflineMinutes, now);
|
||||
} else {
|
||||
const i = intById.get(id);
|
||||
if (i?.enabled) {
|
||||
const st = getSourceStatus(i.type).status;
|
||||
status = st === "failing" ? "bad" : st === "ok" ? "ok" : "unknown";
|
||||
}
|
||||
}
|
||||
return { key, type: type as "server" | "integration", id, name: graph.names.get(key) ?? key, status, href: type === "server" ? `/servers/${id}` : "/integrations" };
|
||||
})
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
res.json({ nodes, edges });
|
||||
}));
|
||||
|
||||
dependenciesRouter.post("/", requireRole("operator"), asyncHandler(async (req, res) => {
|
||||
const parsed = edgeSchema.safeParse(req.body);
|
||||
if (!parsed.success) return res.status(400).json({ error: "invalid_body", message: "Say what needs what: a server or an integration each.", details: parsed.error.flatten() });
|
||||
|
||||
Reference in new issue
Block a user