fix: query index api

This commit is contained in:
ning1875 2021-07-08 20:37:23 +08:00 committed by GitHub
parent 36ec4e09fd
commit 39de0892f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 23 deletions

View File

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

View File

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