diff --git a/backend/prome/query.go b/backend/prome/query.go index 5221c38d..119edcb1 100644 --- a/backend/prome/query.go +++ b/backend/prome/query.go @@ -387,8 +387,14 @@ func (pd *PromeDataSource) QueryTagKeys(recv vos.CommonTagQueryParam) *vos.TagKe } labelNamesSet := make(map[string]struct{}) - for _, x := range recv.Params { + if len(recv.Params) == 0 { + recv.Params = append(recv.Params, vos.TagPairQueryParamOne{ + Idents: []string{}, + Metric: "", + }) + } + for _, x := range recv.Params { cj := &commonQueryObj{ Idents: x.Idents, TagPairs: recv.TagPairs, @@ -444,6 +450,14 @@ func (pd *PromeDataSource) QueryTagKeys(recv vos.CommonTagQueryParam) *vos.TagKe // 对应prometheus 中的 /api/v1/label//values func (pd *PromeDataSource) QueryTagValues(recv vos.CommonTagQueryParam) *vos.TagValueQueryResp { labelValuesSet := make(map[string]struct{}) + + if len(recv.Params) == 0 { + recv.Params = append(recv.Params, vos.TagPairQueryParamOne{ + Idents: []string{}, + Metric: "", + }) + } + for _, x := range recv.Params { cj := &commonQueryObj{ Idents: x.Idents, @@ -553,6 +567,12 @@ func (pd *PromeDataSource) QueryTagPairs(recv vos.CommonTagQueryParam) *vos.TagP Idents: make([]string, 0), } tps := make(map[string]struct{}) + if len(recv.Params) == 0 { + recv.Params = append(recv.Params, vos.TagPairQueryParamOne{ + Idents: []string{}, + Metric: "", + }) + } for _, x := range recv.Params { cj := &commonQueryObj{ Idents: x.Idents, diff --git a/judge/handler.go b/judge/handler.go index 977b930e..2eb02edb 100644 --- a/judge/handler.go +++ b/judge/handler.go @@ -265,7 +265,7 @@ func ToJudge(linkedList *SafeLinkedList, stra *models.AlertRule, val *vos.Metric historyArr = append(historyArr, history) eventInfo += info } - } else { //与条件 + } else { //多个条件 for _, expr := range stra.PushExpr.Exps { respData, err := GetData(stra, expr, val, now) @@ -291,7 +291,12 @@ func ToJudge(linkedList *SafeLinkedList, stra *models.AlertRule, val *vos.Metric if eventInfo == "" { eventInfo = info } else { - eventInfo += fmt.Sprintf(" & %s", info) + if stra.PushExpr.TogetherOrAny == 0 { + eventInfo += fmt.Sprintf(" & %s", info) + } else if stra.PushExpr.TogetherOrAny == 1 { + eventInfo += fmt.Sprintf(" || %s", info) + } + } } @@ -419,8 +424,28 @@ func GetData(stra *models.AlertRule, exp models.Exp, firstItem *vos.MetricPoint, // 虽然最近的数据确实产生了事件(产生事件很频繁),但是未必一定要发送,只有告警/恢复状态发生变化的时候才需发送 func sendEventIfNeed(status []bool, event *models.AlertEvent, stra *models.AlertRule) { isTriggered := true - for _, s := range status { - isTriggered = isTriggered && s + + if stra.Type == 0 { + // 只判断push型的 + switch stra.PushExpr.TogetherOrAny { + + case 0: + // 全部触发 + for _, s := range status { + isTriggered = isTriggered && s + } + + case 1: + // 任意一个触发 + isTriggered = false + for _, s := range status { + if s == true { + isTriggered = true + break + } + } + + } } now := time.Now().Unix() diff --git a/models/alert_rule.go b/models/alert_rule.go index 02d08d98..0e25d867 100644 --- a/models/alert_rule.go +++ b/models/alert_rule.go @@ -48,9 +48,10 @@ type AlertRule struct { } type PushExpression struct { - TagFilters []TagFilter `json:"tags_filters"` - ResFilters []ResFilter `json:"res_filters"` - Exps []Exp `json:"trigger_conditions"` + TagFilters []TagFilter `json:"tags_filters"` + ResFilters []ResFilter `json:"res_filters"` + Exps []Exp `json:"trigger_conditions"` + TogetherOrAny int `json:"together_or_any"` // 所有触发还是触发一条即可,=0所有 =1一条 } type PullExpression struct {