mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
AzureMonitor: Fix permissions issue with Logs template variable queries (#35181)
This commit is contained in:
parent
a30e60a0b8
commit
5fb37ad5dc
@ -33,7 +33,7 @@ describe('AzureLogAnalyticsDatasource', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.instanceSettings = {
|
||||
jsonData: { logAnalyticsSubscriptionId: 'xxx' },
|
||||
jsonData: { logAnalyticsSubscriptionId: 'xxx', azureLogAnalyticsSameAs: false },
|
||||
url: 'http://azureloganalyticsapi',
|
||||
};
|
||||
|
||||
|
@ -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, isLogAnalyticsSameAs } from '../credentials';
|
||||
import { getLogAnalyticsApiRoute, getLogAnalyticsManagementApiRoute } from '../api/routes';
|
||||
import { AzureLogAnalyticsMetadata } from '../types/logAnalyticsMetadata';
|
||||
import { isGUIDish } from '../components/ResourcePicker/utils';
|
||||
@ -55,7 +55,13 @@ export default class AzureLogAnalyticsDatasource extends DataSourceWithBackend<
|
||||
this.azureMonitorUrl = `/${managementRoute}/subscriptions`;
|
||||
|
||||
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 || '';
|
||||
}
|
||||
|
||||
@ -228,8 +234,14 @@ export default class AzureLogAnalyticsDatasource extends DataSourceWithBackend<
|
||||
metricFindQueryInternal(query: string): Promise<MetricFindValue[]> {
|
||||
// workspaces() - Get workspaces in the default subscription
|
||||
const workspacesQuery = query.match(/^workspaces\(\)/i);
|
||||
if (workspacesQuery && this.defaultSubscriptionId) {
|
||||
return this.getWorkspaces(this.defaultSubscriptionId);
|
||||
if (workspacesQuery) {
|
||||
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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user