mirror of
https://github.com/grafana/grafana.git
synced 2024-11-22 08:56:43 -06:00
Notifications: InfluxDB - Fix regex to include metrics with hyphen in aliases (#32224)
* Notifications: InfluxDB - fix regex to include metrics with hyphen * Add hyphen check in tests
This commit is contained in:
parent
89a178dfb4
commit
fdaac2b8fb
@ -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 {
|
||||
@ -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 {
|
||||
|
@ -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")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user