InfluxDB: Fix aliasing with $measurement or $m on backend mode (#76917)
* better interpolation $measurement aliasing * unit tests
This commit is contained in:
@@ -220,7 +220,7 @@ func formatFrameName(row models.Row, column string, query models.Query, frameNam
|
||||
aliasFormat = strings.Replace(aliasFormat, "$", "", 1)
|
||||
|
||||
if aliasFormat == "m" || aliasFormat == "measurement" {
|
||||
return []byte(query.Measurement)
|
||||
return []byte(row.Name)
|
||||
}
|
||||
if aliasFormat == "col" {
|
||||
return []byte(column)
|
||||
|
||||
@@ -319,6 +319,48 @@ func TestInfluxdbResponseParser(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Influxdb response parser with $measurement alias when multiple measurement in response", func(t *testing.T) {
|
||||
response := `
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"series": [
|
||||
{
|
||||
"name": "cpu.upc",
|
||||
"columns": ["time","mean"],
|
||||
"tags": {
|
||||
"datacenter": "America",
|
||||
"dc.region.name": "Northeast",
|
||||
"cluster-name": "Cluster"
|
||||
},
|
||||
"values": [
|
||||
[111,222]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "logins.count",
|
||||
"columns": ["time","mean"],
|
||||
"tags": {
|
||||
"datacenter": "America",
|
||||
"dc.region.name": "Northeast",
|
||||
"cluster-name": "Cluster"
|
||||
},
|
||||
"values": [
|
||||
[111,222]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
|
||||
query := models.Query{Alias: "alias $measurement"}
|
||||
result := ResponseParse(prepare(response), 200, generateQuery(query))
|
||||
assert.Equal(t, "alias cpu.upc", result.Frames[0].Name)
|
||||
assert.Equal(t, "alias logins.count", result.Frames[1].Name)
|
||||
})
|
||||
|
||||
t.Run("Influxdb response parser with alias", func(t *testing.T) {
|
||||
response := `
|
||||
{
|
||||
@@ -369,7 +411,7 @@ func TestInfluxdbResponseParser(t *testing.T) {
|
||||
query = models.Query{Alias: "alias $m $measurement", Measurement: "10m"}
|
||||
result = ResponseParse(prepare(response), 200, generateQuery(query))
|
||||
|
||||
name := "alias 10m 10m"
|
||||
name := "alias cpu.upc cpu.upc"
|
||||
testFrame.Name = name
|
||||
testFrame.Fields[1].Config.DisplayNameFromDS = name
|
||||
if diff := cmp.Diff(testFrame, result.Frames[0], data.FrameTestCompareOptions()...); diff != "" {
|
||||
@@ -477,7 +519,7 @@ func TestInfluxdbResponseParser(t *testing.T) {
|
||||
|
||||
query = models.Query{Alias: "alias [[m]] [[measurement]]", Measurement: "10m"}
|
||||
result = ResponseParse(prepare(response), 200, generateQuery(query))
|
||||
name = "alias 10m 10m"
|
||||
name = "alias cpu.upc cpu.upc"
|
||||
testFrame.Name = name
|
||||
testFrame.Fields[1].Config.DisplayNameFromDS = name
|
||||
if diff := cmp.Diff(testFrame, result.Frames[0], data.FrameTestCompareOptions()...); diff != "" {
|
||||
|
||||
Reference in New Issue
Block a user