fix(api): share one probe-target resolution between both proxy health checks (#10657)

Merged — locally validated (15/15 focused tests, typecheck:core clean, file-size/changelog gates green) after resolving base-drift against #10654 (both landed today, same file — combined import block, no logical conflict). Thanks!
This commit is contained in:
Dizzle
2026-08-20 15:32:38 +02:00
committed by GitHub
parent b43ad73166
commit f4772500bc
6 changed files with 289 additions and 11 deletions

View File

@@ -6,14 +6,20 @@ import { createProxyDispatcher, proxyConfigToUrl } from "@omniroute/open-sse/uti
import { fetch as undiciFetch } from "undici";
import { classifyProbeStatus } from "@/lib/proxyHealth/decision";
import { resolveHealthCheckStatusWrite } from "@/lib/proxyHealth/statusPolicy";
import {
resolveProbeConcurrency,
resolveProbeStaggerMs,
resolveProbeTarget,
waitForProbeSlot,
} from "@/lib/proxyHealth/probeTarget";
import { isValidationFailure, validateBody } from "@/shared/validation/helpers";
import { createErrorResponse } from "@/lib/api/errorResponse";
const TEST_TIMEOUT_MS = 5000;
// Reachability probe target. Configurable so operators can point it at an
// internal/self-hosted endpoint instead of the public default.
const TEST_URL = process.env.PROXY_HEALTH_TEST_URL || "https://httpbin.org/ip";
const CONCURRENCY = 10;
// Shared with the background sweep — see src/lib/proxyHealth/probeTarget.ts.
const TEST_URL = resolveProbeTarget();
const CONCURRENCY = resolveProbeConcurrency();
const STAGGER_MS = resolveProbeStaggerMs();
const autoTestSchema = z.object({
ids: z.array(z.string()).optional(),
@@ -149,7 +155,14 @@ export async function POST(request: Request) {
const results: TestResult[] = [];
for (let i = 0; i < proxiesToTest.length; i += CONCURRENCY) {
const batch = proxiesToTest.slice(i, i + CONCURRENCY);
const batchResults = await Promise.allSettled(batch.map((proxy) => testSingleProxy(proxy)));
const batchResults = await Promise.allSettled(
batch.map(async (proxy, indexInBatch) => {
// Same intra-batch spacing as the background sweep: "Test All" fires the whole
// batch at once too, so it is just as capable of tripping a rate-limited target.
await waitForProbeSlot(indexInBatch, STAGGER_MS);
return testSingleProxy(proxy);
})
);
for (const result of batchResults) {
if (result.status === "fulfilled") results.push(result.value);
}