Add dash / and at @ signs escapes in regex (#32495)

This commit is contained in:
Dimitris Sotirakis 2021-03-30 15:56:15 +03:00 committed by GitHub
parent 009df4fb7a
commit 270a255c08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -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) plugins.DataQueryResult {

View File

@ -70,6 +70,8 @@ func TestInfluxdbResponseParser(t *testing.T) {
"datacenter": "America",
"dc.region.name": "Northeast",
"cluster-name": "Cluster",
"/cluster/name/": "Cluster/",
"@cluster@name@": "Cluster@",
},
Values: [][]interface{}{
{json.Number("111"), json.Number("222"), json.Number("333")},
@ -141,6 +143,16 @@ func TestInfluxdbResponseParser(t *testing.T) {
result = parser.Parse(response, query)
require.Equal(t, result.Series[0].Name, "alias Cluster")
query = &Query{Alias: "alias [[tag_/cluster/name/]]"}
result = parser.Parse(response, query)
require.Equal(t, result.Series[0].Name, "alias Cluster/")
query = &Query{Alias: "alias [[tag_@cluster@name@]]"}
result = parser.Parse(response, query)
require.Equal(t, result.Series[0].Name, "alias Cluster@")
})
t.Run("Influxdb response parser with errors", func(t *testing.T) {