fix: rate limiting breaking smoke tests and backup routes 404 when disabled

- Exempt /healthz and /health from rate limiter
- Increase rate limit from 500 to 2000 req/min
- Register backup routes even when disabled (status shows disabled)
- Guard restore endpoints with 503 when backup not configured
- Add retry with backoff on 429 in audit smoke tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Michal
2026-03-08 13:32:17 +00:00
parent af9f7458fc
commit 225e0dddfc
5 changed files with 41 additions and 20 deletions

View File

@@ -65,24 +65,32 @@ interface AuditSessionResult {
total: number;
}
/** Fetch JSON from mcpd REST API (with auth from credentials). */
function mcpdGet<T>(path: string): Promise<T> {
return new Promise((resolve, reject) => {
const url = new URL(path, MCPD_EFFECTIVE_URL);
const headers: Record<string, string> = { 'Accept': 'application/json' };
if (MCPD_CREDS.token) headers['Authorization'] = `Bearer ${MCPD_CREDS.token}`;
http.get(url, { timeout: 10_000, headers }, (res) => {
const chunks: Buffer[] = [];
res.on('data', (chunk: Buffer) => chunks.push(chunk));
res.on('end', () => {
try {
resolve(JSON.parse(Buffer.concat(chunks).toString('utf-8')) as T);
} catch (err) {
reject(err);
}
});
}).on('error', reject);
});
/** Fetch JSON from mcpd REST API (with auth from credentials). Retries on rate limit. */
async function mcpdGet<T>(path: string, retries = 3): Promise<T> {
for (let attempt = 0; attempt <= retries; attempt++) {
const result = await new Promise<{ status: number; body: T }>((resolve, reject) => {
const url = new URL(path, MCPD_EFFECTIVE_URL);
const headers: Record<string, string> = { 'Accept': 'application/json' };
if (MCPD_CREDS.token) headers['Authorization'] = `Bearer ${MCPD_CREDS.token}`;
http.get(url, { timeout: 10_000, headers }, (res) => {
const chunks: Buffer[] = [];
res.on('data', (chunk: Buffer) => chunks.push(chunk));
res.on('end', () => {
try {
resolve({ status: res.statusCode ?? 0, body: JSON.parse(Buffer.concat(chunks).toString('utf-8')) as T });
} catch (err) {
reject(err);
}
});
}).on('error', reject);
});
if (result.status === 429 && attempt < retries) {
await new Promise((r) => setTimeout(r, 2_000 * (attempt + 1)));
continue;
}
return result.body;
}
throw new Error('mcpdGet: max retries exceeded');
}
/** Query audit events from mcpd. */