DataSourceAPI: Add adhoc filters to DataQueryRequest and make it not depend on global templateSrv (#75552)

* DataSourceAPI: Add adhoc filters to DataQueryRequest and some methods to make it not depend on global templateSrv

* Minor tweaks/fixes

* Renamed to filters

* Fix test

* Log deprecation warning

* I give up
This commit is contained in:
Torkel Ödegaard
2023-09-28 16:28:58 +02:00
committed by GitHub
parent 6ff767a6bb
commit 2fe4ecde19
9 changed files with 82 additions and 41 deletions
@@ -333,7 +333,7 @@ abstract class DataSourceApi<
getVersion?(optionalOptions?: any): Promise<string>;
interpolateVariablesInQueries?(queries: TQuery[], scopedVars: ScopedVars): TQuery[];
interpolateVariablesInQueries?(queries: TQuery[], scopedVars: ScopedVars, filters?: AdHocVariableFilter[]): TQuery[];
/**
* An annotation processor allows explicit control for how annotations are managed.
@@ -552,6 +552,9 @@ export interface DataQueryRequest<TQuery extends DataQuery = DataQuery> {
panelId?: number;
dashboardUID?: string;
/** Filters to dynamically apply to all queries */
filters?: AdHocVariableFilter[];
// Request Timing
startTime: number;
endTime?: number;
@@ -16,6 +16,7 @@ import {
makeClassES5Compatible,
parseLiveChannelAddress,
ScopedVars,
AdHocVariableFilter,
} from '@grafana/data';
import { config } from '../config';
@@ -263,8 +264,8 @@ class DataSourceWithBackend<
/**
* Apply template variables for explore
*/
interpolateVariablesInQueries(queries: TQuery[], scopedVars: ScopedVars | {}): TQuery[] {
return queries.map((q) => this.applyTemplateVariables(q, scopedVars) as TQuery);
interpolateVariablesInQueries(queries: TQuery[], scopedVars: ScopedVars, filters?: AdHocVariableFilter[]): TQuery[] {
return queries.map((q) => this.applyTemplateVariables(q, scopedVars, filters) as TQuery);
}
/**
@@ -278,7 +279,7 @@ class DataSourceWithBackend<
filterQuery?(query: TQuery): boolean;
/**
* Override to apply template variables. The result is usually also `TQuery`, but sometimes this can
* 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.
*
* NOTE: if you do modify the structure or use template variables, alerting queries may not work
@@ -286,7 +287,7 @@ class DataSourceWithBackend<
*
* @virtual
*/
applyTemplateVariables(query: TQuery, scopedVars: ScopedVars): Record<string, any> {
applyTemplateVariables(query: TQuery, scopedVars: ScopedVars, filters?: AdHocVariableFilter[]): Record<string, any> {
return query;
}