Commit c724449d by Kyle Brandt Committed by GitHub

AzureMonitor: fix panic introduced in 7.1.4 (#27113)

happens when unit was "Unspecified" and alias is being used
parent a6cc6429
......@@ -299,8 +299,16 @@ func (e *AzureMonitorDatasource) parseResponse(queryRes *tsdb.QueryResult, amr A
})
}
if query.Alias != "" {
dataField.Config.DisplayName = formatAzureMonitorLegendKey(query.Alias, query.UrlComponents["resourceName"],
displayName := formatAzureMonitorLegendKey(query.Alias, query.UrlComponents["resourceName"],
amr.Value[0].Name.LocalizedValue, "", "", amr.Namespace, amr.Value[0].ID, labels)
if dataField.Config != nil {
dataField.Config.DisplayName = displayName
} else {
dataField.SetConfig(&data.FieldConfig{
DisplayName: displayName,
})
}
}
requestedAgg := query.Params.Get("aggregation")
......
......@@ -405,6 +405,27 @@ func TestAzureMonitorParseResponse(t *testing.T) {
&data.FieldConfig{Unit: "decbytes", DisplayName: "danieltest {Blob Type=Azure Data Lake Storage, Tier=Cool}"})),
},
},
{
name: "unspecified unit with alias should not panic",
responseFile: "8-azure-monitor-response-unspecified-unit.json",
mockQuery: &AzureMonitorQuery{
Alias: "custom",
UrlComponents: map[string]string{
"resourceName": "grafana",
},
Params: url.Values{
"aggregation": {"Average"},
},
},
expectedFrames: data.Frames{
data.NewFrame("",
data.NewField("", nil,
[]time.Time{time.Date(2019, 2, 8, 10, 13, 0, 0, time.UTC)}),
data.NewField("Percentage CPU", nil, []float64{
2.0875,
}).SetConfig(&data.FieldConfig{DisplayName: "custom"})),
},
},
}
datasource := &AzureMonitorDatasource{}
......
{
"cost": 0,
"timespan": "2019-02-08T10:13:50Z\/2019-02-08T16:13:50Z",
"interval": "PT1M",
"value": [
{
"id": "\/subscriptions\/xxx\/resourceGroups\/grafanastaging\/providers\/Microsoft.Compute\/virtualMachines\/grafana\/providers\/Microsoft.Insights\/metrics\/Percentage CPU",
"type": "Microsoft.Insights\/metrics",
"name": {
"value": "Percentage CPU",
"localizedValue": "Percentage CPU"
},
"unit": "Unspecified",
"timeseries": [
{
"metadatavalues": [
],
"data": [
{
"timeStamp": "2019-02-08T10:13:00Z",
"average": 2.0875
}
]
}
]
}
],
"namespace": "Microsoft.Compute\/virtualMachines",
"resourceregion": "westeurope"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment