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

This commit is contained in:
Andres Martinez Gotor 2022-12-22 13:33:54 +01:00 committed by GitHub
parent b8253ac3b9
commit f8cc45f5bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -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', () => {

View File

@ -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));
});
}