mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-28 21:32:05 +00:00
* 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
29 lines
1.2 KiB
TypeScript
29 lines
1.2 KiB
TypeScript
// Metrics module: scenario metric emission logic.
|
|
import { MetricEvent, MetricScenario } from "Metrics/Constants";
|
|
import { createUri } from "../Common/UrlUtility";
|
|
import { configContext, Platform } from "../ConfigContext";
|
|
import { ApiType } from "../UserContext";
|
|
import { getAuthorizationHeader } from "../Utils/AuthorizationUtils";
|
|
import { fetchWithTimeout } from "../Utils/FetchWithTimeout";
|
|
|
|
const RELATIVE_PATH = "/api/dataexplorer/metrics/health"; // Endpoint retains 'health' for backend compatibility.
|
|
|
|
export const reportHealthy = (scenario: MetricScenario, platform: Platform, api: ApiType): Promise<Response> =>
|
|
send({ platform, api, scenario, healthy: true });
|
|
|
|
export const reportUnhealthy = (scenario: MetricScenario, platform: Platform, api: ApiType): Promise<Response> =>
|
|
send({ platform, api, scenario, healthy: false });
|
|
|
|
const send = async (event: MetricEvent): Promise<Response> => {
|
|
const url = createUri(configContext?.PORTAL_BACKEND_ENDPOINT, RELATIVE_PATH);
|
|
const authHeader = getAuthorizationHeader();
|
|
|
|
return await fetchWithTimeout(url, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json", [authHeader.header]: authHeader.token },
|
|
body: JSON.stringify(event),
|
|
});
|
|
};
|
|
|
|
export default MetricScenario;
|