AzureMonitor: Add region to the resource info (#61504)

This commit is contained in:
Andres Martinez Gotor
2023-01-16 11:26:56 +01:00
committed by GitHub
parent 1b6c0d9752
commit a4c2237d16
9 changed files with 20 additions and 7 deletions
@@ -42,6 +42,7 @@ const MetricsQueryEditor: React.FC<MetricsQueryEditorProps> = ({
resourceGroup: query.azureMonitor?.resources?.[0]?.resourceGroup,
metricNamespace: query.azureMonitor?.metricNamespace,
resourceName: query.azureMonitor?.resources?.[0]?.resourceName,
region: query.azureMonitor?.region,
};
return (
<span data-testid="azure-monitor-metrics-query-editor-with-experimental-ui">
@@ -76,7 +76,7 @@ const NestedRow: React.FC<NestedRowProps> = ({
<td className={styles.cell}>{row.typeLabel}</td>
<td className={styles.cell}>{row.location ?? '-'}</td>
<td className={styles.cell}>{row.locationDisplayName ?? '-'}</td>
</tr>
{isOpen &&
@@ -113,7 +113,7 @@ const ResourcePicker = ({
const handleSelectionChanged = useCallback(
(row: ResourceRow, isSelected: boolean) => {
isSelected
? setInternalSelected(resourceIsString ? row.uri : parseResourceDetails(row.uri))
? setInternalSelected(resourceIsString ? row.uri : parseResourceDetails(row.uri, row.location))
: setInternalSelected(resourceIsString ? '' : {});
},
[resourceIsString]
@@ -12,6 +12,7 @@ export interface ResourceRow {
name: string;
type: ResourceRowType;
typeLabel: string;
locationDisplayName?: string;
location?: string;
children?: ResourceRowGroup;
}
@@ -177,6 +177,7 @@ describe('AzureMonitor ResourcePicker utils', () => {
resourceGroup: 'rg',
metricNamespace: 'Microsoft.Storage/storageAccounts',
resourceName: 'testacct',
region: 'westus',
})
).toMatchObject({
subscription: 'sub',
@@ -184,6 +185,7 @@ describe('AzureMonitor ResourcePicker utils', () => {
aggregation: undefined,
metricName: undefined,
metricNamespace: 'microsoft.storage/storageaccounts',
region: 'westus',
resources: [
{
resourceGroup: 'rg',
@@ -34,7 +34,7 @@ function parseNamespaceAndName(metricNamespaceAndName?: string) {
return { metricNamespace: namespaceArray.join('/'), resourceName: resourceNameArray.join('/') };
}
export function parseResourceURI(resourceURI: string) {
export function parseResourceURI(resourceURI: string): AzureMetricResource {
const matches = RESOURCE_URI_REGEX.exec(resourceURI);
const groups: RegexGroups = matches?.groups ?? {};
const { subscription, resourceGroup, metricNamespaceAndResource } = groups;
@@ -43,9 +43,13 @@ export function parseResourceURI(resourceURI: string) {
return { subscription, resourceGroup, metricNamespace, resourceName };
}
export function parseResourceDetails(resource: string | AzureMetricResource) {
export function parseResourceDetails(resource: string | AzureMetricResource, location?: string) {
if (typeof resource === 'string') {
return parseResourceURI(resource);
const res = parseResourceURI(resource);
if (location) {
res.region = location;
}
return res;
}
return resource;
}
@@ -146,6 +150,7 @@ export function setResource(query: AzureMonitorQuery, resource?: string | AzureM
azureMonitor: {
...query.azureMonitor,
metricNamespace: resource?.metricNamespace?.toLocaleLowerCase(),
region: resource?.region,
resources: [{ resourceGroup: resource?.resourceGroup, resourceName: resource?.resourceName }],
metricName: undefined,
aggregation: undefined,
@@ -241,7 +241,8 @@ describe('AzureMonitor resourcePickerData', () => {
id: 'web-server',
name: 'web-server',
type: 'Resource',
location: 'North Europe',
location: 'northeurope',
locationDisplayName: 'North Europe',
resourceGroupName: 'dev',
typeLabel: 'Microsoft.Compute/virtualMachines',
uri: '/subscriptions/def-456/resourceGroups/dev/providers/Microsoft.Compute/virtualMachines/web-server',
@@ -247,7 +247,8 @@ export default class ResourcePickerData extends DataSourceWithBackend<AzureMonit
resourceGroupName: item.resourceGroup,
type: ResourceRowType.Resource,
typeLabel: resourceTypeDisplayNames[item.type] || item.type,
location: this.logLocationsMap.get(item.location)?.displayName || item.location,
locationDisplayName: this.logLocationsMap.get(item.location)?.displayName || item.location,
location: item.location,
};
});
}
@@ -57,6 +57,7 @@ export interface AzureMetricQuery {
/** used as the value for the metricNamespace param when different from the resource namespace */
customNamespace?: string;
metricName?: string;
region?: string;
timeGrain?: string;
aggregation?: string;
dimensionFilters?: AzureMetricDimension[];
@@ -119,4 +120,5 @@ export interface AzureMetricResource {
resourceGroup?: string;
resourceName?: string;
metricNamespace?: string;
region?: string;
}