How big the app's data is, and a webhook delivery log with Send again
Settings -> Data -> Storage measures the database, backups and sessions and every table (size, rows, growth, how long it is kept, how far back it reaches), and flags histories that are not being trimmed or have no limit. Event webhooks now keep a delivery log (last 100 per webhook, 14 days): what was sent, how it went, the message itself, and Send again, which resends it exactly as it was (same id and signature). Resends are audited and in the Change log. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
aebf3c6ce1
commit
e114567d64
22 files changed
+6833
-19
No files matched your search
@@ -8,6 +8,7 @@ import { readableError } from "../../utils/errors";
|
||||
import { toast } from "../../utils/toast";
|
||||
import ExportTableButton from "../../components/ExportTableButton";
|
||||
import { EmptyRow, LoadingRow } from "../../components/EmptyState";
|
||||
import WebhookDeliveries from "./WebhookDeliveries";
|
||||
|
||||
const EVENT_WORDS: Record<WebhookEventName, string> = {
|
||||
"alert.opened": "A problem begins",
|
||||
@@ -43,6 +44,7 @@ export default function ApiSettings() {
|
||||
const [hookEvents, setHookEvents] = useState<Set<WebhookEventName>>(new Set(["alert.opened", "alert.resolved"]));
|
||||
const [testResults, setTestResults] = useState<Record<number, string>>({});
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [logOf, setLogOf] = useState<EventWebhook | null>(null);
|
||||
|
||||
function load() {
|
||||
api.metricsTokens
|
||||
@@ -239,7 +241,7 @@ export default function ApiSettings() {
|
||||
<div className="card-body">
|
||||
<p className="text-secondary">
|
||||
A webhook is sent a JSON message when something happens, for Home Assistant, n8n or a status board. This is separate from the chat-style webhook under Notifications, which carries the sentence a person would read. A problem is announced on the same terms as a
|
||||
notification — one under maintenance isn't until it ends. If you give a secret, each message carries <code>X-HLM-Signature: sha256=…</code>, an HMAC of the body, so the receiver can tell it came from here. A failed delivery is tried once more.
|
||||
notification — one under maintenance isn't until it ends. If you give a secret, each message carries <code>X-HLM-Signature: sha256=…</code>, an HMAC of the body, so the receiver can tell it came from here. A failed delivery is tried once more, and what was sent and how it went is kept under <em>Sent</em> — where a message can be sent again exactly as it was.
|
||||
</p>
|
||||
{adding && (
|
||||
<form className="border rounded p-3 mb-3" onSubmit={makeHook}>
|
||||
@@ -336,6 +338,9 @@ export default function ApiSettings() {
|
||||
<button className="btn btn-sm btn-outline-secondary" onClick={() => void testHook(h)}>
|
||||
Test
|
||||
</button>
|
||||
<button className="btn btn-sm btn-outline-secondary" onClick={() => setLogOf(h)}>
|
||||
Sent
|
||||
</button>
|
||||
<button className="btn btn-sm btn-outline-secondary" onClick={() => void toggleHook(h)}>
|
||||
{h.enabled ? "Turn off" : "Turn on"}
|
||||
</button>
|
||||
@@ -355,6 +360,7 @@ export default function ApiSettings() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{logOf && <WebhookDeliveries hook={logOf} onClose={() => setLogOf(null)} onChanged={load} />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import BadgeSettings from "./BadgeSettings";
|
||||
import BackupSettings from "./BackupSettings";
|
||||
import LogSettings from "./LogSettings";
|
||||
import CacheSettings from "./CacheSettings";
|
||||
import StorageSettings from "./StorageSettings";
|
||||
|
||||
// Settings used to have twelve tabs of its own. Three of them gather the ones that belong together; each part is the same page it always was,
|
||||
// switched by `?view=` (so it can be linked to, and the old addresses redirect here).
|
||||
@@ -47,11 +48,11 @@ export function DisplayGroup() {
|
||||
);
|
||||
}
|
||||
|
||||
/** The upkeep of the app's own data: its backups, how long its logs are kept, and the DNS record cache. */
|
||||
/** The upkeep of the app's own data: its backups, how long its logs are kept, how big it all is, and the DNS record cache. */
|
||||
export function DataGroup() {
|
||||
const [params] = useSearchParams();
|
||||
const asked = params.get("view");
|
||||
const view = asked === "logs" || asked === "cache" ? asked : "backup";
|
||||
const view = asked === "logs" || asked === "cache" || asked === "storage" ? asked : "backup";
|
||||
return (
|
||||
<>
|
||||
<ViewTabs
|
||||
@@ -59,10 +60,11 @@ export function DataGroup() {
|
||||
tabs={[
|
||||
{ to: "/settings/data", label: "Backup", active: view === "backup" },
|
||||
{ to: "/settings/data?view=logs", label: "Logs", active: view === "logs" },
|
||||
{ to: "/settings/data?view=storage", label: "Storage", active: view === "storage" },
|
||||
{ to: "/settings/data?view=cache", label: "Cache", active: view === "cache" },
|
||||
]}
|
||||
/>
|
||||
{view === "logs" ? <LogSettings /> : view === "cache" ? <CacheSettings /> : <BackupSettings />}
|
||||
{view === "logs" ? <LogSettings /> : view === "cache" ? <CacheSettings /> : view === "storage" ? <StorageSettings /> : <BackupSettings />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type DataUsage, type TableUsage, type UsageState } from "../../api/client";
|
||||
import TimeAgo from "../../components/TimeAgo";
|
||||
import { ErrorNotice } from "../../components/Notice";
|
||||
import { PageSkeleton } from "../../components/Skeleton";
|
||||
import { readableError } from "../../utils/errors";
|
||||
|
||||
export function formatBytes(bytes: number | null): string {
|
||||
if (bytes === null) return "—";
|
||||
const units = ["B", "KB", "MB", "GB", "TB"];
|
||||
let value = bytes;
|
||||
let unit = 0;
|
||||
while (value >= 1024 && unit < units.length - 1) {
|
||||
value /= 1024;
|
||||
unit++;
|
||||
}
|
||||
return `${unit === 0 ? value : value.toFixed(value >= 100 ? 0 : 1)} ${units[unit]}`;
|
||||
}
|
||||
|
||||
const STATE_BADGE: Record<UsageState, { label: string; cls: string } | null> = {
|
||||
limit: { label: "trimmed", cls: "bg-green-lt text-green" },
|
||||
filling: { label: "filling up", cls: "bg-blue-lt text-blue" },
|
||||
not_trimmed: { label: "not trimmed", cls: "bg-red-lt text-red" },
|
||||
unlimited: { label: "no limit", cls: "bg-orange-lt text-orange" },
|
||||
plain: null,
|
||||
};
|
||||
|
||||
const keepWords = (t: TableUsage) => (t.keepDays === null ? (t.state === "unlimited" ? "forever" : "—") : t.keepDays >= 365 ? `${Math.round((t.keepDays / 365) * 10) / 10} years` : `${t.keepDays} days`);
|
||||
|
||||
const rate = (t: TableUsage) => (t.perDay === null ? "—" : t.perDay >= 10 ? Math.round(t.perDay).toLocaleString() : t.perDay.toLocaleString());
|
||||
|
||||
/** How big the app's own data is and whether what is meant to be trimmed is being trimmed: the files, then every table by the space it takes. */
|
||||
export default function StorageSettings() {
|
||||
const [usage, setUsage] = useState<DataUsage | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [showAll, setShowAll] = useState(false);
|
||||
|
||||
function load() {
|
||||
setLoading(true);
|
||||
api.dataUsage
|
||||
.get()
|
||||
.then((u) => {
|
||||
setUsage(u);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)))
|
||||
.finally(() => setLoading(false));
|
||||
}
|
||||
useEffect(load, []);
|
||||
|
||||
if (!usage) return error ? <ErrorNotice error={error} /> : <PageSkeleton />;
|
||||
|
||||
const biggest = Math.max(1, ...usage.tables.map((t) => t.bytes ?? t.rows));
|
||||
const shown = showAll ? usage.tables : usage.tables.filter((t) => t.state !== "plain" || (t.bytes ?? 0) >= 64 * 1024 || t.rows >= 500).slice(0, 25);
|
||||
const db = usage.database;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-3">
|
||||
<h3 className="mb-0">Storage</h3>
|
||||
<button className="btn btn-sm ms-auto" onClick={load} disabled={loading}>
|
||||
{loading ? "Measuring…" : "Measure again"}
|
||||
</button>
|
||||
</div>
|
||||
<ErrorNotice error={error} />
|
||||
<p className="text-secondary">
|
||||
How much room the app's own data takes, and whether the histories that are meant to be trimmed are. Measured <TimeAgo value={usage.generatedAt} />.
|
||||
</p>
|
||||
|
||||
{usage.attention.length > 0 && (
|
||||
<div className="alert alert-warning" role="status">
|
||||
<div>
|
||||
<div className="fw-bold mb-1">{usage.attention.length === 1 ? "One history needs a look" : `${usage.attention.length} histories need a look`}</div>
|
||||
<ul className="mb-0 ps-3">
|
||||
{usage.attention.map((a) => (
|
||||
<li key={a.table}>
|
||||
<code>{a.table}</code> — {a.text}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="row row-cards mb-3">
|
||||
{[
|
||||
{ label: "In total", value: formatBytes(usage.totalBytes), sub: "database, backups and sessions" },
|
||||
{ label: "Database", value: formatBytes(db.bytes + db.walBytes), sub: `${db.tables} tables${db.freeBytes > 0 ? `, ${formatBytes(db.freeBytes)} of it free` : ""}` },
|
||||
{ label: "Backups", value: formatBytes(usage.backups.bytes), sub: `${usage.backups.files} ${usage.backups.files === 1 ? "file" : "files"}` },
|
||||
{ label: "Sessions", value: formatBytes(usage.sessions.bytes), sub: `${usage.sessions.files} signed in ${usage.sessions.files === 1 ? "browser" : "browsers"}` },
|
||||
].map((tile) => (
|
||||
<div key={tile.label} className="col-6 col-lg-3">
|
||||
<div className="card card-sm">
|
||||
<div className="card-body">
|
||||
<div className="text-secondary small">{tile.label}</div>
|
||||
<div className="h2 mb-0">{tile.value}</div>
|
||||
<div className="text-secondary small">{tile.sub}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">What takes the room</h3>
|
||||
<div className="card-actions">
|
||||
<button className="btn btn-sm" onClick={() => setShowAll((v) => !v)}>
|
||||
{showAll ? "Only the larger ones" : `All ${usage.tables.length} tables`}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Table</th>
|
||||
<th className="text-end">Size</th>
|
||||
<th className="text-end">Rows</th>
|
||||
<th className="text-end">Added a day</th>
|
||||
<th>Kept</th>
|
||||
<th>Reaches back</th>
|
||||
<th>Trimming</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{shown.map((t) => {
|
||||
const badge = t.rows === 0 && t.state === "limit" ? { label: "empty", cls: "bg-secondary-lt text-secondary" } : STATE_BADGE[t.state];
|
||||
return (
|
||||
<tr key={t.name}>
|
||||
<td>
|
||||
<code>{t.name}</code>
|
||||
{t.note && <div className="text-secondary small">{t.note}</div>}
|
||||
</td>
|
||||
<td className="text-end text-nowrap">
|
||||
{formatBytes(t.bytes)}
|
||||
<div className="progress progress-sm mt-1" aria-hidden="true">
|
||||
<div className="progress-bar" style={{ width: `${Math.max(2, Math.round(((t.bytes ?? t.rows) / biggest) * 100))}%` }} />
|
||||
</div>
|
||||
</td>
|
||||
<td className="text-end">{t.rows.toLocaleString()}</td>
|
||||
<td className="text-end">{rate(t)}</td>
|
||||
<td className="text-nowrap">{keepWords(t)}</td>
|
||||
<td className="text-nowrap">{t.spanDays === null ? <span className="text-secondary">—</span> : `${t.spanDays.toLocaleString()} days`}</td>
|
||||
<td>
|
||||
{badge && <span className={`badge ${badge.cls}`}>{badge.label}</span>}
|
||||
{t.stateText && t.state !== "limit" && <div className="text-secondary small">{t.stateText}</div>}
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div className="card-footer text-secondary small">
|
||||
Sizes count a table with its indexes. Space freed by trimming is reused by the next rows rather than handed back, so the file does not shrink on its own. How long the logs are kept is set under{" "}
|
||||
<Link to="/settings/data?view=logs">Logs</Link>; the rest is fixed.
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, type EventWebhook, type WebhookDelivery } from "../../api/client";
|
||||
import DetailDrawer from "../../components/DetailDrawer";
|
||||
import EmptyState from "../../components/EmptyState";
|
||||
import TimeAgo from "../../components/TimeAgo";
|
||||
import { ErrorNotice } from "../../components/Notice";
|
||||
import { BlockSkeleton } from "../../components/Skeleton";
|
||||
import { readableError } from "../../utils/errors";
|
||||
import { toast } from "../../utils/toast";
|
||||
|
||||
const pretty = (body: string) => {
|
||||
try {
|
||||
return JSON.stringify(JSON.parse(body), null, 2);
|
||||
} catch {
|
||||
return body;
|
||||
}
|
||||
};
|
||||
|
||||
/** What was sent to one webhook lately and how each went, with the message itself and a button to send it again exactly as it was. */
|
||||
export default function WebhookDeliveries({ hook, onClose, onChanged }: { hook: EventWebhook; onClose: () => void; onChanged: () => void }) {
|
||||
const [rows, setRows] = useState<WebhookDelivery[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [open, setOpen] = useState<number | null>(null);
|
||||
const [sending, setSending] = useState<number | null>(null);
|
||||
|
||||
function load() {
|
||||
api.eventWebhooks
|
||||
.deliveries(hook.id)
|
||||
.then((r) => setRows(r.deliveries))
|
||||
.catch((err) => setError(readableError(err)));
|
||||
}
|
||||
useEffect(load, [hook.id]);
|
||||
|
||||
async function retry(d: WebhookDelivery) {
|
||||
setSending(d.id);
|
||||
try {
|
||||
const res = await api.eventWebhooks.retryDelivery(hook.id, d.id);
|
||||
if (res.ok) toast.success(`Sent again — ${hook.label} answered ${res.result}.`);
|
||||
else toast.error(`Sent again, but ${hook.label} answered ${res.result}.`);
|
||||
load();
|
||||
onChanged();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setSending(null);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<DetailDrawer title={`Sent to ${hook.label}`} subtitle="The last 100 messages, and none older than two weeks" onClose={onClose}>
|
||||
<ErrorNotice error={error} />
|
||||
{rows === null && !error && <BlockSkeleton lines={4} />}
|
||||
{rows?.length === 0 && <EmptyState title="Nothing has been sent yet" hint="Each message sent to this webhook is listed here with how it went. Use Test on the webhook to send one." />}
|
||||
<div className="list-group list-group-flush">
|
||||
{rows?.map((d) => (
|
||||
<div key={d.id} className="list-group-item px-0">
|
||||
<div className="d-flex align-items-center gap-2 flex-wrap">
|
||||
<span className={`badge ${d.ok ? "bg-green-lt text-green" : "bg-red-lt text-red"}`}>{d.ok ? "delivered" : "failed"}</span>
|
||||
<code className="small">{d.event}</code>
|
||||
<span className={d.ok ? "text-green" : "text-red"}>{d.result}</span>
|
||||
{d.attempts > 1 && <span className="text-secondary small">tried twice</span>}
|
||||
{d.retryOf !== null && <span className="badge bg-blue-lt text-blue">sent again by hand</span>}
|
||||
<span className="text-secondary small ms-auto">
|
||||
<TimeAgo value={d.createdAt} />
|
||||
</span>
|
||||
</div>
|
||||
<div className="btn-list mt-2">
|
||||
<button className="btn btn-sm" onClick={() => setOpen(open === d.id ? null : d.id)} disabled={d.body === null} aria-expanded={open === d.id}>
|
||||
{open === d.id ? "Hide the message" : "Show the message"}
|
||||
</button>
|
||||
<button className="btn btn-sm btn-outline-primary" onClick={() => void retry(d)} disabled={!d.retryable || sending !== null} title={d.retryable ? "Send exactly this message again, with the same id and signature" : "Too large to have been kept"}>
|
||||
{sending === d.id ? "Sending…" : "Send again"}
|
||||
</button>
|
||||
</div>
|
||||
{!d.retryable && <div className="text-secondary small mt-1">This message was too large to keep, so it cannot be shown or sent again.</div>}
|
||||
{open === d.id && d.body !== null && (
|
||||
<pre className="border rounded p-2 mt-2 mb-0" style={{ fontSize: "0.75rem", maxHeight: 320, overflow: "auto" }}>
|
||||
{pretty(d.body)}
|
||||
</pre>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</DetailDrawer>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user