Files
cosmos-explorer/src/Metrics/ScenarioConfig.ts
sunghyunkang1111 5b7d1a74af 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
2025-12-09 14:14:35 -06:00

48 lines
1.6 KiB
TypeScript

import MetricScenario from "./MetricEvents";
// Common phases shared across all scenarios
export enum CommonMetricPhase {
Interactive = "Interactive",
}
// Application-specific phases
export enum ApplicationMetricPhase {
ExplorerInitialized = "ExplorerInitialized",
DatabasesFetched = "DatabasesFetched",
DatabaseTreeRendered = "DatabaseTreeRendered",
}
// Combined type for all metric phases
export type MetricPhase = CommonMetricPhase | ApplicationMetricPhase;
export interface WebVitals {
lcp?: number; // Largest Contentful Paint
inp?: number; // Interaction to Next Paint
cls?: number; // Cumulative Layout Shift
fcp?: number; // First Contentful Paint
ttfb?: number; // Time to First Byte
}
export interface ScenarioConfig<TPhase extends string = MetricPhase> {
requiredPhases: TPhase[];
timeoutMs: number;
validate?: (ctx: ScenarioContextSnapshot<TPhase>) => boolean; // Optional custom validation
}
export interface PhaseTimings {
endTimeISO: string; // When the phase completed
durationMs: number; // Duration from scenario start to phase completion
}
export interface ScenarioContextSnapshot<TPhase extends string = MetricPhase> {
scenario: MetricScenario;
startTimeISO: string; // Human-readable ISO timestamp
endTimeISO: string; // Human-readable end timestamp
durationMs: number; // Total scenario duration from start to end
completed: TPhase[]; // Array for JSON serialization
failedPhases?: TPhase[]; // Phases that failed
timedOut: boolean;
vitals?: WebVitals;
phaseTimings?: Record<string, PhaseTimings>; // Start/end times for each phase
}