Datasource: Change query filtering (#84656)
* call filterQuery from queryrunner * test query hide filtering * fix more broken tests * lint errrors * remove redundant filterQuery call * skip filter in variable queries * fix broken cypress test * change tooltip text * fix translations * fix comments * do not execute query is targets are empty * add more tests * remove unsued import * update translations * revert id change * change header text * update comment for hide prop * rename hide query prop * change tooltip and introduce different toggle state text * update tests * update comment and regenerate types * run extract again * fix broken e2e test * track event * fix build issues * revert changes in wire file
This commit is contained in:
@@ -190,9 +190,6 @@ type VariableSupport<TQuery extends DataQuery, TOptions extends DataSourceJsonDa
|
||||
|
||||
/**
|
||||
* The main data source abstraction interface, represents an instance of a data source
|
||||
*
|
||||
* Although this is a class, datasource implementations do not *yet* need to extend it.
|
||||
* As such, we can not yet add functions with default implementations.
|
||||
*/
|
||||
abstract class DataSourceApi<
|
||||
TQuery extends DataQuery = DataQuery,
|
||||
@@ -263,11 +260,12 @@ abstract class DataSourceApi<
|
||||
abstract testDatasource(): Promise<TestDataSourceResponse>;
|
||||
|
||||
/**
|
||||
* This function is not called automatically unless running within the DataSourceWithBackend
|
||||
*
|
||||
* @deprecated
|
||||
* Optionally, you can implement this method to prevent certain queries from being executed.
|
||||
* Return false to prevent the query from being executed.
|
||||
*/
|
||||
filterQuery?(query: TQuery): boolean;
|
||||
filterQuery?(query: TQuery): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get hints for query improvements
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import {
|
||||
DataQuery,
|
||||
DataQueryRequest,
|
||||
DataQueryResponse,
|
||||
DataSourceApi,
|
||||
DataSourceInstanceSettings,
|
||||
DataSourceJsonData,
|
||||
DataSourcePluginMeta,
|
||||
PluginMetaInfo,
|
||||
PluginType,
|
||||
TestDataSourceResponse,
|
||||
} from '../../types';
|
||||
|
||||
export interface TestQuery extends DataQuery {
|
||||
query: string;
|
||||
}
|
||||
|
||||
export interface TestJsonData extends DataSourceJsonData {
|
||||
url?: string;
|
||||
}
|
||||
|
||||
const info: PluginMetaInfo = {
|
||||
author: {
|
||||
name: '',
|
||||
},
|
||||
description: '',
|
||||
links: [],
|
||||
logos: {
|
||||
large: '',
|
||||
small: '',
|
||||
},
|
||||
screenshots: [],
|
||||
updated: '',
|
||||
version: '',
|
||||
};
|
||||
|
||||
export const meta: DataSourcePluginMeta<DataSourceJsonData> = {
|
||||
id: '',
|
||||
name: '',
|
||||
type: PluginType.datasource,
|
||||
info,
|
||||
module: '',
|
||||
baseUrl: '',
|
||||
};
|
||||
|
||||
export const TestDataSettings: DataSourceInstanceSettings<TestJsonData> = {
|
||||
jsonData: { url: 'http://localhost:3000' },
|
||||
id: 0,
|
||||
uid: '',
|
||||
type: '',
|
||||
name: 'Test Datasource',
|
||||
meta,
|
||||
readOnly: false,
|
||||
access: 'direct',
|
||||
};
|
||||
|
||||
export class TestDataSource extends DataSourceApi<TestQuery, DataSourceJsonData> {
|
||||
query(request: DataQueryRequest<TestQuery>): Promise<DataQueryResponse> | Observable<DataQueryResponse> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
testDatasource(): Promise<TestDataSourceResponse> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
constructor(instanceSettings: DataSourceInstanceSettings<TestJsonData> = TestDataSettings) {
|
||||
super(instanceSettings);
|
||||
}
|
||||
}
|
||||
@@ -134,10 +134,6 @@ class DataSourceWithBackend<
|
||||
const { intervalMs, maxDataPoints, queryCachingTTL, range, requestId, hideFromInspector = false } = request;
|
||||
let targets = request.targets;
|
||||
|
||||
if (this.filterQuery) {
|
||||
targets = targets.filter((q) => this.filterQuery!(q));
|
||||
}
|
||||
|
||||
let hasExpr = false;
|
||||
const pluginIDs = new Set<string>();
|
||||
const dsUIDs = new Set<string>();
|
||||
@@ -275,16 +271,6 @@ class DataSourceWithBackend<
|
||||
return queries.map((q) => this.applyTemplateVariables(q, scopedVars, filters));
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to skip executing a query. Note this function may not be called
|
||||
* if the query method is overwritten.
|
||||
*
|
||||
* @returns false if the query should be skipped
|
||||
*
|
||||
* @virtual
|
||||
*/
|
||||
filterQuery?(query: TQuery): boolean;
|
||||
|
||||
/**
|
||||
* Override to apply template variables and adhoc filters. The result is usually also `TQuery`, but sometimes this can
|
||||
* be used to modify the query structure before sending to the backend.
|
||||
|
||||
@@ -43,9 +43,7 @@ export interface DataQuery {
|
||||
*/
|
||||
datasource?: unknown;
|
||||
/**
|
||||
* true if query is disabled (ie should not be returned to the dashboard)
|
||||
* Note this does not always imply that the query should not be executed since
|
||||
* the results from a hidden query may be used as the input to other queries (SSE etc)
|
||||
* If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
|
||||
*/
|
||||
hide?: boolean;
|
||||
/**
|
||||
|
||||
@@ -23,9 +23,7 @@ DataQuery: {
|
||||
// By default, the UI will assign A->Z; however setting meaningful names may be useful.
|
||||
refId: string
|
||||
|
||||
// true if query is disabled (ie should not be returned to the dashboard)
|
||||
// Note this does not always imply that the query should not be executed since
|
||||
// the results from a hidden query may be used as the input to other queries (SSE etc)
|
||||
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
|
||||
hide?: bool
|
||||
|
||||
// Specify the query flavor
|
||||
|
||||
Reference in New Issue
Block a user