What changed before this? on every incident, ranked
- A card on the incident page, and GET /api/incidents/:id/before and /api/v1/incidents/:id/before: what the app knows happened in the 30 min to 24 h before an alert began (audit log, maintenance windows, update runs and patch plans, other alerts, a step in the server's own figures), scored by how related, what kind and how close - A host going down is shown once; Likely, Possible and Background; at most ten - Docs and roles updated Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c2e76262ca
commit
0277126add
12 files changed
+887
No files matched your search
@@ -1614,6 +1614,32 @@ export interface IncidentSummary {
|
||||
notes: number;
|
||||
}
|
||||
|
||||
export interface BeforeSuspect {
|
||||
at: string;
|
||||
minutesBefore: number;
|
||||
kind: "maintenance" | "update" | "alert" | "change" | "settings" | "metric" | "rule";
|
||||
title: string;
|
||||
detail: string | null;
|
||||
actor: string | null;
|
||||
relation: "same" | "needs" | "needed_by" | "everything" | "other";
|
||||
about: string;
|
||||
why: string;
|
||||
score: number;
|
||||
confidence: "likely" | "possible" | "background";
|
||||
link: string | null;
|
||||
incidentId?: number;
|
||||
}
|
||||
|
||||
export interface BeforeReport {
|
||||
incidentId: number;
|
||||
openedAt: string;
|
||||
windowMinutes: number;
|
||||
from: string;
|
||||
to: string;
|
||||
suspects: BeforeSuspect[];
|
||||
looked: { auditEntries: number; maintenanceWindows: number; updateRuns: number; otherAlerts: number; series: number };
|
||||
}
|
||||
|
||||
export interface IncidentDetail {
|
||||
incident: IncidentSummary;
|
||||
ack: AlertAck | null;
|
||||
@@ -2648,6 +2674,7 @@ export const api = {
|
||||
incidents: {
|
||||
list: () => request<{ incidents: IncidentSummary[] }>("/api/incidents"),
|
||||
get: (id: number) => request<IncidentDetail>(`/api/incidents/${id}`),
|
||||
before: (id: number, minutes: number) => request<BeforeReport>(`/api/incidents/${id}/before?minutes=${minutes}`),
|
||||
addNote: (id: number, body: string) => request<{ id: number }>(`/api/incidents/${id}/notes`, { method: "POST", body: JSON.stringify({ body }) }),
|
||||
removeNote: (id: number, noteId: number) => request<void>(`/api/incidents/${id}/notes/${noteId}`, { method: "DELETE" }),
|
||||
},
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type BeforeReport, type BeforeSuspect } from "../api/client";
|
||||
import { BlockSkeleton } from "./Skeleton";
|
||||
import { ErrorNotice } from "./Notice";
|
||||
import { formatDateTime } from "../utils/date";
|
||||
import { readableError } from "../utils/errors";
|
||||
|
||||
const RANGES = [
|
||||
{ minutes: 30, label: "30 min" },
|
||||
{ minutes: 120, label: "2 hours" },
|
||||
{ minutes: 360, label: "6 hours" },
|
||||
{ minutes: 1440, label: "24 hours" },
|
||||
];
|
||||
|
||||
const CONFIDENCE: Record<BeforeSuspect["confidence"], { label: string; className: string; title: string }> = {
|
||||
likely: { label: "Likely", className: "bg-red-lt text-red", title: "Close in time and closely related" },
|
||||
possible: { label: "Possible", className: "bg-yellow-lt text-yellow", title: "Either close in time or closely related" },
|
||||
background: { label: "Background", className: "bg-secondary-lt text-secondary", title: "Happened in the window, but little to link it" },
|
||||
};
|
||||
|
||||
const KIND: Record<BeforeSuspect["kind"], string> = {
|
||||
maintenance: "Maintenance",
|
||||
update: "Update",
|
||||
alert: "Another alert",
|
||||
change: "Change",
|
||||
settings: "Setting",
|
||||
metric: "Its own figures",
|
||||
rule: "Alert rule",
|
||||
};
|
||||
|
||||
const minutesWords = (m: number) => (m < 1 ? "at the same moment" : m < 90 ? `${Math.round(m)} min before` : `${Math.round((m / 60) * 10) / 10} h before`);
|
||||
|
||||
/**
|
||||
* "What changed before this?": what the app knows happened in the time before an incident began — a maintenance window ending, a host going down, an update run, a setting changed,
|
||||
* a step in the server's own figures — ranked by how close it was and how related. A list of suspects, not a diagnosis: it says what happened and when, not why.
|
||||
*/
|
||||
export default function WhatChangedBefore({ incidentId, openedAt }: { incidentId: number; openedAt: string }) {
|
||||
const [minutes, setMinutes] = useState(120);
|
||||
const [report, setReport] = useState<BeforeReport | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [showBackground, setShowBackground] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
setReport(null);
|
||||
api.incidents
|
||||
.before(incidentId, minutes)
|
||||
.then((r) => {
|
||||
if (!alive) return;
|
||||
setReport(r);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => alive && setError(readableError(err)));
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [incidentId, minutes]);
|
||||
|
||||
const strong = report?.suspects.filter((s) => s.confidence !== "background") ?? [];
|
||||
const background = report?.suspects.filter((s) => s.confidence === "background") ?? [];
|
||||
const shown = [...strong, ...(showBackground || strong.length === 0 ? background : [])];
|
||||
|
||||
return (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<div>
|
||||
<h3 className="card-title">What changed before this?</h3>
|
||||
<div className="text-secondary small">Before it began, {formatDateTime(new Date(openedAt))}</div>
|
||||
</div>
|
||||
<div className="card-actions">
|
||||
<div className="btn-group btn-group-sm" role="group" aria-label="How far back to look">
|
||||
{RANGES.map((r) => (
|
||||
<button key={r.minutes} type="button" className={`btn ${minutes === r.minutes ? "btn-primary" : "btn-outline-secondary"}`} aria-pressed={minutes === r.minutes} onClick={() => setMinutes(r.minutes)}>
|
||||
{r.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{error && (
|
||||
<div className="card-body">
|
||||
<ErrorNotice error={error} />
|
||||
</div>
|
||||
)}
|
||||
{!report && !error && (
|
||||
<div className="card-body">
|
||||
<BlockSkeleton lines={3} />
|
||||
</div>
|
||||
)}
|
||||
{report && shown.length === 0 && (
|
||||
<div className="card-body text-secondary">
|
||||
Nothing the app knows about changed in the {RANGES.find((r) => r.minutes === report.windowMinutes)?.label ?? `${report.windowMinutes} min`} before this. It looked through {report.looked.auditEntries} recorded{" "}
|
||||
{report.looked.auditEntries === 1 ? "action" : "actions"}, {report.looked.maintenanceWindows} maintenance {report.looked.maintenanceWindows === 1 ? "window" : "windows"}, {report.looked.updateRuns} update{" "}
|
||||
{report.looked.updateRuns === 1 ? "run" : "runs"}, {report.looked.otherAlerts} other {report.looked.otherAlerts === 1 ? "alert" : "alerts"}
|
||||
{report.looked.series > 0 ? ` and ${report.looked.series} of the server's own figures` : ""} — a change made outside the app, such as one on the machine itself, is not something it can see.
|
||||
</div>
|
||||
)}
|
||||
{report && shown.length > 0 && (
|
||||
<div className="list-group list-group-flush">
|
||||
{shown.map((s, i) => (
|
||||
<div className="list-group-item" key={`${s.at}-${i}`}>
|
||||
<div className="d-flex flex-wrap align-items-baseline gap-2">
|
||||
<span className={`badge ${CONFIDENCE[s.confidence].className}`} title={`${CONFIDENCE[s.confidence].title} (score ${s.score})`}>
|
||||
{CONFIDENCE[s.confidence].label}
|
||||
</span>
|
||||
<strong>{s.incidentId ? <Link to={`/incidents/${s.incidentId}`}>{s.title}</Link> : s.link ? <Link to={s.link}>{s.title}</Link> : s.title}</strong>
|
||||
</div>
|
||||
<div className="text-secondary small">
|
||||
{KIND[s.kind]} · {minutesWords(s.minutesBefore)} <span title={formatDateTime(new Date(s.at))}>({formatDateTime(new Date(s.at))})</span>
|
||||
{s.actor && s.actor !== "system" ? ` · ${s.actor}` : ""}
|
||||
</div>
|
||||
{s.detail && <div className="small">{s.detail}</div>}
|
||||
<div className="text-secondary small">
|
||||
{s.why}
|
||||
{s.relation !== "same" && s.relation !== "everything" ? ` · about ${s.about}` : s.relation === "everything" ? " · it touches everything" : ""}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{report && background.length > 0 && strong.length > 0 && (
|
||||
<div className="card-footer">
|
||||
<button type="button" className="btn btn-sm btn-ghost-secondary" onClick={() => setShowBackground((v) => !v)}>
|
||||
{showBackground ? "Hide" : "Show"} {background.length} less likely {background.length === 1 ? "one" : "ones"}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<div className="card-footer text-secondary small">
|
||||
Ranked by how close each was and how related it is to this — the same thing, something it needs (the host it runs on), something that needs it, or a change that touches everything. These are suspects,
|
||||
not a diagnosis: the app can say what happened and when, not why.
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
import { CATEGORY_NAMES, durationWords, incidentPath, SEVERITY_BADGE } from "../components/IncidentHistory";
|
||||
import { useBreadcrumbTail } from "../utils/breadcrumb";
|
||||
import WhatChangedBefore from "../components/WhatChangedBefore";
|
||||
|
||||
const KIND_ICON: Record<TimelineKind, JSX.Element> = {
|
||||
alert: <IconAlertTriangle size={16} />,
|
||||
@@ -193,6 +194,7 @@ export default function IncidentDetail({ user }: { user: CurrentUser }) {
|
||||
|
||||
<div className="row g-3">
|
||||
<div className="col-lg-8">
|
||||
<WhatChangedBefore incidentId={incident.id} openedAt={incident.openedAt} />
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">What happened</h3>
|
||||
|
||||
Reference in new issue
Block a user