From 39de0892f139a2c64c9ecafc21dfac838ab8b5c4 Mon Sep 17 00:00:00 2001 From: ning1875 <907974064@qq.com> Date: Thu, 8 Jul 2021 20:37:23 +0800 Subject: [PATCH] fix: query index api --- backend/prome/query.go | 28 ++++++---------------------- http/router_ts_data.go | 2 +- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/backend/prome/query.go b/backend/prome/query.go index 119edcb1..3270653f 100644 --- a/backend/prome/query.go +++ b/backend/prome/query.go @@ -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) diff --git a/http/router_ts_data.go b/http/router_ts_data.go index 6de848f5..b0f26fe5 100644 --- a/http/router_ts_data.go +++ b/http/router_ts_data.go @@ -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)