-
Notifications
You must be signed in to change notification settings - Fork 389
Expand file tree
/
Copy pathapi.ts
More file actions
153 lines (137 loc) · 3.97 KB
/
Copy pathapi.ts
File metadata and controls
153 lines (137 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
export type MetricValue = {
current: number | null;
baseline: number | null;
regression_pct: number | null;
absolute_delta: number | null;
threshold_percent: number;
threshold_absolute: number;
gated: boolean;
threshold_exceeded: boolean;
regressed: boolean;
label: string;
lower_is_better: boolean;
precision: number;
};
export type CohortValue = string | number | null;
export type ComparisonCohort = {
workload_id: CohortValue;
variant_id: CohortValue;
benchmark_version: CohortValue;
recipe_fingerprint: CohortValue;
hardware_profile_id: CohortValue;
software_profile_id: CohortValue;
};
export type CohortKind = "v2" | "legacy_v1" | "invalid_v2";
export type DashboardRecordMetadata = {
cohort_kind: CohortKind;
result_schema_version: CohortValue;
baseline_status: string;
comparison_status: string;
comparison_status_reason: string;
};
export type SummaryRow = {
model_id: string;
gpu_type: string;
timestamp: string | null;
commit_sha: string | null;
success: boolean;
baseline_n: number;
worst_regression_pct: number | null;
threshold_exceeded_metrics: string[];
failing_metrics: string[];
computed_regression_status: "pass" | "fail";
status: "pass" | "fail";
run_source: RunSource;
baseline_eligible: boolean;
branch: string;
pr_number: string;
test_scope: string;
build_url: string;
build_id: string;
job_id: string;
metrics: Record<string, MetricValue>;
} & ComparisonCohort & DashboardRecordMetadata;
export type RunSource = "pr" | "local" | "scheduled_main" | "unknown";
export type SummaryResponse = {
rows: SummaryRow[];
count: number;
status_counts: {
pass: number;
fail: number;
};
filters: {
days: number | null;
trend_window_days?: number;
model_id: string | null;
gpu_type: string | null;
run_source: string | null;
};
sync: SyncState;
};
export type TrendPoint = {
timestamp: string | null;
commit_sha: string | null;
success: boolean;
run_source: RunSource;
baseline_eligible: boolean;
branch: string;
pr_number: string;
test_scope: string;
build_url: string;
build_id: string;
job_id: string;
metrics: Record<string, number | null>;
} & ComparisonCohort & DashboardRecordMetadata;
export type TrendGroup = {
model_id: string;
gpu_type: string;
points: TrendPoint[];
} & ComparisonCohort & DashboardRecordMetadata;
export type TrendsResponse = {
groups: TrendGroup[];
count: number;
sync: SyncState;
};
export type SyncState = {
ok: boolean;
repo_id: string;
tracking_root: string;
last_sync_at: string | null;
last_sync_error: string | null;
};
const jsonHeaders = {
Accept: "application/json"
};
function params(values: Record<string, string | number | null | undefined>) {
const out = new URLSearchParams();
for (const [key, value] of Object.entries(values)) {
if (value !== null && value !== undefined && value !== "") {
out.set(key, String(value));
}
}
return out.toString();
}
async function getJson<T>(path: string): Promise<T> {
const response = await fetch(path, { headers: jsonHeaders });
if (!response.ok) {
throw new Error(`${response.status} ${response.statusText}`);
}
return response.json() as Promise<T>;
}
export async function fetchSummary(days = 90, modelId?: string, gpuType?: string, runSource?: string) {
return getJson<SummaryResponse>(
`/api/performance/summary?${params({ days, model_id: modelId, gpu_type: gpuType, run_source: runSource })}`
);
}
export async function fetchTrends(days = 90, modelId?: string, gpuType?: string, runSource?: string) {
return getJson<TrendsResponse>(
`/api/performance/trends?${params({ days, model_id: modelId, gpu_type: gpuType, run_source: runSource })}`
);
}
export async function refreshData() {
const response = await fetch("/api/performance/refresh", { method: "POST", headers: jsonHeaders });
if (!response.ok) {
throw new Error(`${response.status} ${response.statusText}`);
}
return response.json() as Promise<SyncState>;
}