AzureMonitor: Add cloud specific deep linking (#35784)

This commit is contained in:
shuotli 2021-06-23 01:26:09 -07:00 committed by GitHub
parent ec9dbdd93c
commit 83860bdcc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 4 deletions

View File

@ -18,7 +18,7 @@ import {
import { getBackendSrv, getTemplateSrv, DataSourceWithBackend, FetchResponse } from '@grafana/runtime';
import { Observable, from } from 'rxjs';
import { mergeMap } from 'rxjs/operators';
import { getAuthType, getAzureCloud } from '../credentials';
import { getAuthType, getAzureCloud, getAzurePortalUrl } from '../credentials';
import { getLogAnalyticsApiRoute, getManagementApiRoute } from '../api/routes';
import { AzureLogAnalyticsMetadata } from '../types/logAnalyticsMetadata';
import { isGUIDish } from '../components/ResourcePicker/utils';
@ -35,6 +35,7 @@ export default class AzureLogAnalyticsDatasource extends DataSourceWithBackend<
> {
url: string;
baseUrl: string;
azurePortalUrl: string;
applicationId: string;
defaultSubscriptionId?: string;
@ -50,6 +51,7 @@ export default class AzureLogAnalyticsDatasource extends DataSourceWithBackend<
const cloud = getAzureCloud(instanceSettings);
const logAnalyticsRoute = getLogAnalyticsApiRoute(cloud);
this.baseUrl = `/${logAnalyticsRoute}`;
this.azurePortalUrl = getAzurePortalUrl(cloud);
const managementRoute = getManagementApiRoute(cloud);
this.azureMonitorUrl = `/${managementRoute}/subscriptions`;
@ -185,7 +187,7 @@ export default class AzureLogAnalyticsDatasource extends DataSourceWithBackend<
}
const url =
`https://portal.azure.com/#blade/Microsoft_OperationsManagementSuite_Workspace/` +
`${this.azurePortalUrl}/#blade/Microsoft_OperationsManagementSuite_Workspace/` +
`AnalyticsBlade/initiator/AnalyticsShareLinkToQuery/isQueryEditorVisible/true/scope/` +
`%7B%22resources%22%3A%5B%7B%22resourceId%22%3A%22%2Fsubscriptions%2F${subscription}` +
`%2Fresourcegroups%2F${details.resourceGroup}%2Fproviders%2Fmicrosoft.operationalinsights%2Fworkspaces%2F${details.workspace}` +

View File

@ -26,7 +26,7 @@ import { from, Observable } from 'rxjs';
import { mergeMap } from 'rxjs/operators';
import { getTimeSrv, TimeSrv } from 'app/features/dashboard/services/TimeSrv';
import { getAuthType, getAzureCloud } from '../credentials';
import { getAuthType, getAzureCloud, getAzurePortalUrl } from '../credentials';
import { getManagementApiRoute } from '../api/routes';
import { resourceTypeDisplayNames } from '../azureMetadata';
@ -47,6 +47,7 @@ export default class AzureMonitorDatasource extends DataSourceWithBackend<AzureM
apiPreviewVersion = '2017-12-01-preview';
defaultSubscriptionId?: string;
baseUrl: string;
azurePortalUrl: string;
resourceGroup: string;
resourceName: string;
url: string;
@ -62,6 +63,7 @@ export default class AzureMonitorDatasource extends DataSourceWithBackend<AzureM
const cloud = getAzureCloud(instanceSettings);
const route = getManagementApiRoute(cloud);
this.baseUrl = `/${route}/subscriptions`;
this.azurePortalUrl = getAzurePortalUrl(cloud);
this.url = instanceSettings.url!;
this.supportedMetricNamespaces = new SupportedNamespaces(cloud).get();
@ -167,7 +169,7 @@ export default class AzureMonitorDatasource extends DataSourceWithBackend<AzureM
},
});
return `https://portal.azure.com/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/${timeContext}/ChartDefinition/${chartDef}`;
return `${this.azurePortalUrl}/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/${timeContext}/ChartDefinition/${chartDef}`;
}
applyTemplateVariables(target: AzureMonitorQuery, scopedVars: ScopedVars): Record<string, any> {

View File

@ -43,6 +43,21 @@ function getDefaultAzureCloud(): string {
}
}
export function getAzurePortalUrl(azureCloud: string): string {
switch (azureCloud) {
case 'azuremonitor':
return 'https://portal.azure.com';
case 'chinaazuremonitor':
return 'https://portal.azure.cn';
case 'govazuremonitor':
return 'https://portal.azure.us';
case 'germanyazuremonitor':
return 'https://portal.microsoftazure.de';
default:
throw new Error('The cloud not supported.');
}
}
export function getAzureCloud(options: AzureDataSourceSettings | AzureDataSourceInstanceSettings): string {
const authType = getAuthType(options);
switch (authType) {