From f8cc45f5bd182afc88c12763834a9e6802cb4c71 Mon Sep 17 00:00:00 2001 From: Andres Martinez Gotor Date: Thu, 22 Dec 2022 13:33:54 +0100 Subject: [PATCH] Azure Monitor: Fix metric metadata retrieval based on template variables (#60674) --- .../azure_monitor_datasource.test.ts | 24 +++++++++++++++++++ .../azure_monitor/azure_monitor_datasource.ts | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/azure_monitor_datasource.test.ts b/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/azure_monitor_datasource.test.ts index dcfa1085ae1..406e9d39891 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/azure_monitor_datasource.test.ts +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/azure_monitor_datasource.test.ts @@ -307,6 +307,30 @@ describe('AzureMonitorDatasource', () => { expect(results.supportedTimeGrains.length).toEqual(5); // 4 time grains from the API + auto }); }); + + it('should replace a template variable for the metric name', () => { + templateSrv.init([ + { + id: 'metric', + name: 'metric', + current: { + value: 'UsedCapacity', + }, + }, + ]); + return ctx.ds.azureMonitorDatasource + .getMetricMetadata({ + resourceUri: + '/subscriptions/mock-subscription-id/resourceGroups/nodeapp/providers/microsoft.insights/components/resource1', + metricNamespace: 'microsoft.insights/components', + metricName: '$metric', + }) + .then((results) => { + expect(results.primaryAggType).toEqual('Total'); + expect(results.supportedAggTypes.length).toEqual(6); + expect(results.supportedTimeGrains.length).toEqual(5); // 4 time grains from the API + auto + }); + }); }); describe('When performing interpolateVariablesInQueries for azure_monitor_metrics', () => { diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/azure_monitor_datasource.ts b/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/azure_monitor_datasource.ts index 1c53a56ad79..ad4633dd32c 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/azure_monitor_datasource.ts +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_monitor/azure_monitor_datasource.ts @@ -260,7 +260,7 @@ export default class AzureMonitorDatasource extends DataSourceWithBackend { - return ResponseParser.parseMetadata(result, metricName); + return ResponseParser.parseMetadata(result, this.templateSrv.replace(metricName)); }); }