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

View File

@@ -60,4 +60,8 @@ export class TemplateSrvMock implements TemplateSrv {
}
updateTimeRange(timeRange: TimeRange) {}
getAdhocFilters(dsName: string) {
return [{ key: 'key', operator: '=', value: 'a' }];
}
}

View File

@@ -51,6 +51,7 @@ export class TemplateSrv implements BaseTemplateSrv {
private index: any = {};
private grafanaVariables = new Map<string, any>();
private timeRange?: TimeRange | null = null;
private _adhocFiltersDeprecationWarningLogged = new Map<string, boolean>();
constructor(private dependencies: TemplateSrvDependencies = runtimeDependencies) {
this._variables = [];
@@ -111,6 +112,11 @@ export class TemplateSrv implements BaseTemplateSrv {
this.index[variable.name] = variable;
}
/**
* @deprecated
* Use filters property on the request (DataQueryRequest) or if this is called from
* interpolateVariablesInQueries or applyTemplateVariables it is passed as a new argument
**/
getAdhocFilters(datasourceName: string): AdHocVariableFilter[] {
let filters: any = [];
let ds = getDataSourceSrv().getInstanceSettings(datasourceName);
@@ -119,6 +125,17 @@ export class TemplateSrv implements BaseTemplateSrv {
return [];
}
if (!this._adhocFiltersDeprecationWarningLogged.get(ds.type)) {
if (process.env.NODE_ENV !== 'test') {
deprecationWarning(
`DataSource ${ds.type}`,
'templateSrv.getAdhocFilters',
'filters property on the request (DataQueryRequest). Or if this is called from interpolateVariablesInQueries or applyTemplateVariables it is passed as a new argument'
);
}
this._adhocFiltersDeprecationWarningLogged.set(ds.type, true);
}
for (const variable of this.getAdHocVariables()) {
const variableUid = variable.datasource?.uid;