Files
Zhero & Rin 4528a55e6a feat(reconciliation): 实现导入对账后端
为什么:T6a 需要一张批次/差异表、全量只读扫描、R1-R8 判定和 finding 级处置;现有解析监控只转述台账状态,无法回答库内是否一致。
做什么:迁移 000084(upload_md5、runs/findings/actions、共享 removal_candidates 视图);WeKnora 字段与 1000/页扫描;runtime 只读客户端(0400 Key、503 降级);扫描/矩阵/动作/定时/僵死回收;9 条接口与 RBAC;overview 队列与删两张常量卡。
边界:只对测试库;对账零写请求;R1/R2 单条确认;R6 复用 /removal;R2 只管理员;生产链路未改。
验证:make verify 全绿(17 项);新增矩阵/扫描 R1-R8/零写/失败整批/动作/运行时/密钥权限测试。
2026-12-01 12:19:54 +08:00

159 lines
6.1 KiB
Go

package governance
import "time"
type MonitorHost struct {
CPUPercent float64 `json:"cpu_percent"`
MemoryUsedBytes int64 `json:"memory_used_bytes"`
MemoryTotalBytes int64 `json:"memory_total_bytes"`
DiskUsedBytes int64 `json:"disk_used_bytes"`
DiskTotalBytes int64 `json:"disk_total_bytes"`
GPUState string `json:"gpu_state"`
GPUDetail string `json:"gpu_detail"`
Simulated bool `json:"simulated"`
}
type MonitorService struct {
Key string `json:"key"`
Name string `json:"name"`
State string `json:"state"`
Detail string `json:"detail"`
LatencyMS int `json:"latency_ms"`
ObservedAt time.Time `json:"observed_at"`
Simulated bool `json:"simulated"`
}
// ServiceHealth (P10) separates "process reachable" (Liveness) from "can
// accept work" (Readiness). not_configured and not_applicable are explicit and
// never collapse into unknown.
type ServiceHealth struct {
Key string `json:"key"`
Name string `json:"name"`
Liveness string `json:"liveness"`
Readiness string `json:"readiness"`
Reason string `json:"reason"`
LatencyMS int64 `json:"latency_ms"`
ObservedAt time.Time `json:"observed_at"`
LastSuccessAt *time.Time `json:"last_success_at"`
ConsecutiveFailures int `json:"consecutive_failures"`
// ProbeTarget names the object being probed (instance + short binding id),
// never credentials or full UUIDs, so a red light can be attributed.
ProbeTarget string `json:"probe_target"`
Configured bool `json:"configured"`
Applicable bool `json:"applicable"`
}
type KnowledgeBaseProgress struct {
ID string `json:"id"`
Name string `json:"name"`
Visibility string `json:"visibility"`
Imported int `json:"imported"`
Completed int `json:"completed"`
Pending int `json:"pending"`
Processing int `json:"processing"`
Finalizing int `json:"finalizing"`
Failed int `json:"failed"`
Cancelled int `json:"cancelled"`
Planned int `json:"planned"`
NeedsRemoval int `json:"needs_removal"`
StalePlanned int `json:"stale_planned"`
InternalImported int `json:"internal_imported"`
InternalCompleted int `json:"internal_completed"`
ExternalImported int `json:"external_imported"`
ExternalCompleted int `json:"external_completed"`
}
// IngestionPipeline summarizes the artifact-fetch lane that sits in front of
// 待入库 so operators can see why planned items are not uploadable yet.
type IngestionPipeline struct {
FetchPending int `json:"fetch_pending"`
FetchFailed int `json:"fetch_failed"`
FetchMissing int `json:"fetch_missing"`
Concurrency int `json:"concurrency"`
}
// JobWindowMetrics reports a frozen statistical window; insufficient samples
// stay null and are never rendered as 0.
type JobWindowMetrics struct {
WindowSeconds int `json:"window_seconds"`
JobsStarted int `json:"jobs_started"`
JobsCompleted int `json:"jobs_completed"`
JobsFailed int `json:"jobs_failed"`
SuccessRate *float64 `json:"success_rate"`
FailureRate *float64 `json:"failure_rate"`
DurationAvgSeconds *float64 `json:"duration_avg_seconds"`
DurationP50Seconds *float64 `json:"duration_p50_seconds"`
DurationP95Seconds *float64 `json:"duration_p95_seconds"`
}
type QueueGauges struct {
Pending int `json:"pending"`
Running int `json:"running"`
Retry int `json:"retry"`
Failed int `json:"failed"`
OldestPendingAgeSeconds *float64 `json:"oldest_pending_age_seconds"`
}
type RunMetrics struct {
ObservedAt time.Time `json:"observed_at"`
ActiveWorkers int `json:"active_workers"`
WorkerSource string `json:"worker_source"`
Queue QueueGauges `json:"queue"`
ShortWindow JobWindowMetrics `json:"short_window"`
LongWindow JobWindowMetrics `json:"long_window"`
}
type MonitorOverview struct {
Mode string `json:"mode"`
Simulated bool `json:"simulated"`
ObservedAt time.Time `json:"observed_at"`
Host MonitorHost `json:"host"`
Services []MonitorService `json:"services"`
KnowledgeBases []KnowledgeBaseProgress `json:"knowledge_bases"`
Pipeline IngestionPipeline `json:"pipeline"`
Health []ServiceHealth `json:"health"`
// WeKnoraQueues is a safe projection of the test instance runtime queues.
// nil means "not configured or unreadable", never "healthy empty".
WeKnoraQueues *WeKnoraQueueSummary `json:"weknora_queues"`
}
// WeKnoraQueueSummary is the bounded queue projection the console may show.
// It deliberately excludes worker addresses, model endpoints and task payloads.
type WeKnoraQueueSummary struct {
Available bool `json:"available"`
QueuesError bool `json:"queues_error"`
WorkersError bool `json:"workers_error"`
Queues []WeKnoraQueue `json:"queues"`
Timestamp int64 `json:"timestamp"`
}
type WeKnoraQueue struct {
Name string `json:"name"`
Pool string `json:"pool"`
Pending int `json:"pending"`
Active int `json:"active"`
Scheduled int `json:"scheduled"`
Retry int `json:"retry"`
Archived int `json:"archived"`
Processed int `json:"processed"`
Failed int `json:"failed"`
}
type KnowledgeMonitorFile struct {
Name string `json:"name"`
Directory string `json:"directory"`
Visibility string `json:"visibility"`
Status string `json:"status"`
StageDetail string `json:"stage_detail"`
ElapsedSecond int `json:"elapsed_seconds"`
ErrorCode string `json:"error_code"`
}
type KnowledgeMonitorFilePage struct {
Items []KnowledgeMonitorFile `json:"items"`
Total int `json:"total"`
Limit int `json:"limit"`
Offset int `json:"offset"`
SampleOnly bool `json:"sample_only"`
}