Replace and then remove searchSource .onError (#13871)
* Stop using onError because there is a memory leak there * Restart segmented fetch errors. * Get rid of all onError calls * Remove unused functions * Continue searching when a doc_table error is encountered Otherwise a single saved search failure won’t try again when it’s on a dashboard. The previous implementation handled this via the request.retry in the default errorHandler. * Fix lint error * don't pass resolve and reject into inner function
This commit is contained in:
parent
d6a5470779
commit
2ab28f2abb
|
@ -390,10 +390,6 @@ function discoverController(
|
|||
};
|
||||
}()));
|
||||
|
||||
$scope.searchSource.onError(function (err) {
|
||||
notify.error(err);
|
||||
}).catch(notify.fatal);
|
||||
|
||||
function initForTime() {
|
||||
return setupVisualization().then($scope.updateTime);
|
||||
}
|
||||
|
@ -457,7 +453,8 @@ function discoverController(
|
|||
$scope.fetch();
|
||||
};
|
||||
|
||||
$scope.searchSource.onBeginSegmentedFetch(function (segmented) {
|
||||
|
||||
function initSegmentedFetch(segmented) {
|
||||
function flushResponseData() {
|
||||
$scope.hits = 0;
|
||||
$scope.faliures = [];
|
||||
|
@ -567,7 +564,18 @@ function discoverController(
|
|||
|
||||
$scope.fetchStatus = null;
|
||||
});
|
||||
}).catch(notify.fatal);
|
||||
}
|
||||
|
||||
|
||||
function beginSegmentedFetch() {
|
||||
$scope.searchSource.onBeginSegmentedFetch(initSegmentedFetch)
|
||||
.catch((error) => {
|
||||
notify.error(error);
|
||||
// Restart.
|
||||
beginSegmentedFetch();
|
||||
});
|
||||
}
|
||||
beginSegmentedFetch();
|
||||
|
||||
$scope.updateTime = function () {
|
||||
$scope.timeRange = {
|
||||
|
|
|
@ -35,7 +35,6 @@ export default function stubSearchSource(Private, $q, Promise) {
|
|||
getOnResultsCount: function () {
|
||||
return onResultsCount;
|
||||
},
|
||||
onError: function () { return $q.defer().promise; },
|
||||
_flatten: function () {
|
||||
return Promise.resolve({ index: indexPattern, body: {} });
|
||||
}
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* Queue of pending error handlers, they are removed as
|
||||
* they are resolved.
|
||||
* @type {Array}
|
||||
*/
|
||||
export const errorHandlersQueue = [];
|
|
@ -4,7 +4,6 @@ import angular from 'angular';
|
|||
import 'ui/promises';
|
||||
|
||||
import { requestQueue } from '../_request_queue';
|
||||
import { errorHandlersQueue } from '../_error_handlers';
|
||||
import { FetchProvider } from '../fetch';
|
||||
import { FieldWildcardProvider } from '../../field_wildcard';
|
||||
import { getHighlightRequest } from '../../../../core_plugins/kibana/common/highlight';
|
||||
|
@ -134,7 +133,13 @@ export function AbstractDataSourceProvider(Private, Promise, PromiseEmitter, con
|
|||
const defer = Promise.defer();
|
||||
defer.promise.then(resolve, reject);
|
||||
|
||||
self._createRequest(defer);
|
||||
const request = self._createRequest(defer);
|
||||
|
||||
request.setErrorHandler((request, error) => {
|
||||
reject(error);
|
||||
request.abort();
|
||||
});
|
||||
|
||||
}, handler);
|
||||
};
|
||||
|
||||
|
@ -145,26 +150,6 @@ export function AbstractDataSourceProvider(Private, Promise, PromiseEmitter, con
|
|||
return this._parent;
|
||||
};
|
||||
|
||||
/**
|
||||
* similar to onResults, but allows a seperate loopy code path
|
||||
* for error handling.
|
||||
*
|
||||
* @return {Promise}
|
||||
*/
|
||||
SourceAbstract.prototype.onError = function (handler) {
|
||||
const self = this;
|
||||
|
||||
return new PromiseEmitter(function (resolve, reject) {
|
||||
const defer = Promise.defer();
|
||||
defer.promise.then(resolve, reject);
|
||||
|
||||
errorHandlersQueue.push({
|
||||
source: self,
|
||||
defer: defer
|
||||
});
|
||||
}, handler);
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetch just this source ASAP
|
||||
*
|
||||
|
|
|
@ -173,12 +173,21 @@ export function SearchSourceProvider(Promise, Private, config) {
|
|||
|
||||
SearchSource.prototype.onBeginSegmentedFetch = function (initFunction) {
|
||||
const self = this;
|
||||
return Promise.try(function addRequest() {
|
||||
const req = new SegmentedRequest(self, Promise.defer(), initFunction);
|
||||
return new Promise((resolve, reject) => {
|
||||
function addRequest() {
|
||||
const defer = Promise.defer();
|
||||
const req = new SegmentedRequest(self, defer, initFunction);
|
||||
|
||||
// return promises created by the completion handler so that
|
||||
// errors will bubble properly
|
||||
return req.getCompletePromise().then(addRequest);
|
||||
req.setErrorHandler((request, error) => {
|
||||
reject(error);
|
||||
request.abort();
|
||||
});
|
||||
|
||||
// Return promises created by the completion handler so that
|
||||
// errors will bubble properly
|
||||
return req.getCompletePromise().then(addRequest);
|
||||
}
|
||||
addRequest();
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
import { Notifier } from 'ui/notify/notifier';
|
||||
|
||||
import { errorHandlersQueue } from '../../_error_handlers';
|
||||
|
||||
const notify = new Notifier({
|
||||
location: 'Courier Fetch Error'
|
||||
});
|
||||
|
||||
export function requestErrorHandler(req, error) {
|
||||
const myHandlers = [];
|
||||
|
||||
errorHandlersQueue.splice(0).forEach(function (handler) {
|
||||
(handler.source === req.source ? myHandlers : errorHandlersQueue).push(handler);
|
||||
});
|
||||
|
||||
if (!myHandlers.length) {
|
||||
notify.fatal(new Error(`unhandled courier request error: ${ notify.describeError(error) }`));
|
||||
} else {
|
||||
myHandlers.forEach(function (handler) {
|
||||
handler.defer.resolve(error);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@ import _ from 'lodash';
|
|||
import moment from 'moment';
|
||||
|
||||
import { requestQueue } from '../../_request_queue';
|
||||
import { requestErrorHandler } from './error_handler';
|
||||
|
||||
export function AbstractRequestProvider(Private, Promise) {
|
||||
|
||||
|
@ -12,11 +11,6 @@ export function AbstractRequestProvider(Private, Promise) {
|
|||
this.defer = defer || Promise.defer();
|
||||
this.abortedDefer = Promise.defer();
|
||||
|
||||
this.setErrorHandler((...args) => {
|
||||
this.retry();
|
||||
return requestErrorHandler(...args);
|
||||
});
|
||||
|
||||
requestQueue.push(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -110,8 +110,7 @@ uiModules.get('kibana')
|
|||
if ($scope.searchSource) $scope.searchSource.destroy();
|
||||
});
|
||||
|
||||
// TODO: we need to have some way to clean up result requests
|
||||
$scope.searchSource.onResults().then(function onResults(resp) {
|
||||
function onResults(resp) {
|
||||
// Reset infinite scroll limit
|
||||
$scope.limit = 50;
|
||||
|
||||
|
@ -129,9 +128,17 @@ uiModules.get('kibana')
|
|||
calculateItemsOnPage();
|
||||
|
||||
return $scope.searchSource.onResults().then(onResults);
|
||||
}).catch(notify.fatal);
|
||||
}
|
||||
|
||||
$scope.searchSource.onError(notify.error).catch(notify.fatal);
|
||||
function startSearching() {
|
||||
$scope.searchSource.onResults()
|
||||
.then(onResults)
|
||||
.catch(error => {
|
||||
notify.error(error);
|
||||
startSearching();
|
||||
});
|
||||
}
|
||||
startSearching();
|
||||
}));
|
||||
|
||||
$scope.pageOfItems = [];
|
||||
|
|
|
@ -40,10 +40,6 @@ const CourierRequestHandlerProvider = function (Private, courier, timefilter) {
|
|||
resolve(resp);
|
||||
}).catch(e => reject(e));
|
||||
|
||||
searchSource.onError(e => {
|
||||
reject(e);
|
||||
}).catch(e => reject(e));
|
||||
|
||||
courier.fetch();
|
||||
} else {
|
||||
resolve(searchSource.rawResponse);
|
||||
|
|
Loading…
Reference in a new issue