Commit a6f2ae1f by sam Committed by GitHub

AzureMonitor: Fix Log Analytics and Application Insights for Azure China (#21803) (#22753)

Something funky going on with GitHub - the build has passed.
parent 59467d3c
......@@ -24,7 +24,23 @@ export default class AppInsightsDatasource {
constructor(instanceSettings: DataSourceInstanceSettings<AzureDataSourceJsonData>, private templateSrv: TemplateSrv) {
this.id = instanceSettings.id;
this.applicationId = instanceSettings.jsonData.appInsightsAppId;
switch (instanceSettings.jsonData.cloudName) {
// Azure US Government
case 'govazuremonitor':
break;
// Azure Germany
case 'germanyazuremonitor':
break;
// Azue China
case 'chinaazuremonitor':
this.baseUrl = `/chinaappinsights/${this.version}/apps/${this.applicationId}`;
break;
// Azure Global
default:
this.baseUrl = `/appinsights/${this.version}/apps/${this.applicationId}`;
}
this.url = instanceSettings.url;
}
......
......@@ -21,7 +21,20 @@ export default class AzureLogAnalyticsDatasource {
private templateSrv: TemplateSrv
) {
this.id = instanceSettings.id;
switch (this.instanceSettings.jsonData.cloudName) {
case 'govazuremonitor': // Azure US Government
break;
case 'germanyazuremonitor': // Azure Germany
break;
case 'chinaazuremonitor': // Azue China
this.baseUrl = '/chinaloganalyticsazure';
break;
default:
// Azure Global
this.baseUrl = '/loganalyticsazure';
}
this.url = instanceSettings.url;
this.defaultOrFirstWorkspace = this.instanceSettings.jsonData.logAnalyticsDefaultWorkspace;
......@@ -43,9 +56,21 @@ export default class AzureLogAnalyticsDatasource {
this.azureMonitorUrl = `/${azureCloud}/subscriptions`;
} else {
this.subscriptionId = this.instanceSettings.jsonData.logAnalyticsSubscriptionId;
switch (this.instanceSettings.jsonData.cloudName) {
case 'govazuremonitor': // Azure US Government
break;
case 'germanyazuremonitor': // Azure Germany
break;
case 'chinaazuremonitor': // Azue China
this.azureMonitorUrl = `/chinaworkspacesloganalytics/subscriptions`;
break;
default:
// Azure Global
this.azureMonitorUrl = `/workspacesloganalytics/subscriptions`;
}
}
}
getWorkspaces(subscription: string): Promise<AzureLogsVariable[]> {
const subscriptionId = this.templateSrv.replace(subscription || this.subscriptionId);
......
......@@ -99,6 +99,15 @@
]
},
{
"path": "chinaappinsights",
"method": "GET",
"url": "https://api.applicationinsights.azure.cn",
"headers": [
{ "name": "X-API-Key", "content": "{{.SecureJsonData.appInsightsApiKey}}" },
{ "name": "x-ms-app", "content": "Grafana" }
]
},
{
"path": "workspacesloganalytics",
"method": "GET",
"url": "https://management.azure.com",
......@@ -114,6 +123,21 @@
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
},
{
"path": "chinaworkspacesloganalytics",
"method": "GET",
"url": "https://management.chinacloudapi.cn",
"tokenAuth": {
"url": "https://login.chinacloudapi.cn/{{.JsonData.logAnalyticsTenantId}}/oauth2/token",
"params": {
"grant_type": "client_credentials",
"client_id": "{{.JsonData.logAnalyticsClientId}}",
"client_secret": "{{.SecureJsonData.logAnalyticsClientSecret}}",
"resource": "https://management.chinacloudapi.cn/"
}
},
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
},
{
"path": "loganalyticsazure",
"method": "GET",
"url": "https://api.loganalytics.io/v1/workspaces",
......@@ -131,6 +155,25 @@
{ "name": "Cache-Control", "content": "public, max-age=60" },
{ "name": "Accept-Encoding", "content": "gzip" }
]
},
{
"path": "chinaloganalyticsazure",
"method": "GET",
"url": "https://api.loganalytics.azure.cn/v1/workspaces",
"tokenAuth": {
"url": "https://login.chinacloudapi.cn/{{.JsonData.logAnalyticsTenantId}}/oauth2/token",
"params": {
"grant_type": "client_credentials",
"client_id": "{{.JsonData.logAnalyticsClientId}}",
"client_secret": "{{.SecureJsonData.logAnalyticsClientSecret}}",
"resource": "https://api.loganalytics.azure.cn"
}
},
"headers": [
{ "name": "x-ms-app", "content": "Grafana" },
{ "name": "Cache-Control", "content": "public, max-age=60" },
{ "name": "Accept-Encoding", "content": "gzip" }
]
}
],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment