feat: complete Loki query, insights, settings and deployment workflows

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.
This commit is contained in:
logan committed 2026-10-25 21:28:32 +08:00
1 parent f9c6c1d826
commit 2d73661dd1
127 files changed
+8117 -2876

No files matched your search

+66
View File
@@ -0,0 +1,66 @@
// 告警域 API — 飞书通知配置 + 告警规则
import { http } from '../http'
export interface NotifyConfig {
enabled: boolean
hasWebhook: boolean
hasSecret: boolean
}
export interface AlertRule {
id: number
name: string
sourceId: number
channelIds: number[]
query: string
windowMin: number
threshold: number
enabled: boolean
cooldownMin: number
lastFiredAt?: string
createdAt?: string
}
export interface AlertDelivery {
id: number
ruleId: number
ruleName: string
count: number
status: 'sent' | 'failed' | 'cooldown'
reason: string
createdAt: string
}
export const alertsApi = {
getNotifyConfig: () => http.get<NotifyConfig>('/alerts/notify-config'),
saveNotifyConfig: (data: { enabled: boolean; webhook?: string; signingSecret?: string }) =>
http.put<{ message: string }>('/alerts/notify-config', data),
testNotifyConfig: () => http.post<{ status: string }>('/alerts/notify-config/test'),
listRules: () => http.get<AlertRule[]>('/alerts/rules'),
createRule: (data: Omit<AlertRule, 'id' | 'lastFiredAt' | 'createdAt'>) =>
http.post<AlertRule>('/alerts/rules', data),
updateRule: (id: number, data: Partial<AlertRule>) =>
http.put<AlertRule>(`/alerts/rules/${id}`, data),
deleteRule: (id: number) => http.delete<{ message: string }>(`/alerts/rules/${id}`),
checkNow: () => http.post<{ message: string }>('/alerts/check'),
deliveries: () => http.get<AlertDelivery[]>('/alerts/deliveries'),
// 通知通道(多 webhook 对应不同告警群)
listChannels: () => http.get<NotifyChannel[]>('/alerts/channels'),
saveChannel: (data: { id?: number; name: string; webhook?: string; signingSecret?: string; enabled: boolean }) =>
http.post<NotifyChannel>('/alerts/channels', data),
updateChannel: (id: number, data: { name: string; webhook?: string; signingSecret?: string; enabled: boolean }) =>
http.put<NotifyChannel>(`/alerts/channels/${id}`, data),
deleteChannel: (id: number) => http.delete<{ message: string }>(`/alerts/channels/${id}`),
testChannel: (data: { id?: number; name?: string; webhook?: string; signingSecret?: string }) =>
http.post<{ status: string }>('/alerts/channels/test', data),
}
export interface NotifyChannel {
id: number
name: string
hasWebhook: boolean
hasSecret: boolean
enabled: boolean
createdAt?: string
}
+10
View File
@@ -14,6 +14,7 @@ export interface ClusterCreateInput {
export type ClusterUpdateInput = Partial<ClusterCreateInput>;
export const clusterApi = {
list: (params: ListParams = {}, options?: RequestOptions) =>
http.get<PageData<Cluster>>(`/clusters${buildQuery(params)}`, options),
@@ -31,4 +32,13 @@ export const clusterApi = {
http.post<{ message: string }>(`/clusters/${id}/validate`),
getInfo: (id: number) => http.get<ClusterInfo>(`/clusters/${id}/info`),
namespaces: (id: number, options?: RequestOptions) =>
http.get<{ namespaces: string[] }>(`/clusters/${id}/namespaces`, options),
deployments: (id: number, namespace: string, options?: RequestOptions) =>
http.get<{ deployments: Array<{ name: string; replicas: number; readyReplicas: number }> }>(
`/clusters/${id}/namespaces/${encodeURIComponent(namespace)}/deployments`, options
),
};
+3
View File
@@ -10,6 +10,9 @@ export const collectorApi = {
create: (data: CreateCollectorRequest) => http.post<Collector>('/collectors', data),
update: (id: number, data: { name: string; logPath: string }) =>
http.put<{ message: string }>(`/collectors/${id}`, data),
remove: (id: number) => http.delete<{ message: string }>(`/collectors/${id}`),
install: (id: number) => http.post<{ message: string }>(`/collectors/${id}/install`),
+6
View File
@@ -21,6 +21,12 @@ export const deploymentApi = {
update: (id: number, data: DeploymentUpdateInput) =>
http.put<{ message: string }>(`/deployments/${id}`, data),
updateRetention: (id: number, yaml: string, apply: boolean) =>
http.post<{ retentionDays: number; applying: boolean }>(`/deployments/${id}/retention`, { yaml, apply }),
liveConfig: (id: number) =>
http.get<{ location: string; yaml: string }>(`/deployments/${id}/config`),
remove: (id: number) => http.delete<{ message: string }>(`/deployments/${id}`),
deploy: (id: number) => http.post<{ message: string }>(`/deployments/${id}/deploy`),
+2
View File
@@ -8,3 +8,5 @@ export * from './storage';
export * from './deployment';
export * from './collector';
export * from './user';
export * from './alerts';
export * from './settings';
+32
View File
@@ -0,0 +1,32 @@
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}`),
}
+17
View File
@@ -0,0 +1,17 @@
// 设置域 API — 镜像源等平台级配置
import { http } from '../http'
export interface ImageRegistryConfig {
mode: 'overseas' | 'cn' | 'custom'
customHost: string
sampleLoki: string
sampleGrafana: string
samplePromtail: string
sampleFluentBit: string
}
export const settingsApi = {
getImageRegistry: () => http.get<ImageRegistryConfig>('/settings/image-registry'),
saveImageRegistry: (data: { mode: string; customHost?: string }) =>
http.put<ImageRegistryConfig>('/settings/image-registry', data),
}
+1
View File
@@ -13,6 +13,7 @@ export interface StorageCreateInput {
pathPrefix?: string;
insecure?: boolean;
isDefault?: boolean;
hasSecretKey?: boolean;
}
export type StorageUpdateInput = Partial<StorageCreateInput>;