Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

anomaly point key #2440

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions alert/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1315,8 +1315,14 @@ func (arw *AlertRuleWorker) VarFillingBeforeQuery(query models.PromQuery, reader
points[i].ValuesUnit = map[string]unit.FormattedValue{
"v": unit.ValueFormatter(query.Unit, 2, points[i].Value),
}
// 每个异常点都需要生成 key,子筛选使用 key 覆盖上层筛选
var cur []string
for _, paramKey := range ParamKeys {
val := string(points[i].Labels[model.LabelName(varToLabel[paramKey])])
cur = append(cur, val)
}
anomalyPointsMap.Store(strings.Join(cur, JoinMark), points[i])
}
anomalyPointsMap.Store(key, points)
}(key, promql)
}
wg.Wait()
Expand All @@ -1325,8 +1331,8 @@ func (arw *AlertRuleWorker) VarFillingBeforeQuery(query models.PromQuery, reader
}
anomalyPoints := make([]models.AnomalyPoint, 0)
anomalyPointsMap.Range(func(key, value any) bool {
if points, ok := value.([]models.AnomalyPoint); ok {
anomalyPoints = append(anomalyPoints, points...)
if point, ok := value.(models.AnomalyPoint); ok {
anomalyPoints = append(anomalyPoints, point)
}
return true
})
Expand Down Expand Up @@ -1386,7 +1392,16 @@ func ExtractVarMapping(promql string) map[string]string {

for _, pair := range pairs {
// 分割键值对
kv := strings.Split(pair, "=")
var kv []string
if strings.Contains(pair, "!=") {
kv = strings.Split(pair, "!=")
} else if strings.Contains(pair, "=~") {
kv = strings.Split(pair, "=~")
} else if strings.Contains(pair, "!~") {
kv = strings.Split(pair, "!~")
} else {
kv = strings.Split(pair, "=")
}
if len(kv) != 2 {
continue
}
Expand Down