DataSourceWithBackend: Switch to new Observable fetch api (#26043)
* BackendSrv: Observable all the way POC * starting to unify code paths * tests pass * Unified error handling * Single request path and error handling * Fixed ts issue * another ts issu * Added back old requestId cancellation * Slow progress trying to grasp the full picture of cancellation * Updates * refactoring * Remove a bunch of stuff from backendSrv * Removed another function * Do not show error alerts for data queries * Muu * Updated comment * DataSourceWithBackend: Switch to new Observable fetch api * fixed ts issue * unify request options type * Made query inspector subscribe to backendSrv stream instead of legacy app events * Add back support for err.isHandled to limit scope * never show success alerts * Updated tests * use ovservable in test * remove processResponse * remove processResponse * trying to get tests to pass :( * no need for the extra tests * Fixed processsing * Fixed tests * Updated tests to mock fetch call * lint fixes Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
co-authored by
Ryan McKinley
parent
4df441f822
commit
2191fe1285
@@ -7,7 +7,8 @@ import {
|
||||
DataSourceJsonData,
|
||||
ScopedVars,
|
||||
} from '@grafana/data';
|
||||
import { Observable, from, of } from 'rxjs';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map, catchError } from 'rxjs/operators';
|
||||
import { config } from '..';
|
||||
import { getBackendSrv } from '../services';
|
||||
import { toDataQueryResponse } from './queryResponse';
|
||||
@@ -101,42 +102,23 @@ export class DataSourceWithBackend<
|
||||
body.to = range.to.valueOf().toString();
|
||||
}
|
||||
|
||||
const req: Promise<DataQueryResponse> = getBackendSrv()
|
||||
.datasourceRequest({
|
||||
return getBackendSrv()
|
||||
.fetch({
|
||||
url: '/api/ds/query',
|
||||
method: 'POST',
|
||||
data: body,
|
||||
requestId,
|
||||
})
|
||||
.then((rsp: any) => {
|
||||
const dqs = toDataQueryResponse(rsp);
|
||||
if (this.processResponse) {
|
||||
return this.processResponse(dqs);
|
||||
}
|
||||
return dqs;
|
||||
})
|
||||
.catch(err => {
|
||||
err.isHandled = true; // Avoid extra popup warning
|
||||
const dqs = toDataQueryResponse(err);
|
||||
if (this.processResponse) {
|
||||
return this.processResponse(dqs);
|
||||
}
|
||||
return dqs;
|
||||
});
|
||||
|
||||
return from(req);
|
||||
.pipe(
|
||||
map((rsp: any) => {
|
||||
return toDataQueryResponse(rsp);
|
||||
}),
|
||||
catchError(err => {
|
||||
return of(toDataQueryResponse(err));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionally augment the response before returning the results to the
|
||||
*
|
||||
* NOTE: this was added in 7.1 for azure, and will be removed in 7.2
|
||||
* when the entire response pipeline is Observable
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
processResponse?(res: DataQueryResponse): Promise<DataQueryResponse>;
|
||||
|
||||
/**
|
||||
* Override to skip executing a query
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user