fix(health check): better logging, decrease request timeouts

This commit is contained in:
WebStreamr 2025-07-24 08:18:46 +00:00
parent cc3dacdd76
commit 9a8e6f9c69
No known key found for this signature in database

View file

@ -4,7 +4,7 @@ import { ProxyAgent, setGlobalDispatcher } from 'undici';
import { v4 as uuidv4 } from 'uuid';
import winston from 'winston';
import { ConfigureController, ManifestController, StreamController } from './controller';
import { BlockedError } from './error';
import { BlockedError, logErrorAndReturnNiceString } from './error';
import { createExtractors, ExtractorRegistry } from './extractor';
import { createSources } from './source';
import { contextFromRequestAndResponse, envGet, envIsProd, Fetcher, isHaydukInstance, StreamResolver } from './utils';
@ -76,14 +76,15 @@ addon.get('/health', async (req: Request, res: Response) => {
const fetchPromises = urls.map(async (url) => {
try {
await fetcher.head(ctx, url, { noCache: true });
await fetcher.head(ctx, url, { noCache: true, timeout: 5000 });
} catch (error) {
if (error instanceof BlockedError) {
blockedCount++;
} else {
logger.error(`health check error: ${JSON.stringify(error)}`, ctx);
errorCount++;
}
logErrorAndReturnNiceString(ctx, logger, url.href, error);
}
});
await Promise.all(fetchPromises);