feat(aiops): 长窗口(>1h)分析必须指定应用
全命名空间 6h/24h 聚合数据量过大会拖垮 Loki:前端时间范围旁新增应用范围选择器 (labelValues 候选),>1h 未选应用禁用开始分析并提示;后端同样强制 400(闸门在服务端); 信号采集选择器按 app 收窄后 histogram/stats 从全量变为单应用流,秒级返回。
This commit is contained in:
1 parent
1610988c2e
commit
c090ba0564
7 files changed
+66
-14
No files matched your search
@@ -59,7 +59,7 @@ JSON 结构:
|
||||
}`
|
||||
|
||||
// RunAIAnalysis 执行一次分析:采集信号 → 脱敏 → 调模型 → 解析 → 落审计。
|
||||
func RunAIAnalysis(ctx context.Context, cfg models.AIConfig, src *models.LogSource, userID uint, username string, admin bool, from, to time.Time, question string) (*AIAnalysisOutcome, error) {
|
||||
func RunAIAnalysis(ctx context.Context, cfg models.AIConfig, src *models.LogSource, userID uint, username string, admin bool, from, to time.Time, question, app string) (*AIAnalysisOutcome, error) {
|
||||
if !cfg.Enabled {
|
||||
return nil, fmt.Errorf("AI 分析未启用:请先在「智能运维 → 模型配置」中开启并保存")
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func RunAIAnalysis(ctx context.Context, cfg models.AIConfig, src *models.LogSour
|
||||
}
|
||||
|
||||
started := time.Now()
|
||||
signals, err := CollectAISignals(ctx, src, userID, admin, from, to)
|
||||
signals, err := CollectAISignals(ctx, src, userID, admin, from, to, app)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -92,15 +92,20 @@ type AIAlert struct {
|
||||
}
|
||||
|
||||
// CollectAISignals 采集一次分析所需的全部信号。
|
||||
func CollectAISignals(ctx context.Context, src *models.LogSource, userID uint, admin bool, from, to time.Time) (*AISignalBundle, error) {
|
||||
func CollectAISignals(ctx context.Context, src *models.LogSource, userID uint, admin bool, from, to time.Time, app string) (*AISignalBundle, error) {
|
||||
if src == nil {
|
||||
return nil, fmt.Errorf("数据源不存在")
|
||||
}
|
||||
if !to.After(from) {
|
||||
return nil, fmt.Errorf("时间范围无效")
|
||||
}
|
||||
// 复用查询授权:AI 能看到的数据范围必须与当前用户一致,不多不少
|
||||
selector, err := AuthorizedLogQuery(src, userID, admin, `{namespace=~".+"}`)
|
||||
// 复用查询授权:AI 能看到的数据范围必须与当前用户一致,不多不少。
|
||||
// 长窗口由上层强制指定 app(缩小聚合范围);15m/1h 允许全命名空间
|
||||
baseSelector := `{namespace=~".+"}`
|
||||
if app != "" {
|
||||
baseSelector = `{namespace=~".+", app="` + app + `"}`
|
||||
}
|
||||
selector, err := AuthorizedLogQuery(src, userID, admin, baseSelector)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user