Skip to content

Commit a7d37d4

Browse files
authored
azuremonitor: add labels for single resource query (#90832)
* azuremonitor: add labels for single resource query * fix tests
1 parent d30f8a0 commit a7d37d4

13 files changed

+239
-213
lines changed

pkg/tsdb/azuremonitor/metrics/azuremonitor-datasource.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,9 @@ func (e *AzureMonitorDatasource) parseResponse(amr types.AzureMonitorResponse, q
424424
resourceName = extractResourceNameFromMetricsURL(query.URL)
425425
resourceID = extractResourceIDFromMetricsURL(query.URL)
426426
}
427-
if _, ok := labels[resourceIdLabel]; ok {
428-
delete(labels, resourceIdLabel)
429-
labels["resourceName"] = resourceName
430-
}
427+
428+
delete(labels, resourceIdLabel)
429+
labels["resourceName"] = resourceName
431430

432431
if query.Alias != "" {
433432
displayName := formatAzureMonitorLegendKey(query, resourceID, &amr, labels, subscription)

pkg/tsdb/azuremonitor/testdata/azuremonitor/1-azure-monitor-response-avg.json.average-aggregate-time-series-response.golden.jsonc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
// }
1010
// Name:
1111
// Dimensions: 2 Fields by 5 Rows
12-
// +-------------------------------+----------------------+
13-
// | Name: Time | Name: Percentage CPU |
14-
// | Labels: | Labels: |
15-
// | Type: []time.Time | Type: []*float64 |
16-
// +-------------------------------+----------------------+
17-
// | 2019-02-08 10:13:00 +0000 UTC | 2.0875 |
18-
// | 2019-02-08 10:14:00 +0000 UTC | 2.1525 |
19-
// | 2019-02-08 10:15:00 +0000 UTC | 2.155 |
20-
// | 2019-02-08 10:16:00 +0000 UTC | 3.6925 |
21-
// | 2019-02-08 10:17:00 +0000 UTC | 2.44 |
22-
// +-------------------------------+----------------------+
12+
// +-------------------------------+------------------------------+
13+
// | Name: Time | Name: Percentage CPU |
14+
// | Labels: | Labels: resourceName=grafana |
15+
// | Type: []time.Time | Type: []*float64 |
16+
// +-------------------------------+------------------------------+
17+
// | 2019-02-08 10:13:00 +0000 UTC | 2.0875 |
18+
// | 2019-02-08 10:14:00 +0000 UTC | 2.1525 |
19+
// | 2019-02-08 10:15:00 +0000 UTC | 2.155 |
20+
// | 2019-02-08 10:16:00 +0000 UTC | 3.6925 |
21+
// | 2019-02-08 10:17:00 +0000 UTC | 2.44 |
22+
// +-------------------------------+------------------------------+
2323
//
2424
//
2525
// 🌟 This was machine generated. Do not edit. 🌟
@@ -59,7 +59,9 @@
5959
"frame": "float64",
6060
"nullable": true
6161
},
62-
"labels": {},
62+
"labels": {
63+
"resourceName": "grafana"
64+
},
6365
"config": {
6466
"unit": "percent",
6567
"links": [

pkg/tsdb/azuremonitor/testdata/azuremonitor/2-azure-monitor-response-total.json.total-aggregate-time-series-response.golden.jsonc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
// }
1010
// Name:
1111
// Dimensions: 2 Fields by 5 Rows
12-
// +-------------------------------+----------------------+
13-
// | Name: Time | Name: Percentage CPU |
14-
// | Labels: | Labels: |
15-
// | Type: []time.Time | Type: []*float64 |
16-
// +-------------------------------+----------------------+
17-
// | 2019-02-09 13:29:00 +0000 UTC | 8.26 |
18-
// | 2019-02-09 13:30:00 +0000 UTC | 8.7 |
19-
// | 2019-02-09 13:31:00 +0000 UTC | 14.82 |
20-
// | 2019-02-09 13:32:00 +0000 UTC | 10.07 |
21-
// | 2019-02-09 13:33:00 +0000 UTC | 8.52 |
22-
// +-------------------------------+----------------------+
12+
// +-------------------------------+------------------------------+
13+
// | Name: Time | Name: Percentage CPU |
14+
// | Labels: | Labels: resourceName=grafana |
15+
// | Type: []time.Time | Type: []*float64 |
16+
// +-------------------------------+------------------------------+
17+
// | 2019-02-09 13:29:00 +0000 UTC | 8.26 |
18+
// | 2019-02-09 13:30:00 +0000 UTC | 8.7 |
19+
// | 2019-02-09 13:31:00 +0000 UTC | 14.82 |
20+
// | 2019-02-09 13:32:00 +0000 UTC | 10.07 |
21+
// | 2019-02-09 13:33:00 +0000 UTC | 8.52 |
22+
// +-------------------------------+------------------------------+
2323
//
2424
//
2525
// 🌟 This was machine generated. Do not edit. 🌟
@@ -59,7 +59,9 @@
5959
"frame": "float64",
6060
"nullable": true
6161
},
62-
"labels": {},
62+
"labels": {
63+
"resourceName": "grafana"
64+
},
6365
"config": {
6466
"unit": "percent",
6567
"links": [

pkg/tsdb/azuremonitor/testdata/azuremonitor/2-azure-monitor-response-total.json.with-alias-patterns-in-the-query.golden.jsonc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
// }
1010
// Name:
1111
// Dimensions: 2 Fields by 5 Rows
12-
// +-------------------------------+----------------------+
13-
// | Name: Time | Name: Percentage CPU |
14-
// | Labels: | Labels: |
15-
// | Type: []time.Time | Type: []*float64 |
16-
// +-------------------------------+----------------------+
17-
// | 2019-02-09 13:29:00 +0000 UTC | 8.26 |
18-
// | 2019-02-09 13:30:00 +0000 UTC | 8.7 |
19-
// | 2019-02-09 13:31:00 +0000 UTC | 14.82 |
20-
// | 2019-02-09 13:32:00 +0000 UTC | 10.07 |
21-
// | 2019-02-09 13:33:00 +0000 UTC | 8.52 |
22-
// +-------------------------------+----------------------+
12+
// +-------------------------------+------------------------------+
13+
// | Name: Time | Name: Percentage CPU |
14+
// | Labels: | Labels: resourceName=grafana |
15+
// | Type: []time.Time | Type: []*float64 |
16+
// +-------------------------------+------------------------------+
17+
// | 2019-02-09 13:29:00 +0000 UTC | 8.26 |
18+
// | 2019-02-09 13:30:00 +0000 UTC | 8.7 |
19+
// | 2019-02-09 13:31:00 +0000 UTC | 14.82 |
20+
// | 2019-02-09 13:32:00 +0000 UTC | 10.07 |
21+
// | 2019-02-09 13:33:00 +0000 UTC | 8.52 |
22+
// +-------------------------------+------------------------------+
2323
//
2424
//
2525
// 🌟 This was machine generated. Do not edit. 🌟
@@ -59,7 +59,9 @@
5959
"frame": "float64",
6060
"nullable": true
6161
},
62-
"labels": {},
62+
"labels": {
63+
"resourceName": "grafana"
64+
},
6365
"config": {
6466
"displayName": "custom grafanastaging Microsoft.Compute/virtualMachines grafana Percentage CPU",
6567
"unit": "percent",

pkg/tsdb/azuremonitor/testdata/azuremonitor/2-azure-monitor-response-total.json.with-legacy-azure-monitor-query-properties-and-with-a-resource-uri-it-should-use-the-resource-uri.golden.jsonc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
// }
1010
// Name:
1111
// Dimensions: 2 Fields by 5 Rows
12-
// +-------------------------------+----------------------+
13-
// | Name: Time | Name: Percentage CPU |
14-
// | Labels: | Labels: |
15-
// | Type: []time.Time | Type: []*float64 |
16-
// +-------------------------------+----------------------+
17-
// | 2019-02-09 13:29:00 +0000 UTC | 8.26 |
18-
// | 2019-02-09 13:30:00 +0000 UTC | 8.7 |
19-
// | 2019-02-09 13:31:00 +0000 UTC | 14.82 |
20-
// | 2019-02-09 13:32:00 +0000 UTC | 10.07 |
21-
// | 2019-02-09 13:33:00 +0000 UTC | 8.52 |
22-
// +-------------------------------+----------------------+
12+
// +-------------------------------+------------------------------+
13+
// | Name: Time | Name: Percentage CPU |
14+
// | Labels: | Labels: resourceName=grafana |
15+
// | Type: []time.Time | Type: []*float64 |
16+
// +-------------------------------+------------------------------+
17+
// | 2019-02-09 13:29:00 +0000 UTC | 8.26 |
18+
// | 2019-02-09 13:30:00 +0000 UTC | 8.7 |
19+
// | 2019-02-09 13:31:00 +0000 UTC | 14.82 |
20+
// | 2019-02-09 13:32:00 +0000 UTC | 10.07 |
21+
// | 2019-02-09 13:33:00 +0000 UTC | 8.52 |
22+
// +-------------------------------+------------------------------+
2323
//
2424
//
2525
// 🌟 This was machine generated. Do not edit. 🌟
@@ -59,7 +59,9 @@
5959
"frame": "float64",
6060
"nullable": true
6161
},
62-
"labels": {},
62+
"labels": {
63+
"resourceName": "grafana"
64+
},
6365
"config": {
6466
"displayName": "custom grafanastaging Microsoft.Compute/virtualMachines grafana Percentage CPU",
6567
"unit": "percent",

pkg/tsdb/azuremonitor/testdata/azuremonitor/2-azure-monitor-response-total.json.with-legacy-azure-monitor-query-properties-and-without-a-resource-uri.golden.jsonc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
// }
1010
// Name:
1111
// Dimensions: 2 Fields by 5 Rows
12-
// +-------------------------------+----------------------+
13-
// | Name: Time | Name: Percentage CPU |
14-
// | Labels: | Labels: |
15-
// | Type: []time.Time | Type: []*float64 |
16-
// +-------------------------------+----------------------+
17-
// | 2019-02-09 13:29:00 +0000 UTC | 8.26 |
18-
// | 2019-02-09 13:30:00 +0000 UTC | 8.7 |
19-
// | 2019-02-09 13:31:00 +0000 UTC | 14.82 |
20-
// | 2019-02-09 13:32:00 +0000 UTC | 10.07 |
21-
// | 2019-02-09 13:33:00 +0000 UTC | 8.52 |
22-
// +-------------------------------+----------------------+
12+
// +-------------------------------+------------------------------+
13+
// | Name: Time | Name: Percentage CPU |
14+
// | Labels: | Labels: resourceName=grafana |
15+
// | Type: []time.Time | Type: []*float64 |
16+
// +-------------------------------+------------------------------+
17+
// | 2019-02-09 13:29:00 +0000 UTC | 8.26 |
18+
// | 2019-02-09 13:30:00 +0000 UTC | 8.7 |
19+
// | 2019-02-09 13:31:00 +0000 UTC | 14.82 |
20+
// | 2019-02-09 13:32:00 +0000 UTC | 10.07 |
21+
// | 2019-02-09 13:33:00 +0000 UTC | 8.52 |
22+
// +-------------------------------+------------------------------+
2323
//
2424
//
2525
// 🌟 This was machine generated. Do not edit. 🌟
@@ -59,7 +59,9 @@
5959
"frame": "float64",
6060
"nullable": true
6161
},
62-
"labels": {},
62+
"labels": {
63+
"resourceName": "grafana"
64+
},
6365
"config": {
6466
"displayName": "custom grafanastaging Microsoft.Compute/virtualMachines grafana Percentage CPU",
6567
"unit": "percent",

pkg/tsdb/azuremonitor/testdata/azuremonitor/3-azure-monitor-response-maximum.json.maximum-aggregate-time-series-response.golden.jsonc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
// }
1010
// Name:
1111
// Dimensions: 2 Fields by 5 Rows
12-
// +-------------------------------+----------------------+
13-
// | Name: Time | Name: Percentage CPU |
14-
// | Labels: | Labels: |
15-
// | Type: []time.Time | Type: []*float64 |
16-
// +-------------------------------+----------------------+
17-
// | 2019-02-09 14:26:00 +0000 UTC | 3.07 |
18-
// | 2019-02-09 14:27:00 +0000 UTC | 2.92 |
19-
// | 2019-02-09 14:28:00 +0000 UTC | 2.87 |
20-
// | 2019-02-09 14:29:00 +0000 UTC | 2.27 |
21-
// | 2019-02-09 14:30:00 +0000 UTC | 2.52 |
22-
// +-------------------------------+----------------------+
12+
// +-------------------------------+------------------------------+
13+
// | Name: Time | Name: Percentage CPU |
14+
// | Labels: | Labels: resourceName=grafana |
15+
// | Type: []time.Time | Type: []*float64 |
16+
// +-------------------------------+------------------------------+
17+
// | 2019-02-09 14:26:00 +0000 UTC | 3.07 |
18+
// | 2019-02-09 14:27:00 +0000 UTC | 2.92 |
19+
// | 2019-02-09 14:28:00 +0000 UTC | 2.87 |
20+
// | 2019-02-09 14:29:00 +0000 UTC | 2.27 |
21+
// | 2019-02-09 14:30:00 +0000 UTC | 2.52 |
22+
// +-------------------------------+------------------------------+
2323
//
2424
//
2525
// 🌟 This was machine generated. Do not edit. 🌟
@@ -59,7 +59,9 @@
5959
"frame": "float64",
6060
"nullable": true
6161
},
62-
"labels": {},
62+
"labels": {
63+
"resourceName": "grafana"
64+
},
6365
"config": {
6466
"unit": "percent",
6567
"links": [

pkg/tsdb/azuremonitor/testdata/azuremonitor/4-azure-monitor-response-minimum.json.minimum-aggregate-time-series-response.golden.jsonc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
// }
1010
// Name:
1111
// Dimensions: 2 Fields by 5 Rows
12-
// +-------------------------------+----------------------+
13-
// | Name: Time | Name: Percentage CPU |
14-
// | Labels: | Labels: |
15-
// | Type: []time.Time | Type: []*float64 |
16-
// +-------------------------------+----------------------+
17-
// | 2019-02-09 14:43:00 +0000 UTC | 1.51 |
18-
// | 2019-02-09 14:44:00 +0000 UTC | 2.38 |
19-
// | 2019-02-09 14:45:00 +0000 UTC | 1.69 |
20-
// | 2019-02-09 14:46:00 +0000 UTC | 2.27 |
21-
// | 2019-02-09 14:47:00 +0000 UTC | 1.96 |
22-
// +-------------------------------+----------------------+
12+
// +-------------------------------+------------------------------+
13+
// | Name: Time | Name: Percentage CPU |
14+
// | Labels: | Labels: resourceName=grafana |
15+
// | Type: []time.Time | Type: []*float64 |
16+
// +-------------------------------+------------------------------+
17+
// | 2019-02-09 14:43:00 +0000 UTC | 1.51 |
18+
// | 2019-02-09 14:44:00 +0000 UTC | 2.38 |
19+
// | 2019-02-09 14:45:00 +0000 UTC | 1.69 |
20+
// | 2019-02-09 14:46:00 +0000 UTC | 2.27 |
21+
// | 2019-02-09 14:47:00 +0000 UTC | 1.96 |
22+
// +-------------------------------+------------------------------+
2323
//
2424
//
2525
// 🌟 This was machine generated. Do not edit. 🌟
@@ -59,7 +59,9 @@
5959
"frame": "float64",
6060
"nullable": true
6161
},
62-
"labels": {},
62+
"labels": {
63+
"resourceName": "grafana"
64+
},
6365
"config": {
6466
"unit": "percent",
6567
"links": [

pkg/tsdb/azuremonitor/testdata/azuremonitor/5-azure-monitor-response-count.json.count-aggregate-time-series-response.golden.jsonc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
// }
1010
// Name:
1111
// Dimensions: 2 Fields by 5 Rows
12-
// +-------------------------------+----------------------+
13-
// | Name: Time | Name: Percentage CPU |
14-
// | Labels: | Labels: |
15-
// | Type: []time.Time | Type: []*float64 |
16-
// +-------------------------------+----------------------+
17-
// | 2019-02-09 14:44:00 +0000 UTC | 4 |
18-
// | 2019-02-09 14:45:00 +0000 UTC | 4 |
19-
// | 2019-02-09 14:46:00 +0000 UTC | 4 |
20-
// | 2019-02-09 14:47:00 +0000 UTC | 4 |
21-
// | 2019-02-09 14:48:00 +0000 UTC | 4 |
22-
// +-------------------------------+----------------------+
12+
// +-------------------------------+------------------------------+
13+
// | Name: Time | Name: Percentage CPU |
14+
// | Labels: | Labels: resourceName=grafana |
15+
// | Type: []time.Time | Type: []*float64 |
16+
// +-------------------------------+------------------------------+
17+
// | 2019-02-09 14:44:00 +0000 UTC | 4 |
18+
// | 2019-02-09 14:45:00 +0000 UTC | 4 |
19+
// | 2019-02-09 14:46:00 +0000 UTC | 4 |
20+
// | 2019-02-09 14:47:00 +0000 UTC | 4 |
21+
// | 2019-02-09 14:48:00 +0000 UTC | 4 |
22+
// +-------------------------------+------------------------------+
2323
//
2424
//
2525
// 🌟 This was machine generated. Do not edit. 🌟
@@ -59,7 +59,9 @@
5959
"frame": "float64",
6060
"nullable": true
6161
},
62-
"labels": {},
62+
"labels": {
63+
"resourceName": "grafana"
64+
},
6365
"config": {
6466
"unit": "percent",
6567
"links": [

0 commit comments

Comments
 (0)