[release-11.4.7] Azure: Fix legend formatting (#106932)

Azure: Fix legend formatting (#106504)

Fix inconsistent casing in resource URIs

(cherry picked from commit 629bd11c07)

Co-authored-by: Andreas Christou <andreas.christou@grafana.com>
This commit is contained in:
grafana-delivery-bot[bot]
2025-06-18 17:07:24 +02:00
committed by GitHub
co-authored by Andreas Christou
parent 881d2fb268
commit f3e031be2b
2 changed files with 11 additions and 7 deletions
@@ -118,7 +118,9 @@ func (e *AzureMonitorDatasource) buildQuery(query backend.DataQuery, dsInfo type
filterInBody = false
if resourceUri != nil {
azureURL = fmt.Sprintf("%s/providers/microsoft.insights/metrics", *resourceUri)
resourceMap[*resourceUri] = dataquery.AzureMonitorResource{ResourceGroup: resourceGroup, ResourceName: resourceName}
// Store the resource URI in the map lowercased to avoid case sensitivity issues
uriLower := strings.ToLower(*resourceUri)
resourceMap[uriLower] = dataquery.AzureMonitorResource{ResourceGroup: resourceGroup, ResourceName: resourceName}
}
} else {
for _, r := range azJSONModel.Resources {
@@ -135,7 +137,9 @@ func (e *AzureMonitorDatasource) buildQuery(query backend.DataQuery, dsInfo type
}
if resourceUri != nil {
resourceMap[*resourceUri] = r
// Store the resource URI in the map lowercased to avoid case sensitivity issues
uriLower := strings.ToLower(*resourceUri)
resourceMap[uriLower] = r
}
resourceIDs = append(resourceIDs, fmt.Sprintf("Microsoft.ResourceId eq '%s'", *resourceUri))
}
@@ -593,7 +597,7 @@ func getQueryUrl(query *types.AzureMonitorQuery, azurePortalUrl, resourceID, res
func formatAzureMonitorLegendKey(query *types.AzureMonitorQuery, resourceId string, amr *types.AzureMonitorResponse, labels data.Labels, subscription string) string {
alias := query.Alias
subscriptionId := query.Subscription
resource := query.Resources[resourceId]
resource := query.Resources[strings.ToLower(resourceId)]
metricName := amr.Value[0].Name.LocalizedValue
namespace := amr.Namespace
// Could be a collision problem if there were two keys that varied only in case, but I don't think that would happen in azure.
@@ -301,10 +301,10 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
if tt.azureMonitorVariedProperties["resources"] != nil {
resourceSlice := tt.azureMonitorVariedProperties["resources"].([]dataquery.AzureMonitorResource)
for _, resource := range resourceSlice {
resources[fmt.Sprintf("/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s", *resource.ResourceGroup, *resource.ResourceName)] = resource
resources[strings.ToLower(fmt.Sprintf("/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s", *resource.ResourceGroup, *resource.ResourceName))] = resource
}
} else {
resources["/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana"] = dataquery.AzureMonitorResource{ResourceGroup: strPtr("grafanastaging"), ResourceName: strPtr("grafana")}
resources[strings.ToLower("/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana")] = dataquery.AzureMonitorResource{ResourceGroup: strPtr("grafanastaging"), ResourceName: strPtr("grafana")}
}
azureMonitorQuery := &types.AzureMonitorQuery{
@@ -368,7 +368,7 @@ func TestCustomNamespace(t *testing.T) {
func TestAzureMonitorParseResponse(t *testing.T) {
resources := map[string]dataquery.AzureMonitorResource{}
resources["/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana"] =
resources[strings.ToLower("/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana")] =
dataquery.AzureMonitorResource{ResourceGroup: strPtr("grafanastaging"), ResourceName: strPtr("grafana")}
subscription := "12345678-aaaa-bbbb-cccc-123456789abc"
@@ -486,7 +486,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
Params: url.Values{
"aggregation": {"Average"},
},
Resources: map[string]dataquery.AzureMonitorResource{"/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanatest/providers/Microsoft.Storage/storageAccounts/testblobaccount/blobServices/default/providers/Microsoft.Insights/metrics": {ResourceGroup: strPtr("grafanatest"), ResourceName: strPtr("testblobaccount")}},
Resources: map[string]dataquery.AzureMonitorResource{strings.ToLower("/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanatest/providers/Microsoft.Storage/storageAccounts/testblobaccount/blobServices/default/providers/Microsoft.Insights/metrics"): {ResourceGroup: strPtr("grafanatest"), ResourceName: strPtr("testblobaccount")}},
Subscription: subscription,
},
},