mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
AzureMonitor: Prevent incomplete Logs queries from running (#40512)
* AzureMonitor: Prevent incomplete queries from running * fix
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
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 { AzureLogsVariable, DatasourceValidationResult } from '../types';
|
||||
import { AzureLogsVariable, AzureMonitorQuery, DatasourceValidationResult } from '../types';
|
||||
import { toUtc } from '@grafana/data';
|
||||
|
||||
const templateSrv = new TemplateSrv();
|
||||
@@ -376,4 +377,73 @@ describe('AzureLogAnalyticsDatasource', () => {
|
||||
expect(workspace).toEqual('foo');
|
||||
});
|
||||
});
|
||||
|
||||
describe('When performing filterQuery', () => {
|
||||
const ctx: any = {};
|
||||
let laDatasource: AzureLogAnalyticsDatasource;
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.instanceSettings = {
|
||||
jsonData: { subscriptionId: 'xxx' },
|
||||
url: 'http://azureloganalyticsapi',
|
||||
};
|
||||
|
||||
laDatasource = new AzureLogAnalyticsDatasource(ctx.instanceSettings);
|
||||
});
|
||||
|
||||
it('should run complete queries', () => {
|
||||
const query: AzureMonitorQuery = {
|
||||
refId: 'A',
|
||||
azureLogAnalytics: {
|
||||
resource: '/sub/124/rg/cloud/vm/server',
|
||||
query: 'perf | take 100',
|
||||
},
|
||||
};
|
||||
|
||||
expect(laDatasource.filterQuery(query)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should not run empty queries', () => {
|
||||
const query: AzureMonitorQuery = {
|
||||
refId: 'A',
|
||||
};
|
||||
|
||||
expect(laDatasource.filterQuery(query)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should not run hidden queries', () => {
|
||||
const query: AzureMonitorQuery = {
|
||||
refId: 'A',
|
||||
hide: true,
|
||||
azureLogAnalytics: {
|
||||
resource: '/sub/124/rg/cloud/vm/server',
|
||||
query: 'perf | take 100',
|
||||
},
|
||||
};
|
||||
|
||||
expect(laDatasource.filterQuery(query)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should not run queries missing a kusto query', () => {
|
||||
const query: AzureMonitorQuery = {
|
||||
refId: 'A',
|
||||
azureLogAnalytics: {
|
||||
resource: '/sub/124/rg/cloud/vm/server',
|
||||
},
|
||||
};
|
||||
|
||||
expect(laDatasource.filterQuery(query)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should not run queries missing a resource', () => {
|
||||
const query: AzureMonitorQuery = {
|
||||
refId: 'A',
|
||||
azureLogAnalytics: {
|
||||
query: 'perf | take 100',
|
||||
},
|
||||
};
|
||||
|
||||
expect(laDatasource.filterQuery(query)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -59,6 +59,10 @@ export default class AzureLogAnalyticsDatasource extends DataSourceWithBackend<
|
||||
return !this.validateDatasource();
|
||||
}
|
||||
|
||||
filterQuery(item: AzureMonitorQuery): boolean {
|
||||
return item.hide !== true && !!item.azureLogAnalytics?.query && !!item.azureLogAnalytics.resource;
|
||||
}
|
||||
|
||||
async getSubscriptions(): Promise<Array<{ text: string; value: string }>> {
|
||||
if (!this.isConfigured()) {
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user