Enhance API and UI for incident management and live updates
- Added a new endpoint `/api/agg/incidents` to provide a normalized snapshot of incidents for fleet triage, including severity and recommended actions. - Implemented live event streaming via `/api/live/events` for real-time updates on fleet status and incidents, enhancing observability. - Updated the Web UI to include dedicated sections for incidents and live updates, improving user navigation and access to critical information. - Enhanced API documentation to reflect new endpoints and their functionalities, ensuring clarity for developers and users.
This commit is contained in:
@@ -20,6 +20,37 @@ export type AggEnvelope<T> = {
|
||||
data: T;
|
||||
};
|
||||
|
||||
export type IncidentSeverity = 'info' | 'warning' | 'critical';
|
||||
|
||||
export type IncidentStatus = 'firing';
|
||||
|
||||
export type IncidentAction = {
|
||||
label: string;
|
||||
href: string;
|
||||
};
|
||||
|
||||
export type IncidentItem = {
|
||||
id: string;
|
||||
kind: string;
|
||||
severity: IncidentSeverity;
|
||||
status: IncidentStatus;
|
||||
title: string;
|
||||
summary: string;
|
||||
affected_aliases?: string[];
|
||||
metric_name?: string;
|
||||
metric_value?: number;
|
||||
metric_threshold?: number;
|
||||
actions?: IncidentAction[];
|
||||
};
|
||||
|
||||
export type IncidentsData = {
|
||||
items: IncidentItem[];
|
||||
total: number;
|
||||
critical_total: number;
|
||||
warning_total: number;
|
||||
info_total: number;
|
||||
};
|
||||
|
||||
export class ApiError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
@@ -120,6 +151,23 @@ export async function fetchAggUser(
|
||||
return body as AggEnvelope<components['schemas']['UsersRow']>;
|
||||
}
|
||||
|
||||
export async function fetchAggIncidents(params?: { aliases?: string }): Promise<AggEnvelope<IncidentsData>> {
|
||||
const q = new URLSearchParams();
|
||||
if (params?.aliases) q.set('aliases', params.aliases);
|
||||
const url = `${gatewayBase()}/api/agg/incidents${q.toString() ? `?${q}` : ''}`;
|
||||
const res = await fetch(url);
|
||||
const body = (await parseJson(res)) as Record<string, unknown> | null;
|
||||
if (!res.ok) throw new ApiError(`incidents HTTP ${res.status}`, res.status, body);
|
||||
if (!body || body.ok !== true) throw new ApiError('incidents: ok !== true', res.status, body);
|
||||
return body as AggEnvelope<IncidentsData>;
|
||||
}
|
||||
|
||||
export function liveEventsUrl(params?: { aliases?: string }): string {
|
||||
const q = new URLSearchParams();
|
||||
if (params?.aliases) q.set('aliases', params.aliases);
|
||||
return `${gatewayBase()}/api/live/events${q.toString() ? `?${q}` : ''}`;
|
||||
}
|
||||
|
||||
/** Путь к upstream без префикса /v1 — шлюз сам добавляет path_prefix. */
|
||||
function apiUrl(alias: string, path: string): string {
|
||||
const p = path.replace(/^\/+/, '');
|
||||
|
||||
Reference in New Issue
Block a user