Skip to content

Commit

Permalink
Don't kill an entire dashboard because of one bad request (#11337)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
stacey-gammon authored May 8, 2017
1 parent a25d99d commit b5e6489
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
47 changes: 34 additions & 13 deletions src/ui/public/courier/fetch/call_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);

Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/ui/public/promises/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './promises';

0 comments on commit b5e6489

Please sign in to comment.