mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Azure Monitor: Fixes broken log queries that use workspace (#45820)
* allow log queries to be executed also without a resource * add unit tests
This commit is contained in:
parent
64ad33f31a
commit
b7a2fda2ae
@ -1,11 +1,12 @@
|
|||||||
import AzureMonitorDatasource from '../datasource';
|
|
||||||
import AzureLogAnalyticsDatasource from './azure_log_analytics_datasource';
|
|
||||||
import FakeSchemaData from './__mocks__/schema';
|
|
||||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
|
||||||
import { AzureMonitorQuery, AzureQueryType, DatasourceValidationResult } from '../types';
|
|
||||||
import { toUtc } from '@grafana/data';
|
import { toUtc } from '@grafana/data';
|
||||||
|
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||||
|
|
||||||
import createMockQuery from '../__mocks__/query';
|
import createMockQuery from '../__mocks__/query';
|
||||||
import { singleVariable } from '../__mocks__/variables';
|
import { singleVariable } from '../__mocks__/variables';
|
||||||
|
import AzureMonitorDatasource from '../datasource';
|
||||||
|
import { AzureMonitorQuery, AzureQueryType, DatasourceValidationResult } from '../types';
|
||||||
|
import FakeSchemaData from './__mocks__/schema';
|
||||||
|
import AzureLogAnalyticsDatasource from './azure_log_analytics_datasource';
|
||||||
|
|
||||||
const templateSrv = new TemplateSrv();
|
const templateSrv = new TemplateSrv();
|
||||||
|
|
||||||
@ -273,7 +274,7 @@ describe('AzureLogAnalyticsDatasource', () => {
|
|||||||
laDatasource = new AzureLogAnalyticsDatasource(ctx.instanceSettings);
|
laDatasource = new AzureLogAnalyticsDatasource(ctx.instanceSettings);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should run complete queries', () => {
|
it('should run queries with a resource', () => {
|
||||||
const query: AzureMonitorQuery = {
|
const query: AzureMonitorQuery = {
|
||||||
refId: 'A',
|
refId: 'A',
|
||||||
azureLogAnalytics: {
|
azureLogAnalytics: {
|
||||||
@ -285,6 +286,18 @@ describe('AzureLogAnalyticsDatasource', () => {
|
|||||||
expect(laDatasource.filterQuery(query)).toBeTruthy();
|
expect(laDatasource.filterQuery(query)).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should run queries with a workspace', () => {
|
||||||
|
const query: AzureMonitorQuery = {
|
||||||
|
refId: 'A',
|
||||||
|
azureLogAnalytics: {
|
||||||
|
query: 'perf | take 100',
|
||||||
|
workspace: 'abc1b44e-3e57-4410-b027-6cc0ae6dee67',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(laDatasource.filterQuery(query)).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
it('should not run empty queries', () => {
|
it('should not run empty queries', () => {
|
||||||
const query: AzureMonitorQuery = {
|
const query: AzureMonitorQuery = {
|
||||||
refId: 'A',
|
refId: 'A',
|
||||||
@ -317,7 +330,7 @@ describe('AzureLogAnalyticsDatasource', () => {
|
|||||||
expect(laDatasource.filterQuery(query)).toBeFalsy();
|
expect(laDatasource.filterQuery(query)).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not run queries missing a resource', () => {
|
it('should not run queries missing a resource and a missing workspace', () => {
|
||||||
const query: AzureMonitorQuery = {
|
const query: AzureMonitorQuery = {
|
||||||
refId: 'A',
|
refId: 'A',
|
||||||
azureLogAnalytics: {
|
azureLogAnalytics: {
|
||||||
|
@ -1,26 +1,27 @@
|
|||||||
import { map } from 'lodash';
|
|
||||||
import LogAnalyticsQuerystringBuilder from '../log_analytics/querystring_builder';
|
|
||||||
import ResponseParser, { transformMetadataToKustoSchema } from './response_parser';
|
|
||||||
import {
|
|
||||||
AzureMonitorQuery,
|
|
||||||
AzureDataSourceJsonData,
|
|
||||||
AzureLogsVariable,
|
|
||||||
AzureQueryType,
|
|
||||||
DatasourceValidationResult,
|
|
||||||
} from '../types';
|
|
||||||
import {
|
import {
|
||||||
DataQueryRequest,
|
DataQueryRequest,
|
||||||
DataQueryResponse,
|
DataQueryResponse,
|
||||||
ScopedVars,
|
|
||||||
DataSourceInstanceSettings,
|
DataSourceInstanceSettings,
|
||||||
DataSourceRef,
|
DataSourceRef,
|
||||||
|
ScopedVars,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { getTemplateSrv, DataSourceWithBackend } from '@grafana/runtime';
|
import { DataSourceWithBackend, getTemplateSrv } from '@grafana/runtime';
|
||||||
import { Observable, from } from 'rxjs';
|
import { map } from 'lodash';
|
||||||
|
import { from, Observable } from 'rxjs';
|
||||||
import { mergeMap } from 'rxjs/operators';
|
import { mergeMap } from 'rxjs/operators';
|
||||||
import { getAuthType, getAzureCloud, getAzurePortalUrl } from '../credentials';
|
|
||||||
import { isGUIDish } from '../components/ResourcePicker/utils';
|
import { isGUIDish } from '../components/ResourcePicker/utils';
|
||||||
|
import { getAuthType, getAzureCloud, getAzurePortalUrl } from '../credentials';
|
||||||
|
import LogAnalyticsQuerystringBuilder from '../log_analytics/querystring_builder';
|
||||||
|
import {
|
||||||
|
AzureDataSourceJsonData,
|
||||||
|
AzureLogsVariable,
|
||||||
|
AzureMonitorQuery,
|
||||||
|
AzureQueryType,
|
||||||
|
DatasourceValidationResult,
|
||||||
|
} from '../types';
|
||||||
import { interpolateVariable, routeNames } from '../utils/common';
|
import { interpolateVariable, routeNames } from '../utils/common';
|
||||||
|
import ResponseParser, { transformMetadataToKustoSchema } from './response_parser';
|
||||||
|
|
||||||
interface AdhocQuery {
|
interface AdhocQuery {
|
||||||
datasource: DataSourceRef;
|
datasource: DataSourceRef;
|
||||||
@ -60,7 +61,11 @@ export default class AzureLogAnalyticsDatasource extends DataSourceWithBackend<
|
|||||||
}
|
}
|
||||||
|
|
||||||
filterQuery(item: AzureMonitorQuery): boolean {
|
filterQuery(item: AzureMonitorQuery): boolean {
|
||||||
return item.hide !== true && !!item.azureLogAnalytics?.query && !!item.azureLogAnalytics.resource;
|
return (
|
||||||
|
item.hide !== true &&
|
||||||
|
!!item.azureLogAnalytics?.query &&
|
||||||
|
(!!item.azureLogAnalytics.resource || !!item.azureLogAnalytics.workspace)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSubscriptions(): Promise<Array<{ text: string; value: string }>> {
|
async getSubscriptions(): Promise<Array<{ text: string; value: string }>> {
|
||||||
|
Loading…
Reference in New Issue
Block a user