From a9b55f7905b41dc262ad0c1d715702c995f5d50c Mon Sep 17 00:00:00 2001 From: Santiago Date: Wed, 23 Mar 2022 21:13:17 -0600 Subject: [PATCH] Fix InfluxDB tag variables parsing (#46862) * regex bug fixed * remove unnecessary test --- pkg/tsdb/influxdb/response_parser.go | 2 +- pkg/tsdb/influxdb/response_parser_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/tsdb/influxdb/response_parser.go b/pkg/tsdb/influxdb/response_parser.go index 19013a315c6..a498088dcfd 100644 --- a/pkg/tsdb/influxdb/response_parser.go +++ b/pkg/tsdb/influxdb/response_parser.go @@ -16,7 +16,7 @@ import ( type ResponseParser struct{} var ( - legendFormat = regexp.MustCompile(`\[\[([\@\/\w-]+)(\.[\@\/\w-]+)*\]\]*|\$(\s*([\@\w-]+?))*`) + legendFormat = regexp.MustCompile(`\[\[([\@\/\w-]+)(\.[\@\/\w-]+)*\]\]*|\$([\@\w-]+?)*`) ) func (rp *ResponseParser) Parse(buf io.ReadCloser, queries []Query) *backend.QueryDataResponse { diff --git a/pkg/tsdb/influxdb/response_parser_test.go b/pkg/tsdb/influxdb/response_parser_test.go index c96aba76f08..e05fc6ebec3 100644 --- a/pkg/tsdb/influxdb/response_parser_test.go +++ b/pkg/tsdb/influxdb/response_parser_test.go @@ -492,6 +492,16 @@ func TestInfluxdbResponseParser(t *testing.T) { t.Errorf("Result mismatch (-want +got):\n%s", diff) } + query = &Query{Alias: "alias $0, $1 - $2 - $3, $4: something"} + result = parser.Parse(prepare(response), addQueryToQueries(*query)) + frame = result.Responses["A"] + name = "alias cpu, upc - $2 - $3, $4: something" + testFrame.Name = name + testFrame.Fields[1].Config.DisplayNameFromDS = name + if diff := cmp.Diff(testFrame, frame.Frames[0], data.FrameTestCompareOptions()...); diff != "" { + t.Errorf("Result mismatch (-want +got):\n%s", diff) + } + query = &Query{Alias: "alias $1"} result = parser.Parse(prepare(response), addQueryToQueries(*query)) frame = result.Responses["A"]