[v9.3.x] Azure Monitor: Fix metric metadata retrieval based on template variables (#60686)

Azure Monitor: Fix metric metadata retrieval based on template variables (#60674)

(cherry picked from commit f8cc45f5bd)

Co-authored-by: Andres Martinez Gotor <andres.martinez@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2022-12-22 07:57:04 -05:00
committed by GitHub
co-authored by Andres Martinez Gotor
parent 386016ccb9
commit 8bcbf85453
2 changed files with 25 additions and 1 deletions
@@ -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', () => {
@@ -260,7 +260,7 @@ export default class AzureMonitorDatasource extends DataSourceWithBackend<AzureM
this.templateSrv
);
return this.getResource(url).then((result: AzureMonitorMetricsMetadataResponse) => {
return ResponseParser.parseMetadata(result, metricName);
return ResponseParser.parseMetadata(result, this.templateSrv.replace(metricName));
});
}