From 4a31dfd90375c15e6c3f93f348a5f186e8f06443 Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Tue, 16 Nov 2021 17:45:55 +0100 Subject: [PATCH] Alerting: Fix issue after AzureMonitor fix (#41746) * check if filterquery exists * update tests * test: re-run CI Co-authored-by: gillesdemey --- .../unified/state/AlertingQueryRunner.test.ts | 11 ++++------- .../alerting/unified/state/AlertingQueryRunner.ts | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/public/app/features/alerting/unified/state/AlertingQueryRunner.test.ts b/public/app/features/alerting/unified/state/AlertingQueryRunner.test.ts index 3569985d99e..84a0a79edb3 100644 --- a/public/app/features/alerting/unified/state/AlertingQueryRunner.test.ts +++ b/public/app/features/alerting/unified/state/AlertingQueryRunner.test.ts @@ -2,7 +2,7 @@ import { ArrayVector, DataFrame, DataFrameJSON, - DataQuery, + DataSourceApi, Field, FieldType, getDefaultRelativeTimeRange, @@ -189,7 +189,7 @@ describe('AlertingQueryRunner', () => { mockBackendSrv({ fetch: () => throwError(new Error("shouldn't happen")), }), - mockDataSourceSrv(() => false) + mockDataSourceSrv({ filterQuery: () => false }) ); const data = runner.get(); @@ -218,12 +218,9 @@ const mockBackendSrv = ({ fetch }: MockBackendSrvConfig): BackendSrv => { } as unknown) as BackendSrv; }; -const mockDataSourceSrv = (filterQuery: (query: DataQuery) => boolean = () => true) => { +const mockDataSourceSrv = (dsApi?: Partial) => { return ({ - get: () => - Promise.resolve({ - filterQuery, - }), + get: () => Promise.resolve(dsApi ?? {}), } as unknown) as DataSourceSrv; }; diff --git a/public/app/features/alerting/unified/state/AlertingQueryRunner.ts b/public/app/features/alerting/unified/state/AlertingQueryRunner.ts index c4f0441c9e7..4822898c950 100644 --- a/public/app/features/alerting/unified/state/AlertingQueryRunner.ts +++ b/public/app/features/alerting/unified/state/AlertingQueryRunner.ts @@ -52,7 +52,7 @@ export class AlertingQueryRunner { for (const query of queries) { if (!isExpressionQuery(query.model)) { const ds = await this.dataSourceSrv.get(query.datasourceUid); - if (!ds.filterQuery?.(query.model)) { + if (ds.filterQuery && !ds.filterQuery(query.model)) { const empty = initialState(queries, LoadingState.Done); return this.subject.next(empty); }