Files
aiops/frontend/src/api/monitor/log-center.ts
T
attacker a04d815efe fix(log): ES 7.2.0 time format .SSSZ + index dropdown + demo always visible
- ES query 502 fix: remove +00:00 conversion, use native .SSSZ format
  (ES 7.2.0 date_time = strict_date_optional_time only, rejects +00:00/epoch)
- parseLogTime: use time.RFC3339Nano for fractional seconds
- new API GET /log-datasources/indices to list ES indices via proxy
- LogDatasourceDialog: add '获取索引' button + Select dropdown for ES
- LogDatasourcePage: always show demo sources alongside real ones
2026-06-27 09:45:21 +00:00

57 lines
1.9 KiB
TypeScript

// 日志中心 API — 无状态代理查询,平台不落库海量日志 // Logan.Li
import { http } from '@/utils/request';
export interface LogDataSource {
id: number;
name: string;
type: 'loki' | 'elasticsearch';
url: string;
basic_auth?: boolean;
basic_auth_user?: string;
basic_auth_pass?: string;
skip_tls_verify?: boolean;
default_index?: string;
is_default?: boolean;
status?: number;
}
/** 查询结果行 — 仅用于当前页展示,不持久化 // Logan.Li */
export interface LogQueryEntry {
timestamp: string;
level?: string;
message: string;
labels?: Record<string, string>;
raw?: string;
}
export const logCenterApi = {
listDatasources: (type?: string) =>
http.get<LogDataSource[]>('/log-datasources', type ? { type } : undefined),
createDatasource: (data: Record<string, unknown>) => http.post('/log-datasources', data),
updateDatasource: (id: number | string, data: Record<string, unknown>) =>
http.put(`/log-datasources/${id}`, data),
deleteDatasource: (id: number | string) => http.delete(`/log-datasources/${id}`),
setDefaultDatasource: (id: number | string) => http.post(`/log-datasources/${id}/default`),
testDatasource: (data: Record<string, unknown>) => http.post('/log-datasources/test', data),
/** 通过代理查询 ES 集群索引列表 // Logan.Li */
listIndices: (params: Record<string, string>) =>
http.get<string[]>('/log-datasources/indices', params),
queryLoki: (data: {
datasource_id: number;
query: string;
limit?: number;
start?: string;
end?: string;
direction?: string;
}) => http.post<{ entries: LogQueryEntry[]; total: number }>('/logs/loki/query', data),
queryElasticsearch: (data: {
datasource_id: number;
index?: string;
query?: string;
query_body?: Record<string, unknown>;
size?: number;
start?: string;
end?: string;
}) => http.post<{ entries: LogQueryEntry[]; total: number }>('/logs/elasticsearch/query', data),
};