mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-12-02 17:13:33 +01:00
feat(admin): errors page built around issues, linked to repositories and users
The admin Errors page now shows one list of issues: records grouped by error code (or exception type), service and route, each with a plain-language title, a likely cause, its impact (failures, repositories, users), a trend and when it was last seen. Expected 4xx answers sit in a collapsed group; slow and interrupted requests are left out and counted, with a link to Performance. - GET /api/admin/errors/issues groups server-side (admin-error-issues.ts). It reads central logs when they answer and the Redis history otherwise, accepts validated repoId/userId/service/window filters and resolves repository owners and user names when the database is connected. - The cause is derived from external_request records of the same requests (#990 field names), fast 429s, storage and network codes, and the first application stack frame; otherwise it says nothing is known. - Issue page (?issue=) with cause, affected repositories and owners, who hit it, failures over time and occurrences. Request view (&occurrence=) with a waterfall from the existing correlation lookup and Request, Exception and All fields tabs; missing data shows as "not recorded". - Repositories (search = one repoId) and user admin pages list their issues, with a "failing now" banner. - The source switch, export, clear history, telemetry and 24-hour counters move to a collapsed "Settings and diagnostics" section. - Synthetic fixtures shared by dev-mock and preview-errors; old errors-page CSS removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c281841f91
commit
2abd6beaa9
21 files changed
+2053
-2323
No files matched your search
@@ -0,0 +1,121 @@
|
||||
// Synthetic admin Errors fixtures, shared by scripts/dev-mock.js and
|
||||
// scripts/preview-errors.js. Generated records only: no production data.
|
||||
// The records have the shape the admin API returns after its projection
|
||||
// (src/server/admin-log-investigation.ts), so the mocks can group them with the
|
||||
// real buildIssues() and answer GET /api/admin/errors/issues like the server.
|
||||
require("ts-node/register/transpile-only");
|
||||
const { buildIssues, filterRows } = require("../../src/server/admin-error-issues");
|
||||
|
||||
const MIN = 60 * 1000;
|
||||
const uuid = (n) => `aaaaaaaa-aaaa-4aaa-8aaa-${String(n).padStart(12, "0")}`;
|
||||
const pick = (list, i) => list[i % list.length];
|
||||
|
||||
/**
|
||||
* @param {object} ids repository IDs and user _ids to attach, so admin links resolve in the mock
|
||||
* @param {number} now reference time (ms)
|
||||
*/
|
||||
function errorFixture({ repos, users, owners = {}, release = "4b2c1e9a7d", previous = "9e1d0a2c55", now = Date.now() }) {
|
||||
const at = (minutesAgo) => new Date(now - minutesAgo * MIN).toISOString();
|
||||
const records = [], external = [], traces = {};
|
||||
let n = 1;
|
||||
const add = (row, trace = []) => { records.push(row); if (row.requestId) traces[row.requestId] = [...trace, row]; return row; };
|
||||
|
||||
// 1. GitHub 502 incident on the file route: failing now, with external_request records (#990).
|
||||
for (let i = 0; i < 46; i++) {
|
||||
const requestId = uuid(n++);
|
||||
const minutesAgo = i < 30 ? i * 2.3 : 75 + i * 4;
|
||||
const repoId = pick(repos.slice(0, 4), i % 7 === 0 ? 3 : i % 3);
|
||||
const signedIn = i % 6 === 0;
|
||||
const end = now - minutesAgo * MIN;
|
||||
const ts = (ms) => new Date(end - 2412 + ms).toISOString();
|
||||
const calls = [0, 1, 2].map((attempt) => ({ timestamp: ts(40 + attempt * 760 + 620), service: "api", module: "external-request", event: "external_request", severity: "info",
|
||||
requestId, upstreamHost: "api.github.com", upstreamMethod: "GET", upstreamEndpoint: "/repos/{owner}/{repo}/contents/*", upstreamStatus: 502, ms: 600 + attempt * 50, release }));
|
||||
external.push(...calls);
|
||||
const base = { service: "api", module: "route", method: "GET", route: "/api/repo/:repoId/file/:path", repoId, requestId, release: i < 30 ? release : previous,
|
||||
requestPath: `/api/repo/${repoId}/file/${pick(["src/model.py", "README.md", "data/cfg.yaml", "eval.py"], i)}`,
|
||||
...(signedIn && owners[repoId] ? { viewer: "owner", userId: owners[repoId] } : { viewer: "visitor" }) };
|
||||
add({ ...base, timestamp: ts(2405), event: "application_log", severity: "error", errorCode: "upstream_error", errorType: "AnonymousError", status: 502 }, [
|
||||
{ timestamp: ts(2412), service: "nginx", module: "proxy", event: "edge_request", severity: "info", status: 502, ms: 2412, requestId, method: "GET", route: base.route, release: "unknown" },
|
||||
...calls,
|
||||
{ ...base, timestamp: ts(2410), event: "request_completed", severity: "info", status: 502, ms: 2398 },
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. A 429 burst: answered from the app's remembered limit state in a few ms. Route names
|
||||
// the GitHub owner, so no repository ID is kept: the "not recorded" state.
|
||||
for (let i = 0; i < 34; i++) {
|
||||
add({ timestamp: at(380 + i * 0.6), service: "api", module: "route", event: "application_log", severity: "warn", errorCode: "github_rate_limit_exceeded",
|
||||
status: 429, method: "GET", route: "/api/repo/:owner/:repo", requestId: uuid(n++), ms: i % 11 === 0 ? 180 : 5 + (i % 9), release: previous });
|
||||
}
|
||||
|
||||
// 3. An internal TypeError with a stack, first seen in the newest release.
|
||||
for (let i = 0; i < 9; i++) {
|
||||
const requestId = uuid(n++);
|
||||
add({ timestamp: at(8 + i * 17), service: "streamer", module: "zip-stream", event: "application_log", severity: "error", errorType: "TypeError",
|
||||
errorStack: "at ZipStream.entry (build/core/zipStream.js:212:31)\nat ZipStream.next (build/core/zipStream.js:188:12)\nat process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
|
||||
causeType: "RangeError", causeStack: "at Archive.readEntry (build/core/archive-entry.js:44:9)",
|
||||
status: 500, method: "GET", route: "/api/repo/:repoId/zip", repoId: repos[1], requestId, requestPath: `/api/repo/${repos[1]}/zip`,
|
||||
viewer: "visitor", ms: 840 + i * 12, release });
|
||||
}
|
||||
|
||||
// 4. Storage failures with a storage external call.
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const requestId = uuid(n++);
|
||||
external.push({ timestamp: at(120 + i * 30), service: "streamer", module: "external-request", event: "external_request", severity: "info", requestId,
|
||||
upstreamHost: "storage", upstreamMethod: "PUT", errorCode: "ECONNRESET", ms: 4100, release: previous });
|
||||
add({ timestamp: at(120 + i * 30), service: "streamer", module: "s3", event: "application_log", severity: "error", errorCode: "storage_write_size_mismatch",
|
||||
status: 500, method: "GET", route: "/api/repo/:repoId/file/:path", repoId: pick([repos[2], repos[0]], i), requestId, viewer: "visitor", ms: 4180, release: previous });
|
||||
}
|
||||
|
||||
// 5. Background job failures carry a job ID, repository and owner.
|
||||
for (let i = 0; i < 4; i++) {
|
||||
add({ timestamp: at(200 + i * 45), service: "worker", module: "queue", event: "job_failed", severity: "error", errorCode: "unable_to_download",
|
||||
queue: "download", jobId: uuid(n++), repoId: repos[3], userId: users[1], attempt: i + 1, ms: 30000, release: previous });
|
||||
}
|
||||
|
||||
// 6. An error with nothing else recorded: no route, no request ID, no stack.
|
||||
for (let i = 0; i < 5; i++) {
|
||||
add({ timestamp: at(900 + i * 40), service: "api", module: "application", event: "application_log", severity: "error", status: 500, errorCode: "server_error", release: "unknown" });
|
||||
}
|
||||
|
||||
// 7. Expected 4xx: visitors asking for something gone or invalid.
|
||||
for (let i = 0; i < 48; i++) {
|
||||
const [code, status] = pick([["file_not_found", 404], ["repository_expired", 410], ["invalid_request", 400], ["repo_not_found", 404]], i);
|
||||
add({ timestamp: at(5 + i * 21), service: "api", module: "route", event: "application_log", severity: i % 3 ? "info" : "warn", errorCode: code, status,
|
||||
method: "GET", route: "/api/repo/:repoId/file/:path", repoId: pick(repos, i), requestId: uuid(n++), viewer: "visitor", release });
|
||||
}
|
||||
|
||||
// 8. Slow and interrupted requests: performance, not errors.
|
||||
for (let i = 0; i < 37; i++) {
|
||||
add({ timestamp: at(3 + i * 30), service: i % 2 ? "streamer" : "api", module: "requests", event: i % 4 ? "request_slow" : "request_cancelled", severity: "warn",
|
||||
status: 200, outcome: i % 4 ? "completed" : "interrupted", method: "GET", route: "/api/repo/:repoId/zip", requestId: uuid(n++), ms: 12000 + i * 100, release });
|
||||
}
|
||||
return { records, external, traces };
|
||||
}
|
||||
|
||||
const WINDOWS = { "15m": 15, "1h": 60, "6h": 360, "24h": 1440 };
|
||||
/** The /api/admin/errors/issues answer for a synthetic scenario. */
|
||||
function issuesResponse(fixture, query, { scenario = "", names = { repos: {}, users: {} }, now = Date.now() } = {}) {
|
||||
const window = WINDOWS[query.window] ? query.window : "24h";
|
||||
const start = new Date(now - WINDOWS[window] * MIN).toISOString(), end = new Date(now).toISOString();
|
||||
const history = query.source === "history" || scenario === "history";
|
||||
const rows = scenario === "empty" ? [] : filterRows(fixture.records, { service: query.service || "", repoId: query.repoId || "", userId: query.userId || "" });
|
||||
const built = buildIssues(history ? rows.filter((row) => row.severity !== "info") : rows, { start, end, external: history ? [] : fixture.external });
|
||||
return { source: history ? "history" : "central", state: rows.length ? "ready" : "empty", centralState: history ? (query.source === "history" ? "skipped" : "disabled") : "ready",
|
||||
grafanaUrl: history ? null : "https://grafana.example.test/d/synthetic", window, start, end,
|
||||
filters: { service: query.service || "", repoId: query.repoId || "", userId: query.userId || "" }, captured: rows.length, redisCollecting: true, ...built, names };
|
||||
}
|
||||
|
||||
/** The /api/admin/errors/correlation answer: every record with the request ID, in time order. */
|
||||
function correlationResponse(fixture, query) {
|
||||
const events = (fixture.traces[query.id] || []).slice().sort((a, b) => Date.parse(a.timestamp) - Date.parse(b.timestamp));
|
||||
return { state: events.length ? "ready" : "empty", source: "victorialogs", events, limit: 200, grafanaUrl: "https://grafana.example.test/d/synthetic?var-request_id=" + query.id };
|
||||
}
|
||||
|
||||
/** Legacy Redis entries ({ ts, level, module, message, raw }) for export and the 24-hour counters. */
|
||||
function historyEntries(fixture) {
|
||||
return fixture.records.filter((row) => row.severity !== "info").map((row) => ({ ts: row.timestamp, level: row.severity, module: row.module,
|
||||
message: row.errorCode || row.errorType || row.event, raw: [row] }));
|
||||
}
|
||||
|
||||
module.exports = { errorFixture, issuesResponse, correlationResponse, historyEntries };
|
||||
Reference in new issue
Block a user