mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
AzureMonitor: fix Azure Resource Graph queries in Azure China (#35235)
* Optimize Azure Monitor routes * Update API version compatible with Azure China
This commit is contained in:
parent
bfcc6a2248
commit
412bcf1fb0
@ -226,7 +226,7 @@ func (e *AzureResourceGraphDatasource) getPluginRoute(plugin *plugins.DataSource
|
|||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
routeName, err := getResourceGraphApiRoute(cloud)
|
routeName, err := getManagementApiRoute(cloud)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
@ -43,19 +43,3 @@ func getAppInsightsApiRoute(azureCloud string) (string, error) {
|
|||||||
return "", err
|
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';
|
return 'chinaworkspacesloganalytics';
|
||||||
case 'govazuremonitor':
|
case 'govazuremonitor':
|
||||||
return 'govworkspacesloganalytics';
|
return 'govworkspacesloganalytics';
|
||||||
|
case 'germanyazuremonitor':
|
||||||
|
return 'germanyworkspacesloganalytics';
|
||||||
default:
|
default:
|
||||||
throw new Error('The cloud not supported.');
|
throw new Error('The cloud not supported.');
|
||||||
}
|
}
|
||||||
@ -49,19 +51,3 @@ export function getAppInsightsApiRoute(azureCloud: string): string {
|
|||||||
throw new Error('The cloud not supported.');
|
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": [
|
"routes": [
|
||||||
{
|
{
|
||||||
"path": "azuremonitor",
|
"path": "azuremonitor",
|
||||||
"method": "GET",
|
"method": "*",
|
||||||
"url": "https://management.azure.com",
|
"url": "https://management.azure.com",
|
||||||
"authType": "azure",
|
"authType": "azure",
|
||||||
"tokenAuth": {
|
"tokenAuth": {
|
||||||
@ -48,7 +48,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "govazuremonitor",
|
"path": "govazuremonitor",
|
||||||
"method": "GET",
|
"method": "*",
|
||||||
"url": "https://management.usgovcloudapi.net",
|
"url": "https://management.usgovcloudapi.net",
|
||||||
"authType": "azure",
|
"authType": "azure",
|
||||||
"tokenAuth": {
|
"tokenAuth": {
|
||||||
@ -65,7 +65,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "germanyazuremonitor",
|
"path": "germanyazuremonitor",
|
||||||
"method": "GET",
|
"method": "*",
|
||||||
"url": "https://management.microsoftazure.de",
|
"url": "https://management.microsoftazure.de",
|
||||||
"authType": "azure",
|
"authType": "azure",
|
||||||
"tokenAuth": {
|
"tokenAuth": {
|
||||||
@ -82,7 +82,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "chinaazuremonitor",
|
"path": "chinaazuremonitor",
|
||||||
"method": "GET",
|
"method": "*",
|
||||||
"url": "https://management.chinacloudapi.cn",
|
"url": "https://management.chinacloudapi.cn",
|
||||||
"authType": "azure",
|
"authType": "azure",
|
||||||
"tokenAuth": {
|
"tokenAuth": {
|
||||||
@ -97,74 +97,6 @@
|
|||||||
},
|
},
|
||||||
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
|
"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",
|
"path": "appinsights",
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
@ -183,60 +115,9 @@
|
|||||||
{ "name": "x-ms-app", "content": "Grafana" }
|
{ "name": "x-ms-app", "content": "Grafana" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"path": "loganalytics-resourcepickerdata",
|
|
||||||
"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.logAnalyticsTenantId | orEmpty}}",
|
|
||||||
"client_id": "{{.JsonData.logAnalyticsClientId | orEmpty}}",
|
|
||||||
"client_secret": "{{.SecureJsonData.logAnalyticsClientSecret | orEmpty}}"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "loganalytics-resourcepickerdata-china",
|
|
||||||
"method": "POST",
|
|
||||||
"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": "loganalytics-resourcepickerdata-gov",
|
|
||||||
"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.logAnalyticsTenantId | orEmpty}}",
|
|
||||||
"client_id": "{{.JsonData.logAnalyticsClientId | orEmpty}}",
|
|
||||||
"client_secret": "{{.SecureJsonData.logAnalyticsClientSecret | orEmpty}}"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"path": "workspacesloganalytics",
|
"path": "workspacesloganalytics",
|
||||||
"method": "GET",
|
"method": "*",
|
||||||
"url": "https://management.azure.com",
|
"url": "https://management.azure.com",
|
||||||
"authType": "azure",
|
"authType": "azure",
|
||||||
"tokenAuth": {
|
"tokenAuth": {
|
||||||
@ -253,7 +134,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "chinaworkspacesloganalytics",
|
"path": "chinaworkspacesloganalytics",
|
||||||
"method": "GET",
|
"method": "*",
|
||||||
"url": "https://management.chinacloudapi.cn",
|
"url": "https://management.chinacloudapi.cn",
|
||||||
"authType": "azure",
|
"authType": "azure",
|
||||||
"tokenAuth": {
|
"tokenAuth": {
|
||||||
@ -270,7 +151,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "govworkspacesloganalytics",
|
"path": "govworkspacesloganalytics",
|
||||||
"method": "GET",
|
"method": "*",
|
||||||
"url": "https://management.usgovcloudapi.net",
|
"url": "https://management.usgovcloudapi.net",
|
||||||
"authType": "azure",
|
"authType": "azure",
|
||||||
"tokenAuth": {
|
"tokenAuth": {
|
||||||
@ -285,6 +166,23 @@
|
|||||||
},
|
},
|
||||||
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
|
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "germanyworkspacesloganalytics",
|
||||||
|
"method": "*",
|
||||||
|
"url": "https://management.microsoftazure.de",
|
||||||
|
"authType": "azure",
|
||||||
|
"tokenAuth": {
|
||||||
|
"scopes": ["https://management.microsoftazure.de/.default"],
|
||||||
|
"params": {
|
||||||
|
"azure_auth_type": "{{.JsonData.azureAuthType | orEmpty}}",
|
||||||
|
"azure_cloud": "AzureUSGovernment",
|
||||||
|
"tenant_id": "{{.JsonData.logAnalyticsTenantId | orEmpty}}",
|
||||||
|
"client_id": "{{.JsonData.logAnalyticsClientId | orEmpty}}",
|
||||||
|
"client_secret": "{{.SecureJsonData.logAnalyticsClientSecret | orEmpty}}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"headers": [{ "name": "x-ms-app", "content": "Grafana" }]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "loganalyticsazure",
|
"path": "loganalyticsazure",
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { FetchResponse, getBackendSrv } from '@grafana/runtime';
|
import { FetchResponse, getBackendSrv } from '@grafana/runtime';
|
||||||
import { getLogAnalyticsResourcePickerApiRoute } from '../api/routes';
|
import { getLogAnalyticsManagementApiRoute } from '../api/routes';
|
||||||
import {
|
import {
|
||||||
locationDisplayNames,
|
locationDisplayNames,
|
||||||
logsSupportedLocationsKusto,
|
logsSupportedLocationsKusto,
|
||||||
@ -17,7 +17,7 @@ import {
|
|||||||
RawAzureResourceItem,
|
RawAzureResourceItem,
|
||||||
} from '../types';
|
} 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 {
|
export default class ResourcePickerData {
|
||||||
private proxyUrl: string;
|
private proxyUrl: string;
|
||||||
@ -148,7 +148,7 @@ export default class ResourcePickerData {
|
|||||||
try {
|
try {
|
||||||
return await getBackendSrv()
|
return await getBackendSrv()
|
||||||
.fetch<AzureGraphResponse<T>>({
|
.fetch<AzureGraphResponse<T>>({
|
||||||
url: this.proxyUrl + '/' + getLogAnalyticsResourcePickerApiRoute(this.cloud) + RESOURCE_GRAPH_URL,
|
url: this.proxyUrl + '/' + getLogAnalyticsManagementApiRoute(this.cloud) + RESOURCE_GRAPH_URL,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: {
|
data: {
|
||||||
query: query,
|
query: query,
|
||||||
|
Loading…
Reference in New Issue
Block a user