Fix transient health checks and avoid unnecessary recovery
This commit is contained in:
@@ -320,7 +320,7 @@ const HEALTHY_STATES = new Set(['running', 'healthy', 'ok', 'started', 'up']);
|
||||
async function fetchJsonWithSnippet(
|
||||
path: string,
|
||||
body: Record<string, string>
|
||||
): Promise<{ ok: true; json: unknown; snippet: string } | { ok: false; reason: string; snippet?: string }> {
|
||||
): Promise<{ ok: true; json: unknown; snippet: string } | { ok: false; reason: string; snippet?: string; unsupportedEndpoint?: boolean }> {
|
||||
const url = `${config.komodo.address.replace(/\/+$/, '')}/${path}`;
|
||||
let res: Response;
|
||||
try {
|
||||
@@ -330,7 +330,11 @@ async function fetchJsonWithSnippet(
|
||||
}
|
||||
const text = await res.text().catch(() => '');
|
||||
if (!res.ok) {
|
||||
return { ok: false, reason: `HTTP ${res.status}`, snippet: truncate(text) };
|
||||
const unsupportedEndpoint = res.status === 404 || (
|
||||
[400, 405, 422, 500, 501].includes(res.status)
|
||||
&& /\b(?:unknown|unsupported|unrecognized)\s+(?:method|endpoint|variant)\b|\bmethod not found\b/i.test(text)
|
||||
);
|
||||
return { ok: false, reason: `HTTP ${res.status}`, snippet: truncate(text), unsupportedEndpoint };
|
||||
}
|
||||
let json: unknown;
|
||||
try {
|
||||
@@ -382,9 +386,10 @@ export async function komodoInspectHealthy(serverName: string): Promise<KomodoHe
|
||||
for (const { path, body } of attempts) {
|
||||
const r = await fetchJsonWithSnippet(path, body);
|
||||
if (!r.ok) {
|
||||
// Alternate endpoints handle API-version differences. Retrying an
|
||||
// outage against every endpoint delays all other server probes.
|
||||
if (!r.unsupportedEndpoint) return { ok: false, reason: r.reason, snippet: r.snippet };
|
||||
lastSnippet = r.snippet ?? lastSnippet;
|
||||
// Try the next endpoint on 404s or unknown-method-shaped errors; a
|
||||
// real error (auth, timeout) will fail every attempt anyway.
|
||||
continue;
|
||||
}
|
||||
const state = extractContainerState(r.json);
|
||||
|
||||
Reference in New Issue
Block a user