AzureMonitor: Fix ResourcePicker hanging

Removed location fetching for every subscription.

Fixes #70523
This commit is contained in:
Adam Simpson
2023-07-21 14:52:14 -04:00
parent 8c86a46440
commit eb39f4bfe1
4 changed files with 7 additions and 22 deletions
@@ -78,7 +78,7 @@ const NestedRow = ({
<td className={styles.cell}>{row.typeLabel}</td>
<td className={styles.cell}>{row.locationDisplayName ?? '-'}</td>
<td className={styles.cell}>{row.location ?? '-'}</td>
</tr>
{isOpen &&
@@ -12,7 +12,6 @@ export interface ResourceRow {
name: string;
type: ResourceRowType;
typeLabel: string;
locationDisplayName?: string;
location?: string;
children?: ResourceRowGroup;
}
@@ -34,8 +34,6 @@ const createResourcePickerData = (responses: AzureGraphResponse[]) => {
resourcePickerData.postResource = postResource;
const locationsMap = mockGetValidLocations();
const getLocations = jest.spyOn(resourcePickerData, 'getLocations').mockResolvedValue(locationsMap);
resourcePickerData.locationsMap = locationsMap;
resourcePickerData.locations = Array.from(locationsMap.values()).map((location) => `"${location.name}"`);
return { resourcePickerData, postResource, mockDatasource, getValidLocations: getLocations };
};
@@ -252,7 +250,7 @@ describe('AzureMonitor resourcePickerData', () => {
name: 'web-server',
type: 'Resource',
location: 'northeurope',
locationDisplayName: 'North Europe',
locationDisplayName: 'northeurope',
resourceGroupName: 'dev',
typeLabel: 'Microsoft.Compute/virtualMachines',
uri: '/subscriptions/def-456/resourceGroups/dev/providers/Microsoft.Compute/virtualMachines/web-server',
@@ -329,7 +327,7 @@ describe('AzureMonitor resourcePickerData', () => {
id: 'vmname',
name: 'vmName',
type: 'Resource',
location: 'North Europe',
location: 'northeurope',
resourceGroupName: 'rgName',
typeLabel: 'Virtual machines',
uri: '/subscriptions/subId/resourceGroups/rgName/providers/Microsoft.Compute/virtualMachines/vmname',
@@ -359,7 +357,7 @@ describe('AzureMonitor resourcePickerData', () => {
id: 'rgName',
name: 'rgName',
type: 'ResourceGroup',
location: 'North Europe',
location: 'northeurope',
resourceGroupName: 'rgName',
typeLabel: 'Resource groups',
uri: '/subscriptions/subId/resourceGroups/rgName',
@@ -39,8 +39,6 @@ export default class ResourcePickerData extends DataSourceWithBackend<AzureMonit
resultLimit = 200;
azureMonitorDatasource;
supportedMetricNamespaces = '';
locationsMap: Map<string, AzureMonitorLocations> = new Map();
locations: string[] = [];
constructor(
instanceSettings: DataSourceInstanceSettings<AzureDataSourceJsonData>,
@@ -57,11 +55,6 @@ export default class ResourcePickerData extends DataSourceWithBackend<AzureMonit
): Promise<ResourceRowGroup> {
const subscriptions = await this.getSubscriptions();
if (this.locationsMap.size === 0) {
this.locationsMap = await this.getLocations(subscriptions);
this.locations = Array.from(this.locationsMap.values()).map((location) => `"${location.name}"`);
}
if (!currentSelection) {
return subscriptions;
}
@@ -140,7 +133,7 @@ export default class ResourcePickerData extends DataSourceWithBackend<AzureMonit
resourceGroupName: item.resourceGroup,
type,
typeLabel: resourceTypeDisplayNames[item.type] || item.type,
location: this.locationsMap.get(item.location)?.displayName || item.location,
location: item.location,
};
});
};
@@ -243,14 +236,10 @@ export default class ResourcePickerData extends DataSourceWithBackend<AzureMonit
resourceGroupId: string,
type: ResourcePickerQueryType
): Promise<ResourceRowGroup> {
if (!this.locations) {
return [];
}
const { data: response } = await this.makeResourceGraphRequest<RawAzureResourceItem[]>(`
resources
| where id hasprefix "${resourceGroupId}"
${await this.filterByType(type)} and location in (${this.locations})
${await this.filterByType(type)}
`);
return response.map((item) => {
@@ -265,7 +254,7 @@ export default class ResourcePickerData extends DataSourceWithBackend<AzureMonit
resourceGroupName: item.resourceGroup,
type: ResourceRowType.Resource,
typeLabel: resourceTypeDisplayNames[item.type] || item.type,
locationDisplayName: this.locationsMap.get(item.location)?.displayName || item.location,
locationDisplayName: item.location,
location: item.location,
};
});
@@ -422,7 +411,6 @@ export default class ResourcePickerData extends DataSourceWithBackend<AzureMonit
uri: resourceToString(resource),
typeLabel:
resourceTypeDisplayNames[resource.metricNamespace?.toLowerCase() ?? ''] ?? resource.metricNamespace ?? '',
locationDisplayName: this.locationsMap.get(resource.region ?? '')?.displayName || resource.region,
location: resource.region,
});
});