Files
anonymous_github/scripts/preview-errors.js
T
Thomas DurieuxandClaude Opus 5.5 2abd6beaa9 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>
2026-11-29 13:27:48 +00:00

38 lines
3.6 KiB
JavaScript

// Local synthetic fixtures only. No production proxy or credentials.
// Run: PORT=4173 node scripts/preview-errors.js, then open /admin/errors.
// Add ?scenario=empty|offline|loading|history to any page to see the other states.
const express = require('express');
const fs = require('node:fs');
const { setTimeout } = require('node:timers');
const path = require('node:path');
const { errorFixture, issuesResponse, correlationResponse, historyEntries } = require('./fixtures/error-issues');
const app = express();
const root = path.resolve(__dirname, '../public');
const port = Number(process.env.PORT) || 4173;
const oid = n => '65f0c0de' + String(n).padStart(16, '0');
const repos = ['neurips-2026-a91f', 'icse27-replication', 'anon-7c2e0b', 'eval-harness-3d1c'];
const users = [oid(1), oid(2)];
const names = { users: { [oid(1)]: 'alice-l', [oid(2)]: 'tmorris' }, repos: {} };
repos.forEach((repoId, i) => { names.repos[repoId] = { ownerId: users[i % 2], owner: names.users[users[i % 2]], source: ['acme-lab/diffusion-bench', 'tmorris/flaky-tests', 'acme-lab/eval-harness', 'tmorris/eval'][i], status: 'ready' }; });
const fixture = errorFixture({ repos, users, owners: Object.fromEntries(repos.map((repoId, i) => [repoId, users[i % 2]])) });
let historyCleared = false;
app.use('/api', async (req, res) => {
const scenario = new URL(req.headers.referer || 'http://localhost').searchParams.get('scenario') || '';
if (scenario === 'loading') await new Promise(resolve => setTimeout(resolve, 20000));
const now = new Date().toISOString();
if (req.path === '/user') return res.json({ username: 'Synthetic preview', isAdmin: true, status: 'ready' });
if (req.path === '/user/default') return res.json({ options: {}, terms: [] });
if (scenario === 'offline' && req.path.startsWith('/admin/errors')) return res.status(503).json({});
if (req.path === '/admin/errors/issues') return res.json(issuesResponse(fixture, req.query, { scenario, names }));
if (req.path === '/admin/errors/correlation') return res.json(correlationResponse(fixture, req.query));
if (req.path === '/admin/errors/investigation') return res.json({ state: 'ready', window: req.query.window || '1h', groups: [], telemetry: { missing: [], instances: [{ service: 'api', instance: 'synthetic-api', last: now, dropped: 0 }], collector: { state: 'reachable', dropped: 0 } } });
if (req.path === '/admin/errors/stats') return res.json({ available: true, last24h: 34, prev24h: 20, severity: { error: 29, warn: 5, info: 0 }, unique: { error: 3, warn: 1, info: 0 }, buckets: [], dropped: 0 });
if (req.path === '/admin/errors' && req.method === 'DELETE') { historyCleared = true; return res.json({ ok: true }); }
if (req.path === '/admin/errors') { const entries = historyCleared ? [] : historyEntries(fixture); return res.json({ available: true, redisCollecting: true, total: entries.length, max: 5000, entries }); }
return res.json([]);
});
app.use((req, res, next) => { req.url = req.url.replace(/\.[a-f0-9]{10}\.min\./, '.min.'); next(); });
app.use(express.static(root, { index: false }));
app.get('/{*path}', (req, res) => res.type('html').send(fs.readFileSync(path.join(root, 'index.html'), 'utf8').replace(/__([A-Z]+)_JS__/g, (_, name) => `${name.toLowerCase()}.min.js`).replace('__ALL_CSS__', 'all.min.css').replace('<body ', '<body data-synthetic-preview="true" ').replace('<div id="app"', '<div style="padding:6px 16px;background:#fff3cd;color:#493800;text-align:center;font:13px sans-serif">Synthetic preview · generated fixtures only · no production connection</div><div id="app"')));
app.listen(port, '127.0.0.1', () => console.log(`Synthetic Errors preview: http://localhost:${port}/admin/errors`));