fix: query index api

master
ning1875 4 years ago committed by GitHub
parent 36ec4e09fd
commit 39de0892f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -56,13 +56,8 @@ func convertToPromql(recv *commonQueryObj) string {
labelStrSlice = append(labelStrSlice, metricName) labelStrSlice = append(labelStrSlice, metricName)
} }
// 匹配ident=~"k1.*|k2.*" // 匹配ident=~"k1|k2"
for _, i := range recv.Idents { labelIdent = strings.Join(recv.Idents, "|")
if i != "" {
labelIdent += fmt.Sprintf(`.*%s.*|`, i)
}
}
labelIdent = strings.TrimRight(labelIdent, "|")
if labelIdent != "" { if labelIdent != "" {
labelStrSlice = append(labelStrSlice, fmt.Sprintf(`ident=~"%s"`, labelIdent)) labelStrSlice = append(labelStrSlice, fmt.Sprintf(`ident=~"%s"`, labelIdent))
} }
@ -83,10 +78,7 @@ func convertToPromql(recv *commonQueryObj) string {
} }
for _, s := range labelStrSlice { qlStr = strings.Join(labelStrSlice, ",")
qlStr += fmt.Sprintf(`%s,`, s)
}
qlStr = strings.TrimRight(qlStr, ",")
qlStrFinal = fmt.Sprintf(`{%s}`, qlStr) qlStrFinal = fmt.Sprintf(`{%s}`, qlStr)
logger.Debugf("[convertToPromql][type=queryLabel][recv:%+v][qlStrFinal:%s]", recv, qlStrFinal) logger.Debugf("[convertToPromql][type=queryLabel][recv:%+v][qlStrFinal:%s]", recv, qlStrFinal)
@ -108,13 +100,8 @@ func convertToPromqlForQueryData(recv *commonQueryObj) string {
labelStrSlice = append(labelStrSlice, metricName) labelStrSlice = append(labelStrSlice, metricName)
} }
// 匹配ident=~"k1.*|k2.*" // 匹配ident=~"k1|k2"
for _, i := range recv.Idents { labelIdent = strings.Join(recv.Idents, "|")
if i != "" {
labelIdent += fmt.Sprintf(`%s|`, i)
}
}
labelIdent = strings.TrimRight(labelIdent, "|")
if labelIdent != "" { if labelIdent != "" {
labelStrSlice = append(labelStrSlice, fmt.Sprintf(`ident=~"%s"`, labelIdent)) labelStrSlice = append(labelStrSlice, fmt.Sprintf(`ident=~"%s"`, labelIdent))
} }
@ -135,10 +122,7 @@ func convertToPromqlForQueryData(recv *commonQueryObj) string {
} }
for _, s := range labelStrSlice { qlStr = strings.Join(labelStrSlice, ",")
qlStr += fmt.Sprintf(`%s,`, s)
}
qlStr = strings.TrimRight(qlStr, ",")
qlStrFinal = fmt.Sprintf(`{%s}`, qlStr) qlStrFinal = fmt.Sprintf(`{%s}`, qlStr)
logger.Debugf("[convertToPromql][type=queryData][recv:%+v][qlStrFinal:%s]", recv, qlStrFinal) logger.Debugf("[convertToPromql][type=queryData][recv:%+v][qlStrFinal:%s]", recv, qlStrFinal)

@ -106,7 +106,7 @@ func GetTagValues(c *gin.Context) {
return return
} }
if recv.TagKey == "" { if recv.TagKey == "" {
renderMessage(c, errors.New("missing tagkey")) renderMessage(c, errors.New("missing tag_key"))
return return
} }
resp := dataSource.QueryTagValues(recv) resp := dataSource.QueryTagValues(recv)

Loading…
Cancel
Save