Azure: Fix resource name determination in template variable queries (#105705)
* Correctly parse resource URIs * Update test * Update variable function
This commit is contained in:
+2
-2
@@ -37,11 +37,11 @@ jest.mock('@grafana/runtime', () => ({
|
||||
const getResourceGroups = jest.fn().mockResolvedValue([{ resourceGroupURI: 'rg', resourceGroupName: 'rg', count: 1 }]);
|
||||
const getResourceNames = jest.fn().mockResolvedValue([
|
||||
{
|
||||
id: 'foobarID',
|
||||
id: '/subscriptions/subID/resourceGroups/resourceGroup/providers/foobarProvider/foobarType/foobar',
|
||||
name: 'foobar',
|
||||
subscriptionId: 'subID',
|
||||
resourceGroup: 'resourceGroup',
|
||||
type: 'foobarType',
|
||||
type: 'foobarProvider/foobarType',
|
||||
location: 'london',
|
||||
},
|
||||
]);
|
||||
|
||||
+7
-1
@@ -15,6 +15,7 @@ import { AzureMonitorOption, AzureMonitorQuery, AzureQueryType } from '../../typ
|
||||
import useLastError from '../../utils/useLastError';
|
||||
import ArgQueryEditor from '../ArgQueryEditor';
|
||||
import LogsQueryEditor from '../LogsQueryEditor';
|
||||
import { parseResourceURI } from '../ResourcePicker/utils';
|
||||
|
||||
import GrafanaTemplateVariableFnInput from './GrafanaTemplateVariableFn';
|
||||
|
||||
@@ -182,7 +183,12 @@ const VariableEditor = (props: Props) => {
|
||||
useEffect(() => {
|
||||
if (subscription && resourceGroup && namespace) {
|
||||
datasource.getResourceNames(subscription, resourceGroup, namespace).then((resources) => {
|
||||
setResources(resources.map((s) => ({ label: s.name, value: s.name })));
|
||||
setResources(
|
||||
resources.map((s) => {
|
||||
const parsedResource = parseResourceURI(s.id);
|
||||
return { label: s.name, value: parsedResource.resourceName };
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
}, [datasource, subscription, resourceGroup, namespace]);
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
import { getTemplateSrv, TemplateSrv } from '@grafana/runtime';
|
||||
|
||||
import UrlBuilder from './azure_monitor/url_builder';
|
||||
import { parseResourceURI } from './components/ResourcePicker/utils';
|
||||
import VariableEditor from './components/VariableEditor/VariableEditor';
|
||||
import DataSource from './datasource';
|
||||
import { migrateQuery } from './grafanaTemplateVariableFns';
|
||||
@@ -29,7 +30,7 @@ export function parseResourceNamesAsTemplateVariable(resources: RawAzureResource
|
||||
|
||||
return {
|
||||
text: r.name,
|
||||
value: r.name,
|
||||
value: parseResourceURI(r.id).resourceName,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user