Add the Loki query UI, access policies, ingress insights, alert and registry settings, and their backend APIs. Include the related Kubernetes deployment and collector updates required by the integrated application. Validated with go test ./..., npm run build, and npm run lint.
33 lines
2.9 KiB
TypeScript
33 lines
2.9 KiB
TypeScript
import { http, buildQuery } from '../http'
|
|
import type { PageData } from '@/types'
|
|
|
|
export interface LogSourceAccess { userId: number; labels: Record<string, string> }
|
|
export interface LogPolicyGroup { id: number; name: string; sourceId: number; labels: Record<string, string>; userIds: number[]; createdAt?: string; updatedAt?: string }
|
|
export interface LogSource {
|
|
id: number; name: string; targetType: 'url' | 'cluster-svc'; clusterID?: number
|
|
namespace: string; service: string; port: number; url: string
|
|
authType: string; basicUser: string; hasBasicPass?: boolean
|
|
headers?: Record<string, string>; headerNames?: string[]; skipTLSVerify?: boolean; hasBearerToken?: boolean
|
|
isDefault: boolean; managed?: boolean; access?: LogSourceAccess[]
|
|
}
|
|
export interface LogEntry { timestamp: string; timestampNs: string; level: string; message: string; labels: Record<string, string> }
|
|
export interface HistogramBucket { timestamp: string; count: number }
|
|
export interface LogResult { entries: LogEntry[]; hasMore: boolean; nextCursor: string }
|
|
export interface LogQuery { sourceId: number; query: string; start: number; end: number; limit?: number; direction?: 'backward' | 'forward'; cursor?: string }
|
|
export const logsApi = {
|
|
sources: () => http.get<PageData<LogSource>>('/logs/sources'),
|
|
createSource: (source: Partial<LogSource> & { basicPass?: string; bearerToken?: string }) => http.post<LogSource>('/logs/sources', source),
|
|
updateSource: (id: number, data: Partial<LogSource>) => http.put(`/logs/sources/${id}`, data),
|
|
deleteSource: (id: number) => http.delete(`/logs/sources/${id}`),
|
|
testSource: (data: Partial<LogSource>) => http.post<{ success: boolean; message: string }>('/logs/sources/test', data),
|
|
query: (data: LogQuery) => http.post<LogResult>('/logs/query', data, { timeout: 125000 }),
|
|
context: (data: { sourceId: number; timestampNs: string; labels: Record<string, string> }) => http.post<{ before: LogEntry[]; after: LogEntry[] }>('/logs/context', data),
|
|
histogram: (data: LogQuery) => http.post<Array<Record<string, unknown>>>('/logs/histogram', data, { timeout: 125000 }),
|
|
labels: (sourceId: number, start?: number, end?: number) => http.get<string[]>(`/logs/labels${buildQuery({ sourceId, start, end } as { page?: number; pageSize?: number })}`),
|
|
labelValues: (sourceId: number, name: string, query = '', start?: number, end?: number) => http.get<string[]>(`/logs/label/${encodeURIComponent(name)}/values${buildQuery({ sourceId, query, start, end } as { page?: number; pageSize?: number })}`),
|
|
policyGroups: () => http.get<LogPolicyGroup[]>('/logs/policy-groups'),
|
|
createPolicyGroup: (data: Omit<LogPolicyGroup, 'id'>) => http.post<LogPolicyGroup>('/logs/policy-groups', data),
|
|
updatePolicyGroup: (id: number, data: Omit<LogPolicyGroup, 'id'>) => http.put<LogPolicyGroup>(`/logs/policy-groups/${id}`, data),
|
|
deletePolicyGroup: (id: number) => http.delete(`/logs/policy-groups/${id}`),
|
|
}
|