Added health metrics for application load and database load (#2257)

* Added health metrics for application load

* Added health metrics for application load

* Fix unit tests

* Added more metrics

* Added few comments

* Added DatabaseLoad Scenario and address comments

* Fix unit tests

* fix unit tests

* Fix unit tests

* fix unit tests

* fix the mock

* Fix unit tests
This commit is contained in:
sunghyunkang1111
2025-12-09 14:14:35 -06:00
committed by GitHub
parent 8c0e6da377
commit 5b7d1a74af
19 changed files with 701 additions and 2 deletions

View File

@@ -0,0 +1,37 @@
/**
* Perform a fetch with an AbortController-based timeout. Returns the Response or throws (including AbortError on timeout).
*
* Usage: await fetchWithTimeout(url, { method: 'GET', headers: {...} }, 10000);
*
* A shared helper to remove duplicated inline implementations across the codebase.
*/
export async function fetchWithTimeout(
url: string,
init: RequestInit = {},
timeoutMs: number = 5000,
): Promise<Response> {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeoutMs);
try {
const response = await fetch(url, { ...init, signal: controller.signal });
return response;
} finally {
clearTimeout(id);
}
}
/**
* Convenience wrapper that returns null instead of throwing on timeout / network error.
* Useful for feature probing scenarios where failure should be treated as absence.
*/
export async function tryFetchWithTimeout(
url: string,
init: RequestInit = {},
timeoutMs: number = 5000,
): Promise<Response | null> {
try {
return await fetchWithTimeout(url, init, timeoutMs);
} catch {
return null;
}
}