QueryRunners: Bind the query function where it is passed on (#73399)

This commit is contained in:
Andrej Ocenas 2023-09-18 17:00:43 +02:00 committed by GitHub
parent 0815d7f627
commit f6f47678a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 4 additions and 12 deletions

View File

@ -196,7 +196,7 @@ describe('QueryRunners', () => {
it('then it should call runRequest with correct args', () => { it('then it should call runRequest with correct args', () => {
expect(runRequest).toHaveBeenCalledTimes(1); expect(runRequest).toHaveBeenCalledTimes(1);
expect(runRequest).toHaveBeenCalledWith(datasource, {}, datasource.variables.query); expect(runRequest).toHaveBeenCalledWith(datasource, {}, expect.anything());
}); });
}); });
@ -263,7 +263,7 @@ describe('QueryRunners', () => {
it('then it should call runRequest with correct args', () => { it('then it should call runRequest with correct args', () => {
expect(runRequest).toHaveBeenCalledTimes(1); expect(runRequest).toHaveBeenCalledTimes(1);
expect(runRequest).toHaveBeenCalledWith(datasource, {}, datasource.variables.query); expect(runRequest).toHaveBeenCalledWith(datasource, {}, expect.anything());
}); });
}); });
}); });

View File

@ -122,7 +122,7 @@ class StandardQueryRunner implements QueryRunner {
return runRequest(datasource, request); return runRequest(datasource, request);
} }
return runRequest(datasource, request, datasource.variables.query); return runRequest(datasource, request, datasource.variables.query.bind(datasource.variables));
} }
} }
@ -146,7 +146,7 @@ class CustomQueryRunner implements QueryRunner {
return getEmptyMetricFindValueObservable(); return getEmptyMetricFindValueObservable();
} }
return runRequest(datasource, request, datasource.variables.query); return runRequest(datasource, request, datasource.variables.query.bind(datasource.variables));
} }
} }

View File

@ -22,7 +22,6 @@ export class VariableSupport extends CustomVariableSupport<DataSource, AzureMoni
constructor(private readonly datasource: DataSource) { constructor(private readonly datasource: DataSource) {
super(); super();
this.datasource = datasource; this.datasource = datasource;
this.query = this.query.bind(this);
this.templateSrv = getTemplateSrv(); this.templateSrv = getTemplateSrv();
} }

View File

@ -17,7 +17,6 @@ export class CloudMonitoringVariableSupport extends CustomVariableSupport<
constructor(private readonly datasource: CloudMonitoringDatasource) { constructor(private readonly datasource: CloudMonitoringDatasource) {
super(); super();
this.metricFindQuery = new CloudMonitoringMetricFindQuery(datasource); this.metricFindQuery = new CloudMonitoringMetricFindQuery(datasource);
this.query = this.query.bind(this);
} }
editor = CloudMonitoringVariableQueryEditor; editor = CloudMonitoringVariableQueryEditor;

View File

@ -21,7 +21,6 @@ import { VariableQuery, VariableQueryType } from './types';
export class CloudWatchVariableSupport extends CustomVariableSupport<CloudWatchDatasource, VariableQuery> { export class CloudWatchVariableSupport extends CustomVariableSupport<CloudWatchDatasource, VariableQuery> {
constructor(private readonly resources: ResourcesAPI) { constructor(private readonly resources: ResourcesAPI) {
super(); super();
this.query = this.query.bind(this);
} }
editor = VariableQueryEditor; editor = VariableQueryEditor;

View File

@ -20,8 +20,6 @@ export class VariableSupport extends CustomVariableSupport<PhlareDataSource> {
private readonly timeSrv: TimeSrv = getTimeSrv() private readonly timeSrv: TimeSrv = getTimeSrv()
) { ) {
super(); super();
// This is needed because code in queryRunners.ts passes this method without binding it.
this.query = this.query.bind(this);
} }
editor = VariableQueryEditor; editor = VariableQueryEditor;

View File

@ -12,7 +12,6 @@ export class LokiVariableSupport extends CustomVariableSupport<LokiDatasource, L
constructor(private datasource: LokiDatasource) { constructor(private datasource: LokiDatasource) {
super(); super();
this.query = this.query.bind(this);
} }
async execute(query: LokiVariableQuery) { async execute(query: LokiVariableQuery) {

View File

@ -18,7 +18,6 @@ export class PrometheusVariableSupport extends CustomVariableSupport<PrometheusD
private readonly timeSrv: TimeSrv = getTimeSrv() private readonly timeSrv: TimeSrv = getTimeSrv()
) { ) {
super(); super();
this.query = this.query.bind(this);
} }
editor = PromVariableQueryEditor; editor = PromVariableQueryEditor;

View File

@ -11,7 +11,6 @@ export class TempoVariableSupport extends CustomVariableSupport<TempoDatasource,
constructor(private datasource: TempoDatasource) { constructor(private datasource: TempoDatasource) {
super(); super();
this.query = this.query.bind(this);
} }
query(request: DataQueryRequest<TempoVariableQuery>): Observable<DataQueryResponse> { query(request: DataQueryRequest<TempoVariableQuery>): Observable<DataQueryResponse> {