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, resourceGroup: query.azureMonitor?.resources?.[0]?.resourceGroup,
metricNamespace: query.azureMonitor?.metricNamespace, metricNamespace: query.azureMonitor?.metricNamespace,
resourceName: query.azureMonitor?.resources?.[0]?.resourceName, resourceName: query.azureMonitor?.resources?.[0]?.resourceName,
region: query.azureMonitor?.region,
}; };
return ( return (
<span data-testid="azure-monitor-metrics-query-editor-with-experimental-ui"> <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.typeLabel}</td>
<td className={styles.cell}>{row.location ?? '-'}</td> <td className={styles.cell}>{row.locationDisplayName ?? '-'}</td>
</tr> </tr>
{isOpen && {isOpen &&

@ -113,7 +113,7 @@ const ResourcePicker = ({
const handleSelectionChanged = useCallback( const handleSelectionChanged = useCallback(
(row: ResourceRow, isSelected: boolean) => { (row: ResourceRow, isSelected: boolean) => {
isSelected isSelected
? setInternalSelected(resourceIsString ? row.uri : parseResourceDetails(row.uri)) ? setInternalSelected(resourceIsString ? row.uri : parseResourceDetails(row.uri, row.location))
: setInternalSelected(resourceIsString ? '' : {}); : setInternalSelected(resourceIsString ? '' : {});
}, },
[resourceIsString] [resourceIsString]

@ -12,6 +12,7 @@ export interface ResourceRow {
name: string; name: string;
type: ResourceRowType; type: ResourceRowType;
typeLabel: string; typeLabel: string;
locationDisplayName?: string;
location?: string; location?: string;
children?: ResourceRowGroup; children?: ResourceRowGroup;
} }

@ -177,6 +177,7 @@ describe('AzureMonitor ResourcePicker utils', () => {
resourceGroup: 'rg', resourceGroup: 'rg',
metricNamespace: 'Microsoft.Storage/storageAccounts', metricNamespace: 'Microsoft.Storage/storageAccounts',
resourceName: 'testacct', resourceName: 'testacct',
region: 'westus',
}) })
).toMatchObject({ ).toMatchObject({
subscription: 'sub', subscription: 'sub',
@ -184,6 +185,7 @@ describe('AzureMonitor ResourcePicker utils', () => {
aggregation: undefined, aggregation: undefined,
metricName: undefined, metricName: undefined,
metricNamespace: 'microsoft.storage/storageaccounts', metricNamespace: 'microsoft.storage/storageaccounts',
region: 'westus',
resources: [ resources: [
{ {
resourceGroup: 'rg', resourceGroup: 'rg',

@ -34,7 +34,7 @@ function parseNamespaceAndName(metricNamespaceAndName?: string) {
return { metricNamespace: namespaceArray.join('/'), resourceName: resourceNameArray.join('/') }; 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 matches = RESOURCE_URI_REGEX.exec(resourceURI);
const groups: RegexGroups = matches?.groups ?? {}; const groups: RegexGroups = matches?.groups ?? {};
const { subscription, resourceGroup, metricNamespaceAndResource } = groups; const { subscription, resourceGroup, metricNamespaceAndResource } = groups;
@ -43,9 +43,13 @@ export function parseResourceURI(resourceURI: string) {
return { subscription, resourceGroup, metricNamespace, resourceName }; return { subscription, resourceGroup, metricNamespace, resourceName };
} }
export function parseResourceDetails(resource: string | AzureMetricResource) { export function parseResourceDetails(resource: string | AzureMetricResource, location?: string) {
if (typeof resource === 'string') { if (typeof resource === 'string') {
return parseResourceURI(resource); const res = parseResourceURI(resource);
if (location) {
res.region = location;
}
return res;
} }
return resource; return resource;
} }
@ -146,6 +150,7 @@ export function setResource(query: AzureMonitorQuery, resource?: string | AzureM
azureMonitor: { azureMonitor: {
...query.azureMonitor, ...query.azureMonitor,
metricNamespace: resource?.metricNamespace?.toLocaleLowerCase(), metricNamespace: resource?.metricNamespace?.toLocaleLowerCase(),
region: resource?.region,
resources: [{ resourceGroup: resource?.resourceGroup, resourceName: resource?.resourceName }], resources: [{ resourceGroup: resource?.resourceGroup, resourceName: resource?.resourceName }],
metricName: undefined, metricName: undefined,
aggregation: undefined, aggregation: undefined,

@ -241,7 +241,8 @@ describe('AzureMonitor resourcePickerData', () => {
id: 'web-server', id: 'web-server',
name: 'web-server', name: 'web-server',
type: 'Resource', type: 'Resource',
location: 'North Europe', location: 'northeurope',
locationDisplayName: 'North Europe',
resourceGroupName: 'dev', resourceGroupName: 'dev',
typeLabel: 'Microsoft.Compute/virtualMachines', typeLabel: 'Microsoft.Compute/virtualMachines',
uri: '/subscriptions/def-456/resourceGroups/dev/providers/Microsoft.Compute/virtualMachines/web-server', 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, resourceGroupName: item.resourceGroup,
type: ResourceRowType.Resource, type: ResourceRowType.Resource,
typeLabel: resourceTypeDisplayNames[item.type] || item.type, 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 */ /** used as the value for the metricNamespace param when different from the resource namespace */
customNamespace?: string; customNamespace?: string;
metricName?: string; metricName?: string;
region?: string;
timeGrain?: string; timeGrain?: string;
aggregation?: string; aggregation?: string;
dimensionFilters?: AzureMetricDimension[]; dimensionFilters?: AzureMetricDimension[];
@ -119,4 +120,5 @@ export interface AzureMetricResource {
resourceGroup?: string; resourceGroup?: string;
resourceName?: string; resourceName?: string;
metricNamespace?: string; metricNamespace?: string;
region?: string;
} }

Loading…
Cancel
Save