AzureMonitor: fix Azure Resource Graph queries in Azure China (#35235)

* Optimize Azure Monitor routes

* Update API version compatible with Azure China
pull/35254/head
Sergey Kostrukov 4 years ago committed by GitHub
parent bfcc6a2248
commit 412bcf1fb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      pkg/tsdb/azuremonitor/azure-resource-graph-datasource.go
  2. 16
      pkg/tsdb/azuremonitor/routes.go
  3. 18
      public/app/plugins/datasource/grafana-azure-monitor-datasource/api/routes.ts
  4. 130
      public/app/plugins/datasource/grafana-azure-monitor-datasource/plugin.json
  5. 6
      public/app/plugins/datasource/grafana-azure-monitor-datasource/resourcePicker/resourcePickerData.ts

@ -226,7 +226,7 @@ func (e *AzureResourceGraphDatasource) getPluginRoute(plugin *plugins.DataSource
return nil, "", err
}
routeName, err := getResourceGraphApiRoute(cloud)
routeName, err := getManagementApiRoute(cloud)
if err != nil {
return nil, "", err
}

@ -43,19 +43,3 @@ func getAppInsightsApiRoute(azureCloud string) (string, error) {
return "", err
}
}
func getResourceGraphApiRoute(azureCloud string) (string, error) {
switch azureCloud {
case azureMonitorPublic:
return "azureresourcegraph", nil
case azureMonitorChina:
return "chinaazureresourcegraph", nil
case azureMonitorUSGovernment:
return "govazureresourcegraph", nil
case azureMonitorGermany:
return "germanyazureresourcegraph", nil
default:
err := fmt.Errorf("the cloud '%s' not supported", azureCloud)
return "", err
}
}

@ -21,6 +21,8 @@ export function getLogAnalyticsManagementApiRoute(azureCloud: string): string {
return 'chinaworkspacesloganalytics';
case 'govazuremonitor':
return 'govworkspacesloganalytics';
case 'germanyazuremonitor':
return 'germanyworkspacesloganalytics';
default:
throw new Error('The cloud not supported.');
}
@ -49,19 +51,3 @@ export function getAppInsightsApiRoute(azureCloud: string): string {
throw new Error('The cloud not supported.');
}
}
export function getLogAnalyticsResourcePickerApiRoute(azureCloud: string) {
switch (azureCloud) {
case 'azuremonitor':
return 'loganalytics-resourcepickerdata';
case 'govazuremonitor': // Azure US Government
return 'loganalytics-resourcepickerdata-gov';
case 'chinaazuremonitor': // Azure China
return 'loganalytics-resourcepickerdata-china';
default:
throw new Error('The cloud not supported.');
}
}

@ -31,7 +31,7 @@
"routes": [
{
"path": "azuremonitor",
"method": "GET",
"method": "*",
"url": "https://management.azure.com",
"authType": "azure",
"tokenAuth": {
@ -48,7 +48,7 @@
},
{
"path": "govazuremonitor",
"method": "GET",
"method": "*",
"url": "https://management.usgovcloudapi.net",
"authType": "azure",
"tokenAuth": {
@ -65,7 +65,7 @@
},
{
"path": "germanyazuremonitor",
"method": "GET",
"method": "*",
"url": "https://management.microsoftazure.de",
"authType": "azure",
"tokenAuth": {
@ -82,7 +82,7 @@
},
{
"path": "chinaazuremonitor",
"method": "GET",
"method": "*",
"url": "https://management.chinacloudapi.cn",
"authType": "azure",
"tokenAuth": {
@ -97,74 +97,6 @@
},
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
},
{
"path": "azureresourcegraph",
"method": "POST",
"url": "https://management.azure.com",
"authType": "azure",
"tokenAuth": {
"scopes": ["https://management.azure.com/.default"],
"params": {
"azure_auth_type": "{{.JsonData.azureAuthType | orEmpty}}",
"azure_cloud": "AzureCloud",
"tenant_id": "{{.JsonData.tenantId | orEmpty}}",
"client_id": "{{.JsonData.clientId | orEmpty}}",
"client_secret": "{{.SecureJsonData.clientSecret | orEmpty}}"
}
},
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
},
{
"path": "chinaazureresourcegraph",
"method": "POST",
"url": "https://management.azure.com",
"authType": "azure",
"tokenAuth": {
"scopes": ["https://management.chinacloudapi.cn/.default"],
"params": {
"azure_auth_type": "{{.JsonData.azureAuthType | orEmpty}}",
"azure_cloud": "AzureChinaCloud",
"tenant_id": "{{.JsonData.tenantId | orEmpty}}",
"client_id": "{{.JsonData.clientId | orEmpty}}",
"client_secret": "{{.SecureJsonData.clientSecret | orEmpty}}"
}
},
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
},
{
"path": "govazureresourcegraph",
"method": "POST",
"url": "https://management.usgovcloudapi.net",
"authType": "azure",
"tokenAuth": {
"scopes": ["https://management.usgovcloudapi.net/.default"],
"params": {
"azure_auth_type": "{{.JsonData.azureAuthType | orEmpty}}",
"azure_cloud": "AzureUSGovernment",
"tenant_id": "{{.JsonData.tenantId | orEmpty}}",
"client_id": "{{.JsonData.clientId | orEmpty}}",
"client_secret": "{{.SecureJsonData.clientSecret | orEmpty}}"
}
},
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
},
{
"path": "germanyazureresourcegraph",
"method": "POST",
"url": "https://management.microsoftazure.de",
"authType": "azure",
"tokenAuth": {
"scopes": ["https://management.microsoftazure.de/.default"],
"params": {
"azure_auth_type": "{{.JsonData.azureAuthType | orEmpty}}",
"azure_cloud": "AzureGermanCloud",
"tenant_id": "{{.JsonData.tenantId | orEmpty}}",
"client_id": "{{.JsonData.clientId | orEmpty}}",
"client_secret": "{{.SecureJsonData.clientSecret | orEmpty}}"
}
},
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
},
{
"path": "appinsights",
"method": "GET",
@ -184,8 +116,8 @@
]
},
{
"path": "loganalytics-resourcepickerdata",
"method": "POST",
"path": "workspacesloganalytics",
"method": "*",
"url": "https://management.azure.com",
"authType": "azure",
"tokenAuth": {
@ -201,8 +133,8 @@
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
},
{
"path": "loganalytics-resourcepickerdata-china",
"method": "POST",
"path": "chinaworkspacesloganalytics",
"method": "*",
"url": "https://management.chinacloudapi.cn",
"authType": "azure",
"tokenAuth": {
@ -218,8 +150,8 @@
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
},
{
"path": "loganalytics-resourcepickerdata-gov",
"method": "POST",
"path": "govworkspacesloganalytics",
"method": "*",
"url": "https://management.usgovcloudapi.net",
"authType": "azure",
"tokenAuth": {
@ -235,46 +167,12 @@
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
},
{
"path": "workspacesloganalytics",
"method": "GET",
"url": "https://management.azure.com",
"authType": "azure",
"tokenAuth": {
"scopes": ["https://management.azure.com/.default"],
"params": {
"azure_auth_type": "{{.JsonData.azureAuthType | orEmpty}}",
"azure_cloud": "AzureCloud",
"tenant_id": "{{.JsonData.logAnalyticsTenantId | orEmpty}}",
"client_id": "{{.JsonData.logAnalyticsClientId | orEmpty}}",
"client_secret": "{{.SecureJsonData.logAnalyticsClientSecret | orEmpty}}"
}
},
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
},
{
"path": "chinaworkspacesloganalytics",
"method": "GET",
"url": "https://management.chinacloudapi.cn",
"authType": "azure",
"tokenAuth": {
"scopes": ["https://management.chinacloudapi.cn/.default"],
"params": {
"azure_auth_type": "{{.JsonData.azureAuthType | orEmpty}}",
"azure_cloud": "AzureChinaCloud",
"tenant_id": "{{.JsonData.logAnalyticsTenantId | orEmpty}}",
"client_id": "{{.JsonData.logAnalyticsClientId | orEmpty}}",
"client_secret": "{{.SecureJsonData.logAnalyticsClientSecret | orEmpty}}"
}
},
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
},
{
"path": "govworkspacesloganalytics",
"method": "GET",
"url": "https://management.usgovcloudapi.net",
"path": "germanyworkspacesloganalytics",
"method": "*",
"url": "https://management.microsoftazure.de",
"authType": "azure",
"tokenAuth": {
"scopes": ["https://management.usgovcloudapi.net/.default"],
"scopes": ["https://management.microsoftazure.de/.default"],
"params": {
"azure_auth_type": "{{.JsonData.azureAuthType | orEmpty}}",
"azure_cloud": "AzureUSGovernment",

@ -1,5 +1,5 @@
import { FetchResponse, getBackendSrv } from '@grafana/runtime';
import { getLogAnalyticsResourcePickerApiRoute } from '../api/routes';
import { getLogAnalyticsManagementApiRoute } from '../api/routes';
import {
locationDisplayNames,
logsSupportedLocationsKusto,
@ -17,7 +17,7 @@ import {
RawAzureResourceItem,
} from '../types';
const RESOURCE_GRAPH_URL = '/providers/Microsoft.ResourceGraph/resources?api-version=2020-04-01-preview';
const RESOURCE_GRAPH_URL = '/providers/Microsoft.ResourceGraph/resources?api-version=2021-03-01';
export default class ResourcePickerData {
private proxyUrl: string;
@ -148,7 +148,7 @@ export default class ResourcePickerData {
try {
return await getBackendSrv()
.fetch<AzureGraphResponse<T>>({
url: this.proxyUrl + '/' + getLogAnalyticsResourcePickerApiRoute(this.cloud) + RESOURCE_GRAPH_URL,
url: this.proxyUrl + '/' + getLogAnalyticsManagementApiRoute(this.cloud) + RESOURCE_GRAPH_URL,
method: 'POST',
data: {
query: query,

Loading…
Cancel
Save