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{})
|
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{
|
cj := &commonQueryObj{
|
||||||
Idents: x.Idents,
|
Idents: x.Idents,
|
||||||
TagPairs: recv.TagPairs,
|
TagPairs: recv.TagPairs,
|
||||||
|
@ -444,6 +450,14 @@ func (pd *PromeDataSource) QueryTagKeys(recv vos.CommonTagQueryParam) *vos.TagKe
|
||||||
// 对应prometheus 中的 /api/v1/label/<label_name>/values
|
// 对应prometheus 中的 /api/v1/label/<label_name>/values
|
||||||
func (pd *PromeDataSource) QueryTagValues(recv vos.CommonTagQueryParam) *vos.TagValueQueryResp {
|
func (pd *PromeDataSource) QueryTagValues(recv vos.CommonTagQueryParam) *vos.TagValueQueryResp {
|
||||||
labelValuesSet := make(map[string]struct{})
|
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 {
|
for _, x := range recv.Params {
|
||||||
cj := &commonQueryObj{
|
cj := &commonQueryObj{
|
||||||
Idents: x.Idents,
|
Idents: x.Idents,
|
||||||
|
@ -553,6 +567,12 @@ func (pd *PromeDataSource) QueryTagPairs(recv vos.CommonTagQueryParam) *vos.TagP
|
||||||
Idents: make([]string, 0),
|
Idents: make([]string, 0),
|
||||||
}
|
}
|
||||||
tps := make(map[string]struct{})
|
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 {
|
for _, x := range recv.Params {
|
||||||
cj := &commonQueryObj{
|
cj := &commonQueryObj{
|
||||||
Idents: x.Idents,
|
Idents: x.Idents,
|
||||||
|
|
|
@ -265,7 +265,7 @@ func ToJudge(linkedList *SafeLinkedList, stra *models.AlertRule, val *vos.Metric
|
||||||
historyArr = append(historyArr, history)
|
historyArr = append(historyArr, history)
|
||||||
eventInfo += info
|
eventInfo += info
|
||||||
}
|
}
|
||||||
} else { //与条件
|
} else { //多个条件
|
||||||
for _, expr := range stra.PushExpr.Exps {
|
for _, expr := range stra.PushExpr.Exps {
|
||||||
|
|
||||||
respData, err := GetData(stra, expr, val, now)
|
respData, err := GetData(stra, expr, val, now)
|
||||||
|
@ -291,7 +291,12 @@ func ToJudge(linkedList *SafeLinkedList, stra *models.AlertRule, val *vos.Metric
|
||||||
if eventInfo == "" {
|
if eventInfo == "" {
|
||||||
eventInfo = info
|
eventInfo = info
|
||||||
} else {
|
} else {
|
||||||
|
if stra.PushExpr.TogetherOrAny == 0 {
|
||||||
eventInfo += fmt.Sprintf(" & %s", info)
|
eventInfo += fmt.Sprintf(" & %s", info)
|
||||||
|
} else if stra.PushExpr.TogetherOrAny == 1 {
|
||||||
|
eventInfo += fmt.Sprintf(" || %s", info)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -419,10 +424,30 @@ func GetData(stra *models.AlertRule, exp models.Exp, firstItem *vos.MetricPoint,
|
||||||
// 虽然最近的数据确实产生了事件(产生事件很频繁),但是未必一定要发送,只有告警/恢复状态发生变化的时候才需发送
|
// 虽然最近的数据确实产生了事件(产生事件很频繁),但是未必一定要发送,只有告警/恢复状态发生变化的时候才需发送
|
||||||
func sendEventIfNeed(status []bool, event *models.AlertEvent, stra *models.AlertRule) {
|
func sendEventIfNeed(status []bool, event *models.AlertEvent, stra *models.AlertRule) {
|
||||||
isTriggered := true
|
isTriggered := true
|
||||||
|
|
||||||
|
if stra.Type == 0 {
|
||||||
|
// 只判断push型的
|
||||||
|
switch stra.PushExpr.TogetherOrAny {
|
||||||
|
|
||||||
|
case 0:
|
||||||
|
// 全部触发
|
||||||
for _, s := range status {
|
for _, s := range status {
|
||||||
isTriggered = isTriggered && s
|
isTriggered = isTriggered && s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
// 任意一个触发
|
||||||
|
isTriggered = false
|
||||||
|
for _, s := range status {
|
||||||
|
if s == true {
|
||||||
|
isTriggered = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
lastEvent, exists := LastEvents.Get(event.HashId)
|
lastEvent, exists := LastEvents.Get(event.HashId)
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ type PushExpression struct {
|
||||||
TagFilters []TagFilter `json:"tags_filters"`
|
TagFilters []TagFilter `json:"tags_filters"`
|
||||||
ResFilters []ResFilter `json:"res_filters"`
|
ResFilters []ResFilter `json:"res_filters"`
|
||||||
Exps []Exp `json:"trigger_conditions"`
|
Exps []Exp `json:"trigger_conditions"`
|
||||||
|
TogetherOrAny int `json:"together_or_any"` // 所有触发还是触发一条即可,=0所有 =1一条
|
||||||
}
|
}
|
||||||
|
|
||||||
type PullExpression struct {
|
type PullExpression struct {
|
||||||
|
|
Loading…
Reference in New Issue