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

pull/61288/head^2
Andres Martinez Gotor 2 years ago committed by GitHub
parent 1b6c0d9752
commit a4c2237d16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      public/app/plugins/datasource/grafana-azure-monitor-datasource/components/MetricsQueryEditor/MetricsQueryEditor.tsx
  2. 2
      public/app/plugins/datasource/grafana-azure-monitor-datasource/components/ResourcePicker/NestedRow.tsx
  3. 2
      public/app/plugins/datasource/grafana-azure-monitor-datasource/components/ResourcePicker/ResourcePicker.tsx
  4. 1
      public/app/plugins/datasource/grafana-azure-monitor-datasource/components/ResourcePicker/types.ts
  5. 2
      public/app/plugins/datasource/grafana-azure-monitor-datasource/components/ResourcePicker/utils.test.ts
  6. 11
      public/app/plugins/datasource/grafana-azure-monitor-datasource/components/ResourcePicker/utils.ts
  7. 3
      public/app/plugins/datasource/grafana-azure-monitor-datasource/resourcePicker/resourcePickerData.test.ts
  8. 3
      public/app/plugins/datasource/grafana-azure-monitor-datasource/resourcePicker/resourcePickerData.ts
  9. 2
      public/app/plugins/datasource/grafana-azure-monitor-datasource/types/query.ts

@ -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;
}

Loading…
Cancel
Save