diff --git a/e2e/cloud-plugins-suite/azure-monitor.spec.ts b/e2e/cloud-plugins-suite/azure-monitor.spec.ts
index 852db5b13c4..03ae9185f16 100644
--- a/e2e/cloud-plugins-suite/azure-monitor.spec.ts
+++ b/e2e/cloud-plugins-suite/azure-monitor.spec.ts
@@ -269,10 +269,14 @@ e2e.scenario({
subscription: '$subscription',
resourceGroup: '$resourceGroups',
});
+ addAzureMonitorVariable('region', AzureQueryType.LocationsQuery, false, {
+ subscription: '$subscription',
+ });
addAzureMonitorVariable('resource', AzureQueryType.ResourceNamesQuery, false, {
subscription: '$subscription',
resourceGroup: '$resourceGroups',
namespace: '$namespace',
+ region: '$region',
});
e2e.pages.Dashboard.SubMenu.submenuItemLabels('subscription').click();
e2e.pages.Dashboard.SubMenu.submenuItemValueDropDownOptionTexts('grafanalabs-datasources-dev').click();
@@ -286,6 +290,8 @@ e2e.scenario({
.parent()
.find('input')
.type('microsoft.storage/storageaccounts{downArrow}{enter}');
+ e2e.pages.Dashboard.SubMenu.submenuItemLabels('region').parent().find('button').click();
+ e2e.pages.Dashboard.SubMenu.submenuItemLabels('region').parent().find('input').type('uk south{downArrow}{enter}');
e2e.pages.Dashboard.SubMenu.submenuItemLabels('resource').parent().find('button').click();
e2e.pages.Dashboard.SubMenu.submenuItemLabels('resource')
.parent()
@@ -300,6 +306,7 @@ e2e.scenario({
e2eSelectors.queryEditor.resourcePicker.advanced.subscription.input().find('input').type('$subscription');
e2eSelectors.queryEditor.resourcePicker.advanced.resourceGroup.input().find('input').type('$resourceGroups');
e2eSelectors.queryEditor.resourcePicker.advanced.namespace.input().find('input').type('$namespaces');
+ e2eSelectors.queryEditor.resourcePicker.advanced.region.input().find('input').type('$region');
e2eSelectors.queryEditor.resourcePicker.advanced.resource.input().find('input').type('$resource');
e2eSelectors.queryEditor.resourcePicker.apply.button().click();
e2eSelectors.queryEditor.metricsQueryEditor.metricName.input().find('input').type('Transactions{enter}');
diff --git a/public/app/plugins/datasource/azuremonitor/components/VariableEditor/VariableEditor.test.tsx b/public/app/plugins/datasource/azuremonitor/components/VariableEditor/VariableEditor.test.tsx
index 0547882c7d2..de3b4cfd9db 100644
--- a/public/app/plugins/datasource/azuremonitor/components/VariableEditor/VariableEditor.test.tsx
+++ b/public/app/plugins/datasource/azuremonitor/components/VariableEditor/VariableEditor.test.tsx
@@ -258,10 +258,12 @@ describe('VariableEditor:', () => {
await waitFor(() => expect(screen.getByText('Logs')).toBeInTheDocument());
await selectAndRerender('select query type', 'Resource Names', onChange, rerender);
await selectAndRerender('select subscription', 'Primary Subscription', onChange, rerender);
+ await selectAndRerender('select region', 'North Europe', onChange, rerender);
expect(onChange).toHaveBeenCalledWith(
expect.objectContaining({
queryType: AzureQueryType.ResourceNamesQuery,
subscription: 'sub',
+ region: 'northeurope',
refId: 'A',
})
);
@@ -323,5 +325,21 @@ describe('VariableEditor:', () => {
})
);
});
+
+ it('should run the query if requesting regions', async () => {
+ const onChange = jest.fn();
+ const { rerender } = render();
+ // wait for initial load
+ await waitFor(() => expect(screen.getByText('Logs')).toBeInTheDocument());
+ await selectAndRerender('select query type', 'Regions', onChange, rerender);
+ await selectAndRerender('select subscription', 'Primary Subscription', onChange, rerender);
+ expect(onChange).toHaveBeenCalledWith(
+ expect.objectContaining({
+ queryType: AzureQueryType.LocationsQuery,
+ subscription: 'sub',
+ refId: 'A',
+ })
+ );
+ });
});
});
diff --git a/public/app/plugins/datasource/azuremonitor/components/VariableEditor/VariableEditor.tsx b/public/app/plugins/datasource/azuremonitor/components/VariableEditor/VariableEditor.tsx
index f9dce486d07..321cc7a887f 100644
--- a/public/app/plugins/datasource/azuremonitor/components/VariableEditor/VariableEditor.tsx
+++ b/public/app/plugins/datasource/azuremonitor/components/VariableEditor/VariableEditor.tsx
@@ -30,6 +30,7 @@ const VariableEditor = (props: Props) => {
{ label: 'Subscriptions', value: AzureQueryType.SubscriptionsQuery },
{ label: 'Resource Groups', value: AzureQueryType.ResourceGroupsQuery },
{ label: 'Namespaces', value: AzureQueryType.NamespacesQuery },
+ { label: 'Regions', value: AzureQueryType.LocationsQuery },
{ label: 'Resource Names', value: AzureQueryType.ResourceNamesQuery },
{ label: 'Metric Names', value: AzureQueryType.MetricNamesQuery },
{ label: 'Workspaces', value: AzureQueryType.WorkspacesQuery },
@@ -50,6 +51,7 @@ const VariableEditor = (props: Props) => {
const [requireSubscription, setRequireSubscription] = useState(false);
const [hasResourceGroup, setHasResourceGroup] = useState(false);
const [hasNamespace, setHasNamespace] = useState(false);
+ const [hasRegion, setHasRegion] = useState(false);
const [requireResourceGroup, setRequireResourceGroup] = useState(false);
const [requireNamespace, setRequireNamespace] = useState(false);
const [requireResource, setRequireResource] = useState(false);
@@ -57,6 +59,7 @@ const VariableEditor = (props: Props) => {
const [resourceGroups, setResourceGroups] = useState([]);
const [namespaces, setNamespaces] = useState([]);
const [resources, setResources] = useState([]);
+ const [regions, setRegions] = useState([]);
const [errorMessage, setError] = useLastError();
const queryType = typeof query === 'string' ? '' : query.queryType;
@@ -88,6 +91,7 @@ const VariableEditor = (props: Props) => {
setRequireSubscription(true);
setHasResourceGroup(true);
setHasNamespace(true);
+ setHasRegion(true);
break;
case AzureQueryType.MetricNamesQuery:
setRequireSubscription(true);
@@ -95,6 +99,9 @@ const VariableEditor = (props: Props) => {
setRequireNamespace(true);
setRequireResource(true);
break;
+ case AzureQueryType.LocationsQuery:
+ setRequireSubscription(true);
+ break;
}
}, [queryType]);
@@ -135,6 +142,16 @@ const VariableEditor = (props: Props) => {
}
}, [datasource, subscription, resourceGroup]);
+ useEffect(() => {
+ if (subscription) {
+ datasource.azureMonitorDatasource.getLocations([subscription]).then((rgs) => {
+ const regions: SelectableValue[] = [];
+ rgs.forEach((r) => regions.push({ label: r.displayName, value: r.name }));
+ setRegions(regions);
+ });
+ }
+ }, [datasource, subscription, resourceGroup]);
+
const namespace = (typeof query === 'object' && query.namespace) || '';
useEffect(() => {
if (subscription) {
@@ -191,6 +208,13 @@ const VariableEditor = (props: Props) => {
});
};
+ const onChangeRegion = (selectableValue: SelectableValue) => {
+ onChange({
+ ...query,
+ region: selectableValue.value,
+ });
+ };
+
const onChangeResource = (selectableValue: SelectableValue) => {
onChange({
...query,
@@ -296,6 +320,22 @@ const VariableEditor = (props: Props) => {
/>
)}
+ {hasRegion && (
+
+
+
+ )}
{requireResource && (
= [];
+ locationMap.forEach((loc) => {
+ res.push({ text: loc.displayName, value: loc.name });
+ });
+ return {
+ data: res?.length ? [toDataFrame(res)] : [],
+ };
+ }
default:
request.targets[0] = queryObj;
const queryResp = await lastValueFrom(this.datasource.query(request));