diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/url_builder.test.ts b/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/url_builder.test.ts index ed61968eed7..0e3a01293ef 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/url_builder.test.ts +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/url_builder.test.ts @@ -7,6 +7,20 @@ describe('AzureMonitorUrlBuilder', () => { '/subscriptions/sub/resourceGroups/group/providers/Microsoft.NetApp/netAppAccounts/name' ); }); + + it('builds a resource uri correctly when a template variable is used as namespace', () => { + expect(UrlBuilder.buildResourceUri('sub', 'group', '$ns', 'name')).toEqual( + '/subscriptions/sub/resourceGroups/group/providers/$ns/name' + ); + }); + + it('builds a resource uri correctly when the namespace includes a storage sub-resource', () => { + expect( + UrlBuilder.buildResourceUri('sub', 'group', 'Microsoft.Storage/storageAccounts/tableServices', 'name') + ).toEqual( + '/subscriptions/sub/resourceGroups/group/providers/Microsoft.Storage/storageAccounts/name/tableServices/default' + ); + }); }); describe('when a resource uri is provided', () => { diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/url_builder.ts b/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/url_builder.ts index 7684a543e07..51dd5a80b35 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/url_builder.ts +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/url_builder.ts @@ -11,9 +11,16 @@ export default class UrlBuilder { const resourceNameArray = resourceName.split('/'); const provider = metricDefinitionArray.shift(); const urlArray = ['/subscriptions', subscriptionId, 'resourceGroups', resourceGroup, 'providers', provider]; - for (const i in metricDefinitionArray) { - urlArray.push(metricDefinitionArray[i]); - urlArray.push(resourceNameArray[i]); + if (metricDefinition.startsWith('Microsoft.Storage/storageAccounts/') && resourceNameArray.at(-1) !== 'default') { + resourceNameArray.push('default'); + } + if (metricDefinitionArray.length > 0) { + for (const i in metricDefinitionArray) { + urlArray.push(metricDefinitionArray[i]); + urlArray.push(resourceNameArray[i]); + } + } else { + urlArray.push(resourceNameArray[0]); } return urlArray.join('/'); } diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/dashboards/adx.json b/public/app/plugins/datasource/grafana-azure-monitor-datasource/dashboards/adx.json index be3d125d7c4..333257194b9 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/dashboards/adx.json +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/dashboards/adx.json @@ -3389,172 +3389,6 @@ "y": 46 }, "hiddenSeries": false, - "id": 34, - "legend": { - "avg": true, - "current": false, - "max": false, - "min": false, - "show": true, - "total": false, - "values": true - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "null", - "options": { - "alertThreshold": true - }, - "percentage": false, - "pluginVersion": "7.4.3", - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "appInsights": { - "dimension": [], - "metricName": "select", - "timeGrain": "auto" - }, - "azureLogAnalytics": { - "query": "//change this example to create your own time series query\n //the table to query (e.g. Usage, Heartbeat, Perf)\n| where $__timeFilter(TimeGenerated) //this is a macro used to show the full chart’s time range, choose the datetime column here\n| summarize count() by , bin(TimeGenerated, $__interval) //change “group by column” to a column in your table, such as “Computer”. The $__interval macro is used to auto-select the time grain. Can also use 1h, 5m etc.\n| order by TimeGenerated asc", - "resultFormat": "time_series", - "workspace": "657b3e91-7c0b-438b-86a5-f769445e237d" - }, - "azureMonitor": { - "aggOptions": ["None", "Average", "Minimum", "Maximum", "Total", "Count"], - "aggregation": "None", - "allowedTimeGrainsMs": [60000, 300000, 900000, 1800000, 3600000, 21600000, 43200000, 86400000], - "dimensionFilter": "*", - "dimensionFilters": [], - "dimensions": [], - "metricDefinition": "$ns", - "metricName": "SteamingIngestRequestRate", - "metricNamespace": "Microsoft.Kusto/clusters", - "resourceGroup": "$rg", - "resourceName": "$resource", - "timeGrain": "auto", - "timeGrains": [ - { - "text": "auto", - "value": "auto" - }, - { - "text": "1 minute", - "value": "PT1M" - }, - { - "text": "5 minutes", - "value": "PT5M" - }, - { - "text": "15 minutes", - "value": "PT15M" - }, - { - "text": "30 minutes", - "value": "PT30M" - }, - { - "text": "1 hour", - "value": "PT1H" - }, - { - "text": "6 hours", - "value": "PT6H" - }, - { - "text": "12 hours", - "value": "PT12H" - }, - { - "text": "1 day", - "value": "P1D" - } - ], - "top": "10" - }, - "insightsAnalytics": { - "query": "", - "resultFormat": "time_series" - }, - "queryType": "Azure Monitor", - "refId": "A", - "subscription": "$sub" - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "Streaming Ingest Request Rate", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "format": "ms", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - }, - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": "$ds", - "fieldConfig": { - "defaults": { - "color": {}, - "custom": {}, - "thresholds": { - "mode": "absolute", - "steps": [] - } - }, - "overrides": [] - }, - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 10, - "w": 6, - "x": 18, - "y": 46 - }, - "hiddenSeries": false, "id": 35, "legend": { "avg": true, @@ -8484,5 +8318,5 @@ "timezone": "", "title": "Azure / Insights / Data Explorer Clusters", "uid": "8UDB1s3Gk", - "version": 10 + "version": 11 } diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/dashboards/storage.json b/public/app/plugins/datasource/grafana-azure-monitor-datasource/dashboards/storage.json index af4f775a4ac..bc4be8330cd 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/dashboards/storage.json +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/dashboards/storage.json @@ -6426,5 +6426,5 @@ "timezone": "", "title": "Azure / Insights / Storage Accounts", "uid": "3n2E8CrGk", - "version": 28 + "version": 29 } diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/utils/migrateQuery.ts b/public/app/plugins/datasource/grafana-azure-monitor-datasource/utils/migrateQuery.ts index ca4ba9e8337..da856ec9496 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/utils/migrateQuery.ts +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/utils/migrateQuery.ts @@ -109,6 +109,10 @@ function migrateResourceUri(query: AzureMonitorQuery): AzureMonitorQuery { return query; } + if (metricDefinition.includes('$') || resourceName.includes('$')) { + return query; + } + const resourceUri = UrlBuilder.buildResourceUri(subscription, resourceGroup, metricDefinition, resourceName); return {