Add a Diagnostic Log, ported and generalized from Sloth Manager
Sloth Manager tracked every API call made to DNS providers for connectivity troubleshooting. Port that here, generalized to cover every outbound integration this app makes, not just DNS -- Tailscale, Proxmox, Synology, Semaphore, Gitea, and Dockhand calls now show up too, since a broken API token or unreachable host on any of them is just as worth diagnosing. New services/diagLog.ts: a generic withDiagLogging(source, adapter) wraps every async method of any adapter object with timing + success/failure recording, without touching a single adapter's request/error-handling internals -- every DNS and integration adapter interface here is already just a flat set of async methods, so this one wrapper works for all twelve of them. Applied it at each adapter factory's own return statement (one line each) rather than at the route layer, so background jobs that construct adapters directly (the Tailscale key-expiry scheduler, IPAM sync, agent-driven Proxmox lookups) get logged too, not just requests through routes/integrations.ts. New diag_log table (ring-buffered to the last 500 rows, mirroring Sloth Manager's approach -- this is for live troubleshooting, not a durable record) and admin-only GET/DELETE /api/diag-log routes, source/ result filters, pagination. New admin-only Diagnostic Log page: filterable, paginated table with a Clear button. Also introduces the shared useSortable hook + SortableTh component used here for the first time -- a follow-up commit applies the same sorting (and CSV export) to the rest of the app's tables, per the same request. Verified end-to-end against a temp SQLite DB with real migrations: a fake wrapped adapter's successful and failing calls both land correctly in the log with the right source/operation/latency/error, and the source/ok filters and clear-log operation all behave correctly. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
42f073df81
commit
e35da87886
26 files changed
+1592
-12
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import { useMemo, useState } from "react";
|
||||
|
||||
export type SortDirection = "asc" | "desc";
|
||||
|
||||
/**
|
||||
* Generic client-side table sort. Sorts on the raw underlying field (numbers
|
||||
* numerically, booleans false-before-true, everything else via a
|
||||
* locale/numeric-aware string compare), not on however a column happens to
|
||||
* render it — so a formatted "1.2 GB" column still sorts by its raw byte
|
||||
* count, and a "5d 15h 2m" column sorts by its raw timestamp/seconds field.
|
||||
* Nulls/undefined always sort to the end regardless of direction.
|
||||
*/
|
||||
export function useSortable<T>(items: T[] | null | undefined, initialKey?: keyof T, initialDir: SortDirection = "asc") {
|
||||
const [sortKey, setSortKey] = useState<keyof T | undefined>(initialKey);
|
||||
const [sortDir, setSortDir] = useState<SortDirection>(initialDir);
|
||||
|
||||
function requestSort(key: keyof T) {
|
||||
if (sortKey === key) {
|
||||
setSortDir((d) => (d === "asc" ? "desc" : "asc"));
|
||||
} else {
|
||||
setSortKey(key);
|
||||
setSortDir("asc");
|
||||
}
|
||||
}
|
||||
|
||||
const sorted = useMemo(() => {
|
||||
if (!items || !sortKey) return items ?? null;
|
||||
const copy = [...items];
|
||||
copy.sort((a, b) => {
|
||||
const av = a[sortKey] as unknown;
|
||||
const bv = b[sortKey] as unknown;
|
||||
if (av === bv) return 0;
|
||||
if (av === null || av === undefined) return 1;
|
||||
if (bv === null || bv === undefined) return -1;
|
||||
let cmp: number;
|
||||
if (typeof av === "number" && typeof bv === "number") cmp = av - bv;
|
||||
else if (typeof av === "boolean" && typeof bv === "boolean") cmp = av === bv ? 0 : av ? 1 : -1;
|
||||
else cmp = String(av).localeCompare(String(bv), undefined, { numeric: true, sensitivity: "base" });
|
||||
return sortDir === "asc" ? cmp : -cmp;
|
||||
});
|
||||
return copy;
|
||||
}, [items, sortKey, sortDir]);
|
||||
|
||||
return { sorted, sortKey, sortDir, requestSort };
|
||||
}
|
||||
Reference in new issue
Block a user