// 日志中心 API — 无状态代理查询,平台不落库海量日志 // Logan.Li import { http, type ListResponse } from '@/utils/request'; export interface LogDataSource { id: number; name: string; type: 'loki' | 'elasticsearch'; url: string; auth_type?: 'none' | 'basic' | 'bearer' | 'custom'; basic_auth?: boolean; basic_auth_user?: string; basic_auth_pass?: string; token?: string; headers?: string; // JSON 字符串,如 [{"name":"X-Scope-OrgID","value":"tenant-1"}] 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; raw?: string; } /** 数据源连接测试结果 // Logan.Li */ export interface TestConnectionResult { status: 'ok' | 'failed'; error?: string; } export const logCenterApi = { listDatasources: (type?: string) => http.get>('/log-datasources', type ? { type } : undefined), createDatasource: (data: Record) => http.post('/log-datasources', data), updateDatasource: (id: number | string, data: Record) => 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) => http.post('/log-datasources/test', data), /** 通过代理查询 ES 集群索引列表 // Logan.Li */ listIndices: (params: Record) => http.get('/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; size?: number; start?: string; end?: string; }) => http.post<{ entries: LogQueryEntry[]; total: number }>('/logs/elasticsearch/query', data), };