Skip to content

Commit

Permalink
Attempt to fix elastic#14653 in 5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed Mar 2, 2018
1 parent dcf1461 commit 206859b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 64 deletions.
17 changes: 12 additions & 5 deletions src/core_plugins/kibana/public/discover/controllers/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,6 @@ function discoverController($scope, config, courier, $route, $window, Notifier,
};
}()));

$scope.searchSource.onError(function (err) {
notify.error(err);
}).catch(notify.fatal);

function initForTime() {
return setupVisualization().then($scope.updateTime);
Expand Down Expand Up @@ -356,7 +353,7 @@ function discoverController($scope, config, courier, $route, $window, Notifier,
.catch(notify.error);
};

$scope.searchSource.onBeginSegmentedFetch(function (segmented) {
function initSegmentedFetch(segmented) {
function flushResponseData() {
$scope.hits = 0;
$scope.faliures = [];
Expand Down Expand Up @@ -456,7 +453,17 @@ function discoverController($scope, config, courier, $route, $window, Notifier,

$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 = {
Expand Down
29 changes: 6 additions & 23 deletions src/ui/public/courier/data_source/_abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import angular from 'angular';
import 'ui/promises';

import { RequestQueueProvider } from '../_request_queue';
import { ErrorHandlersProvider } from '../_error_handlers';
import { FetchProvider } from '../fetch';
import { DecorateQueryProvider } from './_decorate_query';
import { FieldWildcardProvider } from '../../field_wildcard';
Expand All @@ -13,7 +12,6 @@ import { migrateFilter } from './_migrate_filter';

export function AbstractDataSourceProvider(Private, Promise, PromiseEmitter) {
const requestQueue = Private(RequestQueueProvider);
const errorHandlers = Private(ErrorHandlersProvider);
const courierFetch = Private(FetchProvider);
const { fieldWildcardFilter } = Private(FieldWildcardProvider);
const getHighlightRequest = Private(getHighlightRequestProvider);
Expand Down Expand Up @@ -136,7 +134,12 @@ export function AbstractDataSourceProvider(Private, Promise, PromiseEmitter) {
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);
};

Expand All @@ -147,26 +150,6 @@ export function AbstractDataSourceProvider(Private, Promise, PromiseEmitter) {
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);

errorHandlers.push({
source: self,
defer: defer
});
}, handler);
};

/**
* Fetch just this source ASAP
*
Expand Down
19 changes: 14 additions & 5 deletions src/ui/public/courier/data_source/search_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,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();
});
};

Expand Down
7 changes: 0 additions & 7 deletions src/ui/public/courier/fetch/request/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@ import _ from 'lodash';
import moment from 'moment';

import { RequestQueueProvider } from '../../_request_queue';
import { ErrorHandlerRequestProvider } from './error_handler';

export function AbstractRequestProvider(Private, Promise) {
const requestQueue = Private(RequestQueueProvider);
const requestErrorHandler = Private(ErrorHandlerRequestProvider);

return class AbstractReq {
constructor(source, defer) {
this.source = source;
this.defer = defer || Promise.defer();
this.abortedDefer = Promise.defer();

this.setErrorHandler((...args) => {
this.retry();
return requestErrorHandler(...args);
});

requestQueue.push(this);
}

Expand Down
15 changes: 11 additions & 4 deletions src/ui/public/doc_table/doc_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,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;

Expand All @@ -121,9 +120,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 = [];
Expand Down
44 changes: 24 additions & 20 deletions src/ui/public/visualize/visualize.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,30 +166,34 @@ uiModules
}));

if (_.get($scope, 'vis.type.requiresSearch')) {
$scope.$watch('searchSource', prereq(function (searchSource) {
if (!searchSource || attr.esResp) return;

// TODO: we need to have some way to clean up result requests
searchSource.onResults().then(function onResults(resp) {
if ($scope.searchSource !== searchSource) return;
function onResults(resp) {
// if ($scope.searchSource !== searchSource) return;
$scope.esResp = resp;
return $scope.searchSource.onResults().then(onResults);
}

$scope.esResp = resp;
function startSearching() {
$scope.searchSource.onResults()
.then(onResults)
.catch(error => {
$el.trigger('renderComplete');
if (isTermSizeZeroError(error)) {
return notify.error(
`Your visualization ('${$scope.vis.title}') has an error: it has a term ` +
`aggregation with a size of 0. Please set it to a number greater than 0 to resolve ` +
`the error.`
);
}

return searchSource.onResults().then(onResults);
}).catch(notify.fatal);
notify.error(error);
startSearching();
});
}

searchSource.onError(e => {
$el.trigger('renderComplete');
if (isTermSizeZeroError(e)) {
return notify.error(
`Your visualization ('${$scope.vis.title}') has an error: it has a term ` +
`aggregation with a size of 0. Please set it to a number greater than 0 to resolve ` +
`the error.`
);
}
$scope.$watch('searchSource', prereq(function (searchSource) {
if (!searchSource || attr.esResp) return;

notify.error(e);
}).catch(notify.fatal);
startSearching();
}));
}

Expand Down

0 comments on commit 206859b

Please sign in to comment.