mirror of
https://github.com/grafana/grafana.git
synced 2026-08-16 16:14:59 -05:00
AzureMonitor: Fix permissions issue with Logs template variable queries (#35181)
This commit is contained in:
+1
-1
@@ -33,7 +33,7 @@ describe('AzureLogAnalyticsDatasource', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ctx.instanceSettings = {
|
ctx.instanceSettings = {
|
||||||
jsonData: { logAnalyticsSubscriptionId: 'xxx' },
|
jsonData: { logAnalyticsSubscriptionId: 'xxx', azureLogAnalyticsSameAs: false },
|
||||||
url: 'http://azureloganalyticsapi',
|
url: 'http://azureloganalyticsapi',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+16
-4
@@ -18,7 +18,7 @@ import {
|
|||||||
import { getBackendSrv, getTemplateSrv, DataSourceWithBackend, FetchResponse } from '@grafana/runtime';
|
import { getBackendSrv, getTemplateSrv, DataSourceWithBackend, FetchResponse } from '@grafana/runtime';
|
||||||
import { Observable, from } from 'rxjs';
|
import { Observable, from } from 'rxjs';
|
||||||
import { mergeMap } from 'rxjs/operators';
|
import { mergeMap } from 'rxjs/operators';
|
||||||
import { getAuthType, getAzureCloud } from '../credentials';
|
import { getAuthType, getAzureCloud, isLogAnalyticsSameAs } from '../credentials';
|
||||||
import { getLogAnalyticsApiRoute, getLogAnalyticsManagementApiRoute } from '../api/routes';
|
import { getLogAnalyticsApiRoute, getLogAnalyticsManagementApiRoute } from '../api/routes';
|
||||||
import { AzureLogAnalyticsMetadata } from '../types/logAnalyticsMetadata';
|
import { AzureLogAnalyticsMetadata } from '../types/logAnalyticsMetadata';
|
||||||
import { isGUIDish } from '../components/ResourcePicker/utils';
|
import { isGUIDish } from '../components/ResourcePicker/utils';
|
||||||
@@ -55,7 +55,13 @@ export default class AzureLogAnalyticsDatasource extends DataSourceWithBackend<
|
|||||||
this.azureMonitorUrl = `/${managementRoute}/subscriptions`;
|
this.azureMonitorUrl = `/${managementRoute}/subscriptions`;
|
||||||
|
|
||||||
this.url = instanceSettings.url || '';
|
this.url = instanceSettings.url || '';
|
||||||
this.defaultSubscriptionId = this.instanceSettings.jsonData.logAnalyticsSubscriptionId || '';
|
|
||||||
|
const sameAsMonitor = isLogAnalyticsSameAs(instanceSettings);
|
||||||
|
|
||||||
|
this.defaultSubscriptionId = sameAsMonitor
|
||||||
|
? instanceSettings.jsonData.subscriptionId
|
||||||
|
: instanceSettings.jsonData.logAnalyticsSubscriptionId;
|
||||||
|
|
||||||
this.defaultOrFirstWorkspace = this.instanceSettings.jsonData.logAnalyticsDefaultWorkspace || '';
|
this.defaultOrFirstWorkspace = this.instanceSettings.jsonData.logAnalyticsDefaultWorkspace || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,8 +234,14 @@ export default class AzureLogAnalyticsDatasource extends DataSourceWithBackend<
|
|||||||
metricFindQueryInternal(query: string): Promise<MetricFindValue[]> {
|
metricFindQueryInternal(query: string): Promise<MetricFindValue[]> {
|
||||||
// workspaces() - Get workspaces in the default subscription
|
// workspaces() - Get workspaces in the default subscription
|
||||||
const workspacesQuery = query.match(/^workspaces\(\)/i);
|
const workspacesQuery = query.match(/^workspaces\(\)/i);
|
||||||
if (workspacesQuery && this.defaultSubscriptionId) {
|
if (workspacesQuery) {
|
||||||
return this.getWorkspaces(this.defaultSubscriptionId);
|
if (this.defaultSubscriptionId) {
|
||||||
|
return this.getWorkspaces(this.defaultSubscriptionId);
|
||||||
|
} else {
|
||||||
|
throw new Error(
|
||||||
|
'No subscription ID. Specify a default subscription ID in the data source config to use workspaces() without a subscription ID'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// workspaces("abc-def-etc") - Get workspaces a specified subscription
|
// workspaces("abc-def-etc") - Get workspaces a specified subscription
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ function getLogAnalyticsSecret(options: AzureDataSourceSettings): undefined | st
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isLogAnalyticsSameAs(options: AzureDataSourceSettings | AzureDataSourceInstanceSettings): boolean {
|
export function isLogAnalyticsSameAs(options: AzureDataSourceSettings | AzureDataSourceInstanceSettings): boolean {
|
||||||
return typeof options.jsonData.azureLogAnalyticsSameAs !== 'boolean' || options.jsonData.azureLogAnalyticsSameAs;
|
return typeof options.jsonData.azureLogAnalyticsSameAs !== 'boolean' || options.jsonData.azureLogAnalyticsSameAs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user