fix: tag-keys tag-values query when params are empty (#722)
Co-authored-by: ning1875 <907974064@qq.com>
This commit is contained in:
parent
1f16bc9a7b
commit
4585519943
|
@ -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/<label_name>/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,
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue