From 80a4d4296cd3696263a4ad737ecdcf7903169f55 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Tue, 23 Mar 2021 14:51:49 +0000 Subject: [PATCH] Notifications: InfluxDB - Fix regex to include metrics with hyphen in aliases (#32224) (#32262) * Notifications: InfluxDB - fix regex to include metrics with hyphen * Add hyphen check in tests (cherry picked from commit fdaac2b8fb4a7ed652864c77a1f7422f3bc9109e) --- pkg/tsdb/influxdb/response_parser.go | 3 +-- pkg/tsdb/influxdb/response_parser_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/tsdb/influxdb/response_parser.go b/pkg/tsdb/influxdb/response_parser.go index 8fe3d0dc83f..1ce9edfab73 100644 --- a/pkg/tsdb/influxdb/response_parser.go +++ b/pkg/tsdb/influxdb/response_parser.go @@ -18,7 +18,7 @@ var ( ) func init() { - legendFormat = regexp.MustCompile(`\[\[(\w+)(\.\w+)*\]\]*|\$\s*(\w+?)*`) + legendFormat = regexp.MustCompile(`\[\[([\w-]+)(\.[\w-]+)*\]\]*|\$\s*([\w-]+?)*`) } func (rp *ResponseParser) Parse(response *Response, query *Query) *tsdb.QueryResult { @@ -64,7 +64,6 @@ func (rp *ResponseParser) formatSeriesName(row Row, column string, query *Query) if query.Alias == "" { return rp.buildSeriesNameFromQuery(row, column) } - nameSegment := strings.Split(row.Name, ".") result := legendFormat.ReplaceAllFunc([]byte(query.Alias), func(in []byte) []byte { diff --git a/pkg/tsdb/influxdb/response_parser_test.go b/pkg/tsdb/influxdb/response_parser_test.go index a66490d48f5..593beaaff04 100644 --- a/pkg/tsdb/influxdb/response_parser_test.go +++ b/pkg/tsdb/influxdb/response_parser_test.go @@ -80,6 +80,7 @@ func TestInfluxdbResponseParser(t *testing.T) { Tags: map[string]string{ "datacenter": "America", "dc.region.name": "Northeast", + "cluster-name": "Cluster", }, Values: [][]interface{}{ {json.Number("111"), json.Number("222"), json.Number("333")}, @@ -171,6 +172,13 @@ func TestInfluxdbResponseParser(t *testing.T) { So(result.Series[0].Name, ShouldEqual, "alias Northeast") }) + + Convey("tag alias with hyphens", func() { + query := &Query{Alias: "alias [[tag_cluster-name]]"} + result := parser.Parse(response, query) + + So(result.Series[0].Name, ShouldEqual, "alias Cluster") + }) }) })