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
@@ -22,7 +22,7 @@ func (ctrl *AIController) GetConfig(c *gin.Context) {
|
||||
userID := c.GetUint("userId")
|
||||
cfg := services.MaskedAIConfig()
|
||||
utils.Success(c, gin.H{
|
||||
"config": cfg,
|
||||
"config": cfg,
|
||||
"tokenUsedToday": services.AITokenUsedToday(userID),
|
||||
})
|
||||
}
|
||||
@@ -91,6 +91,7 @@ func (ctrl *AIController) Analyze(c *gin.Context) {
|
||||
Start int64 `json:"start" binding:"required"`
|
||||
End int64 `json:"end" binding:"required"`
|
||||
Question string `json:"question"`
|
||||
App string `json:"app"`
|
||||
}
|
||||
if !utils.BindAndValidate(c, &req) {
|
||||
return
|
||||
@@ -110,13 +111,18 @@ func (ctrl *AIController) Analyze(c *gin.Context) {
|
||||
utils.BadRequest(c, fmt.Sprintf("时间范围过大(%d 分钟):AI 分析最多支持 24 小时,建议用 15~60 分钟", int(to.Sub(from).Minutes())))
|
||||
return
|
||||
}
|
||||
// 长窗口必须指定应用:全命名空间聚合在 6h/24h 下数据量过大,查询会拖垮 Loki
|
||||
if to.Sub(from) > time.Hour && req.App == "" {
|
||||
utils.BadRequest(c, "超过 1 小时的分析必须指定应用(app):全命名空间长窗口聚合过慢,请先在应用排行里选一个 app 缩小范围")
|
||||
return
|
||||
}
|
||||
|
||||
userID := c.GetUint("userId")
|
||||
username := c.GetString("username")
|
||||
admin := c.GetString("role") == "admin"
|
||||
|
||||
cfg := services.GetAIConfig()
|
||||
outcome, err := services.RunAIAnalysis(c.Request.Context(), cfg, src, userID, username, admin, from, to, req.Question)
|
||||
outcome, err := services.RunAIAnalysis(c.Request.Context(), cfg, src, userID, username, admin, from, to, req.Question, req.App)
|
||||
if err != nil {
|
||||
// 未配置模型 / 配额用尽 / 上游报错:都给出具体原因,不包装成 500
|
||||
utils.Error(c, 400, err.Error())
|
||||
|
||||
Reference in new issue
Block a user