mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Don't kill an entire dashboard because of one bad request (#11337)
* Don't kill an entire dashboard because of one bad request Some tests get rid of the angular promise library so it works better if it’s a separate function then on the actual angular Promise class. * Fix promise path references after creation of index file. * Remove index suffix from import paths * Remove promiseMapSettled Use a much simpler implementation * Clean up
This commit is contained in:
parent
a25d99d210
commit
b5e6489458
2 changed files with 35 additions and 13 deletions
|
@ -17,8 +17,8 @@ export function CallClientProvider(Private, Promise, esAdmin, es) {
|
|||
const statuses = mergeDuplicateRequests(requests);
|
||||
|
||||
// get the actual list of requests that we will be fetching
|
||||
const executable = statuses.filter(isRequest);
|
||||
let execCount = executable.length;
|
||||
let requestsToFetch = statuses.filter(isRequest);
|
||||
let execCount = requestsToFetch.length;
|
||||
|
||||
if (!execCount) return Promise.resolve([]);
|
||||
|
||||
|
@ -29,14 +29,19 @@ export function CallClientProvider(Private, Promise, esAdmin, es) {
|
|||
// for each respond with either the response or ABORTED
|
||||
const respond = function (responses) {
|
||||
responses = responses || [];
|
||||
return Promise.map(requests, function (req, i) {
|
||||
return Promise.map(requests, function (request, i) {
|
||||
switch (statuses[i]) {
|
||||
case ABORTED:
|
||||
return ABORTED;
|
||||
case DUPLICATE:
|
||||
return req._uniq.resp;
|
||||
return request._uniq.resp;
|
||||
default:
|
||||
return responses[_.findIndex(executable, req)];
|
||||
const index = _.findIndex(requestsToFetch, request);
|
||||
if (index < 0) {
|
||||
// This means the request failed.
|
||||
return ABORTED;
|
||||
}
|
||||
return responses[index];
|
||||
}
|
||||
})
|
||||
.then(
|
||||
|
@ -76,17 +81,33 @@ export function CallClientProvider(Private, Promise, esAdmin, es) {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
// Now that all of THAT^^^ is out of the way, lets actually
|
||||
// call out to elasticsearch
|
||||
Promise.map(executable, function (req) {
|
||||
return Promise.try(req.getFetchParams, void 0, req)
|
||||
.then(function (fetchParams) {
|
||||
return (req.fetchParams = fetchParams);
|
||||
});
|
||||
Promise.map(requestsToFetch, function (request) {
|
||||
return Promise.try(request.getFetchParams, void 0, request)
|
||||
.then(function (fetchParams) {
|
||||
return (request.fetchParams = fetchParams);
|
||||
})
|
||||
.then(value => ({ resolved: value }))
|
||||
.catch(error => ({ rejected: error }));
|
||||
})
|
||||
.then(function (reqsFetchParams) {
|
||||
return strategy.reqsFetchParamsToBody(reqsFetchParams);
|
||||
.then(function (results) {
|
||||
const requestsWithFetchParams = [];
|
||||
// Gather the fetch param responses from all the successful requests.
|
||||
results.forEach((result, index) => {
|
||||
if (result.resolved) {
|
||||
requestsWithFetchParams.push(result.resolved);
|
||||
} else {
|
||||
const request = requestsToFetch[index];
|
||||
request.handleFailure(result.rejected);
|
||||
requestsToFetch[index] = undefined;
|
||||
}
|
||||
});
|
||||
// The index of the request inside requestsToFetch determines which response is mapped to it. If a request
|
||||
// won't generate a response, since it already failed, we need to remove the request
|
||||
// from the requestsToFetch array so the indexes will continue to match up to the responses correctly.
|
||||
requestsToFetch = requestsToFetch.filter(request => request !== undefined);
|
||||
return strategy.reqsFetchParamsToBody(requestsWithFetchParams);
|
||||
})
|
||||
.then(function (body) {
|
||||
// while the strategy was converting, our request was aborted
|
||||
|
|
1
src/ui/public/promises/index.js
Normal file
1
src/ui/public/promises/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
import './promises';
|
Loading…
Add table
Add a link
Reference in a new issue