mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
AzureMonitor: Deduplicate resource picker rows (#93129)
* Use URI for querying resources in RG - Ensure resource group names are correctly slash separated * Update test
This commit is contained in:
parent
488e71226b
commit
76c8975b4f
@ -225,14 +225,14 @@ describe('AzureMonitor resourcePickerData', () => {
|
||||
it('makes 1 call to ARG with the correct path and query arguments', async () => {
|
||||
const mockResponse = createARGResourcesResponse();
|
||||
const { resourcePickerData, postResource } = createResourcePickerData([mockResponse]);
|
||||
await resourcePickerData.getResourcesForResourceGroup('dev', 'logs');
|
||||
await resourcePickerData.getResourcesForResourceGroup('/subscription/sub1/resourceGroups/dev', 'logs');
|
||||
|
||||
expect(postResource).toBeCalledTimes(1);
|
||||
const firstCall = postResource.mock.calls[0];
|
||||
const [path, postBody] = firstCall;
|
||||
expect(path).toEqual('resourcegraph/providers/Microsoft.ResourceGraph/resources?api-version=2021-03-01');
|
||||
expect(postBody.query).toContain('resources');
|
||||
expect(postBody.query).toContain('where id hasprefix "dev"');
|
||||
expect(postBody.query).toContain('where id hasprefix "/subscription/sub1/resourceGroups/dev/"');
|
||||
});
|
||||
|
||||
it('returns formatted resources', async () => {
|
||||
|
@ -91,7 +91,7 @@ export default class ResourcePickerData extends DataSourceWithBackend<AzureMonit
|
||||
const nestedRows =
|
||||
parentRow.type === ResourceRowType.Subscription
|
||||
? await this.getResourceGroupsBySubscriptionId(parentRow.id, type)
|
||||
: await this.getResourcesForResourceGroup(parentRow.id, type);
|
||||
: await this.getResourcesForResourceGroup(parentRow.uri, type);
|
||||
|
||||
return addResources(rows, parentRow.uri, nestedRows);
|
||||
}
|
||||
@ -183,6 +183,7 @@ export default class ResourcePickerData extends DataSourceWithBackend<AzureMonit
|
||||
subscriptionId: string,
|
||||
type: ResourcePickerQueryType
|
||||
): Promise<ResourceRowGroup> {
|
||||
// We can use subscription ID for the filtering here as they're unique
|
||||
const query = `
|
||||
resources
|
||||
| join kind=inner (
|
||||
@ -230,12 +231,15 @@ export default class ResourcePickerData extends DataSourceWithBackend<AzureMonit
|
||||
}
|
||||
|
||||
async getResourcesForResourceGroup(
|
||||
resourceGroupId: string,
|
||||
resourceGroupUri: string,
|
||||
type: ResourcePickerQueryType
|
||||
): Promise<ResourceRowGroup> {
|
||||
// We use resource group URI for the filtering here because resource group names are not unique across subscriptions
|
||||
// We also add a slash at the end of the resource group URI to ensure we do not pull resources from a resource group
|
||||
// that has a similar naming prefix e.g. resourceGroup1 and resourceGroup10
|
||||
const { data: response } = await this.makeResourceGraphRequest<RawAzureResourceItem[]>(`
|
||||
resources
|
||||
| where id hasprefix "${resourceGroupId}"
|
||||
| where id hasprefix "${resourceGroupUri}/"
|
||||
${await this.filterByType(type)}
|
||||
`);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user